Device-Modem-1.47/0000755000175000001440000000000010421767015013116 5ustar cosimousersDevice-Modem-1.47/docs/0000755000175000001440000000000010421767015014046 5ustar cosimousersDevice-Modem-1.47/docs/Modem.html0000644000175000001440000006661510336471344016015 0ustar cosimousers Device::Modem - Perl extension to talk to modem devices connected via serial port


NAME

Device::Modem - Perl extension to talk to modem devices connected via serial port


WARNING

This is BETA software, so use it at your own risk, and without ANY warranty! Have fun.


SYNOPSIS

  use Device::Modem;
  my $modem = new Device::Modem( port => '/dev/ttyS1' );
  if( $modem->connect( baudrate => 9600 ) ) {
      print "connected!\n";
  } else {
      print "sorry, no connection with serial port!\n";
  }
  $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();


DESCRIPTION

Device::Modem class implements basic AT (Hayes) compliant device abstraction. It can be inherited by sub classes (as Device::Gsm), which are based on serial connections.

Things Device::Modem can do

Things Device::Modem can't do yet

Things it will never be able to do

Examples

In the `examples' directory, there are some scripts that should work without big problems, that you can take as (yea) examples:

`examples/active.pl'
Tests if modem is alive

`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.

`examples/dial.pl'
Dials a phone number and display result of call

`examples/shell.pl'
(Very) poor man's minicom/hyperterminal utility

`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!


METHODS

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 $answer that is the string received from modem stripped of all Carriage Return and Line Feed chars only at the beginning and at the end of the string. No in-between 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:

atsend()

Sends a raw AT command to the device connected. Note that this method is most used internally, but can be also used to send your own custom commands. Example:

        $ok = $modem->atsend( $msg )

The only parameter is $msg, that is the raw AT command to be sent to modem expressed as string. You must include the AT prefix and final Carriage Return and/or Line Feed manually. There is the special constant CR that can be used to include such a char sequence into the at command.

Returns $ok flag that is true if all characters are sent successfully, false otherwise.

Example:

        # Enable verbose messages
        $modem->atsend( 'AT V1' . Device::Modem::CR );
        # The same as:
        $modem->verbose(1);

attention()

This command sends an attention sequence to modem. This allows modem to pass in command state and accept AT commands. Example:

        $ok = $modem->attention()

connect()

Connects Device::Modem object to the specified serial port. There are options (the same options that Device::SerialPort has) to control the parameters associated to serial link. Example:

        $ok = $modem->connect( [%options] )

List of allowed options follows:

baudrate
Controls the speed of serial communications. The default is 19200 baud, that should be supported by all modern modems. However, here you can supply a custom value. Common speed values: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200. This parameter is handled directly by Device::SerialPort object.

databits
This tells how many bits your data word is composed of. Default (and most common setting) is 8. This parameter is handled directly by Device::SerialPort object.

init_string
Custom initialization string can be supplied instead of the built-in one, that is the following: H0 Z S7=45 S0=0 Q0 V1 E0 &C0 X4, that is taken shamelessly from minicom utility, I think.

parity
Controls how parity bit is generated and checked. Can be even, odd or none. Default is none. This parameter is handled directly by Device::SerialPort object.

stopbits
Tells how many bits are used to identify the end of a data word. Default (and most common usage) is 1. This parameter is handled directly by Device::SerialPort object.

dial()

Takes the modem off hook, dials the specified number and returns modem answer. Usage:

        # Simple usage (timeout is optional)
        $ok = $modem->dial( $number [,$timeout] )
        # List context: allows to get at exact modem answer
        # like `CONNECT 19200/...', `BUSY', `NO CARRIER', ...
        ($ok, $answer) = $modem->dial( $number [,$timeout] )

If called in scalar context, returns only success of connection. If modem answer contains CONNECT string, dial() returns successful state, else false value is returned.

If called in list context, returns the same $ok flag, but also the exact modem answer to the dial operation in the $answer scalar. $answer typically can contain strings like CONNECT 19200 or NO CARRIER, BUSY, ... all standard modem answers to a dial command.

Parameters are:

disconnect()

Disconnects Device::Modem object from serial port. This method calls underlying disconnect() of Device::SerialPort object. Example:

        $modem->disconnect();

echo()

Enables or disables local echo of commands. This is managed automatically by Device::Modem object. Normally you should not need to worry about this. Usage:

        $ok = $modem->echo( $enable )

hangup()

Does what it is supposed to do. Hang up the phone thus terminating any active call. Usage:

        $ok = $modem->hangup();

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), 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?
        }

log()

Simple accessor to log object instanced at object creation time. Used internally. If you want to know the gory details, see Device::Modem::Log::* objects. You can also see the examples for how to log something without knowing all the gory details.

Hint:
$modem->log->write('warning', 'ok, my log message here');

new()

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 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 3Com US Robotics 56K Message modem at 19200 baud and works ok.

List of allowed options:

offhook()

Takes the modem ``off hook'', ready to dial. Normally you don't need to use this. Also dial() goes automatically off hook before dialing.

parse_answer()

This method works like answer(), it accepts the same parameters, but it does not return the raw modem answer. Instead, it returns the answer string stripped of all CR/LF characters at the beginning and at the end.

parse_answer() is meant as an easy way of extracting result code (OK, ERROR, ...) and information strings that can be sent by modem in response to specific commands. Example:

        > AT xSHOW_MODELx<CR>
        US Robotics 56K Message
        OK
        >

In this example, OK is the result and US Robotics 56K Message is the informational message.

In fact, another difference with answer() is in the return value(s). Here are some examples:

        $modem->atsend( '?my_at_command?' );
        $answer = $modem->parse_answer();

where $answer is the complete response string, or:

        ($result, @lines) = $modem->parse_answer();

where $result is the OK or ERROR final message and @lines is the array of information messages (one or more lines). For the model example, $result would hold ``OK'' and @lines would consist of only 1 line with the string ``US Robotics 56K Message''.

port()

Used internally. Accesses the Device::SerialPort underlying object. If you need to experiment or do low-level serial calls, you may want to access this. Please report any usage of this kind, because probably (?) it is possible to include it in a higher level method.

repeat()

Repeats the last AT command issued. Usage:

        $ok = $modem->repeat()

reset()

Tries in any possible way to reset the modem to the starting state, hanging up all active calls, resending the initialization string and preparing to receive AT commands.

restore_factory_settings()

Restores the modem default factory settings. There are normally two main ``profiles'', two different memories for all modem settings, so you can load profile 0 and profile 1, that can be different depending on your modem manufacturer.

Usage:

        $ok = $modem->restore_factory_settings( [$profile] )

If no $profile is supplied, 0 is assumed as default value.

Check on your modem hardware manual for the meaning of these profiles.

S_register()

Gets or sets an S register value. These are some internal modem registers that hold important information that controls all modem behaviour. If you don't know what you are doing, don't use this method. Usage:

        $value = $modem->S_register( $reg_number [, $new_value] );

$reg_number ranges from 0 to 99 (sure?). If no $new_value is supplied, return value is the current register value. If a $new_value is supplied (you want to set the register value), return value is the new value or undef if there was an error setting the new value.

<!-- Qui &egrave; spiegata da cani -->

Examples:

        # Get value of S7 register
        $modem->S_register(7);
        # Set value of S0 register to 0
        $modem->S_register(0, 0);

send_init_string()

Sends the initialization string to the connected modem. Usage:

        $ok = $modem->send_init_string( [$init_string] );

If you specified an init_string as an option to new() object constructor, that is taken by default to initialize the modem. Else you can specify $init_string parameter to use your own custom intialization string. Be careful!

status()

Returns status of main modem signals as managed by Device::SerialPort (or Win32::SerialPort) objects. The signals reported are:

CTS
Clear to send

DSR
Data set ready

RING
Active if modem is ringing

RLSD
??? Released line ???

Return value of status() call is a hash, where each key is a signal name and each value is > 0 if signal is active, 0 otherwise. Usage:

        ...
        my %sig = $modem->status();
        for ('CTS','DSR','RING','RLSD') {
                print "Signal $_ is ", ($sig{$_} > 0 ? 'on' : 'off'), "\n";
        }

store_number()

Store telephone number in modem internal address book, to be dialed later (see dial() method). Usage:

        $ok = $modem->store_number( $position, $number )

where $position is the address book memory slot to store phone number (usually from 0 to 9), and $number is the number to be stored in the slot. Return value is true if operation was successful, false otherwise.

verbose()

Enables or disables verbose messages. This is managed automatically by Device::Modem object. Normally you should not need to worry about this. Usage:

        $ok = $modem->verbose( $enable )

wait()

Waits (yea) for a given amount of time (in milliseconds). Usage:

        $modem->wait( [$msecs] )

Wait is implemented via select system call. Don't know if this is really a problem on some platforms.


REQUIRES

Device::SerialPort (Win32::SerialPort for Win32 machines)


EXPORT

None


TO-DO

AutoScan
An AT command script with all interesting commands is run when `autoscan' is invoked, creating a `profile' of the current device, with list of supported commands, and database of brand/model-specific commands

Serial speed autodetect
Now if you connect to a different baud rate than that of your modem, probably you will get no response at all. It would be nice if Device::Modem could auto-detect the speed to correctly connect at your modem.

File transfers
It would be nice to implement [xyz]modem like transfers between two Device::Modem objects connected with two modems.


FAQ

There is a minimal FAQ document for this module online at http://www.streppone.it/cosimo/work/perl/CPAN/Device-Modem/FAQ.html


SUPPORT

Please feel free to contact me at my e-mail address cosimo@cpan.org for any information, to resolve problems you can encounter with this module or for any kind of commercial support you may need.


AUTHOR

Cosimo Streppone, cosimo@cpan.org


COPYRIGHT

(C) 2002-2004 Cosimo Streppone, cosimo@cpan.org

This library is free software; you can only redistribute it and/or modify it under the same terms as Perl itself.


SEE ALSO

Device::SerialPort, Win32::SerialPort, Device::Gsm, perl

Device-Modem-1.47/docs/Modem.pod0000644000175000001440000004401110421765763015623 0ustar cosimousers=head1 NAME Device::Modem - Perl extension to talk to modem devices connected via serial port =head1 WARNING This is B software, so use it at your own risk, and without B warranty! Have fun. =head1 SYNOPSIS use Device::Modem; my $modem = new Device::Modem( port => '/dev/ttyS1' ); if( $modem->connect( baudrate => 9600 ) ) { print "connected!\n"; } else { print "sorry, no connection with serial port!\n"; } $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 class implements basic B device abstraction. It can be inherited by sub classes (as C), which are based on serial connections. =head2 Things C 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 commands, getting results from modem =back =head2 Things C 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 and B chars B at the beginning and at the end of the string. No in-between B 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 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 seconds. After that time, answer returns result also if nothing has been received. Example: C<10>. Default: C<0.2> =back =head2 atsend() Sends a raw C command to the device connected. Note that this method is most used internally, but can be also used to send your own custom commands. Example: $ok = $modem->atsend( $msg ) The only parameter is C<$msg>, that is the raw AT command to be sent to modem expressed as string. You must include the C prefix and final B and/or B manually. There is the special constant C that can be used to include such a char sequence into the at command. Returns C<$ok> flag that is true if all characters are sent successfully, false otherwise. Example: # Enable verbose messages $modem->atsend( 'AT V1' . Device::Modem::CR ); # The same as: $modem->verbose(1); =head2 attention() This command sends an B sequence to modem. This allows modem to pass in B and accept B commands. Example: $ok = $modem->attention() =head2 connect() Connects C object to the specified serial port. There are options (the same options that C has) to control the parameters associated to serial link. Example: $ok = $modem->connect( [%options] ) List of allowed options follows: =over 4 =item C Controls the speed of serial communications. The default is B<19200> baud, that should be supported by all modern modems. However, here you can supply a custom value. Common speed values: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200. This parameter is handled directly by C object. =item C This tells how many bits your data word is composed of. Default (and most common setting) is C<8>. This parameter is handled directly by C object. =item C Custom initialization string can be supplied instead of the built-in one, that is the following: C, that is taken shamelessly from C utility, I think. =item C Controls how parity bit is generated and checked. Can be B, B or B. Default is B. This parameter is handled directly by C object. =item C Tells how many bits are used to identify the end of a data word. Default (and most common usage) is C<1>. This parameter is handled directly by C object. =back =head2 dial() Takes the modem off hook, dials the specified number and returns modem answer. Usage: # Simple usage (timeout is optional) $ok = $modem->dial( $number [,$timeout] ) # List context: allows to get at exact modem answer # like `CONNECT 19200/...', `BUSY', `NO CARRIER', ... ($ok, $answer) = $modem->dial( $number [,$timeout] ) If called in B, returns only success of connection. If modem answer contains C string, C returns successful state, else false value is returned. If called in B, returns the same C<$ok> flag, but also the exact modem answer to the dial operation in the C<$answer> scalar. C<$answer> typically can contain strings like C or C, C, ... all standard modem answers to a dial command. Parameters are: =over 4 =item * C<$number> - this is the phone number to dial. If C<$number> is only 1 digit, it is interpreted as: B>. So if your code is: $modem->dial( 2, 10 ); This means: dial number in the modem internal address book (see C 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> - timeout expressed in seconds to wait for the remote device to answer. Please do not expect an B wait for the number of seconds you specified. I'm still studying how to do that exactly. =back =head2 disconnect() Disconnects C object from serial port. This method calls underlying C of C object. Example: $modem->disconnect(); =head2 echo() Enables or disables local echo of commands. This is managed automatically by C 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 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 objects. You can also see the B for how to log something without knowing all the gory details. Hint: $modem->log->write('warning', 'ok, my log message here'); =head2 new() C 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 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 - serial port to connect to. On Unix, can be also a convenient link as F (the default value). For Win32, C can be used. =item * C - this specifies the method and eventually the filename for logging. Logging process with C is controlled by B, stored under F folder. At present, there are two main plugins: C and C. C does not work with Win32 machines. When using C 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 on Unix. Also there is the possibility to pass a B, if this object provides the following C call: $log_object->write( $loglevel, $logmessage ) You can simply pass this object (already instanced) as the C property. Examples: # For Win32, default is to log in "%WINBOOTDIR%/temp/modem.log" file my $modem = Device::Modem->new( port => 'COM1' ); # Unix, custom logfile my $modem = Device::Modem->new( port => '/dev/ttyS0', log => 'file,/home/neo/matrix.log' ) # With custom log object my $modem = Device::modem->new( port => '/dev/ttyS0', log => My::LogObj->new() ); =item * C - default logging level. One of (order of decrescent verbosity): C, C, C, C, C, C, C, C, C. =back =head2 offhook() Takes the modem "off hook", ready to dial. Normally you don't need to use this. Also C goes automatically off hook before dialing. =head2 parse_answer() This method works like C, it accepts the same parameters, but it does not return the raw modem answer. Instead, it returns the answer string stripped of all B/B characters at the beginning B at the end. C is meant as an easy way of extracting result code (C, C, ...) and information strings that can be sent by modem in response to specific commands. Example: > AT xSHOW_MODELx US Robotics 56K Message OK > In this example, C is the result and C is the informational message. In fact, another difference with C is in the return value(s). Here are some examples: $modem->atsend( '?my_at_command?' ); $answer = $modem->parse_answer(); where C<$answer> is the complete response string, or: ($result, @lines) = $modem->parse_answer(); where C<$result> is the C or C final message and C<@lines> is the array of information messages (one or more lines). For the I example, C<$result> would hold "C" and C<@lines> would consist of only 1 line with the string "C". =head2 port() Used internally. Accesses the C underlying object. If you need to experiment or do low-level serial calls, you may want to access this. Please report any usage of this kind, because probably (?) it is possible to include it in a higher level method. =head2 repeat() Repeats the last C command issued. Usage: $ok = $modem->repeat() =head2 reset() Tries in any possible way to reset the modem to the starting state, hanging up all active calls, resending the initialization string and preparing to receive C commands. =head2 restore_factory_settings() Restores the modem default factory settings. There are normally two main "profiles", two different memories for all modem settings, so you can load profile 0 and profile 1, that can be different depending on your modem manufacturer. Usage: $ok = $modem->restore_factory_settings( [$profile] ) If no C<$profile> is supplied, C<0> is assumed as default value. Check on your modem hardware manual for the meaning of these B. =head2 S_register() Gets or sets an B value. These are some internal modem registers that hold important information that controls all modem behaviour. If you don't know what you are doing, don't use this method. Usage: $value = $modem->S_register( $reg_number [, $new_value] ); C<$reg_number> ranges from 0 to 99 (sure?). If no C<$new_value> is supplied, return value is the current register value. If a C<$new_value> is supplied (you want to set the register value), return value is the new value or C if there was an error setting the new value. Examples: # Get value of S7 register $modem->S_register(7); # Set value of S0 register to 0 $modem->S_register(0, 0); =head2 send_init_string() Sends the initialization string to the connected modem. Usage: $ok = $modem->send_init_string( [$init_string] ); If you specified an C as an option to C object constructor, that is taken by default to initialize the modem. Else you can specify C<$init_string> parameter to use your own custom intialization string. Be careful! =head2 status() Returns status of main modem signals as managed by C (or C) objects. The signals reported are: =over 4 =item CTS Clear to send =item DSR Data set ready =item RING Active if modem is ringing =item RLSD ??? Released line ??? =back Return value of C call is a hash, where each key is a signal name and each value is > 0 if signal is active, 0 otherwise. Usage: ... my %sig = $modem->status(); for ('CTS','DSR','RING','RLSD') { print "Signal $_ is ", ($sig{$_} > 0 ? 'on' : 'off'), "\n"; } =head2 store_number() Store telephone number in modem internal address book, to be dialed later (see C method). Usage: $ok = $modem->store_number( $position, $number ) where C<$position> is the address book memory slot to store phone number (usually from 0 to 9), and C<$number> is the number to be stored in the slot. Return value is true if operation was successful, false otherwise. =head2 verbose() Enables or disables verbose messages. This is managed automatically by C object. Normally you should not need to worry about this. Usage: $ok = $modem->verbose( $enable ) =head2 wait() Waits (yea) for a given amount of time (in milliseconds). Usage: $modem->wait( [$msecs] ) Wait is implemented via C system call. Don't know if this is really a problem on some platforms. =head1 REQUIRES =over 4 =item Device::SerialPort (Win32::SerialPort for Win32 machines) =back =head1 EXPORT None =head1 TO-DO =over 4 =item AutoScan An AT command script with all interesting commands is run when `autoscan' is invoked, creating a `profile' of the current device, with list of supported commands, and database of brand/model-specific commands =item Serial speed autodetect Now if you connect to a different baud rate than that of your modem, probably you will get no response at all. It would be nice if C could auto-detect the speed to correctly connect at your modem. =item File transfers It would be nice to implement C<[xyz]modem> like transfers between two C objects connected with two modems. =back =head1 FAQ There is a minimal FAQ document for this module online at L =head1 SUPPORT Please feel free to contact me at my e-mail address L for any information, to resolve problems you can encounter with this module or for any kind of commercial support you may need. =head1 AUTHOR Cosimo Streppone, L =head1 COPYRIGHT (C) 2002-2006 Cosimo Streppone, L This library is free software; you can only redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO Device::SerialPort, Win32::SerialPort, Device::Gsm, perl =cut # vim: set ts=4 sw=4 tw=120 nowrap nu Device-Modem-1.47/README0000644000175000001440000000274210421755047014005 0ustar cosimousers======================================================================= Device::Modem - a Perl class to interface generic modems (AT-compliant) Copyright (C) 2002-2006 Cosimo Streppone, cosimo@cpan.org ======================================================================= This is a perl extension to talk to AT compliant devices via serial port. It should be enough platform independent as you need. For more details, look at the "docs/" folder where you will find a minimal FAQ ("docs/FAQ.pod"), and the full documentation for this extension ("docs/Modem.pod"). Please contact me for any problems you may encounter using this beast. Have fun! Prerequisites ------------- + working perl installation >= 5.005_03 + Device::SerialPort >= 0.19 (Win32::SerialPort in on Windows platform) + a modem or AT-compliant device if you want to use it for some real work Installation ------------ This module installs like all other good old perl modules: $ perl Makefile.PL $ make $ make test $ make install Licensing terms --------------- This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Additionally, this is BETA software, so use it at your own risk, and without ANY warranty! For any need of commercial support and/or licensing, please contact me directly: Cosimo Streppone Advertising :-) --------------- Check out also Device::Gsm module from the same author to work with GSM devices connected via serial port. Device-Modem-1.47/Makefile.PL0000755000175000001440000000452310234776213015101 0ustar cosimousers# $Id: Makefile.PL,v 1.6 2005/04/30 21:45:47 cosimo Exp $ use ExtUtils::MakeMaker; #print "\n\n", '-' x 60, "\n", ' ' x 20, 'Device::Modem setup', "\n", '-' x 60, "\n\n"; my $is_windoze = index($^O, 'Win') >= 0; # # my %config = configure(); # WriteMakefile( 'AUTHOR' => 'Cosimo Streppone ', 'ABSTRACT_FROM' => 'Modem.pm', 'NAME' => 'Device::Modem', 'VERSION_FROM' => 'Modem.pm', 'PREREQ_PM' => $is_windoze ? { 'Win32::SerialPort' => 0 } : { 'Device::SerialPort' => 0 } ); sub configure { my $default; # # Modem setup # my $port; $default = 'n'; # default = no modem do { print <; chomp $port; $port = lc substr $port, 0, 1; $port = $default unless defined $port; } until( index( '01234nm', $port ) != -1 ); if( $port eq 'n' ) { $conf{'port'} = 'NONE'; } elsif( $port eq 'm' ) { $conf{'port'} = '/dev/modem'; } else { $conf{'port'} = $is_windoze ? 'COM%d' : '/dev/ttyS%d'; $conf{'port'} = sprintf $conf{'port'}, $port; } $conf{'port'} = 'COM1' if $conf{'port'} eq 'COM0'; # # Baud rate configuration # my $baud; $default = 4; # default = 19200 do { print <; chomp $baud; $baud =~ s/\D//g; $baud ||= $default; } until( $baud >= 1 and $baud <= 5 ); $conf{'baudrate'} = 2400 << ($baud - 1); print "\n- Selected $conf{'baudrate'} speed\n"; # Write configuration file if( open CONF, '>.config.pm' ) { print CONF "# Device::Modem setup parameters\n# \$Id: Makefile.PL,v 1.6 2005/04/30 21:45:47 cosimo Exp $\n\n"; foreach( sort keys %conf ) { print CONF "\$Device::Modem::$_ = '$conf{$_}';\n"; } print CONF "\n1;\n\n"; close CONF; } return %conf; }