duuchung
November 16th, 2007, 02:58 AM
I am not a programmer. I only know a little programming. My inventor friend asks me to capture data in a file from a test board device connected to the serial port. He wants to use the captured data for further processing.
I found http://ubuntuforums.org/showthread.php?t=432.
I installed Device-SerialPort-1.002 with a bit of hard work.
I read Bill Birthsiel's article, Controlling Modems with Win32::SerialPort.
I connected my friend's test board with the serial interface of my Linux ubuntu.
I played with example1.txt, example4.txt and example5.txt. I set the baud rate to 4800 in example4.txt. I input ASCII numbers into the test board with example5.txt. I read the output of example5.txt in the LCD panel which displayed the numbers I had keyed into the test board.The test board device has been properly connected to my PC and there are signals passing.
I found Bruce Garlock's article, Log Serial Port Data to a Specified Logfile, from the internet.I added Birthsiel's example5.txt with Garlock's logger.pl. The new file does not work. Nothing was sent to the log file. There is something missing. I need help. Can any guru please help me?
example4sve.pl
#!/usr/bin/perl -w
# cross-platform example4
#use strict;
use vars qw( $OS_win $ob $port );
BEGIN {
$OS_win = ($^O eq "MSWin32") ? 1 : 0;
if ($OS_win) {
eval "use Win32::SerialPort";
die "$@\n" if ($@);
}
else {
eval "use Device::SerialPort";
die "$@\n" if ($@);
}
} # End BEGIN
$LOGDIR = "/var/log"; # path to data file
$LOGFILE = "serial.log"; # file name to output to
if ($OS_win) {
$port = '/dev/ttyS0';
$ob = Win32::SerialPort->new ($port);
}
else {
$port = '/dev/ttyS0';
$ob = Device::SerialPort->new ($port);
}
die "Can't open serial port $port: $^E\n" unless ($ob);
$ob->user_msg(1); # misc. warnings
$ob->error_msg(1); # hardware and data errors
$ob->baudrate(4800);
$ob->parity("none");
## $ob->parity_enable(1); # for any parity except "none"
$ob->databits(8);
$ob->stopbits(1);
$ob->handshake('rts');
$ob->write_settings;
####new
#
# Send a string to the port
#
#
#$ob->write("AT");
$ob->write("ATE0X4\r");
sleep 1;
#
# 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: $_";
select(LOG), $| = 1; # set nonbufferd mode
#
# Loop forver, logging data to the log file
#
while($_ = <DEV>){ # print input device to file
print LOG $_;
}
undef $ob;
I added Birthsiel's example5.txt with Garlock's logger.pl. The new file does not work. Nothing was sent to the log file.
I found http://ubuntuforums.org/showthread.php?t=432.
I installed Device-SerialPort-1.002 with a bit of hard work.
I read Bill Birthsiel's article, Controlling Modems with Win32::SerialPort.
I connected my friend's test board with the serial interface of my Linux ubuntu.
I played with example1.txt, example4.txt and example5.txt. I set the baud rate to 4800 in example4.txt. I input ASCII numbers into the test board with example5.txt. I read the output of example5.txt in the LCD panel which displayed the numbers I had keyed into the test board.The test board device has been properly connected to my PC and there are signals passing.
I found Bruce Garlock's article, Log Serial Port Data to a Specified Logfile, from the internet.I added Birthsiel's example5.txt with Garlock's logger.pl. The new file does not work. Nothing was sent to the log file. There is something missing. I need help. Can any guru please help me?
example4sve.pl
#!/usr/bin/perl -w
# cross-platform example4
#use strict;
use vars qw( $OS_win $ob $port );
BEGIN {
$OS_win = ($^O eq "MSWin32") ? 1 : 0;
if ($OS_win) {
eval "use Win32::SerialPort";
die "$@\n" if ($@);
}
else {
eval "use Device::SerialPort";
die "$@\n" if ($@);
}
} # End BEGIN
$LOGDIR = "/var/log"; # path to data file
$LOGFILE = "serial.log"; # file name to output to
if ($OS_win) {
$port = '/dev/ttyS0';
$ob = Win32::SerialPort->new ($port);
}
else {
$port = '/dev/ttyS0';
$ob = Device::SerialPort->new ($port);
}
die "Can't open serial port $port: $^E\n" unless ($ob);
$ob->user_msg(1); # misc. warnings
$ob->error_msg(1); # hardware and data errors
$ob->baudrate(4800);
$ob->parity("none");
## $ob->parity_enable(1); # for any parity except "none"
$ob->databits(8);
$ob->stopbits(1);
$ob->handshake('rts');
$ob->write_settings;
####new
#
# Send a string to the port
#
#
#$ob->write("AT");
$ob->write("ATE0X4\r");
sleep 1;
#
# 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: $_";
select(LOG), $| = 1; # set nonbufferd mode
#
# Loop forver, logging data to the log file
#
while($_ = <DEV>){ # print input device to file
print LOG $_;
}
undef $ob;
I added Birthsiel's example5.txt with Garlock's logger.pl. The new file does not work. Nothing was sent to the log file.