Professional Web Applications Themes

lookfor failure in SerialPort - PERL Modules

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; $ob->are_match($response); 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); ...

  1. #1

    Default lookfor failure in SerialPort

    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;
    $ob->are_match($response);
    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
    closes.

    Troubleshooting help or any advice greatfully received.

    Regards,
    Spin
    Spin Guest

  2. #2

    Default Re: lookfor failure in SerialPort

    Spin wrote:
    >
    > Troubleshooting help or any advice greatfully received.
    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
    telecommuting...

    Spin
    Spin Guest

Similar Threads

  1. Loopback with Device::SerialPort?
    By Eric Schwartz in forum PERL Modules
    Replies: 0
    Last Post: March 18th, 07:24 PM
  2. Serialport Read question
    By Spin in forum PERL Modules
    Replies: 1
    Last Post: October 28th, 05:56 PM
  3. SerialPort write question
    By Spin in forum PERL Modules
    Replies: 0
    Last Post: October 28th, 04:52 PM
  4. Need help with Win32::SerialPort
    By shahriar in forum PERL Modules
    Replies: 1
    Last Post: August 13th, 02:54 PM
  5. Win32::SerialPort to log file
    By perlrw@comcast.net in forum PERL Beginners
    Replies: 3
    Last Post: December 15th, 05:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139