Author Topic: creating driver/data subscriptions without attaching to a form?  (Read 1605 times)

thirdeye73

  • Newbie
  • *
  • Posts: 22
    • View Profile
creating driver/data subscriptions without attaching to a form?
« on: January 19, 2015, 12:15:55 PM »
I think I already know the answer, but wanted to see if anyone has a better way.  Here's what I want to do:

My application is a data server that listens for multiple PLC triggers (each is a DINT field of a UDT array in a CompactLogix processor).  When a trigger is set, the application will read the rest of the UDT and pass the data on to a SQL Server stored procedure.  The returned data is then passed back to the PLC.

I don't need this data to be displayed on a form (except possibly as diagnostic information, but I haven't decided whether I want to implement that yet).  My question, then, is how do I, or can I, declare the driver and data subscription in code, not attached to a form?  In testing I'm getting exceptions when I set the synchronizing object field to a class rather than a form.  I understand why that happens, though.

So here's my current thought on how to do this:

1)  Create a form that will be created when the app loads, but stays hidden (i.e. form.Visible = False).
2)  Add my driver, controls components, and subscribers to the form in design mode.
3)  Comment out the code in the VisibleChanged event so that the subscriptions will be polled even though the form is hidden.

Am I on the right track here?  If I do it right, I think I can just make the form visible when the user clicks a "Diagnostics" button, and hide the form instead of close it when I'm done viewing it.

Thanks,
Scott

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: creating driver/data subscriptions without attaching to a form?
« Reply #1 on: January 19, 2015, 01:15:09 PM »
What driver are you using? The drivers should work without a synchronizing object. If not, then I will fix it.

thirdeye73

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: creating driver/data subscriptions without attaching to a form?
« Reply #2 on: January 19, 2015, 01:41:04 PM »
I don't have a real PLC to test with yet (the PLC should arrive this week), but I will be using EthernetIPforCLXCom.

Scott


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: creating driver/data subscriptions without attaching to a form?
« Reply #3 on: January 19, 2015, 08:37:27 PM »
I did a quick test on the version that will be released soon (version 3.97d) and it read a tag without a synchronizing object:


    Private EDriver As AdvancedHMIDrivers.EthernetIPforCLXCom
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If EDriver Is Nothing Then
            EDriver = New AdvancedHMIDrivers.EthernetIPforCLXCom
            EDriver.IPAddress = "192.168.1.93"
        End If

        Button1.Text = EDriver.Read("DINTTag")
    End Sub

    Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        EDriver.Dispose()
    End Sub

thirdeye73

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: creating driver/data subscriptions without attaching to a form?
« Reply #4 on: January 22, 2015, 01:04:48 PM »
Okay, I finally got my PLC setup.  I can set up form controls and see data change, but the formless driver and subscriptions don't seem to be working.  I'm creating the driver like this:

- as a member declaration in the class
Code: [Select]
Private WithEvents mEIPCLX as New EthernetIPforCLXCom

- in a public method of the class:
Code: [Select]
   
mEIPCLX.DisableSubscriptions = False
mEIPCLX.PollRateOverride = 500
mEIPCLX.IPAddress = pIPAddress
mEIPCLX.ProcessorSlot = pSlot
mEIPCLX.Port = 44818

where mEIPCLX is an instance of EthernetIPforCLXCom.

Then I set up a subscription:

Code: [Select]
' subscribe to PLC heartbeat tag
n = mEIPCLX.Subscribe("PLCHeartbeat", 1, 100, AddressOf PLCHeartbeat_DataChanged)
mSubscriptionIDs.Add(n)

The PLCHeartbeat_Datachanged routine never runs, nor does the ConnectionEstablished event I trap:

- PLCHeartbeat_DataChanged:
Code: [Select]
    Private Sub PLCHeartbeat_DataChanged(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
        ' handle PLC heartbeat
        If e.PlcAddress = "PLCHeartbeat" Then
            ' fire the heartbeat event
            If e.Values(0) = 1 Then
                RaiseEvent PLCHeartbeat(Me, New EventArgs)
            End If
        End If
    End Sub

- ConnectionEstablished event handler:
Code: [Select]
    Public Sub mEIPCLX_Connected(sender As Object, e As EventArgs) Handles mEIPCLX.ConnectionEstablished
        ' start the event driver timer
        If mPollRate < 100 Then
            mPollRate = 100
        End If

        RaiseEvent Connected(sender, e)
    End Sub

I'm sure I'm missing a step somewhere, I just don't know what or where to start looking.

Thanks,
Scott


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5280
    • View Profile
    • AdvancedHMI
Re: creating driver/data subscriptions without attaching to a form?
« Reply #5 on: January 22, 2015, 01:14:46 PM »
I think you will need version 3.97d when it is posted