#!/usr/bin/perl use strict; use Pod::Usage; use Getopt::Std; my @tmp; my $tmp; our $PORT; our $BAUD; our $PARITY; our $DATA; our $STOP; our $ERR; our $ERR1; our $ERR2; our $ob; sub FindCOM{ # modern laptops don't have a RS232 port so a RS232 adapter must be used # DOS command "mode" finds the number of COM when the RS232 is connected open(LISTDIR,"mode |") || die; @tmp=; close(LISTDIR); # detecting the COM port if($tmp[1]=~/COM/){ # variables $ERR, $ERR1 and $ERR2 are temporary $ERR="n"; $ERR1="Type a string in the edit line (below) and press ."; $ERR2="(or wait for the remote device to send data)."; $PORT=$tmp[1]; chomp($PORT); $PORT=~s/Status for device //i; $PORT=~s/://; # setting the COM port # - variable $PORT # - 19200: baud rate # - n: none parity # - 8: data bits # - 1: stop bits open(LISTDIR,"mode $PORT 19200,n,8,1 |") || die; @tmp=; close(LISTDIR); $BAUD=$tmp[3]; chomp($BAUD); $BAUD=~s/ //g; $BAUD=~s/Baud://i; $PARITY=$tmp[4]; chomp($PARITY); $PARITY=~s/ //g; $PARITY=~s/Parity://i; $DATA=$tmp[5]; chomp($DATA); $DATA=~s/ //g; $DATA=~s/databits://i; $STOP=$tmp[6]; chomp($STOP); $STOP=~s/ //g; $STOP=~s/stopbits://i; # opening the COM port # in the version without Tk the opened COM port from here worked $ob = Win32::SerialPort->new ($PORT) || die "\tSERIAL PORT ERROR: $PORT IS BUSY OR NOT AVAILABLE\n\n"; } else{ $ERR="y"; $ERR1="Failed to initialize the port."; $ERR2="Did you forget to connect RS232 adapter to USB?"; } } 1;