Author Topic: Newbie Questions about DataSubscriber2 and IPAddress  (Read 3353 times)

hileta

  • Newbie
  • *
  • Posts: 10
    • View Profile
Newbie Questions about DataSubscriber2 and IPAddress
« on: February 25, 2016, 05:24:52 PM »
Hello everyone,

Let me start off by saying that I am not trying to be a schmooze but I am extremely impressed by HMIAdvanced and the amount of support in the Forums as I have been developing my first distribution and reading through the topics. I am an experienced Controls Engineer but new to VB as when I went to school Quick Basic was all that was offered and I haven't had the time to get back into it since.

I have a scenario where there are 5 different CLX processors on 5 different machines, but all with modular programming and running the exact same portion of code that I wish to access. There is a base program called say 'Data_x' which uses only program level tags with some aliasing to a few controller level tags for I/O and 'Data_x' is called up to four times in the PLC with different instances (Data_1, Data_2...). I need one screen to display about 80 strings and 80 DINTs plus a few other objects. The screen should be identical between the machines. My goal is to develop one screen and set the IP Address for the CLX and the prefix (program name) of the tags with a button push. I could then have only one form but parameterized by 20 buttons. Is something like this possible?

I have tried to pass the IPAddress into the Sub but keep bombing out when m_IPAddress is for some reason blank. I sucessfully get it to the 2nd form but the EthernetIPforCLXCom stops and throws an error.

As I mentioned earlier I also would like to pass down the program name and then build a string to use for getting the PLC data. I have done some direct(literal) addressing with the BasicLabel and gotten a good looking screen but the update time seems a bit sluggish and I haven’t figured out how to build the sting to set the variable address. Is it possible? Would I be better served using the DataSubscriber2 I have read about? I have used it also a little bit with direct addressing but am having trouble getting the Form to update to show changes in the PLC unless I click on the label.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #1 on: February 25, 2016, 06:01:30 PM »
I have tried to pass the IPAddress into the Sub but keep bombing out when m_IPAddress is for some reason blank. I successfully get it to the 2nd form but the EthernetIPforCLXCom stops and throws an error.
Can you post the code you are using to do this?

hileta

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #2 on: February 25, 2016, 09:07:08 PM »
Promise not to laugh. Like I said I am new to VB.


Public Class Form_Template

    Public _plcAddress As String

    Private Sub Template_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CycleTimeACC.Text = "0"
        CycleTimePRE.Text = "0"
    End Sub


    'Sub setIP()

    '    EthernetIPforCLXCom1.IPAddress = _plcAddress
    'End Sub
    'Dim _current As String
    'Public Property EthernetIPforCLX(IPaddress)
    '    Get
    '        Return _current
    '    End Get
    '    Set(ByVal _plcAddress)
    '    End Set
    'End Property

    Public Sub CycleTimeACC_Click(sender As Object, e As EventArgs) Handles CycleTimeACC.TextChanged ', CycleTimeACC.Click

    End Sub

    Public Sub CycleTimePRE_Click(sender As Object, e As EventArgs) Handles CycleTimePRE.TextChanged ', CycleTimeACC.Click

    End Sub
    Private Sub CycleTimeACC_TextChanged(sender As Object, e As EventArgs) Handles CycleTimeACC.TextChanged ', CycleTimeACC.Click
        Dim pre As Double = CDbl(CycleTimePRE.Text)
        Dim acc As Double = CDbl(CycleTimeACC.Text)
        If acc > pre * 0.7 Then
            CycleTimeACC.ForeColor = Color.Yellow
            If acc >= pre Then
                CycleTimeACC.ForeColor = Color.Red
            End If
        Else
            CycleTimeACC.ForeColor = Color.White
        End If
        Label2.ForeColor = CycleTimeACC.ForeColor
        Label4.ForeColor = CycleTimeACC.ForeColor
    End Sub

    Private Sub StackLight_Click(sender As Object, e As EventArgs) Handles StackLight.Click

    End Sub


    Private Sub EthernetIPforCLXCom1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.DataReceived
    End Sub



    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        ReadPLC1.Text = CStr(e.Values(0)) & ": " & CStr(EthernetIPforCLXCom1.IPAddress)
    End Sub



End Class

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #3 on: February 25, 2016, 09:18:53 PM »
I think what you are trying to do is something like this:
Code: [Select]
Public Property PLCIPAddress As String
    Get
        If EthernetIPforCLXCom1 IsNot Nothing Then
            Return EthernetIPforCLXCom1.IPAddress
        Else
            Return ""
        End If
    End Get
    Set(value As String)
        If Not String.IsNullOrEmpty(value) And EthernetIPforCLXCom1 IsNot Nothing Then
            Try
                EthernetIPforCLXCom1.IPAddress = value
            Catch ex As Exception
                MsgBox("Failed to set IP address of " & value & "  - " & ex.Message)
            End Try
        End If
    End Set
End Property

hileta

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #4 on: February 25, 2016, 10:16:26 PM »
WOW! That did it. I just changed my button to point to PLCIPAddress and away it went. I did notice that there has to be some value in the IPAddress Property from the Property Viewer (even just a "1"), if not it bombs out. Thanks for all of your help. I've on been at VB for 3 days in my spare time now and this was killing me. I'm only about 3.5 hours into Bob Tabor's videos from YouTube for VB Beginners.

Now I'm off to the concatenating of a string to address a PLC Variable using the DataSubscriber2.

Thanks again,

Tim

hileta

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #5 on: February 28, 2016, 10:07:15 AM »
Well, I am still at it trying to figure out how to get the Data I need from the PLC in a timely fashion. I need to get about 80 strings and 80 DINTs from a CLX Processor on about a 500ms update time at the most. I have tried a few methods I have read about here on the boards but can't seem to get it quit right. I upgraded to 399d to get the new DataSubscriber2 also.

DataSubscriber2
This seems to work ok, as long as I keep my NumberOfElements low. It does OK at 5, but not so much at 20:
 Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        Dim PlcAddressItem3 As MfgControl.AdvancedHMI.Drivers.PLCAddressItem = New MfgControl.AdvancedHMI.Drivers.PLCAddressItem()

        PlcAddressItem3.LastValue = Nothing
        PlcAddressItem3.NumberOfElements = 5
        PlcAddressItem3.PLCAddress = "Program:Kit_Data1.Sheet1Bins[0]"
        PlcAddressItem3.ScaleFactor = 1.0R
        PlcAddressItem3.ScaleOffset = 0.0R
        PlcAddressItem3.SubscriptionID = 0

        DataSubscriber21.PLCAddressValueItems.Add(PlcAddressItem3)


        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataReturned
        Label5.Text = e.Values(0)
        Label6.Text = e.Values(1)
        Label7.Text = e.Values(2)
        Label8.Text = e.Values(3)
        Label9.Text = e.Values(4)
    End Sub

EthernetIPforCLXCom1.Read:
Seems to be slower that DataSubscriber2. I realize my destinations are the same on the last 15, just testing speed

        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[0]")
        Label6.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[1]")
        Label7.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[2]")
        Label8.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[3]")
        Label9.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[4]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[5]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[6]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[7]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[8]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[9]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[10]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[11]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[12]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[13]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[14]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[15]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[16]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[17]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[18]")
        Label5.Text = EthernetIPforCLXCom1.Read("Program:Kit_Data1.Sheet1Bins[19]")


Any suggestions on a good way to do this? Any help is appreciated.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #6 on: February 28, 2016, 10:54:50 AM »
Let's first consider what is realistic on reading that much data. On an ideal network connection, which would be a single cable between the HMI and the PLC, only AdvancedHMI communicating to the processor, and not Ethernet/IP devices being scanned by the PLC. Under that scenario you can expect and average round trip read of about 5ms per packet.

Now let's assume the worst case of data being read. If the 80 string and 80 DINTs required a packet for each read, then it would take 160 reads. 160x5=800ms

It looks like your Sheet1Bins are an array, which I will assume are the strings. The maximum packet size is 508 bytes. Each string requires 80+ bytes. Then about 25 bytes for header information. So the driver will only be able to read 4 or 5 strings per packet. If it is 4 strings, then it requires 20 packets to read all 80. Once again in an ideal network, that would take about 100ms to complete.

If the 80 DINTs are in an array, they can easily read in a single packet, therefore an additional 5ms.

Total round trip should be 105ms based on a few assumptions about your setup.

What do you have PollRateOverride set to? What update rates are you seeing now? Is DisableMultiServiceRequest set to 0?

The best tool for seeing where the bottleneck is WireShark. Simply start a packet capture, then start the HMI. You will fairly easily see the variable names in the packets to see how requests are handled.

I also see that you are using the DataChanged event, which will only fire when the first element of the array changes. To get a continuous update no matter what changes, you will need to use the DataReturned event.

Just another question out of curiosity, but why are you using a DataSubscriber to push values into a Label, when a BasicLabel will do this without the need to write code?


hileta

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #7 on: February 28, 2016, 11:42:37 AM »
My Replies in RED


Let's first consider what is realistic on reading that much data. On an ideal network connection, which would be a single cable between the HMI and the PLC, only AdvancedHMI communicating to the processor, and not Ethernet/IP devices being scanned by the PLC. Under that scenario you can expect and average round trip read of about 5ms per packet.

Now let's assume the worst case of data being read. If the 80 string and 80 DINTs required a packet for each read, then it would take 160 reads. 160x5=800ms

It looks like your Sheet1Bins are an array, which I will assume are the strings. The maximum packet size is 508 bytes. Each string requires 80+ bytes. Then about 25 bytes for header information. So the driver will only be able to read 4 or 5 strings per packet. If it is 4 strings, then it requires 20 packets to read all 80. Once again in an ideal network, that would take about 100ms to complete.

I have a total of 8 Arrays in the processor. 4 STRING[20] and 4 DINT[20]

If the 80 DINTs are in an array, they can easily read in a single packet, therefore an additional 5ms.

They are in 4 arrays of 20 each

Total round trip should be 105ms based on a few assumptions about your setup.

What do you have PollRateOverride set to? What update rates are you seeing now? Is DisableMultiServiceRequest set to 0?
DisableMultiServiceRequest = False
PollRateOverride for EthernetIPforCLXCom1 = 100
PollRate for DataSubscriber21 = 0


The best tool for seeing where the bottleneck is WireShark. Simply start a packet capture, then start the HMI. You will fairly easily see the variable names in the packets to see how requests are handled.

I will look into this


I also see that you are using the DataChanged event, which will only fire when the first element of the array changes. To get a continuous update no matter what changes, you will need to use the DataReturned event.

Sorry, I had it that way initially but was playing with it to see if Changed would speed up anything

Just another question out of curiosity, but why are you using a DataSubscriber to push values into a Label, when a BasicLabel will do this without the need to write code?

I read in another post somewhere that this method was suggested. I initially used the BasicLabel but again experienced a slowing as I added more strings. I am trying to have one screen show data from different PLCs and Different Programs based on the button used to launch the form. For example:

On MainForm:
If Button1 is pressed: (PLC1 Program1)
- Set IPAddress to 192.168.3.10
- Set ProgramName to "Program:Kit_Data1." for prefixing to "Sheet1Bins[0]" for the PLCAddressValue

If Button2 is pressed: (PLC1 Program2)
- Set IPAddress to 192.168.3.10
- Set ProgramName to "Program:Kit_Data2." for prefixing to "Sheet1Bins[0]" for the PLCAddressValue

If Button3 is pressed: (PLC2 Program1)
- Set IPAddress to 192.168.3.11
- Set ProgramName to "Program:Kit_Data1." for prefixing to "Sheet1Bins[0]" for the PLCAddressValue

If Button4 is pressed: (PLC2 Program2)
- Set IPAddress to 192.168.3.11
- Set ProgramName to "Program:Kit_Data2." for prefixing to "Sheet1Bins[0]" for the PLCAddressValue


Is BasicLabel a better method?


Make any sense?

So do I need to break up the String reads to separate subscriptions?

I am considering making the String Reads event driven from the PLC. They do not need to update as often as the DINTs.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #8 on: February 28, 2016, 02:28:33 PM »

Is BasicLabel a better method?

So do I need to break up the String reads to separate subscriptions?

I am considering making the String Reads event driven from the PLC. They do not need to update as often as the DINTs.
The BasicLabel is just easier for maintenance and easier for the next guy to understand, but the end result will be the same.

Breaking up into separate subscription will not make any difference because the driver optimizer will attempt to combine everything even from multiple different subscriptions.

The optimizer is a very complex piece of code, so I won't yet rule out a problem with it. If you can run a WireShark capture, save the file, then post it, I will be able to determine quickly where the problem resides.

hileta

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #9 on: February 29, 2016, 07:32:13 AM »
I have redone everything to use the BasicLabel and for some reason am having better results. I still have a version with the DataSubscriber2 and will try to test it out with Wireshark today. I have never used Wireshark before, it sounds interesting.

In my project I have a MainForm that uses a button to call another form which contains the my EthernetIPforCLXCom1 connection(I also pass the IPAddress as we discussed above depending on which button is pressed), in jumping back and forth between the screens is there any maintenance that needs to happen? I've read about disposing and closing the connection to keep from multiple instances of the driver. It was an older thread so I'm wondering if it is still relevant.

Tim

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Newbie Questions about DataSubscriber2 and IPAddress
« Reply #10 on: February 29, 2016, 07:37:47 AM »
In my project I have a MainForm that uses a button to call another form which contains the my EthernetIPforCLXCom1 connection(I also pass the IPAddress as we discussed above depending on which button is pressed), in jumping back and forth between the screens is there any maintenance that needs to happen? I've read about disposing and closing the connection to keep from multiple instances of the driver. It was an older thread so I'm wondering if it is still relevant.
As long as your driver is added to the visual design surface of the form, all of the disposing will happen automatically. If you create a driver instance in code, then it is also up to your code to properly dispose the driver instance.