Mailing List Archive

Reading from serial port and dumping to console
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.

Regards,
Thomas.
Reading from serial port and dumping to console [ In reply to ]
On Fri, 20 Aug 1999 09:33:44 +0000, Thomas Lim <englim@pc.jaring.my>
wrote:

>: t = open('/dev/tty0', 'w')

Try with t = sys.stdout

A+

Laurent.

---
Laurent POINTAL - CNRS/LURE - Service Informatique Experiences
Tel/fax: 01 64 46 82 80 / 01 64 46 41 48
email : pointal@lure.u-psud.fr ou lpointal@planete.net
Reading from serial port and dumping to console [ In reply to ]
Thomas Lim <englim@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


I use Python to read out a multimeter and append the data to a logfile.
The serial port was initialized with Kermit before though:

#!/usr/local/bin/python
# UDL45 auslesen und Werte in File 'hv-log' schreiben (append)
import time
udl = open('/dev/cua1','r+')
log = open('hv-log','a')
udl.write('val?\r')
val = udl.readline()
t = time.time()
time.ctime(t)
#print val
log.write(time.ctime(t)),
log.write(': ',)
log.write(val)
udl.close()
log.close()


Rolf
Reading from serial port and dumping to console [ In reply to ]
Laurent POINTAL wrote:

> On Fri, 20 Aug 1999 09:33:44 +0000, Thomas Lim <englim@pc.jaring.my>
> wrote:
>
> >: t = open('/dev/tty0', 'w')
>
> Try with t = sys.stdout
>
> A+
>
> Laurent.
>
> ---
> Laurent POINTAL - CNRS/LURE - Service Informatique Experiences
> Tel/fax: 01 64 46 82 80 / 01 64 46 41 48
> email : pointal@lure.u-psud.fr ou lpointal@planete.net

To be more specific, what I was trying to do was to stuff what I read
from the serial port to the keyboard buffer. Anyway that this can be
done in Python?

Regards,
Thomas.
Reading from serial port and dumping to console [ In reply to ]
Thomas Lim <englim@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>