Reading from serial port and dumping to console
r.skowronek at fz-juelich.de
r.skowronek at fz-juelich.de
Fri Aug 20 09:23:34 EDT 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
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
More information about the Python-list
mailing list