I have a simple program to query a serial port to list its current settings. When I run the program, it reports the following:
Current baud rate is 1200
Current data bits setting is 7
Current parity setting is none
Current stop bits setting is 1
Current handshake setting is none
When I re-run the program again on a device with known different settings (such as 9600 baud) the variables are not changing - I get the same output. I figured out that this is due to the fact that the Win32::SerialPort module is querying my host machine for the serial port settings, not the device I'm connected to. Is there a way to query the connected device for its current settings using this module? Here is the code:
#!c:/perl/bin/perl
use strict;
use warnings;
use Win32::SerialPort qw( :STAT 0.19 );
my $Configuration_File_Name = "serialport_settings.txt";
print "Enter a COM port number:\n";
chomp (my $PortNumber = <>);
my $PortName = "COM" . $PortNumber;
my $PortObj = new Win32::SerialPort ($PortName) || die "Can't open $Po
+rtName: $^E\n"; # $quiet is optional
#$PortObj->save($Configuration_File_Name) || warn "Can't save $Configu
+ration_File_Name: $^E\n";
my $current_baud = $PortObj->baudrate;
my $current_parity = $PortObj->parity;
my $current_databits = $PortObj->databits;
my $current_stopbits = $PortObj->stopbits;
my $current_handshake = $PortObj->handshake;
print "Current baud rate is $current_baud\n";
print "Current data bits setting is $current_databits\n";
print "Current parity setting is $current_parity\n";
print "Current stop bits setting is $current_stopbits\n";
print "Current handshake setting is $current_handshake\n";
undef $PortObj;
__END__