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

Hi, I hope many of the monks worked on Win32::Serialport. I am using Win32::Serialport (Novice to working with such prots) to receive data. Is there any way to find whether the complete data received or not from the serial port? Also after receiving the data i want to flush the serialport, is there any specific method for this . Pls help me out with your suggestions....

Replies are listed 'Best First'.
Re: win32::serial port
by lostjimmy (Chaplain) on Oct 29, 2008 at 14:44 UTC

    What moritz has said is correct.

    In my experience the best way to deal with serial communications is to formulate a protocol that both sides of the line will follow. Usually this involves having a fixed message size or ending the message with a terminating character (such as a CR). Also, it is common to have a checksum of the bytes embedded in the message. As long as both parties agree and there isn't too much noise on the line, it should work.

    As for the Win32::SerialPort module, it looks to be very outdated, the interface isn't very good, and the examples are somewhat complicated. I also didn't see anything having to do with flushing.

      the interface isn't very good

      How so? It uses the standard Perl IO interface (print $comm $data;) and some setters/getters to set/query communication settings.

      I also didn't see anything having to do with flushing.

      Why would expect it to be buffered?

        How so?
        I guess I would want something a little more akin to IO::Socket::Inet. Otherwise, it's fine.
        Why would expect it to be buffered?
        I did not expect it to be buffered, but it was asked in the question how one could flush the serial port. Usually what I've seen is that people want to flush the rx buffer to get rid of any remaining bytes after reading the current message.
Re: win32::serial port
by moritz (Cardinal) on Oct 29, 2008 at 08:50 UTC
    My very limited understand of the serial port is that it's a mechanism to transmit an endless stream of bytes.

    If that's the case it has never received the complete data, unless you have a protocol on top of it that tells you that it's finished.

Re: win32::serial port
by Anonymous Monk on Jul 15, 2013 at 01:25 UTC
    $Win32SerialObject->lookclear;
    $Win32SerialObject->purge_all;