Hi,
I am writing a PERL GUI application that need to use the Win32::SerialPort
module. I have no problem of read and display information on a command
prompt window. But when I tried to write to a file with the information
that I'd read from the serial port, I got this control characer "^M" inside
the file and the line was very long. There are several examples and manual
how to use the Win32::SerialPort in internet, but they are not helping me
much. I am just wondered if anyone has experience with module or know how
fix the problem, please show me.
Below is the code:
use Win32::SerialPort;
$PortObj = new Win32::SerialPort ('COM1')
|| die "Can't open $PortName: $^E\n";
$flowcontrol = $PortObj->handshake("none");
$baudrate = $PortObj->baudrate(38400);
$parity = $PortObj->parity("none");
$databit = $PortObj->databits(8);
$stopbit = $PortObj->stopbits(1);
$PortObj->write_settings || undef $PortObj;
print "Can't change Device_Control_Block: $^E\n" unless ($PortObj);
open(LOG,">test.log");
Loop:
$input = $PortObj->input;
if ($input ne "") {
print "$input";
print LOG "$input";
}
goto Loop;
Thanks in advance.
Khoa D.
|