in reply to Device::Modem Help
For example, if you look at the following loop, a 'q' will stop it, but the 'print' is fast and the loop will be looping fast checking for the 'q'. In your case, if you try dialing instead of printing, the loop will not proceed, while the dial sub is running.
#!/usr/bin/perl use Term::ReadKey; $char='q'; while(1){ ReadMode ('cbreak'); if (defined ($ch = ReadKey(-1))){ #input was waiting and it was $ch if ($ch eq $char){exit(0);} }else{ # no input was waiting #your program goes here print "############################\n"; select(undef,undef,undef,.01); } ReadMode ('normal'); # restore normal tty settings } __END__
Now if you have an event lopp, like this Tk program, the dial can proceed, and you can interrupt it with a key press. This is just pseudo code, because I don't have the code you are using, but it should give you the idea.
#!/usr/bin/perl use warnings; use strict; use Tk; #use Device::Modem; #my $modem = new Device::Modem( log =>'file,modemlog',port => '/dev/tt +yS1' ); my $mw = MainWindow->new; $mw->Label( -text => 'press q to quit dial' )->pack; $mw->Button(-text=> 'Start Dial', -command => \&start_dial )->pack; $mw->Button(-text=> 'Quit', -command => \&exit )->pack; $mw->bind( '<q>' => \&stop_dial ); MainLoop; sub start_dial{ print "dial started\n"; #you would do something like #$modem->dial('123-456-2345'); } ############################ sub stop_dial { print "q pressed\n"; # do something like # $modem->reset(); } __END__
There are other Event modules, search cpan for them, or look at Roll your own Event-loop for ideas which will let you do it from a commandline script, without a GUI.
|
|---|