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 example4

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

BEGIN {
        $OS_win = ($^O eq "MSWin32") ? 1 : 0;
        if ($OS_win) {
            eval "use Win32::SerialPort";
	    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);

$ob->user_msg(1);	# misc. warnings
$ob->error_msg(1);	# hardware and data errors

$ob->baudrate(38400);
$ob->parity("none");
## $ob->parity_enable(1);   # for any parity except "none"
$ob->databits(8);
$ob->stopbits(1);
$ob->handshake('rts');

$ob->write_settings;
$ob->save("tpj4.cfg");

print "wrote configuration file tpj4.cfg\n";

undef $ob;