Dear Monks!

I am desparately trying to connect to a serial port. However whatever I do, it simply walks through my <FH> or $PortObj->input statements. Currently I am testing between 2 PCs using perl on one end, Teraterm on the other

Just for completeness: This is perl 5, version 16, subversion 1 (v5.16.1) built for MSWin32-x64-multi-thread (strawberry perl) OS is WinXP 32bit SP3

This is my script:

use Win32::SerialPort qw( :STAT 0.19 ); use Convert::ASCIInames; use String::HexConvert ':all'; #use strict; $PortName = "COM1"; $Configuration_File_Name = "Serial_Settings.cfg"; $PortObj = new Win32::SerialPort ($PortName, $quiet) || die "Can't open $PortName: $^E\n"; # $quiet is optional #$PortObj->user_msg(1); $PortObj->databits(8); $PortObj->baudrate(115200); $PortObj->parity("none"); $PortObj->stopbits(1); $PortObj->handshake("none"); $PortObj->buffers(4096, 4096); $PortObj->are_match("\n"); # possible end strings $PortObj->read_interval(100); # max time between read char (millise +conds) $PortObj->read_char_time(5); # avg time between read char $PortObj->read_const_time(100); # total = (avg * bytes) + const $PortObj->write_char_time(5); $PortObj->write_const_time(100); $PortObj->write_settings || undef $PortObj; $PortObj->save($Configuration_File_Name); $PortObj->close || die "close failed"; undef $PortObj; #--------------------------------------------------------- $PortObj = tie (*FH, 'Win32::SerialPort', $Configuration_File_Name) || die "Can't tie: $^E\n"; $PortObj->are_match("\n","\r"); # possible end strings $PortObj->write_settings || undef $PortObj; $PortObj->lookclear; # empty buffers sleep 5; print FH "Enter string:\n"; # works well my $out = <FH>; # shouldn't this be blocking? print "$out\n"; print FH "Enter another string:\n"; # works well my $out = <FH>; # shouldn't this be blocking? print "$out\n"; close FH || warn "close failed"; ## CLOSE ## undef $PortObj; untie *FH; ## DESTROY ##

Whats the problem? I sometimes receive the right chars from serial port, but seldom all. The expected behavior is that the script waits at <FH> for an input with enter. Instead it just goes through. If I put the <FH> ito a loop then I can randomly catch my input.

I am using the native RS232, but I saw similar behavior with Win7 and USB a serial adapter. Any hints? Please save my strong believe into Perl :-)

Cheers and thanks, Archie


In reply to Win32::SerialPort is not blocking by Archimedeus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.