Reading from serial port and dumping to console

Fredrik Lundh fredrik at pythonware.com
Fri Aug 20 16:02:17 CEST 1999


Thomas Lim <englim at pc.jaring.my> wrote:
> I'm trying write a program to read from the serial port (barcode reader
> attached) and dump to the console, so that my application program can
> receive the data.
> OS: Red Hat Linux 6
> Python: 1.5.2
> 
> Program listing:
> p = open('/dev/ttyS0', 'r')
> t = open('/dev/tty0', 'w')
> while 1:
>     x = p.readline()
>     print x   # yes, I could read from /dev/ttyS0
>     t.write(x)  # but this has no effect on console
> 
> Hope that someone could help.

how about:

p = open('/dev/ttyS0', 'r', 0)
t = open('/dev/tty0', 'w', 0)

(0 means unbuffered I/O)

hope this helps!

</F>





More information about the Python-list mailing list