capturing serial input

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: sinck@ugive.comsinckugive.com
Date:  
Subject: capturing serial input

\_ I may have asked this before, but I'm not sure
\_ if I got anything out of it..........
\_
\_ I have a phone system to which I have a line
\_ attached to com1 on one of my debian boxes.
\_ Once I set the baud, blah, blah, I can open
\_ minicom and capture the input from this port
\_ to a file. Problem is, minicom will only
\_ write to the file once a buffer is filled.
\_
\_ What I would really like is some simple command
\_ line that can read the input and I can redirect
\_ this to a file.
\_
\_ Anyone have any tips here?

YMMV, this code stripped down and untested:

#!/usr/bin/perl -w

use Device::SerialPort qw( :PARAM :STAT 0.07);
use vars qw ($portdevice $configfile $po $count);


#
# the name of the port device
$portdevice = "/dev/modem";

#
# configuration file
$configfile = "/tmp/modem.cfg";

#
# config the 'modem' one hopes...
#
sub config
{

my $portobj = new Device::SerialPort($portdevice);
$portobj->user_msg(1);
$portobj->error_msg(1);
$portobj->devicetype('modem');
$portobj->hostname('localhost');
$portobj->datatype('raw');
$portobj->cfg_param_1('none');
$portobj->cfg_param_2('none');
$portobj->cfg_param_3('none');

$portobj->baudrate(9600);
$portobj->databits(8);
$portobj->parity('none');
$portobj->stopbits(1);

$portobj->save($configfile);

return($portobj);
}


$po = &config;

$count = 2500; # make sure it doesn't go hog wild at first

open FH, "> leaky";
my $oldfh = select(FH); $| = 1; select($oldfh); # Magic

while ($count--)
  {
    my $line = $po->input;  # this may or may not be a blocking read
    print FH $line if ($line);
  }


close FH;
undef $po;

# David