#!/usr/bin/perl use Win32::SerialPort; use Time::HiRes qw(usleep); $com="COM1"; $PortObj=Win32::SerialPort->new($com); $PortObj->baudrate(38400); $PortObj->databits(8); $PortObj->parity("none"); $PortObj->stopbits(1); $PortObj->handshake("xoff"); $PortObj->xon_limit(100); # bytes left in buffer $PortObj->xoff_limit(100); # space left in buffer $PortObj->xon_char(0x11); $PortObj->xoff_char(0x13); $PortObj->read_interval(2); # max time between read char (milliseconds) $PortObj->read_char_time(1); # avg time between read char $PortObj->read_const_time(2); # total = (avg * bytes) + const #writes the settings into the port $PortObj->write_settings; $PortObj->are_match("CorrRsp", ""); # correct response for CMD1 my $gotit = ""; until ("" ne $gotit) { $gotit = $PortObj->lookfor(100); #blocking read if($gotit){last;} $cmd= "CMD1\n"; # CMD1 Send in loop till CorrRsp is received $PortObj->write($cmd); $microseconds = "600"; usleep ($microseconds); } $cmd= "CMD2\n"; $PortObj->write($cmd); print("$gotit\n"); $mydata1 = $gotit; $PortObj->close; undef $PortObj;