apexcommanalyse.bas

来自「vb写的串口调试助手」· BAS 代码 · 共 59 行

BAS
59
字号
Attribute VB_Name = "Module1"
Option Explicit

Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWDEFAULT = 10

' API call to execute commands with the windows shell
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


Public Const cnMaxFrameByteSize = 2048  ' 每帧最多cnMaxFrameByteSize字节

Global blTesting As Boolean ' 是否处于测试中

Global iBytesPerSend As Integer ' 每次写入控件的字节数

Global blFrameBeginFlagReceived As Boolean ' 收到了帧开始标识
Global blFrameEndFlagReceived As Boolean ' 收到了帧结束标识

Global iTotalSendBytes As Integer ' 发送缓冲有效字节数
Global bSendBuffer() As Byte ' 发送缓冲
Global strSendBytesHexString As String ' 发送内容的HEX显示内容

Global iTotalRecvCmpBytes As Integer ' 接收比较缓冲有效字节数
Global bRecvCmpBuffer() As Byte ' 接收比较缓冲

Global sglSecondsPer10Bytes As Single ' 正常情况下接收10字节需要的时间(秒),用于计算超时
Global sglLastRecvBytesTimer As Single '上次接收字节的时间

Global sglSecondsPerSendFrame As Single ' 正常情况下发送1帧需要的时间(秒),用于计算基本时间,防止发送超速
Global sglLastSendFrameTimer As Single '上次发送帧的时间

Global sglSecondsPer3SendFrame As Single ' 正常情况下接收3帧需要的时间(秒),用于计算超时
Global sglLastRecvFrameTimer As Single '上次接收帧的时间

Global iRecvFrameBytes As Integer ' 接收帧有效字节计数
Global bRecvFrameBuffer(cnMaxFrameByteSize) As Byte ' 接收帧缓冲

Global lngRecvBytesOK As Long ' 接收累计有效字节数
Global lngSendFrames As Long ' 发送帧计数
Global lngRecvFramesIntegrity As Long ' 接收完整帧计数
Global lngRecvFramesOk As Long ' 正确接收帧计数
Global lngRecvFrames As Long ' 接收帧计数

Global strLastInfor As String ' 连续相同的信息仅显示一次
Global iInforLineCount As Integer ' 累计显示信息行

' 将BYTE型转换成16进制显示的字符串
Function ConvertByteToHex(code As Byte) As String
    On Error Resume Next
    
    ConvertByteToHex = Hex$(code)
    
    If (Len(ConvertByteToHex) < 2) Then
        ConvertByteToHex = "0" + ConvertByteToHex
    End If
End Function

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?