我想在串行端口上写数据。我的环境是科学的Linux 7.5和python 3.6。我无法在串行端口上写数据。代码为:
import serial
ser=serial.Serial(
port='/dev/tnt4',
baudrate=115200,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
ser.open()
ser.write(b'1')
ser.close()
上面的代码产生以下错误:
Traceback (most recent call last):
File "/opt/ActivePython-3.6/lib/python3.6/site-packages/serial/serialposix.py", line 537, in write
n = os.write(self.fd, d)
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shakeel/Python3.6 Projects/SerialPortReadWrite/SerialPortReadWrite.py", line 13, in <module>
ser.write(b'1')
File "/opt/ActivePython-3.6/lib/python3.6/site-packages/serial/serialposix.py", line 571, in write
raise SerialException('write failed: {}'.format(e))
serial.serialutil.SerialException: write failed: [Errno 22] Invalid argument