Basic telephony
14.2 Basic telephony
This chapter is focused on using the telephony API, but it is possible to control a modem by issuing COM port commands. These will provide the ability to dial telephone numbers and control the physical connection to the phone line.
Even if your modem is internal or connected via USB, it will always be mapped to a COM port. To discover the number of this COM port, you can look at Start → → → → Control Panel → → → → phone and Modem options → → → → Modems. Under the Attached To tab will be the number of the COM port to which the modem is attached.
Any command that is sent to this COM port will be interpreted by the modem. A list of common AT commands shown in Table 14.1.
Table 14.1 AT commands.
AT Command
Purpose
ATDT< phone Dials the specified phone number using touch-tone dialing. number ><enter>
A comma in the number represents a pause, a W waits for a second dial tone, and an @ waits for a five-second silence.
ATPT< phone Dials the specified number using pulse dialing. number ><enter>
AT S0=< number > Picks up the line after the specified number of rings. +++
Drop line.
The responses the modem will send back shown in Table 14.2.
Table 14.2 Modem responses .
Response
Meaning
OK The command has executed without errors. CONNECT
A connection to the remote phone has been made. RING
An incoming call is detected.
NO CARRIER No carrier signal has been detected (in GSM modems, this can mean that there is no network).
ERROR
The command is not understood.
14.2 Basic telephony 381
Table 14.2 Modem responses (continued).
Response
Meaning
NO DIAL TONE There is no dial tone on the phone line. BUSY
The remote end is too busy to take the call. NO ANSWER
The remote end did not take the call.
To implement a simple phone dialer in .NET, open Visual Studio .NET and start a new Windows forms project. Right-click on the toolbox and click Customize Toolbox (or Add/Remove Items in Visual Studio .NET 2003). Click on the COM Controls tab, and then add the Microsoft Communications control ( MSCOMM.OCX ). Drag this onto the form, and set the comport property to the COM port number to which your modem is connected. Add a button to the form, named btnPhone , click it, and add this code:
C#
private void btnPhone_Click(object sender, System.EventArgs e)
{ axMSComm1.PortOpen=true; axMSComm1.Output="ATDT00353877519575\r\n";
VB.NET
Private Sub btnPhone_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) axMSComm1.PortOpen=True axMSComm1.Output="ATDT00353877519575" + vbcrlf
End Sub
Note: Running the code listed above may incur phone charges. It is advis- able to change the phone number listed (00353877519575) to some other, less expensive number.
Only one program can control each COM port at a time. This code will fail if you are using the modem at the time. Several settings are associated with a COM port; in this case, however, the default parameters (9600
Chapter 14
382 14.3 Listening for incoming phone calls
baud, no parity, 8 data bits, 1 stop bit—or “9600,n,8,1”) are suitable for communication with a modem. When the modem begins communication at full speed, it will use a baud rate of 56 Kbps. This can be set using the settings property of the Microsoft communications control.