37
Source Code Examples
Modem-RAS sample application
This application shows how to use modem and RAS libraries on the Digitax 4GMCU:
The modem library
allows to get real time information about telephony environment;
The RAS library
simply permits to open (dial) and close (hang-up) a remote dial-up
connection providing its system name.
The RAS link library
tries to keep the RAS entry connected in the best way by analyzing
modem status.
The application shows the modem status in real time, allows to dial and hang-up the RAS connection,
enable and disable the RAS link manager. It also demonstrates how to send SMS messages.
Sample code:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Threading;
using
System.Net;
using
Digitax.Mobile.Modem;
using
Digitax.Mobile.RAS;
using
Digitax.Mobile.RAS.Link;
namespace
Digitax.Mobile.Demo
{
public
partial
class
Demo
:
Form
{
private
const
string
MODEM_PORT_NAME =
"COM4:"
;
// set here Com Port Name (leave 'COM4:' for the 3GMDT+)
private
const
int
MODEM_PORT_BAUD = 57600;
// set here Com Port baud rate (leave 57600 for the 3GMDT+)
private
const
string
RAS_ENTRY_NAME =
"GPRS"
;
// set here the system RAS connection name
private
ModemManager
_modem;
private
RasEntryManager
_rasEntry;
private
LinkManager
_rasLink;
public
Demo()
{
InitializeComponent();
// instantiate modem manager
_modem =
new
ModemManager
(MODEM_PORT_NAME, MODEM_PORT_BAUD);
//_modem.PIN = "1234"; // set here you SIM PIN
// register to modem events
_modem.CellNameC=
new
CellNameChangedHandler
(_modem_CellNameChanged);
_modem.DataProtocolC=
new
DataProtocolChangedHandler
(_modem_DataProtocolChanged);
_modem.IMEIC=
new
IMEIChangedHandler
(_modem_IMEIChanged);
_modem.IMSIC=
new
IMSIChangedHandler
(_modem_IMSIChanged);
_modem.NetOperatorC=
new
NetworkOperatorChangedHandler
(_modem_NetOperatorChanged);
_modem.NetStatusC=
new
NetworkStatusChangedHandler
(_modem_NetStatusChanged);
_modem.SignalStrengthC=
new
SignalStrengthChangedHandler
(_modem_SignalStrengthChanged);
_modem.SimCardStatusC=
new
SimCardStatusChangedHandler
(_modem_SimCardStatusChanged);
_modem.RxSms +=
new
RxSmsHandler
(_modem_RxSms);
// check for the existance of the RAS connection name
bool
connectionNameFound =
false
;
foreach
(
RasEntryName
rasName
in
RasManager
.GetEntryNames())
{
if
(rasName.Name == RAS_ENTRY_NAME)
{
connectionNameFound =
true
;
break
;
}
}
if
(!connectionNameFound)
{
// RAS connection name DOES NOT exist
MessageBox
.Show(
"The RAS connection '"
+ RAS_ENTR
"' does not seem to be configured. RAS connection will not be opened."
,
"Demo"
);
return
;
}
// create RAS and Link managers
_rasEntry =
new
RasEntryManager
(RAS_ENTRY_NAME);
_rasLink =
new
LinkManager
(_rasEntry, _modem,
false
);
// register to RAS events
_rasEntry.ConnectionStateC=
new
RasEntryManager
.
ConnectionStateChangedHandler
(_rasEntry_ConnectionStateChanged);
// register to Link events
Содержание 4GMCU
Страница 1: ...4GMCU Technical Manual V 1 3...
Страница 11: ...11 Technical Views 4GMCU...
Страница 63: ......