G
gluphus
1. I am using Win32::SerialPort to communicate with an MCU.
My Win32::SerialPort will hang when it tries to read a 0 from the MCU
using
the following snippet of code:
my $pkt = 0x00;
print "$app_name|S|$pkt\n";
$PortObj->lookclear;
$PortObj->write($pkt);
$waitstr = waitfor(1);
$waitstr=~s/\n|\r//g;
print "$app_name|$ctime|->got back $waitstr\n";
$PortObj->lookclear;
which calls:
sub waitfor {
my $timeout=$PortObj->get_tick_count + (1000 * shift);
$PortObj->lookclear; # clear buffers
my $gotit = "";
for (; {
return unless (defined ($gotit = $PortObj->read(1)));
if ($gotit ne "") {
my ($found, $end) = $PortObj->lastlook;
return $gotit.$found;
}
return if ($PortObj->reset_error);
return if ($PortObj->get_tick_count > $timeout);
}
}
2. Also, often when it rcvs a buffer of text, it will omit the 0 when
processing to STDOUT
(it seems like it is ignoring or processing the 0's as some sort of
null char) using the following code:
RC1: while ($tmout > 0) {
my ($cnt,$saw)=$PortObj->read(255);
if ($cnt>0) {
$chars+=$count;
$ret_buffer.=$saw;
if ($ret_buffer=~/EOT/ ) {
.....
Can someone tell me what needs to be done to properly process the
0/null char within Serial Port?
My Win32::SerialPort will hang when it tries to read a 0 from the MCU
using
the following snippet of code:
my $pkt = 0x00;
print "$app_name|S|$pkt\n";
$PortObj->lookclear;
$PortObj->write($pkt);
$waitstr = waitfor(1);
$waitstr=~s/\n|\r//g;
print "$app_name|$ctime|->got back $waitstr\n";
$PortObj->lookclear;
which calls:
sub waitfor {
my $timeout=$PortObj->get_tick_count + (1000 * shift);
$PortObj->lookclear; # clear buffers
my $gotit = "";
for (; {
return unless (defined ($gotit = $PortObj->read(1)));
if ($gotit ne "") {
my ($found, $end) = $PortObj->lastlook;
return $gotit.$found;
}
return if ($PortObj->reset_error);
return if ($PortObj->get_tick_count > $timeout);
}
}
2. Also, often when it rcvs a buffer of text, it will omit the 0 when
processing to STDOUT
(it seems like it is ignoring or processing the 0's as some sort of
null char) using the following code:
RC1: while ($tmout > 0) {
my ($cnt,$saw)=$PortObj->read(255);
if ($cnt>0) {
$chars+=$count;
$ret_buffer.=$saw;
if ($ret_buffer=~/EOT/ ) {
.....
Can someone tell me what needs to be done to properly process the
0/null char within Serial Port?