Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: issues reading from serial port

by PodMaster (Abbot)
on Aug 06, 2005 at 09:31 UTC ( [id://481463]=note: print w/replies, xml ) Need Help??


in reply to issues reading from serial port

The documentation says:
Because all the tied methods block, they should ALWAYS be used with timeout settings and are not suitable for background operations and polled loops. The sysread method may return fewer characters than requested when a timeout occurs. The method call is still considered successful. If a sysread times out after receiving some characters, the actual elapsed time may be as much as twice the programmed limit. If no bytes are received, the normal timing applies.
Timeouts are also discussed further down in the documentation. They are also used in some of the demos. Good luck.

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^2: issues reading from serial port
by EvanK (Chaplain) on Aug 06, 2005 at 20:45 UTC
    Ah! i can't believe I missed the answer and it was IN the documentation! I'm so ashamed...What can i say, it was a very long workday. ::shrugs apologetically::

    UPDATE: ok, this is kind of wierd, it seems that everything is blocked from printing in the main loop until I ctrl+c, after which it all prints out and dumps back to command line.
    while($EXIT == 0) { $temp = pollForData(); print $temp; print LOG $temp; sleep(1); }
    however, if i print the returned data and include something else within the same print command, it works fine.
    while($EXIT == 0) { $temp = pollForData(); print "$temp\n"; print LOG $temp; sleep(1); }
    the thing is, i don't want to print the data every iteration through the loop, but otherwise NOTHING at all happens until i ctrl+c...OH, almost forgot. the pollForData sub:
    sub pollForData { my($length,$buffer); # Poll controller to send any pending data (if there is none, # it will send back a 'RES' control character print SERIAL $IM{'POL'}; $upstream++; # read in $BUFFER amount of bytes $length = read(SERIAL,$buffer,$BUFFER); # update num of bytes received so far $downstream += $length; # return data return $buffer; }

    __________
    Give a man a match and he'll be warm for an hour. Set him on fire and he'll be warm for the rest of his life.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://481463]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found