fsonnichsen has asked for the wisdom of the Perl Monks concerning the following question:

I am assuming the Object Oriented technique for serial is the preferred method with PERL now? For the OO serial methods under Device::SerialPort, can someone tell me the difference between: $PortObj->input and $PortObj->read Blocked, unblocked? Byte read vs line read etc? A better answer--is this documented somewhere? Thanks! Fritz

Replies are listed 'Best First'.
Re: Serial port - "input" vs "read"
by haukex (Archbishop) on Jun 29, 2017 at 19:11 UTC

    Device::SerialPort has the advantage that it provides an extra layer of abstraction, and porting to Windows is easier (Win32::SerialPort). However, if you know your application is staying on a *NIX system, then personally my preference is to do away with that extra layer of abstraction and work with a more native API - I wrote about that here: Lower-Level Serial Port Access on *NIX.

    I've used both Device::SerialPort and IO::Termios to write serial loggers - the former here, the latter here (which uses this helper module - warning, not yet really production ready), plus a POE-based logger/server here (again, it's just a beta, although so far it seems to have been running well).

    Anyway, as for your question, the docs seem to say that ->input is nonblocking, and ->read is AFAIK blocking. (The indeed somewhat lacking documentation is another reason I prefer the lower-level approach, with IO::Select and similar it is more clear to me what is going on.)

Re: Serial port - "input" vs "read"
by jmlynesjr (Deacon) on Jun 29, 2017 at 17:45 UTC

    Look at Device::SerialPort on CPAN - www.cpan.org. You may have to look through the code. It seems one call reads a line and one reads a requested number of characters.

    James

    There's never enough time to do it right, but always enough time to do it over...

Re: Serial port - "input" vs "read"
by dasgar (Priest) on Jun 29, 2017 at 19:05 UTC

    In doing a super quick scan of Device::SerialPort, I didn't see documentation on those methods. Since the module is described as "Linux/POSIX emulation of Win32::SerialPort functions", I did a super quick scan of Win32::SerialPort, but again didn't find much. Perhaps my super quick scans were too fast and I overlooked the information.

    If you're ok with adding a layer of abstraction, you could check out Control::CLI, which will use Win32::SerialPort or Device::SerialPort for serial port communication. It's read and readwait methods are definitely documented.

    I'm not necessarily advocating using Control::CLI over directly using Device::SerialPort. Just tossing out a suggestion on another module that you might find easier to use in your code.

      Thanks all for the responses. I have tried the other methods that you mentioned but probably did not play with them enough. At present I get "stale" data returns even thought I have -icanon set via a system call to stty (e.g. I am running in non canonical mode). I would have thought that in this mode the buffer is continuously flushed but it apparently is not even if I wait several seconds before a read. I have to "read down" the buffer to get the most recent data. I will try again with the other methods mentioned. fritz