Pyserial again

Petr Jakes petr at tpc.cz
Tue Mar 7 11:24:26 EST 2006


1)
Peter Hansen was asking you for the code AFTER the "ser.readline()" not
BEFORE!! the code you have originally posted here

2)
the best way how to examine if your code works is to try to write some
simplest code as possible first (not buttons, not GUI etc..., just a
simple code)
(all this suggestions were already mentioned in one of your previous
postings, see http://tinyurl.com/zz3s5)

Regarding to your questions in this posting I think you can try
something like:

import serial
ser=serial.Serial(0, 9600, 8, "E", stopbits=2, timeout=1)
while 1:
    print s.readline()

In your original code you have posted here, you read one line from the
serial port only. It means the code reads byte by byte from the serial
port till the "end of line" byte ('\n') is recognized. Than the reading
stops and after that the whole code is finished because no
other code lines after the ser.readline(). If no data present on the
serial port for longer than "timeout" defined, it will stop reading
serial port and the code finishes as well.

3) please note, you can define serial port as following as well which
is ,IMHO, more readable:

ser=serial.Serial(0, 9600, 8, "E", stopbits=2, timeout=1)

(it was recommended to you in above mentioned posting as well)

You can find plenty of examples on http://pyserial.sourceforge.net/ in
the "Examples" paragraph. Try to study and search before you ask.

HTH

Petr Jakes




More information about the Python-list mailing list