Hi!
I need to make a PBX's CDR log. Is it possible to simply write everything that came from Serial port to some text file on HDD?
#!/usr/bin/perl
#
# Serial port data receiver (logger)
# Receives at any speed without data loss and uses practicaly no CPU
use Device::SerialPort;
use Time::HiRes "usleep";
my $port = '/dev/ttyS0';
my $ob = Device::SerialPort->new ($port);
$baud = '2400';
$parity = 'none';
$data = '7';
$stop = '1';
$hshake = 'none';
$ob->baudrate($baud) || die "fail setting baud";
$ob->parity($parity) || die "fail setting parity";
$ob->databits($data) || die "fail setting databits";
$ob->stopbits($stop) || die "fail setting stopbits";
$ob->handshake($hshake) || die "fail setting handshake";
# Open the file where all data will be logged
open(LOG, ">>/opt/logger/logs/logfile.log") || die "Cannot open logfile";
# Nonbuffered output to file !
select(LOG), $| = 1;
# Endless loop
while (1)
{
# Get data from serial port
$stream = $ob->input;
# If the variable contains data, process it else sleep
if ($stream)
{
print LOG $stream;
}
else
{
usleep(1);
}
}