0

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.

asked Jul 24, 2015 at 8:06
2
  • You traceback indicates you're trying to write address 410001 instead of 10001. Is it a typo? Commented Jul 24, 2015 at 8:12
  • yeah sorry, I am trying to write 410001 Commented Jul 24, 2015 at 8:13

1 Answer 1

1

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.

answered Jul 24, 2015 at 13:58
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.