As I mention about modem, it is modem for internet. Usually, working to connect with modem will have processed program for use, but if experiment for knowledge for one who like programming, it will be useful. It can apply for many.

 

This article will be the fundamental of step of programming and protocol command that is used for Dial-Up Phone, so we begin to know about protocol of modem first.

 

The protocol for connecting with modem

 

For connecting with modem, will have command according to standard of industry that produce modem, is protocol called AT Command in order to send command for controlling or get data from modem. Maybe, there is different command; we can see the form of command from manual of each modem that is bought. For command that is sent to control at modem that we will program, it has AT Command that must be used in the followings,

Table 1 AT Command for Dial-Up

AT Command The working of command
ATZ Reset modem
ATHn Set modem in Hook Mode n, is 0 = off ,1= on
ATDTn Send the number of telephone in order to connect with signal destination called n is the number of telephone.

The 8 step of programming for connecting with modem

The step of programming

  1. Set the number Com Port for connecting with modem (Detect) with Com Port.

MSComm1.ComPort=numPort

  1. Set connection with Com Port is rate of sending data.

(Baud Rate),Parity,Data(the number of bit),Stop Bit

MSComm1.Settings=”28800, N, 8, 1″

  1. Set to open value of DTR and RTS

MSComm1.DTREnable = True
MSComm1.RTSEnable = True

  1. Set size while data is coming to read all data in buffer.

MSComm1.InputLen=1

  1. Inspired by Event-driven when there is data to buffer of getting data, occurs CommEvent in OnComm Event

MSComm1.Rthreshold=1

6. Open Com port

MSComm1.OpenPort=True

  1. Phone Dial-Up by Command AT followed by the number of telephone and connecting by function in order to send command Enter. In computer that is used for connecting sentences will be the sign (+) or &. For function works as Chr$(13) is the followings,

Chr$(10)

+ vbCr

& Chr$(10) & Chr$(13)

& vbCrLf

+ Chr$(13)

+ vbCrLf

& vbCr

& Chr$(13)

The example of command

MSComm1.Output=”ATDT1234567″+Chr(13)

  1. Open the way sending value of DTS, RTS and Com port.

MSComm1.DTREnable = True
MSComm1.RTSEnable = True
MSComm1.OpenPort=False

The example of program connecting to modem

Phone Dial-Up

Sub Modem_Dial_Up()

Dim valStartTime

‘Set values for connecting port with modem

‘MSComm1.CommPort = 1

MSComm1.Settings =”28800,N,8,1″

If Not MSComm1.PortOpen Then MSComm1.PortOpen = True

MSComm1.DTREnable = True

MSComm1.RTSEnable = True

MSComm1.RThreshold = 1

MSComm1.InputLen = 1

‘ Send AT Command for connecting with modem and Phone Dial-Up

MSComm1.Output = “ATH1″ & Chr$(13) ‘ open Hook Mode

MSComm1.Output = “ATDT” & txtPhoneNum & Chr$(13) ‘ Phone Dial-Up to delay the time to waiting signal that send to modem for work

valStartTime = Timer

While Timer < valStartTime + 5 delay for 5 minutes

DoEvents

Wend

MSComm1.Output = “ATH0″ & Chr$(13) ‘ close Hook Mode

MSComm1.DTREnable = False

MSComm1.RTSEnable = False

MSComm1.PortOpen = False

End Sub

Reset Modem program

Sub Reset_Modem()

Set values for connecting port with modem

MSComm1.CommPort =1

MSComm1.Settings = “28800,N,8,1″

If Not MSComm1.PortOpen Then MSComm1.PortOpen = True

MSComm1.DTREnable = True

MSComm1.RTSEnable = True

MSComm1.RThreshold = 1

MSComm1.InputLen = 1

‘Reset modem and cancel connection

MSComm1.Output = Chr$(13) & “ATZ” & Chr$(13) Reset modem

MSComm1.Output = “ATH0″ & Chr$(13) ‘ Hook Mode as Off

MSComm1.DTREnable = False

MSComm1.RTSEnable = False

MSComm1.PortOpen = False

End Sub


The learning outcome of this article

  1. To know how to program by Microsoft Visual Basic to control modem’s working.
  2. To know basic AT Command for Phone Dial-Up.
  3. To review programming to connect Serial Port (RS-232).