AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 82 forks source link

start client #62

Closed anotherkeycode closed 5 years ago

anotherkeycode commented 5 years ago

I can't start the client example.

Python 3.7.0 (default, Sep 15 2018, 19:13:07) [GCC 8.2.1 20180831] on linux

[dev@dev-vm modbus]$ python modbus_client.py 
Traceback (most recent call last):
  File "modbus_client.py", line 18, in <module>
    response = tcp.send_message(message, sock)
  File "/usr/lib/python3.7/site-packages/umodbus/client/tcp.py", line 262, in send_message
    raise_for_exception_adu(response_error_adu)
  File "/usr/lib/python3.7/site-packages/umodbus/client/tcp.py", line 247, in raise_for_exception_adu
    pdu_to_function_code_or_raise_error(resp_pdu)
  File "/usr/lib/python3.7/site-packages/umodbus/functions.py", line 111, in pdu_to_function_code_or_raise_error
    raise error_code_to_exception_map[error_code]
umodbus.exceptions.IllegalDataAddressError:  The data address received in de request is not an allowable address for
    the server.

How can I fix it?

OrangeTux commented 5 years ago

Thanks for you question!

The server responds with an IllegalDataAddressError. So you're requesting a coil or register which does't exists in the server.

Oh, and could use wrap the code snippet with '```'. This will apply some markup to the code to make it more readable. Read more about it here.

codevak commented 4 years ago

Python 3.6.9 [GCC 8.4.0] on linux

As a newbie to modbus protocol, I am facing the same issue of umodbus.exceptions.IllegalDataAddressError: The data address received in the request is not an allowable address for the server. Can the client and server example in the repo for TCP be used as is? If not, how should they be modified to work together? I am trying to simulate both the client and server using the python code given in the repo.

OrangeTux commented 4 years ago

Can the client and server example in the repo for TCP be used as is?

Yes, they can work together.

codevak commented 4 years ago

Hi, Thanks for your reply. I tried it already but end up with this error:umodbus.exceptions.IllegalDataAddressError: The data address received in the request is not an allowable address for the server I start the server first (which is listening for incoming connections). Then I start the client in a different terminal. The client throws this error and stops. Any idea what I could be doing wrong?

albcp commented 4 years ago

Hi @codevak, the code for the server included in the Readme is wrong, you need to modify _functioncodes=[3, 4] to _functioncodes=[1, 2] and _functioncodes=[6, 16] to _functioncodes=[5, 15].

codevak commented 4 years ago

Hi, This works now. Thanks a lot!