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

Discussion in 'Perl Misc' started by gluphus, Sep 1, 2006.

  1. gluphus

    gluphus Guest

    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?
    gluphus, Sep 1, 2006
    #1
    1. Advertising

  2. gluphus

    Joe Smith Guest

    gluphus wrote:
    > 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
    Joe Smith, Sep 2, 2006
    #2
    1. Advertising

  3. gluphus

    gluphus Guest

    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...

    Joe Smith wrote:
    > gluphus wrote:
    > > 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
    gluphus, Sep 2, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lovecreatesbeauty
    Replies:
    1
    Views:
    1,012
    Ian Collins
    May 9, 2006
  2. Stephan Kämper

    ruby-serialport on Win32

    Stephan Kämper, Feb 3, 2004, in forum: Ruby
    Replies:
    9
    Views:
    180
    Stephan Kämper
    Feb 6, 2004
  3. Stephan Kämper

    Usability of Ruby/SerialPort on Win32

    Stephan Kämper, Feb 10, 2004, in forum: Ruby
    Replies:
    0
    Views:
    112
    Stephan Kämper
    Feb 10, 2004
  4. Richard S Beckett

    Problem installing Win32::SerialPort

    Richard S Beckett, Jul 7, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    371
    Richard S Beckett
    Jul 7, 2003
  5. Schmigz

    win32::SerialPort; Sending Raw Data

    Schmigz, Jan 26, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    284
    Schmigz
    Jan 26, 2004
Loading...

Share This Page