我想使用我的投影机与树莓派2的串行连接。 我有一个小的python脚本在Windows上工作(来自Full examples of using pySerial package)。
import time
import serial
ser = serial.Serial(
port='COM3',
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
if ser.isOpen() :
ser.close()
ser.open()
print ser.portstr
print 'Enter your commands below.\r\nInsert "exit" to leave the application.'
input=1
while 1 :
# get keyboard input
input = raw_input(">> ")
if input == 'exit':
ser.close()
exit()
else:
ser.write('\r' + input + '\r')
out = ''
time.sleep(1)
while ser.inWaiting() > 0:
out += ser.read(1)
if out != '':
print ">>" + out
要在linux上使用它,我唯一改变的是port ='COM3'到port ='/ dev / ttyUSB0'。我检查了dmesg | grep -i tty,这是好的。
我的问题是当我发送如下命令: “* pow = on#”打开投影机,它适用于Windows但不适用于Linux。可能是一些编码问题?
感谢。
编辑:dmesg的输出(回复时间太长)
[ 211.001768] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
[ 211.104934] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
[ 211.104965] usb 1-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 211.104981] usb 1-1.2: Product: USB2.0-Ser!
[ 211.131759] usbcore: registered new interface driver usbserial
[ 211.131932] usbcore: registered new interface driver usbserial_generic
[ 211.132061] usbserial: USB Serial support registered for generic
[ 211.136250] usbcore: registered new interface driver ch341
[ 211.136485] usbserial: USB Serial support registered for ch341-uart
[ 211.136623] ch341 1-1.2:1.0: ch341-uart converter detected
[ 211.143994] usb 1-1.2: ch341-uart converter now attached to ttyUSB0