Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mat

Pages: [1]
1
Open Discussion / Re: ModbusTCP display value of partial register.
« on: April 27, 2023, 02:49:30 PM »
Thanks for the response Godra, I did read both of those before posting and they didn't quite fit what I was trying to do.

There are many examples of reading individual bits or values of complete registers. This application requires reading the value of the first 5 bits and the value of the next 19 bits both as integers spread across 2 16bit registers.
The only way I could figure out how to do it was with bitwise operators.
There are 40 event registers so I just duplicated this code and changed the register address and the event numbers.
Here is the code I came up with:

Private Event1 As Integer
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Event1 = ModbusTCPCom1.Subscribe("L41511", 1, 500, AddressOf Event1_Data_Received)
End Sub
 Private Sub Event1_Data_Received(sender As Object, e As Drivers.Common.PlcComEventArgs)
        Dim code, FMI, SPN As Integer
        If e.ErrorId = 0 AndAlso e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
            code = e.Values(0) And 16777184
            SPN = code >> 5
            FMI = e.Values(0) And 31
        End If
        Label1.Text = "SPN " & SPN & "_" & "FMI " & FMI
    End Sub

2
Open Discussion / ModbusTCP display value of partial register.
« on: April 21, 2023, 11:38:04 AM »
Is it possible to return the value of a group of bits from a register?
I am trying to display the J1939 codes from a generator controller. The data is spread across two 16bit registers. The first 5 bits are the FMI number, the next 19 bits are the SPN number, and the last 8 bits are unused.
I would like to do a MessageDisplayByValue, but I do not see a way to mask bits or define a start bit and quantity.

- Version of AdvancedHMI  3.99x
- Version of Visual Studio 2022 17.4.1
- Operating System Windows 10
- Hardware Dell PC
- PLC make and model CAT EMCP 4
- Communication Driver ModbusTCPCom

From the manual for the EMCP 4 controller:
Bits 31:24 = UNUSED, set to zeros
Bits 23:5 = SPN (0 to 524287)
Bits 4:0 = FMI (0 to 31)

Pages: [1]