Hi there. I tried thousand ways the last weeks and I am desparing.
I need to write and read to /dev/ttyUSB0 where a infrared head is attached to read an electric meter.

The settings are 300 baud 7E1, no handshake
If I do this from shell in that way:
1. cat /dev/ttyUSB0&amp 2. stty -F /dev/ttyUSB0 300 -parodd cs7 -cstopb parenb -ixoff -crtscts + -hupcl -ixon -opost -onlcr -isig -icanon -iexten -echo -echoe -echoc +tl -echoke 3. echo -n -e '\x2F\x3F\x21\x0D\x0A' > /dev/ttyUSB0 4. echo -n -e '\x06\x30\x30\x30\x0D\x0A' > /dev/ttyUSB0
I get an answer as expected:

/LOG4LK13BD202015 C.1.0(06091772) 0.0.0(001LOG0006091772) F.F(0000) 1.8.0(021183.342*kWh) C.7.1(00000000) C.7.2(00000001) C.7.3(00000002) 0.2.1(ver.02, 150228, 671A) C.2.1(1510121019) C.2.9(1510121019)

Now I try to realize in perl to catch this output but all ways I have gone, nothing comes back to perl.
Only using Device::SerialPort I receive the first line "/LOG4LK13BD202015" but not more.

One of many examples:

open( com, "+&lt;","/dev/ttyUSB0" ) || die "Cannot open serial port : +$!\n"; my $raw = "\x2F\x3F\x21\x0D\x0A"; print com $raw; my $raw = "\x06\x30\x30\x30\x0D\x0A"; print com $raw; while( 1 ) { my $in = <com&gt;; print "$in\n"; }
gives me:
/?! 000 /LOG4LK13BD202015
Finish!

I tried system calls in different way, different ways to open an file handle on the device, some perl modules - nothing worked for me.
Has anyone an idea or realized something like that in the past and can give me some help?

2019-05-28 Athanasius added code tags


In reply to r/w attached infrared head on /dev/ttyUSB0 by stoerti

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.