Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#154 stty equivalents (Linux)

v2.6
closed-rejected
Chris Liechti
5
2013-10-17
2013-09-03
Ryan Pessa
No

Hello,

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:

'serial.baudrate': 9600,
'serial.parity': serial.PARITY_EVEN,
'serial.bytesize': serial.SEVENBITS,
'serial.timeout': 0,
'serial.writeTimeout': 0,

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.

Discussion

  • Chris Liechti
    Chris Liechti
    2013-10-10

    port processing is intentionally disabled with pySerial as other platforms do not have such a thing.

    the "onlcr" option you are enabling is, according to the manpage of stty, translating \n to \r\n. so i suspect that sending "W\r\n" from pySerial should have the same effect as enabling that with stty.

     
  • Chris Liechti
    Chris Liechti
    2013-10-10

    • status: open --> pending-works-for-me
    • assigned_to: Chris Liechti
     
  • Chris Liechti
    Chris Liechti
    2013-10-17

    • status: pending-works-for-me --> closed-rejected
    • Group: v1.0 (example) --> v2.6
     
  • Chris Liechti
    Chris Liechti
    2013-10-17

    Post processing of the OS (like configured with stty) is not an option for pySerial, as it should be cross platform and other platforms do not support this.

    Such processing needs to be emulated by the application itself.