The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl -w
# cross-platform example2

use strict;
use vars qw( $OS_win $ob $port );

BEGIN {
        $OS_win = ($^O eq "MSWin32") ? 1 : 0;
        if ($OS_win) {
            eval "use Win32::SerialPort 0.11";
	    die "$@\n" if ($@);
        }
        else {
            eval "use Device::SerialPort";
	    die "$@\n" if ($@);
        }
} # End BEGIN

if ($OS_win) {
    $port = 'COM2';
    $ob = Win32::SerialPort->new ($port);
}
else {
    $port = '/dev/modem';
    $ob = Device::SerialPort->new ($port);
}
die "Can't open serial port $port: $^E\n" unless ($ob);

my $baud = $ob->baudrate;
my $parity = $ob->parity;
my $data = $ob->databits;
my $stop = $ob->stopbits;
my $hshake = $ob->handshake;

my @baud_opt = $ob->baudrate;
my @parity_opt = $ob->parity;
my @data_opt = $ob->databits;
my @stop_opt = $ob->stopbits;
my @hshake_opt = $ob->handshake;

my $c = 8;

print "\nData Bit Options:   ";
foreach $a (@data_opt) { print "  $a"; }

print "\n\nStop Bit Options:   ";
foreach $a (@stop_opt) { print "  $a"; }

print "\n\nHandshake Options:  ";
foreach $a (@hshake_opt) { print "  $a"; }

print "\n\nParity Options:     ";
foreach $a (@parity_opt) { print "  $a"; }

print "\n\nBaudrate Options:   ";
foreach $a (@baud_opt) {
    print "  $a";
    unless (--$c > 0) {
        $c = 8;
        print "\n                    ";
    }
}
print "\n\nCurrent Settings:     ";
print "B = $baud, D = $data, S = $stop, P = $parity, H = $hshake\n";

undef $ob;