I'm trying to adapt Bruce Garlock's logger.pl code example to log call records from an old NEC NEAX 2400 PBX on a PC running Linux. These records are terminated by <Ctrl-C> rather than <CR> or <LF>. The script replaces the <Ctrl-C> with a newline when it logs it.

I've tried using the Device::SerialPort setting "$ob->is_tty_eol(3)" to set the end-of-line character on the port but it appears to have no effect. (Am I mistaken about its intended function?)

I test the script by executing it in background and use "tail -f /var/log/router.log" to monitor records as they arrive. Data in the format "record1<Ctrl-C>record2<Ctrl-C>" will not show up until a newline character is written to the serial port by the remote device. (I'm emulating the NEC by sending a test data file from a Linux laptop, so that's how I'm able to force the newline character to the port.) As soon as the newline character is received, the buffered records are logged properly to the file as:

record1
record2

Is there a way to release each buffered record as soon as the <Ctrl-C> EOL character is seen? In actual usage, I can't force a newline character from the NEC PBX to release the buffer.

For this application, I'm using perl 5.8.0, Device::SerialPort 0.22, and Linux kernel 2.4.20.
#!/usr/bin/perl # # # Author: Bruce S. Garlock # Date: 2002-09-11 # Requirements: Device::SerialPort 0.12 (from cpan) # # Modifications: # # jabo 4/20/2005 Hardcode port settings for /dev/ttyS0 # and insert ^C to newline conversion. # Attempt to make ^C the EOL character. # # Version: 0.1 # # # Description: This perl script is for logging of data from a serial # port, to a specified logfile. The logfile can then be parsed with # other programs for reporting purposes. # # This program was written for specifically logging Multitech's # MTASR2-203 T1 Router. The router outputs text to the command # port with 57.6k, 8-1-N, and No flow control. # # use Device::SerialPort 0.12; $LOGDIR = "/var/log"; # path to data file $LOGFILE = "router.log"; # file name to output to $PORT = "/dev/ttyS0"; # 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(7) || die "failed setting databits"; $ob->handshake("none") || die "failed setting handshake"; $ob->is_stty_eol(3) || die "failed to set eol"; $ob->write_settings || die "no settings"; # # Send a string to the port # # #$pass=$ob->write("AT"); #sleep 1; # # open the logfile, and Port # open(LOG,">>${LOGDIR}/${LOGFILE}") ||die "can't open smdr file $LOGDIR/$LOGFILE for append: $SUB $!\n +"; open(DEV, "<$PORT") || die "Cannot open $PORT: $_"; select(LOG), $| = 1; # set nonbufferd mode # # Loop forver, logging data to the log file # while($_ = <DEV>){ # print input device to file s/\003/\012/g; # convert ^C to newline print LOG $_; } undef $ob;

In reply to How can I log a record with Ctrl-C as EOL from a serial port? by jabo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.