Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Reading a single byte by Modbus protocol (ModbusMaster function)


nanopol Jan 9, 2019 03:49 AM

Hi,
How could I read a single Byte with the ModbusMaster function? So far I have only been able to make readings of floating numbers.


eastmanjoe Jan 10, 2019 09:57 PM

Hi Nanopo,

To read is a single Modbus register use the "ModbusOption" parameter to indicate if it is a 16-bit signed integer (1) or a 16-bit unsigned integer (3).  The variable array the data is to be stored in will need to be declared as "Long".  The "Length" paramater can be set to 1 for a single register.

Since a Modbus register is made up of two bytes (16-bit) then you will need to manipulate the data after it is received.  To split a single Modbus register into two bytes you can perform the following operation:

 

Public register As Long
Public high_byte As Long
Public low_byte As Long

high_byte = (register AND &HFF00) >> 8
low_byte = register AND &H00FF

 


nanopol Mar 12, 2019 02:59 AM

It was very useful, thank you.

Log in or register to post/reply in the forum.