pyhys / minimalmodbus

Easy-to-use Modbus RTU and Modbus ASCII implementation for Python.
Apache License 2.0
306 stars 146 forks source link

extend modbus with 'readfloats' and 'readlongs' #97

Open FLMuller opened 1 year ago

FLMuller commented 1 year ago

I am using minmodbus in lab automation, and many devices can read individual 2 register 32bit floats, (say a single 4-20 mAmp channel) but also allow reading multiple registers (so reading 4*2registers to give the current in 4 channels).

I have extended mm by adding FLOATS as a payload format and implementing a read/writefloats code in the relevant sections build request and parse results. (commented by @@@FLM). This essentially automates the combination of read/write REGISTERS and interpretation of the registers as 32bit FLOATS

This could also be extended to longs, but I have not done so, simply because I did not have the need.

I thought it might be useful to others to see, and maybe to implement in future releases of mm (which works great out of the box!)

Cheers

Frans

minimalmodbus_FLOATS.txt