Page 1 of 1

Log serial port with Mikrotik?

Posted: Mon Nov 28, 2005 6:37 pm
by gosha
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?

Posted: Tue Nov 29, 2005 12:45 am
by jurisv
you can youse linux and this perl script:
#!/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);                                                                                                                  
    }                                                                                                                               
                                                                                                                                    
}                                                                                                                                   
But MT could do it, that was greate due routerboard size :)

Posted: Tue Nov 29, 2005 9:36 pm
by gosha
yes, i can use linux for it but I don't want to place another comp for it. Is it possible to do it with linux or not?