Module BLV_INFO Private DEBUG_PRINTF_EN As Byte = &H1 ''' ''' 协议处理返回值 ''' Enum PROCESS_RETURN Correct Check_Error DevType_Error Len_Error Cmd_Error End Enum ''' ''' BUS协议格式 ''' Enum BUS_PKT PKT_ADD_FM PKT_TYPE PKT_DevType PKT_ADD_TO PKT_LEN PKT_CHKSUM PKT_CMD PKT_PARA End Enum Enum BUS_PKT2 PKT_ADD_FM PKT_TYPE PKT_DevType PKT_ADD_TO PKT_LEN PKT_LEN_8 PKT_CHKSUM PKT_CMD PKT_PARA End Enum Enum DEBUG_WIN File_Info Content_Info End Enum ''' ''' 和校验取余数 ''' 求Byte数组的和校验取余数 ''' ''' Byte数组 ''' 计算校验值 Public Function CheckSum(dataPacket As Byte(), datalen As Byte) As Byte Dim sum As Integer For idx = 0 To datalen - 1 sum += dataPacket(idx) sum = sum And &HFF Next Dim sumMod As Byte = &HFF - sum Return sumMod End Function ''' ''' 调试信息输出到调试窗口信息 ''' ''' Public Sub DEBUG_Printf(str As String) If DEBUG_PRINTF_EN = &H1 Then Console.WriteLine(str & vbCrLf) End If End Sub ''' ''' 将调试信息输出到界面窗口中 ''' ''' 选择输出窗口 ''' 输出的信息 ''' 输出信息颜色 Public Sub Debug_Info_Display_On_Window(type As Byte, str As String, col As Color) Dim show_str As String = str Select Case type Case DEBUG_WIN.File_Info '文件解析信息内容显示窗口 If Form1.CheckBox1.Checked = True Then '判断当前是否打开该窗口 Form1.RichTextBox1.SelectionStart = Form1.RichTextBox1.TextLength Form1.RichTextBox1.SelectionColor = col Form1.RichTextBox1.AppendText(show_str & vbCrLf) End If Case DEBUG_WIN.Content_Info '数据内容解析信息显示窗口 If Form1.CheckBox2.Checked = True Then '判断当前是否打开该窗口 Form1.RichTextBox2.SelectionStart = Form1.RichTextBox2.TextLength Form1.RichTextBox2.SelectionColor = col Form1.RichTextBox2.AppendText(show_str & vbCrLf) End If Case Else End Select End Sub Public Sub Debug_Display_Clear(type As Byte) Select Case type Case DEBUG_WIN.File_Info '文件解析信息内容显示窗口 Form1.RichTextBox1.Clear() Case DEBUG_WIN.Content_Info '数据内容解析信息显示窗口 Form1.RichTextBox2.Clear() Case Else End Select End Sub End Module