I'm trying to write a python program which can communicate over a serial interface using PySerial module as follows:
import serial
if __name__ == '__main__':
    port = "/dev/tnt0"
    ser = serial.Serial(port, 38400)
    print ser.name
    print ser.isOpen()
    x = ser.write('hello')
    ser.close()
    print "Done!"
But if I execute the above I get the following error:
/dev/tnt0
True
Traceback (most recent call last):
File "/home/root/nested/test.py", line 15, in <module>
x = ser.write('hello')
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 518, in write
raise SerialException('write failed: %s' % (v,))
serial.serialutil.SerialException: write failed: [Errno 22] Invalid argument
I referred to the pyserial documentation and according to that this should work without an issue. Please let me know what i'm doing wrong in this.
TIA!
                        
/dev/tntXare emulated port pairs, and to perform a successful read or write you need to open both ports from a pair.Think of it as a pipe - if one end is closed, you will be not able to push the data through.