Hi Monks,
I try to communicate with a serial device which should return 17 bytes if I send the command 0x11 0x00.
But this works only if I put a sleep between the write and read command.
Without sleep the read function return zero bytes. I also tried lookfor instead of read, but this did also not work.
How can I block during read/lookfor until I received all bytes?
#!/usr/local/bin/perl -w use Device::SerialPort; use strict; $|=1; my %ergoCommands; ## initialize serial port my $portname="/dev/ttyS0"; my $port = new Device::SerialPort ($portname); $port->user_msg("ON"); $port->databits(8); $port->baudrate(4800); $port->parity("none"); $port->stopbits(1); $port->handshake("xoff"); $port->write_settings() || undef $port; my $count_out = $port->write("\x40\x0"); warn "command failed:$_[0]\n" unless ($count_out eq length($cmddata)); ## I don't want to go asleep :( ##sleep(1); ## hmm.. does not block ($real_in, $data_in) = $port->read(17);

MP


In reply to read does not block by Monky Python

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.