Author Topic: Using Data Subscriber to dynamically change PLC Address  (Read 2269 times)

FuzyDragon

  • Newbie
  • *
  • Posts: 19
    • View Profile
Using Data Subscriber to dynamically change PLC Address
« on: October 01, 2015, 04:32:40 PM »
I am currently working on calibrating multiple channels by passing a single variable upon loading a form but I'm stuck with how to make the PLC Addresses actually change and add into the data subscriber. Am I on the right track with this.


Public Class MainForm
    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private NotFirstShow As Boolean
    Public TagInfo(2) As String
    Public PLCAddress As AdvancedHMIDrivers.PLCAddressItem
    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles Me.Load
        Me.Text = "Room Name Channel Name"
        Me.Tag = "10.193.114.72,ANALOG_IN.chamberPressure" 'Will be passed from form opening. Both of these values are temporary
        TagInfo = Split(Me.Tag, ",")
        BasicLabel1.Text = "Current A/D Input ="
        BasicLabel2.Text = "Current EU Output ="
        BasicLabel3.Text = "Low"
        BasicLabel4.Text = "Med"
        BasicLabel5.Text = "High"

        BasicLabel7.Text = TagInfo(0)
        Label2.Text = "A/D"
        Label3.Text = "Engineering Units"
        EthernetIPforMicro800Com1.IPAddress = TagInfo(0)
        BasicLabel6.Text = (TagInfo(1) + ".in1")

        'Starts not passing
        PLCAddress.PLCAddress = (TagInfo(1) + ".in1")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".in1")
        'AddHandler DataSubscriber1.DataChanged, AddressOf DataSubscriber_DataChanged

        PLCAddress.PLCAddress = (TagInfo(1) + ".in2")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".in2")

        PLCAddress.PLCAddress = (TagInfo(1) + ".in3")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".in3")

        PLCAddress.PLCAddress = (TagInfo(1) + ".out1")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".out1")

        PLCAddress.PLCAddress = (TagInfo(1) + ".out2")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".out2")

        PLCAddress.PLCAddress = (TagInfo(1) + ".out3")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".out3")

        PLCAddress.PLCAddress = (TagInfo(1) + ".input")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".input")

        PLCAddress.PLCAddress = (TagInfo(1) + ".output")
        DataSubscriber1.CommComponent = EthernetIPforMicro800Com1
        DataSubscriber1.SynchronizingObject = Me
        DataSubscriber1.PLCAddressValue = (TagInfo(1) + ".output")
    End Sub

    Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs)
        If e.PlcAddress = "ANALOG_IN.chamberPressure.input" Then
            BasicLabel1.Text = e.Values(0)
            BasicLabel1.Text = "Current A/D Input =" + "ANALOG_IN.chamberPressure.input"
        End If

        If e.PlcAddress = "ANALOG_IN.chamberPressure.output" Then
            BasicLabel2.Text = e.Values(0)
            BasicLabel2.Text = "Current EU Input =" + "ANALOG_IN.chamberPressure.output"
        End If

        If e.PlcAddress = "ANALOG_IN.chamberPressure.in1" Then
            BasicLabel3.Text = e.Values(0)
            BasicLabel3.Text = "low" + "ANALOG_IN.chamberPressure.in1"
        End If

        If e.PlcAddress = "ANALOG_IN.chamberPressure.in2" Then
            BasicLabel4.Text = e.Values(0)
            BasicLabel4.Text = "Med" + "ANALOG_IN.chamberPressure.in2"
        End If

        If e.PlcAddress = "ANALOG_IN.chamberPressure.in3" Then
            BasicLabel5.Text = e.Values(0)
            BasicLabel5.Text = "High" + "ANALOG_IN.chamberPressure.in3"
        End If

        If e.PlcAddress = " ThenANALOG_IN.chamberPressure.out1" Then
            BasicLabel6.Text = e.Values(0)
            BasicLabel6.Text = "ANALOG_IN.chamberPressure.out1"
        End If

        If e.PlcAddress = "ANALOG_IN.chamberPressure.out2" Then
            BasicLabel7.Text = e.Values(0)
            BasicLabel7.Text = +"ANALOG_IN.chamberPressure.out2"
        End If

        If e.PlcAddress = "ANALOG_IN.chamberPressure.out3" Then
            BasicLabel8.Text = e.Values(0)
            BasicLabel8.Text = "ANALOG_IN.chamberPressure.out3"
        End If
    End Sub

End Class

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5270
    • View Profile
    • AdvancedHMI
Re: Using Data Subscriber to dynamically change PLC Address
« Reply #1 on: October 01, 2015, 05:03:13 PM »
So let's start with the basics. I don't think you need a DataSubscriber or even to write any code. This is how I interpret what you want to do:

- Open the MainForm
- Set the Text property to Room Name Channel Name
- Add a EthernetIPforMicro800Com driver to the form
- Set the IPAddress property to 10.193.114.72
- Add a BasicLabel to the form and set ValuePrefix property to "Current A/D Input = "
- Set the PLCAddressValue property to ANALOG_IN.chamberPressure.In1

Now run the app and see if that much works. If so, then add the rest of the BasicLabels using the same steps.

FuzyDragon

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Using Data Subscriber to dynamically change PLC Address
« Reply #2 on: October 02, 2015, 09:07:34 AM »
Thank you very much for your help so far. What you gave works for this application.

I have another quick question though.  I have a list of variables that I want to dump into the data subscriber without using the ellipses in the data subscriber 2 properties. Is there a way to set up the configuration for a data subscriber in a configuration file?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5270
    • View Profile
    • AdvancedHMI
Re: Using Data Subscriber to dynamically change PLC Address
« Reply #3 on: October 02, 2015, 09:34:47 AM »
This would be the pattern for adding addresses to a DataSubscriber2 via code:


For index = 1 To 3
       Dim PLCItem As New AdvancedHMIDrivers.PLCAddressItem
       PLCItem.PLCAddress = TagInfo(1) & ".in" & index
       DataSubscriber21.PLCAddressValueItems.Add(PLCItem)
Next

FuzyDragon

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Using Data Subscriber to dynamically change PLC Address
« Reply #4 on: October 02, 2015, 09:51:14 AM »
Thank you again for your quick response. I will try this out and see how it works