spickles has asked for the wisdom of the Perl Monks concerning the following question:
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: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
#!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__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::SerialPort Query Current Values
by GrandFather (Saint) on Sep 21, 2009 at 20:53 UTC | |
by spickles (Scribe) on Sep 21, 2009 at 21:03 UTC | |
by GrandFather (Saint) on Sep 21, 2009 at 21:44 UTC | |
by spickles (Scribe) on Sep 23, 2009 at 15:11 UTC | |
by GrandFather (Saint) on Sep 23, 2009 at 20:16 UTC |