Thank you for your kind suggestions. All your guess is truly my problem.
1. I tried to confine ALL code of GSM module to the thread
2. I am getting the following error:
"Thread 1 terminated abnormally: Can't call method "purge_all" on an undefined value at widget.pl line 4198."
3. The subroutine in which the "purge_all" appears is given below:
(Note: this method is take from Module Device::Modem so i did not code this subroutine. Only thing I am passing arguments to this subroutine from my program).For complete code this module please see CPAN
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;
}
4. In the above subroutine the error is exactly coming at the line: $me->port->purge_all;
5. The subroutine which calls the above module subroutine from my program is given below:
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 'war
+ning'
);
$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_RE
+SPONSE);
return "$ok";
}
6.Additional Information:
a)The value of arguments passed to the module subroutine atsend() from my program subroutine keypress()are:
AT+CKPD="m",1,1
b)The value of the arguments received in the atsend() subroutine for variable $me is: Device::Modem::GSM=HASH(0xaece500)
Note: This values I got from compiling.
So whats the problem here? why it is not able to call method in Modem.pm module?
My program owrks like gem when same arguments are passed without creating a thread.
|