Device-Modem
view release on metacpan or search on metacpan
lib/Device/Modem.pm view on Meta::CPAN
$modem->attention(); # send `attention' sequence (+++)
($ok, $answer) = $modem->dial('02270469012'); # dial phone number
$ok = $modem->dial(3); # 1-digit parameter = dial number stored in memory 3
$modem->echo(1); # enable local echo (0 to disable)
$modem->offhook(); # Take off hook (ready to dial)
$modem->hangup(); # returns modem answer
$modem->is_active(); # Tests whether modem device is active or not
# So far it works for modem OFF/ modem ON condition
$modem->reset(); # hangup + attention + restore setting 0 (Z0)
$modem->restore_factory_settings(); # Handle with care!
$modem->restore_factory_settings(1); # Same with preset profile 1 (can be 0 or 1)
$modem->send_init_string(); # Send initialization string
# Now this is fixed to 'AT H0 Z S7=45 S0=0 Q0 V1 E0 &C0 X4'
# Get/Set value of S1 register
my $S1 = $modem->S_register(1);
my $S1 = $modem->S_register(1, 55); # Don't do that if you definitely don't know!
# Get status of managed signals (CTS, DSR, RLSD, RING)
my %signal = $modem->status();
if( $signal{DSR} ) { print "Data Set Ready signal active!\n"; }
# Stores this number in modem memory number 3
$modem->store_number(3, '01005552817');
$modem->repeat(); # Repeat last command
$modem->verbose(1); # Normal text responses (0=numeric codes)
# Some raw AT commands
$modem->atsend( 'ATH0' );
print $modem->answer();
$modem->atsend( 'ATDT01234567' . Device::Modem::CR );
print $modem->answer();
=head1 DESCRIPTION
C<Device::Modem> class implements basic B<AT (Hayes) compliant> device abstraction.
It can be inherited by sub classes (as C<Device::Gsm>), which are based on serial connections.
=head2 Things C<Device::Modem> can do
=over 4
=item *
connect to a modem on your serial port
=item *
test if the modem is alive and working
=item *
dial a number and connect to a remote modem
=item *
work with registers and settings of the modem
=item *
issue standard or arbitrary C<AT> commands, getting results from modem
=back
=head2 Things C<Device::Modem> can't do yet
=over 4
=item *
Transfer a file to a remote modem
=item *
Control a terminal-like (or a PPP) connection. This should really not
be very hard to do anyway.
=item *
Many others...
=back
=head2 Things it will never be able to do
=over 4
=item *
Coffee :-)
=back
=head2 Examples
In the `examples' directory, there are some scripts that should work without big problems,
that you can take as (yea) examples:
=over 4
=item `examples/active.pl'
Tests if modem is alive
=item `examples/caller-id.pl'
Waits for an incoming call and displays date, time and phone number of the caller.
Normally this is available everywhere, but you should check your local phone line
and settings.
=item `examples/dial.pl'
Dials a phone number and display result of call
=item `examples/shell.pl'
(Very) poor man's minicom/hyperterminal utility
=item `examples/xmodem.pl'
First attempt at a test script to receive a file via xmodem protocol.
Please be warned that this thing does not have a chance to work. It's
only a (very low priority) work in progress...
If you want to help out, be welcome!
=back
=head1 METHODS
=head2 answer()
One of the most used methods, waits for an answer from the device. It waits until
$timeout (seconds) is reached (but don't rely on this time to be very correct) or until an
expected string is encountered. Example:
$answer = $modem->answer( [$expect [, $timeout]] )
Returns C<$answer> that is the string received from modem stripped of all
B<Carriage Return> and B<Line Feed> chars B<only> at the beginning and at the end of the
string. No in-between B<CR+LF> are stripped.
Note that if you need the raw answer from the modem, you can use the _answer() (note
that underscore char before answer) method, which does not strip anything from the response,
so you get the real modem answer string.
Parameters:
=over 4
=item *
C<$expect> - Can be a regexp compiled with C<qr> or a simple substring. Input coming from the
modem is matched against this parameter. If input matches, result is returned.
=item *
C<$timeout> - Expressed in milliseconds. After that time, answer returns result also if nothing
has been received. Example: C<10000>. Default: C<$Device::Modem::TIMEOUT>, currently 500 ms.
=back
lib/Device/Modem.pm view on Meta::CPAN
$modem->dial( 2, 10 );
This means: dial number in the modem internal address book
(see C<store_number> for a way to read/write address book)
in position number B<2> and wait for a timeout of B<10> seconds.
=item C<$timeout>
B<optional>, default is B<30 seconds>.
Timeout expressed in seconds to wait for the remote device
to answer. Please do not expect an B<exact> wait for the number of
seconds you specified.
=item C<$mode>
B<optional>, default is C<DATA>, as string.
Allows to specify the type of call. Can be either:
=over 4
=item C<DATA> (default)
To perform a B<data call>.
=item C<VOICE>
To perform a B<voice call>, if your device supports it.
No attempt to verify whether your device can do that will be made.
=back
=back
=head2 disconnect()
Disconnects C<Device::Modem> object from serial port. This method calls underlying
C<disconnect()> of C<Device::SerialPort> object.
Example:
$modem->disconnect();
=head2 echo()
Enables or disables local echo of commands. This is managed automatically by C<Device::Modem>
object. Normally you should not need to worry about this. Usage:
$ok = $modem->echo( $enable )
=head2 hangup()
Does what it is supposed to do. Hang up the phone thus terminating any active call.
Usage:
$ok = $modem->hangup();
=head2 is_active()
Can be used to check if there is a modem attached to your computer.
If modem is alive and responding (on serial link, not to a remote call),
C<is_active()> returns true (1), otherwise returns false (0).
Test of modem activity is done through DSR (Data Set Ready) signal. If
this signal is in off state, modem is probably turned off, or not working.
From my tests I've found that DSR stays in "on" state after more or less
one second I turn off my modem, so know you know that.
Example:
if( $modem->is_active() ) {
# Ok!
} else {
# Modem turned off?
}
=head2 log()
Simple accessor to log object instanced at object creation time.
Used internally. If you want to know the gory details, see C<Device::Modem::Log::*> objects.
You can also see the B<examples> for how to log something without knowing
all the gory details.
Hint:
$modem->log->write('warning', 'ok, my log message here');
=head2 new()
C<Device::Modem> constructor. This takes several options. A basic example:
my $modem = Device::Modem->new( port => '/dev/ttyS0' );
if under Linux or some kind of unix machine, or
my $modem = Device::Modem->new( port => 'COM1' );
if you are using a Win32 machine.
This builds the C<Device::Modem> object with all the default parameters.
This should be fairly usable if you want to connect to a real modem.
Note that I'm testing it with a B<3Com US Robotics 56K Message> modem
at B<19200> baud and works ok.
List of allowed options:
=over 4
=item *
C<port> - serial port to connect to. On Unix, can be also a convenient link as
F</dev/modem> (the default value). For Win32, C<COM1,2,3,4> can be used.
=item *
C<log> - this specifies the method and eventually the filename for logging.
Logging process with C<Device::Modem> is controlled by B<log plugins>, stored under
F<Device/Modem/Log/> folder. At present, there are two main plugins: C<Syslog> and C<File>.
C<Syslog> does not work with Win32 machines.
When using C<File> plug-in, all log information will be written to a default filename
if you don't specify one yourself. The default is F<%WINBOOTDIR%\temp\modem.log> on
Win32 and F</var/log/modem.log> on Unix.
( run in 0.962 second using v1.01-cache-2.11-cpan-39bf76dae61 )