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

Good morning to all who are in the monastery!!

Fellow Monks, I need some assistance with a Win32::SerialPort issue that is driving me nuts. I can write to the serial device all day long and it works just fine. In fact, I have written my script completely to do what I need to do with configuring my serial device from the "write" perspective. However, reading from the device doesn't appear to be working at all like I expect it to work. When I login to the device through PuTTY, this is what I see...

Welcome to the MRV Communications' LX Series Server Port 0 Speed 9600 Login: InReach Password: ******** { screen refresh and blank, then } InReach:0 >

This is what I expect to see when I run my script against the device, but it's not. I pulled the relevant pieces of my script out into a separate test script and have been playing around with "read" and "input". Here is my code:

#!C:/Perl/bin/perl.exe use warnings; use strict; use Win32::SerialPort; my $response; my $port = Win32::SerialPort->new("COM1"); $port->user_msg(1); $port->error_msg(1); $port->baudrate(9600); $port->databits(8); $port->parity("none"); $port->stopbits(1); $port->handshake("xoff"); $port->buffers(8192, 8192); $port->are_match(":", ">", ">>", "\n"); $port->write_settings; $response = $port->input; print "DEBUG: response1 = $response\n"; $port->write("InReach\r"); sleep 1; $response = $port->input; print "DEBUG: response2 = $response\n"; $port->write("********\r"); sleep 1; $response = $port->input; print "DEBUG: response3 = $response\n"; $port->write("exit\r"); sleep 1; $response = $port->input; print "DEBUG: response4 = $response\n";

This is what I get back when I run my script:

C:\Users\MyID\Documents\Perl\Test>SerialPortTest.pl DEBUG: response1 = DEBUG: response2 = InReach Password: DEBUG: response3 = ******** InReach:0 >exit[H[2J[2J Disconnected [H[2J Welcome to the MRV Communications' LX Series Server

What I expect to see is response1 equal to the first three lines of the manual login, response2 equal to "Password:", response3 equal to "InReach:0 >", and response 4 equal to the first three lines of the manual login again. What I don't expect to see is the string I am writing echoed back to me before the response. Am I not understanding the "input" command properly? Am I expecting too much? Also, is there a way to get rid of the control characters in the response3 lines above?

Many thanks in advance!!

ImJustAFriend

Replies are listed 'Best First'.
Re: Win32::SerialPort read/input issues
by Random_Walk (Prior) on May 01, 2013 at 13:35 UTC

    Perhaps you have local echo in your terminal, and that is displaying your input back at you.

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

      Thanks Random_Walk... I looked for that, but everything I can see in the POD (which is TERRIBLE, IMHO) says I shouldn't have local echo on...

      ImJustAFriend

Re: Win32::SerialPort read/input issues
by jmlynesjr (Deacon) on May 02, 2013 at 02:57 UTC

    Do you have to send out some attention character to get the LX to respond with the prompt information? I don't see that in your test code. Also look at:http://www.foo.be/docs/tpj/issues/vol4_1/tpj0401-0020.html and the POD for Device::SerialPort has additional information.

    James

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

      Thanks James... will check that link and POD out...

      ImJustAFriend