use warnings; use Win32::SerialPort; use Time::HiRes qw (usleep); open (CODES, "$ARGV[0]"); my @codes = ; close CODES; my $serial = new Win32::SerialPort ('COM3') or die "Can't open COM3: $^E\n"; $serial->databits(8); $serial->baudrate(9600); $serial->parity("none"); $serial->stopbits(1); $serial->write_settings; my $clearout = $serial->input; undef $clearout; my $correctionUs = 13800; //setting to offset the transfer time of serial communication, not working print "Hit Enter To Begin"; ; my $starttimeepoch = time; my $starttime = localtime; print "Start Time is: $starttime, epoch time is: " . $starttimeepoch . "\n"; print "Correction is: " . $correctionUs . "\n"; foreach my $line (@codes){ $line =~ /(\d{5})(\d{2})/; $serial->write($2); usleep(($1 * 1000 )- $correctionUs); } my $endtimeepoch = time; my $endtime = localtime; print "End Time is: $endtime, epoch time is: " . $endtimeepoch . "\n"; print "Total time is: " . ($endtimeepoch - $starttimeepoch) . "\n"; print "I should be done now, sleeping for 10 seconds\n"; sleep(10); $serial->close or die "Failed to close COM3"; undef $serial;