Com Ports and the MSComm Control

Sending Data

For this example to work, ensure that the following properties are set.

Property Value
RThreshold  1
SThreshold  1
InputLen      0
ComPort The location of your modem

After this, firstly, we need to open the COM port. To do this, simply set the PortOpen property to true:

MSComm1.PortOpen = True

Then, we need to send the command. For this example, we will ask your modem to dial your own number. So, the command will be

ATDT01992245365

AT tells the modem that a command is coming up. DT tells it to dial the upcoming number using Tone dial. Then the text in red is the number to dial. Change the number in red to your own number. We also need to add a Chr$(13) after the command. You nearly always need to do this. So, to send this command, we enter

MSComm1.Output = "ATDT01992245365" & Chr$(13)

You could of course, substitute the telephone number with a Text box, so that the user could enter the number:

MSComm1.Output = "ATDT" & txtNumber.Text & Chr$(13)

Then, the modem will attempt to dial the number. If you want a list of the main commands to control a modem, click here. Of course, if the device connected to the COM port is not a modem, you will need to know what commands to send it.

At the moment, we have no way of knowing if the dialing was successful. This is where the OnComm event is useful. This is discussed in the next section. 

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky