Thu, 28 Feb 2008, by drankinatty@suddenlinkmail.com:
Listmates,
A linux question. I have a phone system that will output call logs through an rs-232 cable. I would like to write a script that will read the data from the serial port and input it into a mysql table. I can handle the mysql interface, but how do I read data from a serial port? I have never tried to interface directly with one and I don't know what tools are involved other than it will take some type of tty configured to read from the port. That's where I'm stuck. Which one?, getty, mgetty, what? What kind of script do I write that will read from the serial port each time a call is made or received? Do I use a loop? (seems kind of process intensive for data that will only appear every once in a while) Can I create some type of buffer or file for the data and then use cron to periodically sweep the data from the buffer and stick it in mysql? Interesting problem.
Go with Python.
It has a really easy to use module, aptly called "serial", with
which serial communication is very simple.
$ pydoc serial
Help on package serial:
NAME
serial
FILE
/usr/lib/python2.5/site-packages/serial/__init__.py
DESCRIPTION
#portable serial port access with python
#this is a wrapper module for different platform implementations
#
# (C)2001-2002 Chris Liechti
ser = serial.Serial('/dev/ttyS1', 19200, timeout=1) x = ser.read() #read one byte s = ser.read(10) #read up to ten bytes (timeout) line = ser.readline() #read a '\n' terminated line ser.close()
Python also has good support for all sorts of databases, so you can easily write a relatively small program to get and put your data. Theo -- Theo v. Werkhoven Registered Linux user# 99872 http://counter.li.org ICBM 52 13 26N , 4 29 47E. + ICQ: 277217131 SUSE 10.3 + Jabber: muadib@jabber.xs4all.nl Kernel 2.6.22 + See headers for PGP/GPG info. Claimer: any email I receive will become my property. Disclaimers do not apply. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org