Files
Desktop_LogAnalysisTools/BLV_INFO.vb
2025-12-11 11:51:00 +08:00

123 lines
3.1 KiB
VB.net
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Module BLV_INFO
Private DEBUG_PRINTF_EN As Byte = &H1
''' <summary>
''' 协议处理返回值
''' </summary>
Enum PROCESS_RETURN
Correct
Check_Error
DevType_Error
Len_Error
Cmd_Error
End Enum
''' <summary>
''' BUS协议格式
''' </summary>
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
''' <summary>
''' 和校验取余数
''' 求Byte数组的和校验取余数
''' </summary>
''' <param name="dataPacket">Byte数组</param>
''' <returns>计算校验值</returns>
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
''' <summary>
''' 调试信息输出到调试窗口信息
''' </summary>
''' <param name="str"></param>
Public Sub DEBUG_Printf(str As String)
If DEBUG_PRINTF_EN = &H1 Then
Console.WriteLine(str & vbCrLf)
End If
End Sub
''' <summary>
''' 将调试信息输出到界面窗口中
''' </summary>
''' <param name="type">选择输出窗口</param>
''' <param name="str">输出的信息</param>
''' <param name="col">输出信息颜色</param>
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