mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
modem-lib.pl: Check if character device exists before trying to connect to it.
This commit is contained in:
@@ -33,7 +33,10 @@ sub new() {
|
|||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
# Initialize the connetion to the modem.
|
# Initialize the connetion to the modem.
|
||||||
$self->_initialize($port, $baud);
|
my $ret = $self->_initialize($port, $baud);
|
||||||
|
if ($ret) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
if ($self->_is_working()) {
|
if ($self->_is_working()) {
|
||||||
return $self;
|
return $self;
|
||||||
@@ -54,9 +57,16 @@ sub DESTROY() {
|
|||||||
sub _initialize() {
|
sub _initialize() {
|
||||||
my ($self, $port, $baud) = @_;
|
my ($self, $port, $baud) = @_;
|
||||||
|
|
||||||
|
# Check if the character device actually exists.
|
||||||
|
if (! -c $port) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
# Establish connection to the modem.
|
# Establish connection to the modem.
|
||||||
$self->{modem} = new Device::Modem(port => $port);
|
$self->{modem} = new Device::Modem(port => $port);
|
||||||
$self->{modem}->connect(baudrate => $baud);
|
$self->{modem}->connect(baudrate => $baud);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _is_working() {
|
sub _is_working() {
|
||||||
|
|||||||
Reference in New Issue
Block a user