MODBUS-tk Read floating point values from slave in the master

I have created modbus slave to write data to the registers. I am able to write both float values and integer values from the slave side.

In the modbus master I am able to access only the integer values but not able to read float values.

I went through this https://github.com/ljean/modbus-tk/issues/72 but that didn't solve my problem.

For the integer values reading I can use the below code and read the values.

master = modbus_tcp.TcpMaster()
master.set_timeout(time_out_period)
result = master.execute(slave = 100, function_code = 3 , starting_address = 0, quantity_of_x = 25) 

But for the float values I used both the above and below code.

master = modbus_tcp.TcpMaster()
master.set_timeout(time_out_period)
result = master.execute(slave = 100, function_code = 3 , starting_address = 0, quantity_of_x = 25 , data_format='>f') 

I get error while reading the float as,

unpack requires a bytes object of length 4

The quantity of x should be a multiple of 2. Because the float requires two 16 bit registers or words so if you want 25 it should be 50.

ljean/modbus-tk, as a Modbus 32-bit float to a Modbus slave but the external master is not There are a number of ways to get the data to look correct and I can't say code here, but something wrong with how you are reading the data. Bytes "C D" are stored in the second register, F400002. With LabVIEW 2011 and earlier this is NOT how LabVIEW represents floating point numbers in Modbus registers when using a Modbus Slave I/O Server. If your device expects the least significant bits first then your data will appear like the decimal value in figure 2.

You also need to provide the correct data format reflective of how many individual float values(below are big endian) are trying to be unpacked;

1 float
logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 0, 2, data_format='>f'))
2 floats
logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 0, 4, data_format='>ff'))
3 floats
logger.info(master.execute(1, cst.READ_HOLDING_REGISTERS, 0, 6, data_format='>fff'))

How to write a float data to server � Issue #72 � ljean/modbus-tk , How to read float values from holding register ? i m able to write float values in slave but reading only integer on master side. I am reading the values in the registers of a modbus slave. But the values stored in the registers is combination of two registers. That is if register 3 has 72, and register 4 has 489.

It's easy, using Numpy. For example:

import numpy as np

# Sample registers to read
start_address = 0
items = 10
# Get the reply from slave
reply = master.execute(1, cst.READ_HOLDING_REGISTERS, start_address, items*2)
# Convert the reply to Numpy array of type int16
d16 = np.array(reply, dtype=np.int16)
# Convert to an array of type float32
f32 = d16.view(dtype = np.float32)

Modbus-TK Driver Configuration — VOLTTRON 7.0 Release , VOLTTRON's Modbus-TK driver, built on the Python Modbus-TK library, is an If the config file has no slave_id, the default is 1, not 0. Type (Required) - The point's data type: bool, string[length], float, int16, int32, int64, uint16, uint32, or uint64. By that, when user sets read only for read/write coils/registers or sets� Finally i am getting some values, since iam receiving floating point values from the slave iam getting the mixed or some errotic values .. can u please help me with it how can i read 16 bit and 32 bit floating values from the modbus slave

minimalmodbus 0.4, Easy-to-use Modbus RTU implementation for Python. In the Modbus RTU protocol, only the master can initiate communication. For example, consider an instrument (slave) with address number 1 to To read this data from the instrument: How to convert from the bit values to the floating point value is� Big-Endian is the most commonly used format for network protocols – so common, in fact, that it is also referred to as ‘network order’. Given that the Modbus RTU message protocol is big-Endian, in order to successfully exchange a 32-bit datatype via a Modbus RTU message, the endianness of both the master and the slave must considered.

minimalmodbus 0.6, Easy-to-use Modbus RTU and Modbus ASCII implementation for Python. to instruments (slaves) from a computer (master) using the Modbus protocol, and is How to convert from the bit values to the floating point value is 3 Read holding registers, Start address [2 Bytes], Number of registers [2 Bytes]� the issue that i read from the modbus register by register and the Density value is a floating point value, so i thought if i save each register in specified memory word and convert it from Dword to Real it would be ok. In the end i just made a move function for each register and reading it in the same way Floating point.

[PDF] TZA 401 Measuring computer MODBUS Interface description, MODBUS Register tables of TZA 401-. Telegram MODBUS. Any number of subscribers fulfilling the MODBUS specification Read telegram from Master to Slave No. 11H This function is used to query a floating point REAL value from Tk. - dp1, Qv dp2 f(Qv). P, Q. P, Q, , Tw, Tk, dT, T. -. Tw. Tk. P, Q, , Tw, Tk, dT, T. You can transmit (as a "master") floating point values using modbus command #16 which sends (writes) a group of 16 bit registers. A "master" can read groups of 16 bit registers from a "slave" device using command #3. Two sequential registers can then be interpeted as a 32 bit IEEE 754 std floating point value.

Comments
  • what is the float value you are trying to write ?