Author Topic: PlcEventArgs from the DataReceived Event of OmronBaseCom?  (Read 935 times)

Ellis

  • Newbie
  • *
  • Posts: 1
    • View Profile
PlcEventArgs from the DataReceived Event of OmronBaseCom?
« on: March 17, 2020, 11:11:04 AM »
Hello all,

First off, let me just say that I have almost no experience in this realm, so I'd appreciate your patience. :-\

I am attempting to programmatically access values from an Omron CJ1M CPU13. I want to access the data over ethernet, so I'm using the AdvancedHMIDrivers.Omron.OmronEthernetFINSCom driver (named Line1). Here is my handler code:

Code: [Select]
Private Sub Line1_DataReceived(sender As Object, e As PlcComEventArgs) Handles Line1.DataReceived

        Console.Write(e.PlcAddress + " ")
        For i As Integer = 0 To e.Values.Count - 1
            Console.Write(" " + e.Values(i))
        Next
        Console.WriteLine()

End Sub

From this I get the output:
D4 va0, val1, val2...etc.

As you can see, I'm just writing the values from the PLC to stdout. Here is my question though: is e.PlcAddress the starting address, and every value following that one is the next address? For example, I start at location D4, so I'm assuming Values(0) is D4. Would Values(1), Values(2)...Values(n) match up to D4, D5...Dn? It doesn't seem to be contiguous. So, I guess in so many words, I'm wondering: is there a way to get the e.PlcAddress for each one of the values of Line1.DataReceived?

Thanks in advance,
Ellis

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: PlcEventArgs from the DataReceived Event of OmronBaseCom?
« Reply #1 on: March 18, 2020, 05:31:57 PM »
Your assumption should be correct and you can first check if the e.PLCAddress starts with "D" just like this:

Code: [Select]
        If e.PlcAddress.StartsWith("D") Then
            For i As Integer = 0 To e.Values.Count - 1
                If i = e.Values.Count - 1 Then
                    Console.Write("D" & (CInt(e.PlcAddress.Substring(1)) + i) & " " & e.Values(i))
                Else
                    Console.Write("D" & (CInt(e.PlcAddress.Substring(1)) + i) & " " & e.Values(i) & ", ")
                End If
            Next
            Console.WriteLine()
        End If

Then compare the output to what you have in the PLC to see if they are contiguous.

« Last Edit: March 18, 2020, 05:59:54 PM by Godra »