Author Topic: EthernetIPforSLCMicroCom  (Read 4990 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforSLCMicroCom
« Reply #30 on: May 18, 2018, 05:39:57 AM »
Code: [Select]
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       SubID = EthernetIPforSLCMicroCom1.Subscribe("B3:0", 2, 0, AddressOf DataReturned)
       subID2 = EthernetIPforSLCMicroCom1.Subscribe("F8:0", 2, 0, AddressOf DataReturned)
     End Sub

    Private Sub DataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        If e.PlcAddress = "B3:0" Then
            Label1.Text = e.Values(0)
            Label2.Text = e.Values(1)
        ElseIf e.PlcAddress = "F8:0" Then
            Label3.Text = e.Values(0)
            Label4.Text = e.Values(1)
        End If
    End Sub

dhananjay.j@outlook.com

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: EthernetIPforSLCMicroCom
« Reply #31 on: May 18, 2018, 06:05:46 AM »
Quote
EthernetIPforSLCMicroCom1.Subscribe("B3:0", 2, 0, AddressOf DataReturned)

Just Checking...
So you say I should use numberOfElements = 2 to get a Word and then Convert the received 2 values to binary 16 bits and get individual flag?(B3:0/1,2,3...15) cause my e.Values(0) =79 while e.Values(1) = 0, so,
79(2) = 01001111 and 0(2)=00000000. Is that right?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: EthernetIPforSLCMicroCom
« Reply #32 on: May 18, 2018, 07:15:41 AM »
Quote
EthernetIPforSLCMicroCom1.Subscribe("B3:0", 2, 0, AddressOf DataReturned)

Just Checking...
So you say I should use numberOfElements = 2 to get a Word and then Convert the received 2 values to binary 16 bits and get individual flag?(B3:0/1,2,3...15) cause my e.Values(0) =79 while e.Values(1) = 0, so,
79(2) = 01001111 and 0(2)=00000000. Is that right?
No, I just picked an arbitrary number of 2. It will return 2 words. Are you using the subscription callback and e.Vaues?

dhananjay.j@outlook.com

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: EthernetIPforSLCMicroCom
« Reply #33 on: May 18, 2018, 10:04:46 AM »
Now I am Testing with following
            Connection.Subscribe("B3:18", 2, 100, CallBackHandlerB18);
Do I hope that I will get B3:18 (0 to 15) and B3:19 (0 to 15) in CallBackHandlerB18 e.values?

update

I am not getting any data in CallBackHandlerB18 ...

When I do this
            Connection.SubscriptionDataReceived += CallBackHandlerB18Global;
I get call to CallBackHandlerB18Global.

Do I use values in e.Values like this?
int valueint1 = Convert.ToUInt16(e.Values[0]);
var value1 = Convert.ToString(valueint1, 2);
int valueint2 = Convert.ToUInt16(e.Values[1]);
var value2 = Convert.ToString(valueint2, 2);
           
then each char is a Tag value?

UPDATE:

Works like Charm....

For Anyone who wants to this sollution then here it is,

do
EthernetIPforSLCMicroCom  Connection = new EthernetIPforSLCMicroCom ();
//Setup Ip
Connection.Subscribe("B3:18", 2, 100, CallBackHandlerB18);
Connection.SubscriptionDataReceived += CallBackHandlerB18Global;

CallBackHandlerB18- Dont bother to implement- never called

public void CallBackHandlerB18Global(object sender, SubscriptionEventArgs e)
        {
            var value1 = Convert.ToString(Convert.ToUInt16(e.Values[0]), 2);//B3:18
            var value2 = Convert.ToString(Convert.ToUInt16(e.Values[1]), 2);// B3:19
            }
        }

Now if you have configured B3:18 0 to 11, like in my case,

Reverse string

public string Reverse( string s )
{
    char[] charArray = s.ToCharArray();
    Array.Reverse( charArray );
    return new string( charArray );
}

then
var newvalue = Reverse(value1);
if(value1.Length!= 11)
{
for(int i = 0;i<11-value1.Length;i++)
{
//Append enough Zeros to make it 11 char in length
newvalue1 += "0";
}
}

do same for B3:19 based on configured Bits (B3:19 0 to 6 7 flags)


 for (int i = 0; i < newvalue1.Length; i++)
            {
                File.AppendAllText("E:/value.txt", $"value of B3:18/{i} is {(newvalue1 == '1').ToString()}" + Environment.NewLine);
            }


 for (int i = 0; i < newvalue2.Length; i++)
            {
                File.AppendAllText("E:/value.txt", $"value of B3:19/{i} is {(newvalue2 == '1').ToString()}" + Environment.NewLine);
            }

If you subscribe to multiple Tags on a Same Connection like
Connection.Subscribe("B3:18", 2, 100, CallBackHandlerB18);
Connection.Subscribe("F20:0", 90, 100, CallBackHandlerF20);
Connection.SubscriptionDataReceived += CallBackHandlerGlobal;

Then Both callbacks will call CallBackHandlerGlobal with e.PLCAddress = "B3:18"/"F20:0". so you can Fetch values accordingly. CallBackHandlerB18 & CallBackHandlerF20 are never called.

And thats all!!!!!!! 8)

Thanks Archie and bachphi for support.

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: EthernetIPforSLCMicroCom
« Reply #34 on: May 18, 2018, 06:20:52 PM »
I am glad it's working for you using SubscriptionDataReceived event, but your case could be similar to this:
https://www.advancedhmi.com/forum/index.php?topic=1823.msg10155#msg10155

I did a test using Archie example and it's work fine for me , including bit. I am using 399y beta10, btw.

Code: [Select]
Imports AdvancedHMIDrivers

Public Class Form1

    Public PLC As EthernetIPforSLCMicroCom = New EthernetIPforSLCMicroCom()

    Private SubID, SubID2, SubID3 As Integer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PLC.IPAddress = "192.168.1.10"
        PLC.PollRateOverride = "0"
        '
        SubID = PLC.Subscribe("T4:0.ACC", 1, 0, AddressOf DataReturned) '
        SubID2 = PLC.Subscribe("B3:1/0", 1, 0, AddressOf DataReturned)
        SubID3 = PLC.Subscribe("B3:1", 2, 0, AddressOf DataReturned)
    End Sub

    Private Sub DataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        If e.PlcAddress = "T4:0.ACC" Then
            Label1.Text = e.Values(0)
        End If
        If e.PlcAddress = "B3:1/0" Then
            Label2.Text = e.Values(0)
        End If
        If e.PlcAddress = "B3:1" Then
            Label3.Text = e.Values(0)
            Label4.Text = e.Values(1)
        End If

    End Sub

End Class
« Last Edit: May 18, 2018, 06:24:36 PM by bachphi »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

dhananjay.j@outlook.com

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: EthernetIPforSLCMicroCom
« Reply #35 on: May 19, 2018, 02:05:53 AM »
I am glad it's working for you using SubscriptionDataReceived event, but your case could be similar to this:
https://www.advancedhmi.com/forum/index.php?topic=1823.msg10155#msg10155

What is the "DINTTag" or "dateTime[0]" Mentioned in your Link? Looks like some sort of Connection status strategy to me...

2. You subscribed to multiple Tags with same Callback and the you are sorting data using PLCAddress. I guess thats the catch. I was subscribing to diff tags with individual CallBackHandler. (like CallbackHandlerforB18& CallbackHandlerforF20) etc. which is why None of them were ever called. I'll put same callback for all tags and see what happens but the fact that I cannot have a Different callback for each subscriptionID looks strange.

Archie can we categorize this as a Bug, CallBacks should be called based on either PLCAddress or SubscriptionID. Let me know.
« Last Edit: May 19, 2018, 02:57:55 AM by dhananjay.j@outlook.com »

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: EthernetIPforSLCMicroCom
« Reply #36 on: May 19, 2018, 07:19:57 AM »
Quote
What is the "DINTTag" or "dateTime[0]" Mentioned in your Link? Looks like some sort of Connection status strategy to me...
DINTTag translates loosely to N7:0 (INT) in RSLogix500 and dateTime[0] is element 0 of an array integer/ dint/string
« Last Edit: May 19, 2018, 07:25:54 AM by bachphi »
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================