I am trying to write a code in VB6 that accepts a data through a COM port. Right now a single GSM phone is sending the data. Data could be anything including a call or message. I am able to get the format for a call and message:
For a call:
RING+CLIP: "+919823596784",145,"",,"",0
and for message:
+CMT: "AD-bytwoo",,"14/06/05,17:19:31+22"
9860939518:
Hi Hw r u
Now the issue is, I have to change the RThreshold
value every time for call and message. Like MSComm1.Rthreshold = 47
for a call to get the whole string and MSComm1.RThreshold = 70
for small messages as mentioned above. For call if RThreshold is less than or greater than 47, data keeps on shifting. Whatever thread I have read about MSComm1
, it says RThreshold
should be equal to 1 as MSComm1.Oncom
event will trigger on reception of 1 character itself, but it's not happening with my code. Here is my code:
Dim str_1 As String
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
'On Error GoTo errx:
Dim strValue As String ' define Buffer value from Modem
MSComm1.CommPort = 6 'comm port no.
MSComm1.InBufferSize = 100
MSComm1.Handshaking = comNone
MSComm1.Settings = "9600,n,8,1"
MSComm1.RThreshold = 67 'no. of chr to receive
MSComm1.InputLen = 0 ' no. of chr on which oncomm event fires
MSComm1.RTSEnable = True
MSComm1.PortOpen = True 'open comm port
''MSComm1.Output = "AT + CLIP = 1" + Chr(13)
'Sleep 1500
'MSComm1.Output = "AT + CNUM" + Chr(13)
'Sleep 1500
'MSComm1.Output = "AT+CMGF=1" + Chr(13) '& Chr(10)
'Sleep 500
MSComm1.Output = "AT+CNMI=1,2" + Chr$(13)
Sleep 500
'Exit Sub
'errx:
'MsgBox "error"
End Sub
Private Sub MSComm1_OnComm()
If MSComm1.CommEvent = comEvReceive Then
If MSComm1.InBufferCount Then
Text1.Text = MSComm1.Input
End If
End If
MSComm1.InBufferCount = 0
str_1 = Text1.Text
End Sub
If MSComm1.RThreshold = 1
, then no character is received. Can anybody please tell me what is the issue?
Setting Communication of Serial Port
Using Buffer for receive and sent data
About Hardware