?? 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 + -