how to create just one virtual port with socat?
I want to test pyserial to read and write via one port
I'm already try :
socat -d -d pty,raw,echo=1 pty,raw,echo=1
it creates two virtual ports /dev/pts/9 and /dev/pts/10
when I'm try:
ser.write('test\n')
in another console, I'm try to read :
ser2.readline()
when timeout, pyserial read '\n' as '^J'
^J
is the same as \n
, see Wikiepdia. I cannot reproduce the blocking you experience:
$ socat -d -d pty,raw,echo=1 pty,raw,echo=1
2012/06/14 14:29:13 socat[28866] N PTY is /dev/pts/3
2012/06/14 14:29:13 socat[28866] N PTY is /dev/pts/5
2012/06/14 14:29:13 socat[28866] N starting data transfer loop with FDs [3,3] and [5,5]
Terminal 1:
>>> import serial
>>> s = serial.Serial('/dev/pts/5')
>>> s.readline()
'hello\r\n'
>>> s.readline()
'hello\n'
Terminal 2:
>>> import serial
>>> s = serial.Serial('/dev/pts/3')
>>> s.write('hello\r\n')
7
>>> s.write('hello\n')
6
The readline()
calls return as soon as I execute write in the other terminal.