hmmm...I've tried this two ways, one with jsut the built-in i/o methods, and another way with a tied filehandle. here's what i'm usign right now:
# note, ive tried ttyS0 and S1, same error with both
$port = '/dev/ttyS0';
# creates a hidden config file in user's home dir
$config = '~/.conf';
# this tests for an existing config file,
# and creates one if necessary...
if(! -e $config)
{
$PortObj = new Device::SerialPort ($port) ||
die(RED,"Can't open $port: $^E\n",RESET);
$PortObj->databits(7);
$PortObj->baudrate(19200);
$PortObj->parity("even");
$PortObj->stopbits(1);
$PortObj->handshake("xoff");
$PortObj->buffers(4096, 4096);
$PortObj->write_settings || undef $PortObj;
$PortObj->save("$config");
$PortObj->close || die(RED,"failed to close",RESET);
undef $PortObj;
}
# and this connects to the port by loading said
# config file and tying to SERIAL filehandle
$PortObj = tie (*SERIAL, 'Device::SerialPort', "$config")
|| die(RED,"Can't open $port: $^E\n",RESET);
# use non-blocking read on serial port
$PortObj->read_char_time(5);
$PortObj->read_const_time(500);
# create flag variables initialized to zero...
my $EXIT = 0;
# ...when a trapped system signal is sent, set flag to 1
$SIG{'INT'} = sub { $EXIT = 1 };
i've used this before with a tied filehandle, so it should work.
__________
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
- Terry Pratchett