hello there

Iam using python 2.5.4
pyserial 2.4
pywin32-214

on windows 7

i hav a small test script written to query a serial device (arduino)
and get back reply appropriately

////file: test.py

import serial
print 'hi'
ser=serial.Serial(port='\\.\COM2', baudrate=9600)
ser.close()
ser.open()
ser.write('1')
ser.readline()
ser.readline()
ser.close()

the device waits for '1' through its serial interface and print two
lines if it gets '1'

"Some Data found" and "Header received"

the script works on IDLE well when given one line at a time

but when given in command line as python test.py it prints hi and wait
forever

can anyone help?
thanks in advance

You should really use code tags.

It waits forever because it does not get a reply.

import serial
print 'hi'
ser = serial.Serial('COM2', baudrate=9600, timeout=5)#timeout in case no reply

#you don't need to open the port either

ser.write('1\r') #sometimes \r is needed to indicate data is done transferring 
ser.readline() #you only need one readline if its under one line of data
ser.close()

as for the arduino code, you need to make sure there is a line break charicter to flag an end of line so pythons readline can pick up on it.

something like:

//wiring code
serial.print("test data")
serial.println()

or
//wiring code
serial.println("test data")

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.