Wednesday, December 12, 2012

VB6 SMS Gateway: AT Command Tester Sederhana

Option Explicit 

Dim strBuffer As String

Private Sub cmdSend_Click()
txtResult.Text = ""
txtProcess.Text = ""
strBuffer = ""
If UCase$(Left$(txtATCommand.Text, 2)) <> "AT" Then
MSComm1.Output = txtATCommand.Text & Chr(26)
Else
MSComm1.Output = txtATCommand.Text & vbCrLf
End If
End Sub

Private Sub Form_Load()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
With MSComm1
.CommPort = 7
.Settings = "115200,N,8,1"
.Handshaking = comRTS
.RTSEnable = True
.DTREnable = True
.RThreshold = 1
.SThreshold = 1
.InputMode = comInputModeText
.InputLen = 0
.PortOpen = True
End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub

Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
strBuffer = strBuffer & MSComm1.Input
End Select
txtProcess.Text = strBuffer
txtProcess.SelStart = Len(txtProcess.Text)
Do
strBuffer = strBuffer & MSComm1.Input
Loop While MSComm1.InBufferCount
If InStr(1, strBuffer, "OK") > 0 Then
txtResult.Text = strBuffer
txtResult.SelStart = Len(txtResult.Text)
ElseIf InStr(1, strBuffer, "ERROR") Then
txtResult.Text = strBuffer
strBuffer = ""
End If
End Sub

Download: Source Code