pyhys / minimalmodbus

Easy-to-use Modbus RTU and Modbus ASCII implementation for Python.
Apache License 2.0
308 stars 145 forks source link

cannot change serial.parity #54

Closed rma-ln closed 4 years ago

rma-ln commented 4 years ago

The following code works correctly: import minimalmodbus # pip3 install -U minimalmodbus device = minimalmodbus.Instrument('/dev/ttyS0', 7) device.serial.baudrate = 9600 device.serial.bytesize = 8 device.serial.parity = 'N' device.serial.stopbits = 1 print(device)

An attempt to change the serial.parity 'N' to e.g. 'E' or 'O' ends in an error: import minimalmodbus # pip3 install -U minimalmodbus device = minimalmodbus.Instrument('/dev/ttyS0', 7) device.serial.baudrate = 9600 device.serial.bytesize = 8 device.serial.parity = 'E' # <-- place of change, possible values 'N', 'E', 'O', 'M', 'S' device.serial.stopbits = 1

[iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) termios.error: (22, 'Invalid argument')

screenshot

it's probably a minimalmodbus module error

j123b567 commented 4 years ago

This is definitely not a problem of minimalmodbus. Minimalmodbus is using pyserial module, which is responsible for this configuration and this error message.

If you have similar problems, please always report operating system, python version and hardware you are using. Because it seems to be related to some crappy hardware which lacks support for setting parity, e.g. mini UART on RaspberryPi, so just use/configure other serial port or use USB/serial converter.

If it is not your case, please report this to pyserial project.

rma-ln commented 4 years ago

You're right. When you change the serial port to Moxa NPort, everything works fine. Thank you for your help and very quick response.