Author Topic: ModbusTCP display value of partial register.  (Read 1061 times)

Mat

  • Newbie
  • *
  • Posts: 2
    • View Profile
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)
« Last Edit: April 21, 2023, 03:27:28 PM by Mat »

guney

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: ModbusTCP display value of partial register.
« Reply #1 on: April 24, 2023, 07:15:20 AM »
How Can I read Modbuss Adress=1006 bit:4 with ModbusTCPIP ?

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: ModbusTCP display value of partial register.
« Reply #2 on: April 24, 2023, 09:49:57 AM »
Both of you should search the forum to see what info is available on reading bits with Modbus and also what controls can / should be used.

Here are some links:

   https://www.advancedhmi.com/forum/index.php?topic=765.0
   https://www.advancedhmi.com/forum/index.php?topic=2452.0

Mat

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: ModbusTCP display value of partial register.
« Reply #3 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

bachphi

  • Hero Member
  • *****
  • Posts: 642
    • View Profile
Re: ModbusTCP display value of partial register.
« Reply #4 on: April 28, 2023, 10:41:51 AM »
Looks like you know what you are doing.  Does it work?
A while back I was doing J1587/ J1708  protocol for serial.
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================