Hi
1/. Would be interested in how to clear the input serial buffer (and output ?) as the following program example starts. When (re)starting the program the Pi seems to have happily accumulated everything and anything seen on the UART Rx line. This can be time consuming / messy esp if processing and forwarding data off the UART as we are doing to a web server etc...
import serial, time #this imports the libraries needed
port = serial.Serial("/dev/ttyAMA0", baudrate=2400)
#This sets up the serial port ttyAMA0 GPIO
#baudrate is the bits per second.
while True:
rcv = port.readline()
#read buffer until cr/lf
#if not null then...
if(rcv):
print ('Serial # = ' + repr(rcv))
#Echo the buffer bytes back to screen
#&c.
2/. Can someone indicate where and how such a clear buffer command would go in the above example so it runs once on startup. I imagine it would be somewhere between the port command and the port.readline() command I imagine.
For anyone interested the above port.readline() example works FAB with serial data arriving at the GPIO ad hoc / variable length and responds to the 13/10 LF/CR very nicely. Highly recommended when conversing and talking to picaxe etc. The read byte, read bytes and timeout functions have been 'discovered' already. These took weeks to pull out of the www all over the place and usual fault finding and time consuming trial and error. Is there a code refference for this pyserial that is easy to find and use with syntax and examples some place. I imagine there will be an 'open' and 'close' command as well that would pretty much do the same thing and keep things tidy and under control.
Thanks
~ Andrew