Win32::SerialPort null char/0 RX/TX issue

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?
 
J

Joe Smith

gluphus said:
my $pkt = 0x00;

That is the same as
my $pkt = 0;
which is not the same as
my $pkt = "\0";
or
my $pkt = "\x00";

Try again after using a proper NULL character.
-Joe
 
G

gluphus

Joe,

Thanks.

Any idea on how I can get the Perl rcving side to actually read and
process the 0 that comes across from the MCU?

I was looking at the ignore_null, but cannot find any info on it or
others...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top