Hello,i am using VB6 in the development of my project which deals with sending sms messages if an intrusion in home/office is detected. However the application hangs whenever i try to run it.At sometimes even if it rarely runs it hangs after 2 or 3 minutes.Please help me with this problem. Here is the code:
Dim GET_HWSW_VERSION, ACK_HWSW_VERSION, ACK_SMS_RECD, SEND_SMS_MESSAGE, ACK_SMS_SENT, SMS_CENTER As String Dim bytesReceived(1) As Byte Dim rbuffer As Variant Dim bytestosend(1) As Byte
Private Sub CmdExit_Click() End End Sub
Private Sub Command1_Click() MessageTxt.Text = "Fire Sensing" Call SendSms ' for sms
End Sub
Private Sub Form_Load() Dim PORTNUMBER As Integer PORTNUMBER = 3 'WANT TO CHANGE PORT NUMBER FOR KIT MSComm1.CommPort = PORTNUMBER MSComm1.PortOpen = True MSComm1.Settings = "1200,N,8,1" MSComm1.InputMode = comInputModeBinary MSComm1.RThreshold = 1 MSComm1.SThreshold = 1 MSComm1.Output = Chr$(&H41)
GET_HWSW_VERSION = "1E 00 0C D1 00 07 00 01 00 03 00 01 60 00 72 D5 " ACK_HWSW_VERSION = "1E 00 0C 7F 00 02 D2 01 C0 7C " ACK_SMS_RECD = "1E 00 0C 7F 00 02 02 05 10 78 " ACK_SMS_SENT = "1E 00 0C 7F 00 02 02 04 10 79" SMS_CENTER = "1E 00 0C 02 00 08 00 01 00 33 64 01 01 42 77 7B " SEND_SMS_MESSAGE = "1E 00 0C 02 00 2D 00 01 00 01 02 00 07 91 19 89 48 00 45 44 00 00 00 00 15 00 00 00 01 0A 81 89 48 01 61 22 00 00 00 00 00 A7 00 00 00 00 00 00 45 01 43 00 " MSComm2.PortOpen = True 'SMS End Sub
Private Sub MSComm1_OnComm() Dim bytesReceived() As Byte Dim rcount As Byte Dim buffer As Variant Dim ComEventMessage As String Select Case MSComm1.CommEvent Case comEvReceive
buffer = MSComm1.Input bytesReceived() = buffer rcount = bytesReceived(0) Select Case rcount
Case 1 Label2.Caption = "Smoke Sensing" MessageTxt.Text = "Smoke Sensing" Call SendSms ' for sms Case 2 Label2.Caption = "Fire Sensing" MessageTxt.Text = "Fire Sensing" Call SendSms ' for sms Case 3 Label2.Caption = "High Temp Sensing" MessageTxt.Text = "High Temp Sensing" Call SendSms ' for sms Case 4 Label2.Caption = "Obstacle Sensing" MessageTxt.Text = "Obstacle Sensing" Call SendSms ' for sms End Select End Select End Sub Public Sub SendCommand(ByVal cmstr As String) Cmdlen = Len(cmstr) / 3 Rstr = "" For Tmp = 0 To (Cmdlen - 1) Sstr = "&H" Sstr = Sstr & Trim(Mid$(cmstr, (Tmp * 3) + 1, 3)) MSComm2.Output = Chr(Val(Sstr)) Next End Sub Private Sub SendSms() For Tmp = 1 To 128 MSComm2.Output = "U" Next
Sleep 100
SendCommand (GET_HWSW_VERSION) Sleep 1000 Sleep 1000 Do Tstr1 = MSComm2.Input Loop Until Len(Tstr1) <> 0 SendCommand (ACK_HWSW_VERSION) Sleep 100 Tstr1 = "1E 00 0C 02 00 AA 00 01 00 01 02 00 07 91 " For Tmp = 1 To (Len(MsgCntrNo.Text) / 2) Tstr1 = Tstr1 & Mid$(MsgCntrNo.Text, (Tmp * 2), 1) Tstr1 = Tstr1 & Mid$(MsgCntrNo.Text, (Tmp * 2) - 1, 1) & " " Next Tmp
Tstr1 = Tstr1 & "00 00 00 00 15 00 00 00 FF 0A 81 " If Len(CStr(Hex(Len((MessageTxt.Text))))) = 1 Then Tstr1 = Replace(Tstr1, "FF", "0" & CStr(Hex(Len((MessageTxt.Text))))) Else Tstr1 = Replace(Tstr1, "FF", CStr(Hex(Len((MessageTxt.Text))))) End If For Tmp = 1 To (Len(txtDestNo.Text) / 2) Tstr1 = Tstr1 & Mid$(txtDestNo.Text, (Tmp * 2), 1) Tstr1 = Tstr1 & Mid$(txtDestNo.Text, (Tmp * 2) - 1, 1) & " " Next Tmp
Tstr1 = Tstr1 & "00 00 00 00 00 A7 00 00 00 00 00 00 " Tstr1 = Tstr1 & PACK_Message(MessageTxt.Text) Tstr1 = Tstr1 & "01 43 " If ((Len(Tstr1) / 3) Mod 2) <> 0 Then Tstr1 = Tstr1 & "00 " MsgLen = Len(Mid$(Tstr1, 19, (Len(Tstr1) - 18))) / 3 MsgLen = (MsgLen - 1) Tstr1 = Replace(Tstr1, "AA", CStr(Hex(MsgLen))) Else MsgLen = Len(Mid$(Tstr1, 19, (Len(Tstr1) - 18))) / 3 Tstr1 = Replace(Tstr1, "AA", CStr(Hex(MsgLen))) End If SendCommand (Calculate_CheckSum(Tstr1)) Sleep 1000 SendCommand (Calculate_CheckSum(Tstr1))
End Sub[code=VB6]
Dim GET_HWSW_VERSION, ACK_HWSW_VERSION, ACK_SMS_RECD, SEND_SMS_MESSAGE, ACK_SMS_SENT, SMS_CENTER As String
Dim bytesReceived(1) As Byte
Dim rbuffer As Variant
Dim bytestosend(1) As Byte
Private Sub CmdExit_Click()
End
End Sub
Private Sub Command1_Click()
MessageTxt.Text = "Fire Sensing"
Call SendSms ' for sms
End Sub
Private Sub Form_Load()
Dim PORTNUMBER As Integer
PORTNUMBER = 3 'WANT TO CHANGE PORT NUMBER FOR KIT
MSComm1.CommPort = PORTNUMBER
MSComm1.PortOpen = True
MSComm1.Settings = "1200,N,8,1"
MSComm1.InputMode = comInputModeBinary
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.Output = Chr$(&H41)
GET_HWSW_VERSION = "1E 00 0C D1 00 07 00 01 00 03 00 01 60 00 72 D5 "
ACK_HWSW_VERSION = "1E 00 0C 7F 00 02 D2 01 C0 7C "
ACK_SMS_RECD = "1E 00 0C 7F 00 02 02 05 10 78 "
ACK_SMS_SENT = "1E 00 0C 7F 00 02 02 04 10 79"
SMS_CENTER = "1E 00 0C 02 00 08 00 01 00 33 64 01 01 42 77 7B "
SEND_SMS_MESSAGE = "1E 00 0C 02 00 2D 00 01 00 01 02 00 07 91 19 89 48 00 45 44 00 00 00 00 15 00 00 00 01 0A 81 89 48 01 61 22 00 00 00 00 00 A7 00 00 00 00 00 00 45 01 43 00 "
MSComm2.PortOpen = True 'SMS
End Sub
Private Sub MSComm1_OnComm()
Dim bytesReceived() As Byte
Dim rcount As Byte
Dim buffer As Variant
Dim ComEventMessage As String
Select Case MSComm1.CommEvent
Case comEvReceive
buffer = MSComm1.Input
bytesReceived() = buffer
rcount = bytesReceived(0)
Select Case rcount
Case 1
Label2.Caption = "Smoke Sensing"
MessageTxt.Text = "Smoke Sensing"
Call SendSms ' for sms
Case 2
Label2.Caption = "Fire Sensing"
MessageTxt.Text = "Fire Sensing"
Call SendSms ' for sms
Case 3
Label2.Caption = "High Temp Sensing"
MessageTxt.Text = "High Temp Sensing"
Call SendSms ' for sms
Case 4
Label2.Caption = "Obstacle Sensing"
MessageTxt.Text = "Obstacle Sensing"
Call SendSms ' for sms
End Select
End Select
End Sub
Public Sub SendCommand(ByVal cmstr As String)
Cmdlen = Len(cmstr) / 3
Rstr = ""
For Tmp = 0 To (Cmdlen - 1)
Sstr = "&H"
Sstr = Sstr & Trim(Mid$(cmstr, (Tmp * 3) + 1, 3))
MSComm2.Output = Chr(Val(Sstr))
Next
End Sub
Private Sub SendSms()
For Tmp = 1 To 128
MSComm2.Output = "U"
Next
Sleep 100
SendCommand (GET_HWSW_VERSION)
Sleep 1000
Sleep 1000
Do
Tstr1 = MSComm2.Input
Loop Until Len(Tstr1) <> 0
SendCommand (ACK_HWSW_VERSION)
Sleep 100
Tstr1 = "1E 00 0C 02 00 AA 00 01 00 01 02 00 07 91 "
For Tmp = 1 To (Len(MsgCntrNo.Text) / 2)
Tstr1 = Tstr1 & Mid$(MsgCntrNo.Text, (Tmp * 2), 1)
Tstr1 = Tstr1 & Mid$(MsgCntrNo.Text, (Tmp * 2) - 1, 1) & " "
Next Tmp
Tstr1 = Tstr1 & "00 00 00 00 15 00 00 00 FF 0A 81 "
If Len(CStr(Hex(Len((MessageTxt.Text))))) = 1 Then
Tstr1 = Replace(Tstr1, "FF", "0" & CStr(Hex(Len((MessageTxt.Text)))))
Else
Tstr1 = Replace(Tstr1, "FF", CStr(Hex(Len((MessageTxt.Text)))))
End If
For Tmp = 1 To (Len(txtDestNo.Text) / 2)
Tstr1 = Tstr1 & Mid$(txtDestNo.Text, (Tmp * 2), 1)
Tstr1 = Tstr1 & Mid$(txtDestNo.Text, (Tmp * 2) - 1, 1) & " "
Next Tmp
Tstr1 = Tstr1 & "00 00 00 00 00 A7 00 00 00 00 00 00 "
Tstr1 = Tstr1 & PACK_Message(MessageTxt.Text)
Tstr1 = Tstr1 & "01 43 "
If ((Len(Tstr1) / 3) Mod 2) <> 0 Then
Tstr1 = Tstr1 & "00 "
MsgLen = Len(Mid$(Tstr1, 19, (Len(Tstr1) - 18))) / 3
MsgLen = (MsgLen - 1)
Tstr1 = Replace(Tstr1, "AA", CStr(Hex(MsgLen)))
Else
MsgLen = Len(Mid$(Tstr1, 19, (Len(Tstr1) - 18))) / 3
Tstr1 = Replace(Tstr1, "AA", CStr(Hex(MsgLen)))
End If
SendCommand (Calculate_CheckSum(Tstr1))
Sleep 1000
SendCommand (Calculate_CheckSum(Tstr1))
End Sub