📄 module1.bas
字号:
Attribute VB_Name = "Module1"
'*********************************************
'用于变量声明
'*********************************************
'Public Test_COM As Boolean
Public com_setting As String '串口设置参数串
Public com_now_num As Integer '当前串口号
Public com_last_num As Integer '上一个串口号
Public com_last_open_num As Integer '上一个打开的端口,在打开下个端口钱要关闭
Public jiaoyan As String '转换为校验值
Public intTime As Integer '周期发送间隔
'**********************************
'发送模块
'**********************************
Public intOutMode As Integer '发送模式
Public strSendText As String '发送文本数据
Public bytSendByte() As Byte '发送二进制数据
'**********************************
'接收模块
'**********************************
Public bytReceiveByte() As Byte '接收到的字节
Public intReceiveLen As Integer '接收到的字节数
'**********************************
'显示模块
'**********************************
Public strAddress As String '地址信息
Public strHex As String '十六进制编码
Public strAscii As String 'ASCII码
'**********************************
'输入处理
'处理接收到的字节流,并保存在全局变量
'bytReceiveRyte()
'**********************************
Public Sub InputManage(bytInput() As Byte, intInputLenth As Integer)
Dim n As Integer '定义变量及初始化
ReDim Preserve bytReceiveByte(intReceiveLen + intInputLenth)
For n = 1 To intInputLenth Step 1
bytReceiveByte(intReceiveLen + n - 1) = bytInput(n - 1)
Next n
intReceiveLen = intReceiveLen + intInputLenth
End Sub
'***********************************
'为输出准备文本
'保存在全局变量
'strText
'strHex
Public Sub GetDisplayText()
Dim n As Integer
Dim intValue As Integer
Dim intHighHex As Integer
Dim intLowHex As Integer
Dim strSingleChr As String * 1
Dim intAddress As Integer
Dim intAddressArray(8) As Integer
Dim intHighAddress As Integer
strAscii = "" '设置初值
strHex = ""
'*****************************************
'获得16进制码和ASCII码的字符串
'*****************************************
For n = 1 To intReceiveLen
intValue = bytReceiveByte(n - 1)
If intValue < 32 Or intValue > 128 Then '处理非法字符
strSingleChr = Chr(46) '对于不能显示的ASCII码,
Else '用"."表示
strSingleChr = Chr(intValue)
End If
strAscii = strAscii + strSingleChr
intHighHex = intValue \ 16
intLowHex = intValue - intHighHex * 16
If intHighHex < 10 Then
intHighHex = intHighHex + 48
Else
intHighHex = intHighHex + 55
End If
If intLowHex < 10 Then
intLowHex = intLowHex + 48
Else
intLowHex = intLowHex + 55
End If
strHex = strHex + " " + Chr$(intHighHex) + Chr$(intLowHex) + " "
' If (n Mod intHexWidth) = 0 Then '设置换行
' strAscii = strAscii + Chr$(13) + Chr$(10)
' strHex = strHex + Chr$(13) + Chr$(10)
Next n
End Sub
Public Sub display()
If frmmain.Option1.Value = True Then
frmmain.Text1.Text = strHex '0:文本方式,1:二进制方式
Else
frmmain.Text1.Text = strAscii '0:文本方式,1:二进制方式
End If
'frmmain.Text1.Text = strHex
'frmmain.txtHexEditText.Text = strDisplayAscii
'frmmain.txtHexEditAddress.Text = strDisplayAddress
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -