Hello,

I am trying to use an RS232 port (via FTDI on USB) and have unexpected trouble: Perl complains that the port is blocked since it has to wait for RLSD(DCD). I spent hours in the Internet to find and try solutions ... but no luck. I even soldered a bridge between DTR and DCD, set DTR to active, and could confirm the physical level change ... still a blocked port.

Here's what I do:

#!/usr/bin/perl require 5.003; use English; use strict; use Win32::SerialPort qw(:PARAM :STAT ); use Win32API::CommPort qw( :RAW :PARAM :STAT 0.20 ); $OUTPUT_AUTOFLUSH=1; my $BlockingFlags; my $buffer; my $Configuration_File_Name='c:\\temp\\tty-conf.txt'; my $count_in; my $count_out; my $flowcontrol; my $InBytes; my $LatchErrorFlags; my $OutBytes; my $quiet=1; my $PortObj; my $string_in; $PortObj = new Win32::SerialPort ('COM3', $quiet)|| die "Can't open CO +M Port: $^E\n"; # $quiet is optional $buffer = $PortObj->can_rlsd_config; print("RLSD_CONF: >$buffer<\n"); $PortObj->baudrate(9600); $PortObj->parity("none"); $PortObj->databits(8); $PortObj->stopbits(1); $PortObj->handshake("none"); # set parameter $PortObj->dtr_active(1); $PortObj->buffers(4096, 4096); # read, write $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->debug(1); $PortObj->stty("-icanon"); # disable eof, erase and kill char, Unix +-style $PortObj->write_settings||undef($PortObj); $PortObj->save($Configuration_File_Name); $flowcontrol = $PortObj->handshake; # current value (scalar) print("HS: >$flowcontrol<\n"); ($BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags) = $PortObj->st +atus|| warn "could not get port status\n"; print("BF: >$BlockingFlags<\n"); warn "Port is blocked" if ($BlockingFlags!=0); if ($BlockingFlags & BM_fXoffHold) { warn "Waiting for Xoff"; } if ($BlockingFlags & BM_fDsrHold) { warn "Waiting for DSR"; } if ($BlockingFlags & BM_fRlsdHold) { warn "Waiting for Rlsd"; } if ($BlockingFlags & BM_fCtsHold) { warn "Waiting for CTS"; } if ($LatchErrorFlags & CE_FRAME) { warn "Framing Error"; } $buffer=ClearCommError($PortObj, 65535, 0); $count_out = $PortObj->write('TEST'); warn "write failed\n" unless ($count_out); warn "write incomplete\n" if ( $count_out != 4 ); # Bridging TXD and RXD should put 'TEST' into the reveive buffer ($count_in, $string_in) = $PortObj->read($count_out); warn "read unsuccessful\n" unless ($count_in == $count_out); print("RX: >$string_in<\n"); undef $PortObj; exit;
The result is:
RLSD_CONF: >64< HS: >none< Blocking Bits= 0 Input Queue= 0 Output Queue= 0 Latched Errors= 0 ok= 1 BlockingFlags= 0 Error_BitMask= 0 BF: >4< RX: >< Destroying \\.\COM3 Port is blocked at P:/tools/perl/test-serial-monk.pl line 50. Waiting for Rlsd at P:/tools/perl/test-serial-monk.pl line 53. write failed write incomplete Use of uninitialized value $wanted in numeric gt (>) at C:/progs/Perl6 +4/site/lib/Win32/SerialPort.pm line 1212. Closing Win32::SerialPort=HASH(0x60c580) COM3 at P:/tools/perl/test-se +rial-monk.pl line 66.
Any clues? Platform: Windows 7 (can't use Linux at this application).

In reply to Perl on Windows insists on waiting for serial port's RLSD(DCD) by UltraDMA

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.