Author Topic: VB.NET DataReceived Not Working CLX Driver  (Read 2395 times)

JoeBProgamming

  • Newbie
  • *
  • Posts: 4
    • View Profile
VB.NET DataReceived Not Working CLX Driver
« on: March 21, 2018, 10:43:04 AM »
I need to pull the data from the BeginReadMultiple values but cannot. Bellow is the code, what am doing wrong? Or is there another way to do this?

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim MyStr As String
        Dim PLC1Read(10) As String
        Dim PLC1 As New EthernetIPforCLXCom
        PLC1.IPAddress = "192.168.1.8"
   
        PLC1Read(0) = ("Cell1.PerfTrackReport.PLC1SinceLastResetHours")
        PLC1Read(1) = ("Cell1.PerfTrackReport.PLC1SinceLastResetMinutes")
        PLC1Read(2) = ("Cell1.PerfTrackReport.PLC1SinceLastResetSeconds")
        PLC1Read(3) = ("AndOnBoard_DINT[1]") ' Idle Time Seconds
        PLC1Read(4) = ("AndOnBoard_DINT[2]") ' Idle Time Minutes
        PLC1Read(5) = ("AndOnBoard_DINT[3]") ' Idle Time Hours
        PLC1Read(6) = ("AndOnBoard_Excel_DINT[6]") ' Hourly Count
        PLC1Read(7) = ("AndOnBoard_Excel_DINT[7]") ' Shift Count
        PLC1Read(8) = ("AndOnBoard_Excel_DINT[4]") ' Good Parts Count
        PLC1Read(9) = ("AndOnBoard_Excel_DINT[5]") ' Bad Parts Count
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[1]") ' Average Cycle Time
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[2]") ' Last Cycle Time
        PLC1.BeginReadMultiple(PLC1Read)
    End Sub

    Private Sub PLC1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.DataReceived
        MsgBox(e.PlcAddress & "=" & e.Values(0))
    End Sub

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #1 on: March 21, 2018, 10:56:57 AM »
The scope of your PLC1 object only exists for the life of your button click event handler, therefore it cannot raise the event. Either add the driver to your form and use that instance or move the declaration outside of the event handler subroutine.

JoeBProgamming

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #2 on: March 21, 2018, 11:02:15 AM »
This is what I have now but still cannot get it to fire.

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim MyStr As String
        Dim PLC1Read(10) As String
        PLC1Read(0) = ("Cell1.PerfTrackReport.PLC1SinceLastResetHours")
        PLC1Read(1) = ("Cell1.PerfTrackReport.PLC1SinceLastResetMinutes")
        PLC1Read(2) = ("Cell1.PerfTrackReport.PLC1SinceLastResetSeconds")
        PLC1Read(3) = ("AndOnBoard_DINT[1]") ' Idle Time Seconds
        PLC1Read(4) = ("AndOnBoard_DINT[2]") ' Idle Time Minutes
        PLC1Read(5) = ("AndOnBoard_DINT[3]") ' Idle Time Hours
        PLC1Read(6) = ("AndOnBoard_Excel_DINT[6]") ' Hourly Count
        PLC1Read(7) = ("AndOnBoard_Excel_DINT[7]") ' Shift Count
        PLC1Read(8) = ("AndOnBoard_Excel_DINT[4]") ' Good Parts Count
        PLC1Read(9) = ("AndOnBoard_Excel_DINT[5]") ' Bad Parts Count
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[1]") ' Average Cycle Time
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[2]") ' Last Cycle Time
        EthernetIPforCLXCom2.BeginReadMultiple(PLC1Read)
    End Sub


    Private Sub EthernetIPforCLXCom2_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom2.DataReceived
        MsgBox(e.PlcAddress & "=" & e.Values(0))
    End Sub
End Class

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #3 on: March 21, 2018, 11:10:18 AM »
This is the test I just ran and it worked as expected:
Code: [Select]
   Private Sub Button1_Click_2(sender As Object, e As EventArgs) Handles Button1.Click
        Dim PLC1Read(1) As String
        PLC1Read(0) = ("DINTTag")
        PLC1Read(1) = ("StringTag")

        EthernetIPforCLXCom1.BeginReadMultiple(PLC1Read)
    End Sub

    Private Sub EthernetIPforCLXCom1_DataReceived_1(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.DataReceived
        MsgBox(e.PlcAddress & "=" & e.Values(0))
    End Sub

Try adding an error trap to see if it is reporting any problem:
Code: [Select]
    Private Sub EthernetIPforCLXCom1_ComError(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.ComError
        MsgBox("Com Error = " & e.ErrorMessage)
    End Sub


JoeBProgamming

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #4 on: March 21, 2018, 11:23:01 AM »
When I click the button I do not get any errors. Still nothing is being displayed.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim MyStr As String
        Dim PLC1Read(10) As String
        Try
            PLC1Read(0) = ("Cell1.PerfTrackReport.PLC1SinceLastResetHours")
            PLC1Read(1) = ("Cell1.PerfTrackReport.PLC1SinceLastResetMinutes")
            PLC1Read(2) = ("Cell1.PerfTrackReport.PLC1SinceLastResetSeconds")
            PLC1Read(3) = ("AndOnBoard_DINT[1]") ' Idle Time Seconds
            PLC1Read(4) = ("AndOnBoard_DINT[2]") ' Idle Time Minutes
            PLC1Read(5) = ("AndOnBoard_DINT[3]") ' Idle Time Hours
            PLC1Read(6) = ("AndOnBoard_Excel_DINT[6]") ' Hourly Count
            PLC1Read(7) = ("AndOnBoard_Excel_DINT[7]") ' Shift Count
            PLC1Read(8) = ("AndOnBoard_Excel_DINT[4]") ' Good Parts Count
            PLC1Read(9) = ("AndOnBoard_Excel_DINT[5]") ' Bad Parts Count
            PLC1Read(10) = ("AndOnBoard_Excel_REAL[1]") ' Average Cycle Time
            PLC1Read(10) = ("AndOnBoard_Excel_REAL[2]") ' Last Cycle Time
            EthernetIPforCLXCom2.BeginReadMultiple(PLC1Read)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    Private Sub EthernetIPforCLXCom2_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom2.DataReceived
        MsgBox(e.PlcAddress & "=" & e.Values(0))
    End Sub

    Private Sub EthernetIPforCLXCom2_ComError(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.ComError
        MsgBox("Com Error = " & e.ErrorMessage)
    End Sub
End Class

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #5 on: March 21, 2018, 11:37:33 AM »
You can try this code:

    Private WithEvents PLC1 As New AdvancedHMIDrivers.EthernetIPforCLXCom
    Private PLC1Read(10) As String
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        PLC1.IPAddress = "192.168.1.8"

        PLC1Read(0) = ("Cell1.PerfTrackReport.PLC1SinceLastResetHours")
        PLC1Read(1) = ("Cell1.PerfTrackReport.PLC1SinceLastResetMinutes")
        PLC1Read(2) = ("Cell1.PerfTrackReport.PLC1SinceLastResetSeconds")
        PLC1Read(3) = ("AndOnBoard_DINT[1]") ' Idle Time Seconds
        PLC1Read(4) = ("AndOnBoard_DINT[2]") ' Idle Time Minutes
        PLC1Read(5) = ("AndOnBoard_DINT[3]") ' Idle Time Hours
        PLC1Read(6) = ("AndOnBoard_Excel_DINT[6]") ' Hourly Count
        PLC1Read(7) = ("AndOnBoard_Excel_DINT[7]") ' Shift Count
        PLC1Read(8) = ("AndOnBoard_Excel_DINT[4]") ' Good Parts Count
        PLC1Read(9) = ("AndOnBoard_Excel_DINT[5]") ' Bad Parts Count
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[1]") ' Average Cycle Time
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[2]") ' Last Cycle Time
        PLC1.BeginReadMultiple(PLC1Read)
    End Sub

    Private Sub PLC1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles PLC1.DataReceived
        MsgBox(e.PlcAddress & "=" & e.Values(0))
    End Sub

Make sure to also set properties like PLC1.ProcessorSlot if necessary.

When you have lines like these:

        PLC1Read(10) = ("AndOnBoard_Excel_REAL[1]") ' Average Cycle Time
        PLC1Read(10) = ("AndOnBoard_Excel_REAL[2]") ' Last Cycle Time

the "AndOnBoard_Excel_REAL[1]" will be overwritten by "AndOnBoard_Excel_REAL[2]".

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #6 on: March 21, 2018, 11:42:18 AM »
    Private Sub EthernetIPforCLXCom2_ComError(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.ComError
        MsgBox("Com Error = " & e.ErrorMessage)
    End Sub
End Class
Change your error handler to point to your specific driver instance you are using. Change EthernetIPforCLXCom1 to EthernetIPforCLXCom2

JoeBProgamming

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #7 on: March 21, 2018, 01:25:47 PM »
Thanks Archie and Godra for your fast replies. After I rebooted my computer the problem fixed itself. But now I am having other problems. When I try to use

mystrng = Me.EthernetIPforCLXCom1.Read("AndOnBoard_Excel_REAL[2]") to read I keep getting the following error.
MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException
  HResult=0x80131500
  Message=Read Failed. Path Segment Error (Invalid Tag Name),  Status Code=4

The IP is correct and the tag is a controller tag. What is going on?

If I Dim myplc As New EthernetIPforCLXCom
        myplc.IPAddress = "192.168.1.8"
and then mystrng = myplc.Read("AndOnBoard_Excel_REAL[2]") it works??


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: VB.NET DataReceived Not Working CLX Driver
« Reply #8 on: March 21, 2018, 02:26:41 PM »
Error code 4 does come directly from the PLC. Most of the time it means the tag does not exist, but could also mean the RoutePath is incorrect. Double check and even triple check the tag name you have in your code because I would give it a 99% chance that is the issue.

If still not convinced, use Wireshark to do a packet capture and look at the tag name being sent to the PLC, then the response.