0

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
Community
  • 1
  • 1
rogeeeer
  • 1
  • 2
  • What usb to serial device are you using? Do you see any problems in dmesg after plugin of the convertor, like driver issues? Did you test the convertor with any other device tha your projector? – fvu Aug 26 '15 at 21:39
  • I don't know the device name, some old thing I had in a closet ! The driver show "ch34" or "ch340". Nothing in the dmesg everything is fine, the convertor is recognized and attached to ttyUSB0. I only tried the convertor with the projector, but it's the same I use with the windows device and the raspberry pi. – rogeeeer Aug 26 '15 at 21:53
  • Would it be possible to add the output of dmesg to your question, from the time the device is inserted (a message starting with `New USB device found`) and the lines that follow? – fvu Aug 26 '15 at 22:02
  • As [that manufacturer offers a source code driver for Linux](http://www.wch.cn/download/CH341SER_LINUX_ZIP.html) the might not be supported by the current kernels, or poorly. Maybe it's easier to get some FTDI or Prolific based USB-SER adapter... – fvu Aug 26 '15 at 22:15
  • I found a prolific based adapter and it works fine ! Thanks :) – rogeeeer Aug 27 '15 at 19:07
  • I've done a lot of work with pySerial, and your byte-at-a-time loop for reading gave me a little chill (I won't talk about using time.sleep() to allow the response to fill the input buffer, not great, but works). Anyway, you could replace that loop with: `if ser.inWaiting(): out=ser.read(ser.inWaiting())` – RufusVS Sep 01 '17 at 17:46

0 Answers0