pyserial

Petr Jakes petr at tpc.cz
Thu Feb 23 20:44:07 EST 2006


Few notes from the Python beginner :) HTH.
I do not understand what do you mean by the expression: ".... I can
read data without try and try again....." Can you be more specific
please. I do not understand what do you exactly mean. AFIK the pyserial
is waiting while the data occur on the serial port (so called blocking
read) so it is not necessary to do some "polling" (checking the serial
port periodically) .

Following snippets of code is running in infinitive loop, but it is not
necessary too be worried about processor utilization because the
readline waits for the data on the serial port and the code continues
to run when data occurs or when timeout passes.

import serial
s = serial.Serial(port=0,baudrate=4800, timeout=20)
while 1:
    line = s.readline()
#   byte = s.read(1) # or you can read No. of bytes according your
needs

Alternatively you can monitor buffer of the serial port and while data
in it, you can read it.

while fd.inWaiting() != 0:
    s.read(1)

you can find plenty of examples about pyserial here
http://tinyurl.com/p8tt5

What I am not able to figure out is why are you trying to print out
input and output buffers (print self.ser.flushInput()) Does it print
out something?

Petr Jakes




More information about the Python-list mailing list