📄 comprotocol.bas
字号:
ucComReadDataLen = Len(sComReceiveDataBuff)
If (ucComReadDataLen > 2) Then
sTempString = Right(sComReceiveDataBuff, 2)
If (StrComp(sTempString, "UU") = 0) Then
bSendCmd_SelectProgramDeviceIDNuberFlag = True
bFunctionReturnValue = True
' Call MsgBox("联机通讯成功")
Else
Call MsgBox("以当前波率无法完成通讯!", vbCritical, "请检查")
End If
Else
Call MsgBox("设备无响应,联机通讯约定波率出错!", vbCritical, "请检查")
End If
End If
Cmd_SelectProgramDeviceIDNumber = bFunctionReturnValue
End Function
Function CMD_ReadSignature(ByRef ucDataBuff As String) As Boolean
Dim bFunctionReturnValue As Boolean
If (bSendCmd_SelectProgramDeviceIDNuberFlag = False) Then
bFunctionReturnValue = Cmd_SelectProgramDeviceIDNumber()
End If
bFunctionReturnValue = False
Call ClearComInputBuff
sComSendDataBuff = ":020000050000F9"
Call ComSendData
If (ComReceivePackage(18)) Then
Dim sTempString As String
'sTempDebugString = ConvertComReceiveToDispString()
' Debug.Print sTempDebugString
sTempString = Right(sComReceiveDataBuff, 3)
ucDataBuff = Left(sTempString, 2)
Call ClearComInputBuff
sComSendDataBuff = ":020000050001F8"
Call ComSendData
If (ComReceivePackage(18)) Then
sTempString = Right(sComReceiveDataBuff, 3)
ucDataBuff = ucDataBuff & " " & Left(sTempString, 2)
Call ClearComInputBuff
sComSendDataBuff = ":020000050002F7"
Call ComSendData
If (ComReceivePackage(18)) Then
sTempString = Right(sComReceiveDataBuff, 3)
ucDataBuff = ucDataBuff & " " & Left(sTempString, 2)
bFunctionReturnValue = True
Else
Call MsgBox("读特征字操作发生错误", vbCritical, "请检查")
End If
Else
Call MsgBox("读特征字操作发生错误", vbCritical, "请检查")
End If
Else
Call MsgBox("读特征字操作发生错误", vbCritical, "请检查")
End If
CMD_ReadSignature = bFunctionReturnValue
End Function
Function CMD_PageReadProgramMemory(ByVal lCodeDataLen As Long) As Boolean
Dim iPageCount As Integer
Dim lAddress As Long
Dim iBaseNumber As Integer
Dim ucCompleteRatio As Byte
Dim iOffsetInPageCount As Integer
Dim bFunctionReturnValue As Boolean
Dim lTempAddress As Long
FrmMain.Lbl_ProgressPrompt.Caption = "完成进度"
FrmMain.Lbl_ProgressPrompt.Visible = True
FrmMain.Lbl_ProgressPrompt.Refresh
FrmMain.WritePGMCodeProgressBar.Min = 0
FrmMain.WritePGMCodeProgressBar.Max = lMaxCodeLength
FrmMain.WritePGMCodeProgressBar.Value = 0
FrmMain.WritePGMCodeProgressBar.Visible = True
iBaseNumber = lMaxCodeLength / 100 + 1
ucCompleteRatio = 0
FrmMain.lbl_DispCompleteRatio.Caption = CStr(ucCompleteRatio) & "%"
FrmMain.lbl_DispCompleteRatio.Visible = True
FrmMain.lbl_DispCompleteRatio.Refresh
bFunctionReturnValue = True
lAddress = 0
For iPageCount = 0 To (lCodeDataLen \ c_PackDataLength - 1) Step 1
'For iPageCount = 0 To (lCodeDataLen \ c_PackDataLength) Step 1
FrmMain.WritePGMCodeProgressBar.Value = lAddress
ucCompleteRatio = lAddress \ iBaseNumber
FrmMain.lbl_DispCompleteRatio.Caption = CStr(ucCompleteRatio) & "%"
FrmMain.lbl_DispCompleteRatio.Refresh
Next iPageCount
ucCompleteRatio = 100
FrmMain.lbl_DispCompleteRatio.Caption = CStr(ucCompleteRatio) & "%"
FrmMain.Lbl_ProgressPrompt.Visible = False
FrmMain.lbl_DispCompleteRatio.Visible = False
FrmMain.WritePGMCodeProgressBar.Visible = False
CMD_PageReadProgramMemory = bFunctionReturnValue
'CMD_PageReadProgramMemory = bFunctionReturnValue
' CMD_PageReadProgramMemory = True
End Function
Function CMD_WriteProgramMemory(ByVal lCodeDataLen As Long) As Boolean
Dim iPageCount As Integer
Dim lAddress As Long
Dim iBaseNumber As Integer
Dim ucCompleteRatio As Byte
Dim iOffsetInPageCount As Integer
Dim bFunctionReturnValue As Boolean
Dim lTempAddress As Long
Dim sOnePackageProgramCode As String '经过封包处理后发给设备的编程数据缓冲区
Dim sLowAddressByte As String
Dim sHighAddressByte As String
Dim sTempString As String
FrmMain.Lbl_ProgressPrompt.Caption = "完成进度"
FrmMain.Lbl_ProgressPrompt.Visible = True
FrmMain.Lbl_ProgressPrompt.Refresh
FrmMain.WritePGMCodeProgressBar.Min = 0
FrmMain.WritePGMCodeProgressBar.Max = lMaxCodeLength
FrmMain.WritePGMCodeProgressBar.Value = 0
FrmMain.WritePGMCodeProgressBar.Visible = True
iBaseNumber = lMaxCodeLength / 100 + 1
ucCompleteRatio = 0
FrmMain.lbl_DispCompleteRatio.Caption = CStr(ucCompleteRatio) & "%"
FrmMain.lbl_DispCompleteRatio.Visible = True
FrmMain.lbl_DispCompleteRatio.Refresh
bFunctionReturnValue = True
lAddress = 0
For iPageCount = 0 To (lCodeDataLen \ c_PackDataLength - 1) Step 1
'For iPageCount = 0 To (lCodeDataLen \ c_PackDataLength) Step 1
Call ClearComInputBuff
sOnePackageProgramCode = ":10"
lTempAddress = lAddress
lTempAddress = lTempAddress Mod &H1000000
lTempAddress = lTempAddress Mod &H10000
sHighAddressByte = CStr_Hex(CByte(lTempAddress \ &H100))
lTempAddress = lTempAddress Mod &H100
sLowAddressByte = CStr_Hex(CByte(lTempAddress))
sOnePackageProgramCode = sOnePackageProgramCode & sHighAddressByte & sLowAddressByte
sOnePackageProgramCode = sOnePackageProgramCode & "00"
' ucComSendDataBuff(iOffsetInPageCount + 10) = ucDataBuff(lAddress) 'bug Address 191 Err
'ucComSendDataBuff(10) = ucDataBuff(lAddress)
'For iOffsetInPageCount = 0 To c_PackDataLength - 2 Step 1
For iOffsetInPageCount = 0 To c_PackDataLength - 1 Step 1
' lAddress = lAddress + 1
' ucComSendDataBuff(iOffsetInPageCount + 11) = ucDataBuff(lAddress)
sOnePackageProgramCode = sOnePackageProgramCode & CStr_Hex(CByte(ucDataBuff(lAddress)))
lAddress = lAddress + 1
Next iOffsetInPageCount
sTempString = IntelHexFile_RecordLine_CheckSum(sOnePackageProgramCode)
sOnePackageProgramCode = sOnePackageProgramCode & sTempString
sComSendDataBuff = sOnePackageProgramCode
Call ComSendData
Delay (20)
If (ComReceivePackage(12 + c_PackDataLength * 2) = False) Then '无应答
bFunctionReturnValue = False
Exit For
End If
sTempString = Right(sComReceiveDataBuff, 1)
If (StrComp(sTempString, ".") = 0) Then
FrmMain.WritePGMCodeProgressBar.Value = lAddress
ucCompleteRatio = lAddress \ iBaseNumber
FrmMain.lbl_DispCompleteRatio.Caption = CStr(ucCompleteRatio) & "%"
FrmMain.lbl_DispCompleteRatio.Refresh
Else
bFunctionReturnValue = False
Call MsgBox("写编程数据操作发生错误", vbCritical, "请检查")
Exit For
End If
Next iPageCount
ucCompleteRatio = 100
FrmMain.lbl_DispCompleteRatio.Caption = CStr(ucCompleteRatio) & "%"
FrmMain.Lbl_ProgressPrompt.Visible = False
FrmMain.lbl_DispCompleteRatio.Visible = False
FrmMain.WritePGMCodeProgressBar.Visible = False
CMD_WriteProgramMemory = bFunctionReturnValue
End Function
Function CMD_WriteLockBits(ByVal ucLockType As Byte) As Boolean
Dim bFunctionReturnValue As Boolean
Dim sTempString As String
bFunctionReturnValue = False
Select Case (ucLockType)
Case c_LockType_unLock:
bFunctionReturnValue = True
CMD_WriteLockBits = bFunctionReturnValue
Exit Function
Case c_LockType_LockLevel1:
sComSendDataBuff = ":020000030500F6"
Case c_LockType_LockLevel2:
sComSendDataBuff = ":020000030501F5"
Case c_LockType_LockLevel3:
sComSendDataBuff = ":020000030502F4"
End Select
Call ClearComInputBuff
Call ComSendData
If (ComReceivePackage(16)) Then
sTempString = Right(sComReceiveDataBuff, 1)
If (StrComp(sTempString, ".") = 0) Then
bFunctionReturnValue = True
Else
Call MsgBox("加密操作发生错误!", vbCritical, "请检查")
End If
Else
Call MsgBox("加密操作发生错误,无应答或应答数据长度不符", vbCritical, "请检查")
End If
CMD_WriteLockBits = bFunctionReturnValue
End Function
Function CMD_PageVerifyProgramMemory(ByVal lCodeDataLen As Long) As Boolean
CMD_PageVerifyProgramMemory = True
End Function
Function CMD_CheckBank(ByVal lStartAddress As Long, ByVal lCheckBankDataLength As Long) As Boolean
Dim lTempAddress As Long
Dim ucBankFlag As Byte
Dim bFunctionReturnValue As Boolean
Dim sTempString As String
Call ClearComInputBuff
sComSendDataBuff = ":050000040000FFFF01F8"
Call ComSendData
Delay (1)
sComSendDataBuff = "U"
Call ComSendData
Delay (1000)
bFunctionReturnValue = False
If (ComReceivePackage(22)) Then
sTempString = Right(sComReceiveDataBuff, 1)
If (StrComp(sTempString, ".") = 0) Then
Else
MsgBox "器件非空"
End If
bFunctionReturnValue = True
Else
Call MsgBox("读超时!")
End If
CMD_CheckBank = bFunctionReturnValue
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -