lookfor failure in SerialPort

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am using Win32::SerialPort 0.19 and am having trouble getting the
lookfor to work. My understanding is that lookfor(1) should sit and wait
to read one character coming inbound on my serial port.

This is the sub that wraps the lookfor:
sub waitfor {
     my $debug = 'y';
     $ob->lookclear;  # clear buffers
     my $gotit = "";
     my $response = shift;
     print "DEBUG: Waiting for \"$response\".\n" if $debug;

     for (;;) {
         return unless (defined ($gotit = $ob->lookfor(1)));
         if ($gotit ne "") {
             my ($match, $after, $pattern) = $ob->lastlook;
             print "DEBUG: Got .\"$gotit$match$after\".\n" if $debug;
             return $match;
         return if ($ob->reset_error);

This is some of the context in which it is called:
while ($in) {
     $loc = $ob->read(1);
     if ($loc) {
    # do stuff
     } else {
    $ob->write(chr(05));        # send <ENQ>
    waitfor(chr(06)) or die;    # wait for <ACK>
    ...send next piece etc

This is the output I get from the sub and the die:

DEBUG: Waiting for "?".
Died at C:\horiba_pentra60Cplus.pl line 259, <UPLOAD> line 2.
         (in cleanup) Can't call method "Call" on an undefined value at
C:/Perl/site/lib/Win32API/CommPort.pm line 211, <UPLOAD> line 2 during
global destruction.

Outbound and inbound communications are working otherwise. I am using
Portmon and it indicates that the chr(05) goes out successfully, there
is one read on the port which returns with length of 0 and then the port

Troubleshooting help or any advice greatfully received.


Re: lookfor failure in SerialPort

Spin wrote:
Quoted text here. Click to load it

Actually, the most effective way to use lookfor in conjunction with a
serial connection is to make sure that the machine at the far end of the
  cable is turned on. There are, indeed, some disadvantages to


Site Timeline