Default simple tcp client and server programs in the example directory are working fine. I extended client code it to add a request to write single register it gave me illegalDataAddressError. After which I tried multiple registers write request which resulted in the same error.
I am trying to write the register on the address 5. Server code is default where it's accepting address range from 0 to 9.
CLIENT SIDE snip:
message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1])
read_message = tcp.read_coils(slave_id=1, starting_address=1, quantity=4)
write_register=tcp.write_multiple_registers(slave_id=1, starting_address=5, values=[23,45])
with create_connection((host, port)) as sock:
Response depends on Modbus function code. This particular returns the
# amount of coils written, in this case it is.
print('writing to the server...')
response = tcp.send_message(message, sock)
print('reading from the server...')
response = tcp.send_message(read_message, sock)
print(response)
print('writing registers...')
response = tcp.send_message(write_register, sock)
print(response)
SERVER SIDE snip:
@app.route(slave_ids=[1], function_codes=[5, 15], addresses=list(range(0, 5000)))
def write_data_store(slave_id, function_code, address, value):
"""" Set value for address. """
print('writing at address '+str(address)+' with value '+str(value))
data_store[address] = value
if name == 'main':
try:
app.serve_forever()
finally:
app.shutdown()
app.server_close()
Thank you so much for building such an open source package!
Hi Sir,
I have installed umodbus on raspberry pi 3B+
Default simple tcp client and server programs in the example directory are working fine. I extended client code it to add a request to write single register it gave me illegalDataAddressError. After which I tried multiple registers write request which resulted in the same error.
I am trying to write the register on the address 5. Server code is default where it's accepting address range from 0 to 9.
CLIENT SIDE snip: message = tcp.write_multiple_coils(slave_id=1, starting_address=1, values=[1, 0, 1, 1]) read_message = tcp.read_coils(slave_id=1, starting_address=1, quantity=4) write_register=tcp.write_multiple_registers(slave_id=1, starting_address=5, values=[23,45]) with create_connection((host, port)) as sock:
Response depends on Modbus function code. This particular returns the
SERVER SIDE snip:
@app.route(slave_ids=[1], function_codes=[5, 15], addresses=list(range(0, 5000))) def write_data_store(slave_id, function_code, address, value): """" Set value for address. """ print('writing at address '+str(address)+' with value '+str(value)) data_store[address] = value
if name == 'main': try: app.serve_forever() finally: app.shutdown() app.server_close()
Thank you so much for building such an open source package!