How to: Dial Modems Attached to Serial Ports in Visual Basic
This topic describes how to use My.Computer.Ports to dial a modem in Visual Basic.
Typically, the modem is connected to one of the serial ports on the computer. For your application to communicate with the modem, it must send commands to the appropriate serial port.
To dial a modem
Determine which serial port the modem is connected to. This example assumes the modem is on COM1.
Use the My.Computer.Ports.OpenSerialPort method to obtain a reference to the port. For more information, see OpenSerialPort.
The Using block allows the application to close the serial port even if it generates an exception. All code that manipulates the serial port should appear within this block, or within a Try...Catch...Finally block.
Set the DtrEnable property to indicate that the computer is ready to accept an incoming transmission from the modem.
Send the dial command and the phone number to the modem through the serial port by means of the Write method.
This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Connectivity and Networking. For more information, see Code Snippets.
This example assumes the modem is connected to COM1. We recommend that your code allow the user to select the desired serial port from a list of available ports. For more information, see How to: Show Available Serial Ports in Visual Basic.
This example uses a Using block to make sure that the application closes the port even if it throws an exception. For more information, see Using Statement (Visual Basic).
In this example, the application disconnects the serial port after it dials the modem. Realistically, you will want to transfer data to and from the modem. For more information, see How to: Receive Strings From Serial Ports in Visual Basic.