我正在尝试在 VB6 中编写一个通过 COM 端口接受数据的代码。现在,一部 GSM 手机正在发送数据。数据可以是任何东西,包括电话或消息。我能够获得呼叫和消息的格式:
来电:
RING+CLIP: "+919823596784",145,"",,"",0
和消息:
+CMT: "AD-bytwoo",,"14/06/05,17:19:31+22"
9860939518:
Hi Hw r u
RThreshold
现在的问题是,我每次都必须更改呼叫和消息的值。就像上面提到的MSComm1.Rthreshold = 47
获取整个字符串和小消息的调用一样。MSComm1.RThreshold = 70
对于调用,如果 RThreshold 小于或大于 47,则数据继续移动。无论我读过什么线程MSComm1
,它都说RThreshold
应该等于 1,因为MSComm1.Oncom
事件将在接收到 1 个字符本身时触发,但我的代码不会发生这种情况。这是我的代码:
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
如果MSComm1.RThreshold = 1
,则不接收任何字符。谁能告诉我是什么问题?