Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Serial port - again

by rkrasowski (Sexton)
on Mar 15, 2013 at 15:54 UTC ( #1023729=perlquestion: print w/ replies, xml ) Need Help??
rkrasowski has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, I know, the answer is probably easy, but I can not get this to work. I am trying to communicate with satellite modem using serial port. I am sendng command to the modem and wait for "OK" response, for some rason "OK" is not recognized ( it is printed in terminal window just fine). Here is a code:
#!/usr/bin/perl use strict; use warnings; use Device::SerialPort; my $PORT = "/dev/ttyUSB0"; my $serialData; my $tx; my $rx; my $ob = Device::SerialPort->new($PORT) || die "Can't Open $PORT: $!"; $ob->baudrate(115200) || die "failed setting baudrate"; $ob->parity("none") || die "failed setting parity"; $ob->databits(8) || die "failed setting databits"; $ob->handshake("none") || die "failed setting handshake"; $ob->write_settings || die "no settings"; $| = 1; $tx = $ob->write("AT&K0\n"); do { $rx = $ob->read(255); chomp $rx; print $rx; } until ($rx =~ m/OK/); print "OK received\n";
When I try to emulate satellite modem and sent OK response to my program it is still not recognized. When I change line until ($rx =~ m/OK/); to until ($rx =~ m/O/);("OK" changed to just one character "O" )it is recognized with no trouble. Any idea what is the problem?? Thanks in advance Robert OK, it looks like the issue was with Hyperterminal on win XP that I used aas emulator. I swich to Linux and used perl script as emulator and things are moving as expected. Thanks like always, Robert

Comment on Serial port - again
Select or Download Code
Replies are listed 'Best First'.
Re: Serial port - again
by RichardK (Parson) on Mar 15, 2013 at 17:20 UTC

    I think you just answered your own question :) , perhaps the read returns as soon as it gets the first character?

    Try printing $rx in the loop and then you'll know for sure.

    I've never used that module but from a quick scan of the pod it does have a lookfor method.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1023729]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2016-02-10 15:26 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (350 votes), past polls