0

I am attempting to control a projector using RS232 from python. This link has the needed information about the port settings and expected responses. http://www.audiogeneral.com/Optoma/w501_rs232.pdf

To summerise it baud = 9600, Data bits = 8, No parity, 1 stop bit, no flow control.

when the command "~00124 1\r" is sent the projector should respond okn where n is the power state.

when the command "~0000 1\r" is sent the projector should power on

From Putty I am able to send the power on command and other commands and see that the projector does what it is supposed to. I can also send the read command and get the appropriate okn response back to putty.

From python I can send the power on command and see the projector power on. however when I send the power state command I never see any character come into the read buffer.

Here is the code for a test script i wrote trying to 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 an okn after the power state line but it does not show up

asked Jan 6, 2016 at 1:28
2
  • I don't see anything print after "Power State" which suggests that ser.inWaiting() return is <= 0, so you should print it and it's type() as it may be a string not an int. Commented Jan 6, 2016 at 2:12
  • I Printed that its type is int but its value is 0 so the loop wont run. I tried it with while True: and it just hangs until I kill the program. Commented Jan 6, 2016 at 2:31

1 Answer 1

2

Putty emulate a serial terminal, like minicom in Linux/Unix or HyperTerminal on Windows. Try adding \n\r at the end of the string to act as a real serial terminal.

I suggest you to try reading your data byte per byte instead of 3 bytes at time. Better if you use readline method.

answered Jan 6, 2016 at 2:35
Sign up to request clarification or add additional context in comments.

3 Comments

don't think readine will work since as best I can tell the projector does not send\n to cause a new line it only sends \r after the characters. Ill try 1 byte and adding \n to the write statement now
The \r was part of the problem I also had to add a time.sleep(0.05) between the write and the read to give the projector time to respond
You can also try setting port timeout to None, which cause all read calls to be blocking. In this way yout python script will wait until at least n bytes ar received. Try also calling method flush on serial port to ensure that all bytes are sent before calling the read method

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.