https://rt.cpan.org/Public/Bug/Display.html?id=113337#txn-1691722 #### #! C:\perl\bin\perl.exe use strict; use warnings; use Win32::SerialPort; use Time::HiRes qw(usleep); my $port_name = 'COM5'; #my $config_file = 'setup.cfg'; # use this to configure from the file my $port = new Win32::SerialPort( $port_name ) || die "Unable to open: $^E\n"; # $^E EXTENDED_OS_ERROR #my $port = new Win32::SerialPort($port_name, $config_file) || die "Unable to open: $^E\n"; $port->handshake('none'); # none dtr rts xoff $port->baudrate(38400); # 19200 57600 1200 9600 115200 4800 600 2400 300 38400 $port->parity('none'); # space none odd even mark #$port->parity_enable(1); # for any parity except "none" $port->databits(8); # 7 8 $port->stopbits(1); # 2 1 $port->buffers(256, 256); $port->read_interval(0); #RI $port->read_const_time(20); #RC $port->write_char_time(1); #WM $port->write_const_time(100); #WC print "Write settings \n"; $port->write_settings || undef $port; # A report out to this console my $baud = $port->baudrate; my $parity = $port->parity; my $data = $port->databits; my $stop = $port->stopbits; my $hshake = $port->handshake; print "B = $baud, D = $data, S = $stop, P = $parity, H = $hshake\n"; # use the below to save the current configuration # if ( $port ) { $port->save('setup.cfg') ; print "Serial Port OK \n" }; # pack: used for assembling binary stuff # my $status = pack('H2' * 6, 'ca', '00', '01', '00', '00', 'fe'); $port->write("ati"."\r"); #$port->write("ati\x0D\x0A"); # carriage return and line feed: no different #$port->write("ate0"."\r"); usleep 0; my $debug = 1; my $cmd = " "; while ($cmd ne "quit") { print "Input command: "; $cmd = ; chomp $cmd; if ($cmd eq "quit") {next;} $port->write($cmd."\r"); my $loop = 1; while( $loop ) { usleep(200000); # 0.2 of a second my $response = $port->input; chomp $response; print $response; #my $responseHex = unpack ('H*', $response); #print $responseHex."\n"; my $last = substr ( $response, -1 ); # get the last character if ($last eq ">") { $loop = 0; next; } print "."; } }