Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found