|
From: jcluthe on 1 Feb 2008 10:44 I need to convert data that I'm getting via serial port to a .csv file on the fly all day every day. Anyone know how to make this happen in the simplest way possible? Can sed listen on a serial port? I understand how sed works, but I have never really used it. I have access to several different O/S's and lots of hardware, I prefer to do this in RHEL5 to keep the cyber security folks happy.......We have a satellite up2date server ...etc.etc. but I could run Fedora if needed.
From: dold on 1 Feb 2008 15:00 jcluthe(a)gmail.com <jcluthe(a)gmail.com> wrote: > I need to convert data that I'm getting via serial port to a .csv file > on the fly all day every day. Anyone know how to make this happen in > the simplest way possible? Can sed listen on a serial port? I > understand how sed works, but I have never really used it. I have > access to several different O/S's and lots of hardware, I prefer to do > this in RHEL5 to keep the cyber security folks happy.......We have a > satellite up2date server ...etc.etc. but I could run Fedora if needed. I used kermit to log serial data to a file constantly, switching log files every midnight. It could also stream to a pipe, so you could manipulate the data on the fly, if the built in scripting wasn't enough. It's probably on your Linux distro already. comp.protocols.kermit.misc http://www.columbia.edu/kermit/ck80.html -- Clarence A Dold - Hidden Valley Lake, CA, USA GPS: 38.8,-122.5
From: Tim Boyer on 1 Feb 2008 19:34 On Fri, 1 Feb 2008 07:44:58 -0800 (PST), "jcluthe(a)gmail.com" <jcluthe(a)gmail.com> wrote: >I need to convert data that I'm getting via serial port to a .csv file >on the fly all day every day. Anyone know how to make this happen in >the simplest way possible? Can sed listen on a serial port? I >understand how sed works, but I have never really used it. I have >access to several different O/S's and lots of hardware, I prefer to do >this in RHEL5 to keep the cyber security folks happy.......We have a >satellite up2date server ...etc.etc. but I could run Fedora if needed. Here's what I do. I've got a PBX system that outputs a line every time a call comes in. I've got a Perl program sitting on the serial line that reads it, does some string conversion, and writes it out to a log file. This was written under Red Hat 5-something, but is currently running on a RHEL5.1 paravirtualized system. Perl gurus, please forgive the code... #/usr/bin/perl -w # # use bytes; use Device::SerialPort; time_str(); $LOGDIR = "/var/log/phonelog"; # path to data file $LOGFILE = "$ymd.csv"; # file name to output to $PORT = "/dev/ttySI0"; # port to watch # # # Serial Settings # # $ob = Device::SerialPort->new ($PORT) || die "Can't Open $PORT: $!"; $ob->baudrate(9600) || die "failed setting baudrate"; $ob->parity("none") || die "failed setting parity"; $ob->databits(8) || die "failed setting databits"; $ob->stopbits(1) || die "failed setting stopbits"; $ob->handshake("none") || die "failed setting handshake"; $ob->stty_icrnl(1) || die "failed setting convert cr to new line"; $ob->write_settings || die "no settings"; # # open the logfile, and Port # open(LOG,">>${LOGDIR}/${LOGFILE}") ||die "can't open smdr file $LOGDIR/$LOGFILE for append: $!\n"; open(DEV, "+<$PORT") || die "Cannot open $PORT: $_"; # # Loop forver, logging data to the log file # while($_ = <DEV>){ # print input device to file $phone_line=substr($_,1); # Chomp leading LF $phone_line=~ s/\|/\,/g; # Convert pipe to comma time_str(); print LOG "$fulldate,$phone_line" ||die "can't print to $LOGDIR/$LOGFILE: $!\n"; } undef $ob; ### Subroutines: sub time_str { my($sec, $min, $hour, $mday, $mon, $year, $junk); ($sec, $min, $hour, $mday, $mon, $year, $junk) = localtime(time()); $fulldate=sprintf("%02d-%02d-%04d", $mon+1, $mday, $year + 1900); $ymd=sprintf("%04d_%02d", $year + 1900, $mon+1); } -- tim boyer tim(a)denmantire.com
|
Pages: 1 Prev: Log Message - DHCP server Next: XEN and virt-manager on RedHat 5.1 |