pySerial help please!

B

bmaschino

Hello all,

I am very new to Python and I am using it because I needed an easy
language to control a piece of equipment that connects to my computer
via a serial cable. I am running Python 2.6 with pySerial 2.4 under
Windows. I can get Python to create a serial port on COM1, but when I
try to write to the device, nothing happens. Here is an example:

import serial
ser = serial.Serial(0)
ser.write("otpm 2 16 0")
ser.close()

If I connect to the device in Hyperterminal the device will behave as
expected when I give it the command 'otpm 2 16 0' but not in Python. I
have confirmed Python is actually controlling the port because
Hyperterminal will not open the port while Python has it open,
although I have not been able to try a loopback connector as of yet.
Any suggestions out there? Thanks in advance!

Cheers,
Bryce
 
M

MRAB

Hello all,

I am very new to Python and I am using it because I needed an easy
language to control a piece of equipment that connects to my computer
via a serial cable. I am running Python 2.6 with pySerial 2.4 under
Windows. I can get Python to create a serial port on COM1, but when I
try to write to the device, nothing happens. Here is an example:

import serial
ser = serial.Serial(0)
ser.write("otpm 2 16 0")
ser.close()

If I connect to the device in Hyperterminal the device will behave as
expected when I give it the command 'otpm 2 16 0' but not in Python. I
have confirmed Python is actually controlling the port because
Hyperterminal will not open the port while Python has it open,
although I have not been able to try a loopback connector as of yet.
Any suggestions out there? Thanks in advance!
Have you checked that the baud rate, parity, etc, are the same as in
Hyperterminal?
 
D

Diez B. Roggisch

Hello all,

I am very new to Python and I am using it because I needed an easy
language to control a piece of equipment that connects to my computer
via a serial cable. I am running Python 2.6 with pySerial 2.4 under
Windows. I can get Python to create a serial port on COM1, but when I
try to write to the device, nothing happens. Here is an example:

import serial
ser = serial.Serial(0)
ser.write("otpm 2 16 0")
ser.close()

If I connect to the device in Hyperterminal the device will behave as
expected when I give it the command 'otpm 2 16 0' but not in Python. I
have confirmed Python is actually controlling the port because
Hyperterminal will not open the port while Python has it open,
although I have not been able to try a loopback connector as of yet.
Any suggestions out there? Thanks in advance!

You need to give a newline, you press return on the terminal as well,
don't you?

Diez
 
B

bmaschino

(e-mail address removed) schrieb:









You need to give a newline, you press return on the terminal as well,
don't you?

Diez- Hide quoted text -

- Show quoted text -

Yes! That was exactly the problem. I replaced ser.write("otpm x x x")
to ("otpm x x x\n") and it WORKS!! Thank you!
 
Joined
Jan 13, 2011
Messages
2
Reaction score
0
Help!

Hello!

I am having a similar problem, I am trying to communicate to a Sanyo projector using pySerial and am having issues as well. I tried the newline that seemed to help the OP, but has not solved my problem. I have verified that my baudrate and parity are all set correctly. Here is my code (using COM13):

import serial
ser = serial.Serial(12)
ser.baudrate = 19200

print ser
print ser.write("CR0\n")
ser.close()


I have also tried variations using "CR0\r", "CR0\r\n", "CR0\x0D" and nothing seems to change it. I'm using another application to ensure that I can speak to the Sanyo projector, and I get a correct response.

CR0 is a status read of the hardware that should return something like "80" which would mean "STANDBY"

However, the responses that I keep getting are things like 3,4, or 5 which seem to be errors, given that they are returned apparently based solely on the length of the String I send, not based on the actual command.

Any ideas?

Thanks so much in advance!

-Damic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top