linux - Python Serial Read Not Working -
i attempting control projector using rs232 python. link has needed information port settings , expected responses. http://www.audiogeneral.com/optoma/w501_rs232.pdf
to summerise baud = 9600, data bits = 8, no parity, 1 stop bit, no flow control.
when command "~00124 1\r" sent projector should respond okn n power state.
when command "~0000 1\r" sent projector should power on
from putty able send power on command , other commands , see projector supposed to. can send read command , appropriate okn response putty.
from python can send power on command , see projector power on. when send power state command never see character come read buffer.
here code test script wrote trying debug this.
import serial ser = serial.serial("/dev/ttyusb0") print ser.baudrate print ser.bytesize print ser.parity print ser.stopbits print ser.xonxoff print ser.rtscts print ser.dsrdtr print ser.name print "power state" ser.write("~00124 1") while ser.inwaiting() > 0: response = ser.read(3) print response output: 9600 8 n 1 false false false /dev/ttyusb0 true power state i expect okn after power state line not show
putty emulate serial terminal, minicom in linux/unix or hyperterminal on windows. try adding \n\r @ end of string act real serial terminal.
i suggest try reading data byte per byte instead of 3 bytes @ time. better if use readline method.
Comments
Post a Comment