sub atsend { my ( $me, $msg ) = @_; my $cnt = 0; print "\nThe port \$me in keypress function is $me\n"; # Write message on port $me->port->purge_all; $cnt = $me->port->write($msg); my $lbuf=length($msg); my $ret; while ($cnt < $lbuf) { $ret = $me->port->write(substr($msg, $cnt)); $me->write_drain(); last unless defined $ret; $cnt += $ret; } $me->log->write('debug', 'atsend: wrote '.$cnt.'/'.length($msg).' chars'); # If wrote all chars of `msg', we are successful return $cnt == length $msg; } #### sub keypress { my ($port_no,$key) = @_; $port_no =~ m/(\d+)/g; print "\nThe port \$port_no in keypress function is $port_no\n"; my $ms=$1; use Device::Modem::GSM; my $mod= new Device::Modem::GSM(port => "/dev/$port_no", log=> 'file,logfile.log', loglevel => 'info' # default is 'warning' ); $modem[$ms]=$mod; $key =~ s/^\s+//;# to remove leading whitespace $key =~ s/\s+$//;# to remove trailing whitespace my $st = "AT+CKPD="."\"$key\"".",1,1" ; $modem[$ms]-> atsend($st . Device::Modem::CR); my ($ok, $response) = $modem[$ms]->parse_answer($Device::Modem::STD_RESPONSE); return "$ok"; }