Reputation: 1
I have been trying to read data from a weather sensor using MODBUS RTU through the RS485 pins on a Raspberry Pi. I am having trouble recognizing the syntax of the commands that I have to write. On the pymodbus readme it says:
read_coils(address, count=1, **kwargs)
Parameters:
address – The starting address to read from
count – The number of coils to read
unit – The slave unit this request is targeting
I am not able to understand whether I should type in the address in Hex format or DEC format, I am also not able to understand what the parameter "unit" means.
In the datasheet of the weather station, the following values are given as register addresses but I don't know which values go into the command Datasheet of weather station Can anyone please tell me in which format I am supposed to write the address, and also what I should write in the "unit" field
Thanks in advance to this amazing community
Upvotes: 0
Views: 592
Reputation: 5467
The address is passed as an integer type (number). In Python, you can write a number in hexadecimal (e.g. 0x75fb) or in decimal (e.g. 30203) or even in binary (0b111010111111011). Whichever you prefer.
In Modbus, the term coil refers to a boolean output. You can set a coil to "on" or "off". You probably wanted read_input_registers()
instead. You can tell by the address from your linked datasheet: 30001-39999 (in decimal) are input registers. You should read a bit about Modbus basics, e.g. the simplymodbus.ca FAQ has a table of address ranges.
The term "unit" is just a very bad and confusing name. I think it refers to the Modbus slave ID. You can have more than one slave ("units") on the same bus. You probably can configure it on your device, and the manual should tell you about it. For Modbus-RTU (not Modbus-TCP), if you pick the wrong number you'll get no answer. But keep in mind there are a hundred other possible reasons for why you might get no answer from the device.
It's best to have an oscilloscope in reach if it doesn't work, to check if your device is not sending or the other device is not answering or if the voltages are wrong. There is also a chance to fix problems "blindly", by double-checking everything you did, but it can be frustrating.
Upvotes: 0