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__

In reply to Win32::SerialPort Query Current Values by spickles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.