How to open a serial port with pyserial?
I am trying to open a serial port with python. This is on Ubuntu. I import the openinterface.py and enter in this
ser = openinterface.CreateBot(com_port = "/dev/ttyUSB1", mode="full")
I get an error saying "unsupported operand types for -: 'str' and 'int'" I tried the same call with single quotes instead of double, and with no quotes at all.
How can I fix this? Or is there an alternative function to use? I only know the basics of Python so maybe its some small syntax thing I am not noticing? Any h开发者_开发百科elp would be appreciated, thanks.
According to this page in Russian, there's a bug with the openinterface.py
file that tries to subtract one from the port argument. It suggests making this change (removing the - 1
on line 803) with sed
:
sed -ie "803s/ - 1//" openinterface.py
Either try that, or see if there's an updated version of openinterface.py
.
This is what you want if you are using python 3:
import serial #import pyserial lib
ser = serial.Serial("/dev/ttyS0", 9600) #specify your port and braudrate
data = ser.read() #read byte from serial device
print(data) #display the read byte
精彩评论