Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have been working with a simple program using pymodbus library in python. This is the sample program I found with the library documentation. The code is as follows
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('192.168.10.3')
client.write_coil(410001, False)
result = client.read_coils(410001,1,unit=1)
print result.bits[0]
client.close()
I am getting the error
Traceback (most recent call last):
File "start_2407.py", line 4, in <module>
client.write_coil(410001, False)
File "build\bdist.win-amd64\egg\pymodbus\client\common.py", line 61, in write_coil
File "build\bdist.win-amd64\egg\pymodbus\client\sync.py", line 131, in execute
File "build\bdist.win-amd64\egg\pymodbus\client\sync.py", line 46, in execute
File "build\bdist.win-amd64\egg\pymodbus\transaction.py", line 243, in buildPacket
File "build\bdist.win-amd64\egg\pymodbus\bit_write_message.py", line 58, in encode
struct.error: 'H' format requires 0 <= number <= 65535
Do I need to provide the address locations in hexadecimal? I have tried that also but the output do not match with that which I get from Modscan2.
–
Modbus variables are addressed in the 0-65535 range. You can have up to 65536 coils, discrete inputs, input registers and holding registers.
You are not allowed to use 410001 as an input to PyModbus. 410001 is a very conventional (not standard) way to represent the 10000th holding register.
Yes, it's strange. Modbus vendors are very creative when coming up with their memory maps.
You can read that register using the read_holding_registers method with address=10000.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.