📄 mdlcommon.bas
字号:
End If
If g_strThisAT <> "" Then g_blIsWaiting = Not AnalysisData(g_strSave, g_strThisAT, blIfInprogress, CommandStatus)
End If
If TimedOut = True Then
TimedOut = False
End If
TimedOut = g_blIsWaiting
If g_strSave <> "" And g_strSave <> vbCr Then
If g_strThisAT = "" Then
iCountMonitor = iCountMonitor + 1
If Not g_blIsWaiting Then GoTo ProcessNextData
End If
ElseIf g_strSave = vbCr Or g_strSave = "" Then
g_strSave = ""
g_blIsWaiting = False
g_strThisAT = ""
g_strLastAT = ""
End If
' Me.Caption = Len(g_strSave)
strATData = g_strSave
GetDataFromCommPort = True
Exit Function
ErrorG:
CommandStatus = "获取串口数据:" & Err.Description
End Function
Private Function AnalysisData(strTmpSave1 As String, _
strThisAt1 As String, _
Optional blIsInprogress1 As Boolean, _
Optional CommandStatus As String) As Boolean
On Error GoTo ErrorN
Static nCountSMSList As Long
Dim strTmp As String, strTmp1 As String, strTmp2 As String, strTmp3 As String
Dim i As Integer, iTmp As Integer, iLen As Integer, iCr As Integer
Dim sglTmpLeft As Single, sglTmpWidth As Single
Dim blTmp As Boolean
Dim iCMTI As Integer, iCSQ As Integer
strTmp2 = ""
'把AT响应字符串中的非可视字符滤除
For i = 1 To Len(strThisAt1)
strTmp1 = Mid(strThisAt1, i, 1)
If Asc(strTmp1) > 32 Then strTmp2 = strTmp2 & strTmp1
Next i
strThisAt1 = strTmp2
strTmp2 = ""
Select Case strThisAt1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case "OK"
iTmp = InStr(strTmpSave1, "OK")
iCr = InStr(strTmpSave1, vbCr)
If iTmp > 0 And iCr > 0 And iCr > iTmp Then
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr)
CommandStatus = "OK."
g_blIsSysBusy = False
g_blIsSendingSMS = False
AnalysisData = True
strThisAt1 = ""
ElseIf iTmp > 0 And iCr > 0 Then
g_blIsSysBusy = False
g_blIsSendingSMS = False
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr)
AnalysisData = True
strThisAt1 = ""
Else
AnalysisData = False
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case "ERROR"
iTmp = InStr(strTmpSave1, "ERROR")
iCr = InStr(strTmpSave1, vbCr)
g_blIsSysBusy = False
g_blIsSendingSMS = False
If iTmp > 0 And iCr > 0 And iCr > iTmp Then
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr)
CommandStatus = "错误。"
AnalysisData = True
Else
AnalysisData = False
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case "RING"
iTmp = InStr(strTmpSave1, "RING")
iCr = InStr(strTmpSave1, vbCr)
g_blIsSendingSMS = False
If iTmp > 0 And iCr > 0 And iCr > iTmp Then
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr)
CommandStatus = "有电话呼入。"
g_blIsNewCallIn = True
AnalysisData = True
ElseIf iTmp > 0 And iCr > 0 Then
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr)
AnalysisData = True
Else
AnalysisData = False
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case "IsEcho"
'把上次命令中的非可视字符滤除
strTmp2 = ""
For i = 1 To Len(g_strLastAT)
strTmp1 = Mid(g_strLastAT, i, 1)
If Asc(strTmp1) > 32 Then strTmp2 = strTmp2 & strTmp1
Next i
g_strLastAT = strTmp2
'把上次命令中=之后的参数滤除,如果有的话
iLen = InStr(g_strLastAT, "=")
If iLen > 0 Then
strTmp = Right(g_strLastAT, Len(g_strLastAT) - iLen)
g_strLastAT = Left(g_strLastAT, iLen - 1)
End If
blTmp = False
g_strLastAT = UCase(g_strLastAT)
iLen = InStr(g_strLastAT, "OK")
If iLen = 0 Then
g_strLatestAT = g_strLastAT
Select Case g_strLastAT
'=================================================================================
Case "AT+CSQ" '查询信号
Dim nTmpSignal As Long
Dim strImgKey As String
On Error Resume Next
g_blIsSysBusy = False
g_blIsSendingSMS = False
blTmp = QueryRSSI(strTmpSave1, iLen, iTmp)
If blTmp Then
If iLen <> 99 Then
nTmpSignal = CLng(iLen / 31 * 5)
strImgKey = "Signal" & nTmpSignal
End If
strThisAt1 = ""
End If
'=================================================================================
Case "AT+CMGR"
iCr = InStr(strTmpSave1, "OK" & vbCr)
If iCr > 0 Then
'去除双引号
g_blIsSysBusy = False
g_blIsSendingSMS = False
For i = 1 To Len(strTmpSave1)
strTmp1 = Mid(strTmpSave1, i, 1)
If strTmp1 <> """" Then strTmp = strTmp & strTmp1
Next i
strTmpSave1 = strTmp
CommandStatus = "完毕。"
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr - 2)
strThisAt1 = ""
blTmp = True
ElseIf InStr(strTmpSave1, "ERROR:") > 0 And InStr(strTmpSave1, vbCr) > 0 _
Or InStr(strTmpSave1, "ERROR" & vbCr) > 0 Then
CommandStatus = "序号为" & strTmp & "的短信不存在。"
iCr = InStr(strTmpSave1, vbCr)
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr)
strThisAt1 = ""
blTmp = True
Else
CommandStatus = CommandStatus & "·"
blTmp = False
End If
'=================================================================================
Case "AT+CMGD"
iCr = InStr(strTmpSave1, "OK" & vbCr)
' txtIdxSMS.BackColor = vbWhite
' txtIdxSMS.ForeColor = vbRed
If iCr > 0 Then
g_blIsSysBusy = False
g_blIsSendingSMS = False
CommandStatus = CommandStatus & "完成。"
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr - 2)
strThisAt1 = ""
blTmp = True
Else
CommandStatus = "正在删除" & strTmp & "条短信..."
If InStr(strTmp, "1,1") > 0 Then CommandStatus = "正在删除全部已读短信..."
blTmp = False
End If
'=================================================================================
Case "AT+CMGL"
Dim strTmpBuf As String
Static nTmpCountList As Long
iCr = InStr(strTmpSave1, "OK" & vbCr)
If iCr > 0 Then
strTmp = Left(strTmpSave1, iCr - 1)
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr - 2)
strThisAt1 = ""
'txtTmpData.Text = strTmp
nTmpCountList = 0
For i = 1 To Len(strTmp)
strTmp1 = Mid(strTmp, i, 6)
If strTmp1 = "+CMGL:" Then nTmpCountList = nTmpCountList + 1
Next i
If nTmpCountList > 0 Then
nCountSMSList = nTmpCountList
End If
CommandStatus = "共有" & nCountSMSList & "条短消息,AT完毕。"
g_blIsSysBusy = False
g_blIsSendingSMS = False
If nCountSMSList > 0 Then
g_blMaySaveAllSMS = True
n_CountListSMS = nCountSMSList
g_blIsListSMS = True
g_blIsNewSMSIn = False
'Call AddTask(SaveAllMSGTask, 5, 0, 10)
'tmrAuto.Enabled = True
Else
g_blMaySaveAllSMS = False
End If
nCountSMSList = 0
blTmp = True
Else
strTmpBuf = strTmpSave1
nTmpCountList = 0
For i = 1 To Len(strTmpBuf)
strTmp1 = Mid(strTmpBuf, i, 6)
If strTmp1 = "+CMGL:" Then nTmpCountList = nTmpCountList + 1
Next i
If nTmpCountList > 0 Then
'txtTmpData.Text = strTmpSave1
nCountSMSList = nTmpCountList
End If
CommandStatus = "读取中···"
AnalysisData = True
blTmp = False
End If
'=================================================================================
Case "AT+CMGS"
iCr = InStr(strTmpSave1, "> ")
iTmp = InStr(strTmpSave1, Chr(26) & vbCr)
If iCr > 0 And iTmp = 0 Then
If Right(strTmpSave1, Len(strTmpSave1) - iCr - 1) = "" Then
'tmrSendSMS.Enabled = True
'Call AddTask(TimeToSendSMSUDTask, 4, 0, 30)
End If
CommandStatus = "正在发送短消息..."
blTmp = False
ElseIf iTmp > 0 Then
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iTmp - 1)
g_strLastAT = ""
strThisAt1 = ""
blTmp = True
End If
'=================================================================================
Case Else
iCr = InStr(strTmpSave1, "OK" & vbCr)
If iCr > 0 Then
g_blIsSysBusy = False
g_blIsSendingSMS = False
CommandStatus = Left(strTmpSave1, Len(strTmpSave1) - 1)
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iCr - 2)
strThisAt1 = ""
blTmp = True
ElseIf InStr(strTmpSave1, "ERROR" & vbCr) > 0 Or _
InStr(strTmpSave1, "ERROR:") > 0 And InStr(strTmpSave1, vbCr) > 0 Then
g_blIsSysBusy = False
g_blIsSendingSMS = False
iTmp = InStr(strTmpSave1, vbCr)
CommandStatus = Left(strTmpSave1, Len(strTmpSave1) - 1)
strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iTmp)
strThisAt1 = ""
blTmp = True
Else
blTmp = False
End If
'=================================================================================
End Select
If blTmp Then g_strLastAT = "": strThisAt1 = ""
AnalysisData = blTmp
Else
If Len(strTmpSave1) - iLen - 1 >= 0 Then strTmpSave1 = Right(strTmpSave1, Len(strTmpSave1) - iLen - 1)
strThisAt1 = ""
AnalysisData = True
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Case "+CSQ:"
g_blIsSysBusy = False
g_blIsSendingSMS = False
blTmp = QueryRSSI(strTmpSave1, iLen, iTmp)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -