[opensuse] howto - Read Data from Serial Port?
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. The data that comes into the serial port is simple text and will look something like this: c 02/28/08 11:34 14095551212 00:05:13 02 11 2671 00:05:16 The fields represent: calltype date time phonenumber duration outsideline extension account talktime We may have 4 calls come in at once or none during the entire night. Anybody have experience with the tools are available in openSuSE that will let me read this stuff from the port each time a call is made or received? If you can point me in the right direction, I can go from there. I just need to know which building block I should start from. Thanks. -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
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
2008/2/28, David C. Rankin
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.
The data that comes into the serial port is simple text and will look something like this:
c 02/28/08 11:34 14095551212 00:05:13 02 11 2671 00:05:16
The fields represent:
calltype date time phonenumber duration outsideline extension account talktime
We may have 4 calls come in at once or none during the entire night. Anybody have experience with the tools are available in openSuSE that will let me read this stuff from the port each time a call is made or received? If you can point me in the right direction, I can go from there. I just need to know which building block I should start from. Thanks.
-- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
There's already a project on sourceforge that extracts data using serial connection and inserts it on a database.... I'ts currently stale (no features added), so you can contribute :D Regards, Ciro -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
2008/3/2, Ciro Iriarte
There's already a project on sourceforge that extracts data using serial connection and inserts it on a database.... I'ts currently stale (no features added), so you can contribute :D
Regards,
Ciro
Found it, it's unmantained but works, tried it 4 years ago, more or less... http://pblogan.sourceforge.net/ Ciro -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Ciro Iriarte wrote:
2008/3/2, Ciro Iriarte
: There's already a project on sourceforge that extracts data using serial connection and inserts it on a database.... I'ts currently stale (no features added), so you can contribute :D
Regards,
Ciro
Found it, it's unmantained but works, tried it 4 years ago, more or less...
http://pblogan.sourceforge.net/
Ciro
Thanks Ciro, I knew I wasn't the only one to think about this :) -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (3)
-
Ciro Iriarte
-
David C. Rankin
-
Theo v. Werkhoven