gavinying / modpoll

A New Command-line Tool for Modbus and MQTT
https://gavinying.github.io/modpoll
MIT License
84 stars 17 forks source link

Ensure pymodbus is installed with serial support #27

Closed schroepf closed 9 months ago

schroepf commented 9 months ago

Fixes an issue with the docker container when trying to use serial devices.

Prior to this change running

modpoll --rtu /dev/ttyUSB0 --config https://raw.githubusercontent.com/gavinying/modpoll/master/examples/modsim.csv

within the docker container would cause the following error:

Traceback (most recent call last):
  File "/home/tobias/.local/lib/python3.10/site-packages/pymodbus/client/serial.py", line 206, in connect
    self.socket = serial.serial_for_url(
NameError: name 'serial' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tobias/.local/bin/modpoll", line 8, in <module>
    sys.exit(app())
  File "/home/tobias/.local/lib/python3.10/site-packages/modpoll/main.py", line 84, in app
    modbus_poll()
  File "/home/tobias/.local/lib/python3.10/site-packages/modpoll/modbus_task.py", line 429, in modbus_poll
    master.connect()
  File "/home/tobias/.local/lib/python3.10/site-packages/pymodbus/client/serial.py", line 217, in connect
    except serial.SerialException as msg:
NameError: name 'serial' is not defined

This error is fixed by installing pymodbus with serial support.

gavinying commented 9 months ago

Hi @schroepf , thank you very much for raising this issue, your fix absolutely works, but I think it is better to directly integrate pyserial library into our package as an optional dependency (version 0.6.3+), so that users can easily get serial support using,

pip install -U modpoll[serial]

Feel free to try the latest version. I will close the PR for now, welcome to open another one if needed. Thanks.