Pages

Tuesday, May 24, 2005

PySerial

A really nice module for Python that proved efficient and easy to use if pySerial... There are many devices that can comunicate with a PC through a serial port, so here is a script(listener) that uses pySerial to catch the output from such a device and store it in a file. Can be ajusted to handle a faster output from serial port...
import serial

#open second serial port, 0 for the first
ser=serial.Serial(1)

#loop forever
while 1:
  s=ser.readline()
  fileLog=open('serial_log.txt','a')
  fileLog.write('%s'%s)
  fileLog.close()
ser.close()