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

Greetings Fellow Monks,
I have worked on Win32::SerialPort for more than 2 months. But I'm having some trouble.
When I get data from FH(The COM1 Handle) with $binData = getc FH; or sysread(FH, $binData, 1);, I cannot get right data. "0A" always chenged into "0D0A". Then I get more data than sent by COM. How can I get the right data?
If anyone could provide some advice would be greatly appreciated.

Thank you for your time and trouble

Replies are listed 'Best First'.
Re: How to get right data from COM1 using Win32::SerialPort
by BrowserUk (Patriarch) on Mar 21, 2006 at 10:12 UTC

    Have you tried binmode FH; before reading?...see binmode for details.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks for your attention. My code is as follow:
      #initial SerialPort to $configurationFileName; $portCom1 = tie (*FH, 'Win32::SerialPort', $configurationFileName) || +die "Can't tie: $^E\n";
      I have tried binmode as "binmode (FH);" But error: Can't locate object method "BINMODE" via package "Win32::SerialPort"...
      br> BTW, "Ports are opened for binary transfers. A separate binmode is not needed." (From http://members.aol.com/Bbirthisel/SerialPort.html or CPAN)

      Then what should I do?
        Any other suggestion? Thanks!