I am working with an ECR scale device. This device requires specific serial port settings in order to work correctly. The reference application I am using calls stty as so:
stty -parodd cs7 parenb -hupcl opost -olcuc -ocrnl onlcr -isig -icanon -iexten -echo -echoe -echok -echonl -echoctl -echoke -F /dev/ttyUSB0
Now I am trying to get this same device working in Python using PySerial. It mostly works, however, the serial post processing options are required to make everything work.
I open my serial port with the following options:
However, the messages from the scale should be 16 bytes; instead I receive a three byte message ('\nJ\003') in response to the read weight command ('W\n').
I have managed to get everything working by using subprocess.call to run stty manually after opening the port with PySerial:
call('stty opost -olcuc -ocrnl onlcr -F /dev/ttyUSB0'.split(' '))
('opost' is the only option I actually need, but I figure it's a good idea to send all of the post-processing options just in case)
So my question is: is there any plan to implement these post-processing options in PySerial? Calling stty works, but it is ugly.
Log in to post a comment.