CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Win32 Programming Help:
Win32 SerialPort script

 



qratman
New User

Oct 4, 2008, 5:29 AM

Post #1 of 1 (3410 views)
Win32 SerialPort script Can't Post

Hi,

I am trying to understand the following code written in unix. I am porting it to Win32::SerialPort.


Code
#!/usr/bin/perl 
#
# Chatboard test utility
# Answer 'OK' to everything and spit out the communication

$| = 1;

system('stty 9600 -F /dev/tts/5');

open(TTS, "+< /dev/tts/5") or die;
print TTS "OK\n";

while(<TTS>) {
print TTS "OK\n";

# cut them into pieces...
if (/^(AT\+CKPD=")([0-9a-f]+)(".*)$/) {
my $pre = $1;
my $pieces = $2;
my $post = $3;
$pieces =~ s/(..)/$1 /g;

$_ = "$pre$pieces$post\n";
}

print;
}


Installed Win32::SerialPort. Works ok.Now i dont understand the if( ) part in while loop in code above. Can someone please explain it a bit or help with little code snippet. I have no previous background in perl. Done some Python and C thougth.

My win32 code is here. Runs nice so far. But how to code this if( ) ?


Code
#! perl 
use strict;
use Win32::SerialPort;
$| = 1;
my $ob = Win32::SerialPort->new('COM1') or die "fail opening COM1";
print "COM1 opened successfully \n";

$ob->baudrate(9600) || die "fail setting baud";
$ob->parity('none') || die "fail setting parity";
$ob->databits(8) || die "fail setting databits";
$ob->stopbits(1) || die "fail setting stopbits";
$ob->handshake('none') || die "fail setting handshake";
$ob->write_settings || die "no settings";

$ob->write("OK\n");
my $result = $ob->input;

while(1){
$ob->write("OK\n");
$result = $ob->input;

# Help here:
#if()
#{
#
#}
}

undef $ob;
print "COM1 closed..\n";


Thanks.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives