python - Pyserial does not play well with virtual port -


motivation

i want start leraning how use python library pyserial. seems nice library works lot of people. want use upcoming project in have automate serial communications.

environment

i'm running ubuntu 15.04. i'm using python 2.7.

setting virtual ports

i don't have device can communicate on serial port. i'm using socat application create 2 virtual ports connected each other baudrate of 9600.

$ socat -d -d pty,raw,echo=0,b9600 pty,raw,echo=0,b9600 2016/01/16 12:57:51 socat[18255] n pty /dev/pts/2 2016/01/16 12:57:51 socat[18255] n pty /dev/pts/4 2016/01/16 12:57:51 socat[18255] n starting data transfer loop fds [5,5] , [7,7] $ echo "hello" > /dev/pts/2 $ cat /dev/pts/4 hello 

great! seems ports work!

a simple pyserial script

i install pyserial using pip

$ sudo pip install pyserial 

then wrote little serialtest.py

#!/usr/bin/env python import serial  ser = serial.serial('/dev/pts/2', 9600) 

that entirety of serialtest.py

running script , encountering error

$ python serialtest.py  traceback (most recent call last):   file "serialtest.py", line 4, in <module>     ser = serial.serial('/dev/pts/2')   file "/home/sbl/.local/lib/python2.7/site-packages/serial/serialutil.py", line 180, in __init__     self.open()   file "/home/sbl/.local/lib/python2.7/site-packages/serial/serialposix.py", line 311, in open     self._update_dtr_state()   file "/home/sbl/.local/lib/python2.7/site-packages/serial/serialposix.py", line 605, in _update_dtr_state     fcntl.ioctl(self.fd, tiocmbis, tiocm_dtr_str) ioerror: [errno 22] invalid argument 

what's that?

unsuccessful attempts @ debugging

this guy said had success when using python 2.6. couldn't pyserial work 2.6.

this guy having trouble baudrate. double check baudrate command $stty -f /dev/pts/2 , confirmed was, in fact, @ baudrate of 9600.

this guy claims have problems baudrate , attributes kernel. in 2012, don't think it's relevant anymore.

my question

how can serialtest.py script run without error?

to make q&a complete, solution (as found in link austin philips):

#!/usr/bin/env python import serial  ser = serial.serial('/dev/pts/2', 9600, rtscts=true,dsrdtr=true) 

see pyserial github issue more explanation.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -