📄 frmmain.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Begin VB.Form frmMain
BorderStyle = 3 'Fixed Dialog
Caption = "串口编程调试精灵"
ClientHeight = 6045
ClientLeft = 45
ClientTop = 435
ClientWidth = 8445
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6045
ScaleWidth = 8445
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame3
Caption = "发送内容"
Height = 975
Left = 360
TabIndex = 12
Top = 4680
Width = 7695
Begin VB.ComboBox cboHexASCII
Height = 300
Left = 5640
TabIndex = 14
Text = "Combo1"
Top = 360
Width = 1695
End
Begin VB.TextBox txtSend
Height = 270
Left = 120
TabIndex = 13
Text = "Text2"
Top = 360
Width = 5175
End
End
Begin VB.Frame Frame2
Caption = "接收回显"
Height = 3135
Left = 360
TabIndex = 6
Top = 1320
Width = 7815
Begin ComctlLib.Slider sldLenth
Height = 255
Left = 6000
TabIndex = 15
Top = 2400
Width = 1095
_ExtentX = 1931
_ExtentY = 450
_Version = 327682
LargeChange = 3
Min = 1
Max = 32
SelStart = 8
Value = 8
End
Begin VB.HScrollBar hsclHexEdit
Height = 255
Left = 240
TabIndex = 22
Top = 2640
Width = 4455
End
Begin VB.VScrollBar vsclHexEdit
Height = 2295
Left = 4920
TabIndex = 21
Top = 360
Width = 255
End
Begin VB.Frame fraHexEditBackground
Caption = "Frame4"
Height = 2415
Left = 240
TabIndex = 16
Top = 240
Width = 4455
Begin VB.TextBox txtBlank
Height = 2055
Left = 3360
TabIndex = 20
Text = "Text1"
Top = 120
Width = 975
End
Begin VB.TextBox txtHexEditASCII
Height = 2055
Left = 2280
TabIndex = 19
Text = "Text1"
Top = 120
Width = 975
End
Begin VB.TextBox txtHexEditHex
Height = 2055
Left = 1200
TabIndex = 18
Text = "Text1"
Top = 120
Width = 975
End
Begin VB.TextBox txtHexEditAddress
Height = 2055
Left = 120
TabIndex = 17
Text = "Text1"
Top = 120
Width = 975
End
End
Begin VB.CheckBox chkAddress48
Caption = "4/8位地址"
Height = 180
Left = 5760
TabIndex = 11
Top = 1800
Width = 1695
End
Begin VB.CheckBox chkAddress
Caption = "地址"
Height = 180
Left = 5760
TabIndex = 10
Top = 1320
Width = 1695
End
Begin VB.CheckBox chkASCII
Caption = "ASCII码"
Height = 180
Left = 5760
TabIndex = 9
Top = 840
Width = 1695
End
Begin VB.CheckBox chkHex
Caption = "十六进制码"
Height = 180
Left = 5760
TabIndex = 8
Top = 360
Width = 1695
End
Begin VB.TextBox txtReceive
Height = 2775
Left = 120
TabIndex = 7
Text = "Text1"
Top = 240
Width = 5175
End
End
Begin VB.CommandButton cmdClear
Caption = "清除"
Height = 375
Left = 6000
TabIndex = 5
Top = 480
Width = 1215
End
Begin VB.CommandButton cmdSetting
Caption = "设置参数"
Height = 375
Left = 4800
TabIndex = 4
Top = 480
Width = 1215
End
Begin VB.Frame Frame1
Caption = "操作提示"
Height = 855
Left = 360
TabIndex = 0
Top = 240
Width = 7815
Begin VB.CommandButton cmdReceive
Caption = "开始接收"
Height = 375
Left = 3240
TabIndex = 3
Top = 240
Width = 1215
End
Begin VB.CommandButton cmdManualSend
Caption = "手动发送"
Height = 375
Left = 2040
TabIndex = 2
Top = 240
Width = 1215
End
Begin VB.CommandButton cmdAutoSend
Caption = "自动发送"
Height = 375
Left = 840
TabIndex = 1
Top = 240
Width = 1215
End
End
Begin VB.Timer ctrTimer
Enabled = 0 'False
Interval = 1000
Left = 7440
Top = 120
End
Begin MSCommLib.MSComm ctrMSComm
Left = 7800
Top = 720
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'字符串表示的十六进制数据转化为相应的字节串
'返回转化的字节数
Function strHexToByteArray(strText As String, bytByte() As Byte) As Integer
Dim HexData As Integer '十六进制(二进制)数据字节对应值
Dim hstr As String * 1 '高位字符
Dim lstr As String * 1 '低位字符
Dim HighHexData As Integer '高位数值
Dim LowHexData As Integer '低位数值
Dim HexDataLen As Integer '字节数
Dim StringLen As Integer '字符串长度
Dim Account As Integer '计数
strText = ""
HexDataLen = 0
strHexToByteArray = 0
StringLen = Len(strText)
Account = StringLen / 2
ReDim bytByte(Account)
For n = 1 To StringLen
Do '清除空格
hstr = Mid(strText, n, 1)
n = n + 1
If (n - 1) > StringLen Then
HexDataLen = HexDataLen - 1
Exit For
End If
Loop While hstr = ""
Do '清除空格
lstr = Mid(strText, n, 1)
n = n + 1
If (n - 1) > StringLen Then
HexDataLen = HexDataLen - 1
Exit For
End If
Loop While lstr = ""
n = n - 1
If n > stinglen Then
HexDataLen = HexDataLen - 1
Exit For
End If
HighHexData = ConvertHexChr(hstr) '获得高位值
LowHexData = converhexchr(lstr) '获得低位值
If HighHexData - 1 Or LowHexData - 1 Then '遇到非法字符中断转化
HexDataLen = HexDataLen - 1 '
Exit For
Else
HexData = HighHexData * 16 + LowHexData
bytByte(HexDataLen) = HexData
HexDataLen = HexDataLen + 1
End If
Next n
If HexDataLen > 0 Then
HexDataLen = HexDataLen - 1
ReDim Preserve bytByte(HexDataLen)
Else
ReDim Preserve bytByte(0)
End If
If HexDataLen = 0 Then
strHexToByteArray = 0
Else
strHexToByteArray = HexDataLen + 1
End If
End Function
'字符表示的十六进制数转化为相应的整数
'错误则返回-1
Function ConvertHexChr(str As String) As Integer
Dim test As Integer
test = Asc(str)
If test >= Asc("0") And test <= Asc("9") Then
test = test - Asc("0")
ElseIf test >= Asc("a") And test <= Asc("f") Then
test = test - Asc("a")
ElseIf test >= Asc("A") And test <= Asc("F") Then
test = test - Asc("A")
Else
test = -1 '出错信息
End If
ConvertHexChr = test
End Function
'对组合框的响应
Private Sub cboHexASCII_Change()
If cboHexASCII.Text = "按ASCII码" Then
intOutMode = 0
Else
intOutMode = 1
End If
End Sub
'选择地址
Private Sub chkAddress_Click()
If chkAddress.Value = 0 Then
intAddressChk = 0
Else
intAddressChk = 1
End If
Call ScrollRedisplay
End Sub
'选择4/8位地址
Private Sub chkAddress48_Click()
If chkAddress48.Value = 1 Then
intAdd48Chk = 1
Else
intAdd48Chk = 0
End If
Call SlideRedisplay
End Sub
'选择ASCII码
Private Sub chkASCII_Click()
If chkASCII.Value = 1 Then
intASCIIChk = 1
Else
intASCIIChk = 0
End If
Call ScrollRedisplay
End Sub
'选择十六进制编码
Private Sub chkHex_Click()
If chkHex.Value = 1 Then
intHexChk = 1
Else
intHexChk = 0
End If
Call ScrollRedisplay
End Sub
'自动发送
Private Sub cmdAutoSend_Click()
If blnAutoSendFlag Then
frmMain.ctrTimer.Enabled = False '禁止Timer
If Not blnReceiveFlag Then
frmMain.ctrMSComm.PortOpen = False '关闭串行口
End If
frmMain.cmdAutoSend.Caption = "自动发送"
Else
If Not frmMain.ctrMSComm.PortOpen Then '打开串行口,准备发送
frmMain.ctrMSComm.CommPort = intPort '设置串行口号
frmMain.ctrMSComm.Settings = strSet '设置波特率等
frmMain.ctrMSComm.PortOpen = True '打开串行口
End If
frmMain.ctrTimer.Interval = intTime
frmMain.ctrTimer.Enabled = True '激活Timer,进行发送
frmMain.cmdAutoSend.Caption = "停止发送"
End If
blnAutoSendFlag = Not blnAutoSendFlag
End Sub
'清除
Private Sub cmdClear_Click()
Dim bytTemp(0) As Byte
ReDim bytReceiveByte(0) '清空已接收的数据
intReceiveLen = 0
Call InputManage(bytTemp, 0) '清空转换后的预输出文本
Call GetDisplayText
Call display
End Sub
'手动发送
Private Sub cmdManualSend_Click()
If Not frmMain.ctrMSComm.PortOpen Then '打开串行口,准备发送
frmMain.ctrMSComm.CommPort = intPort '设置串行口号
frmMain.ctrMSComm.Settings = strSet '设置波特率等
frmMain.ctrMSComm.PortOpen = True '打开串行口
End If
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -