I would like to use the serial connexion of my projector with a raspberry pi 2. I have a little python script working on windows (from 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
To use it on linux the only thing I changed is port='COM3' to port='/dev/ttyUSB0'. I checked with dmesg | grep -i tty, it's the good one.
My problem is that when I send a command like : "*pow=on#" to turn the projector on, it works well on windows but not linux. Could it be some encoding issues ?
Thanks.
Edit : The output of the dmesg (too long for a reply)
[ 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