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.


In reply to Re^2: Perl/Tk Multithreading by mahis_431
in thread Perl/Tk Multithreading by mahis_431

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.