📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "电源供应器的控制"
ClientHeight = 5010
ClientLeft = 60
ClientTop = 345
ClientWidth = 6855
LinkTopic = "Form1"
ScaleHeight = 5010
ScaleWidth = 6855
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 480
Left = 90
TabIndex = 10
Top = 2025
Width = 3135
End
Begin VB.CommandButton Command3
Caption = "设置电压"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 3780
TabIndex = 9
Top = 2430
Width = 1725
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1335
Left = 90
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 6
Text = "Form1.frx":0000
Top = 3030
Width = 3135
End
Begin VB.CommandButton Command1
Caption = "送出命令"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 3780
TabIndex = 5
Top = 1170
Width = 1725
End
Begin VB.CommandButton Command2
Caption = "结束系统"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 855
Left = 3780
TabIndex = 4
Top = 3735
Width = 1725
End
Begin VB.TextBox txtCmd
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 480
Left = 90
TabIndex = 3
Top = 990
Width = 3135
End
Begin VB.Frame Frame1
Caption = "选择串行端口"
Height = 732
Left = 3555
TabIndex = 0
Top = 135
Width = 2652
Begin VB.OptionButton optCom
Caption = "COM2"
Height = 252
Index = 1
Left = 1584
TabIndex = 2
Top = 336
Value = -1 'True
Width = 855
End
Begin VB.OptionButton optCom
Caption = "COM1"
Height = 252
Index = 0
Left = 384
TabIndex = 1
Top = 336
Width = 855
End
End
Begin MSCommLib.MSComm MSComm1
Left = 5940
Top = 1350
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
RThreshold = 1
BaudRate = 2400
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "电压设置区"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 1
Left = 225
TabIndex = 11
Top = 1665
Width = 1200
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "返回字符串"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 2
Left = 135
TabIndex = 8
Top = 2655
Width = 1200
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "命令输入区"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 240
Index = 0
Left = 225
TabIndex = 7
Top = 630
Width = 1200
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
''''''''''''''''''''''''''''''''''''''''''''''
'使用按钮控件
'将命令分成一个一个的字符,再使用Output属性送出
'每一个字符间延迟50毫秒
'''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()
Dim Buf$, BufLen%, i%, PowerDelay&
PowerDelay = 50
Buf = CStr(Trim(txtCmd.Text))
BufLen = Len(Buf)
For i = 1 To BufLen
MSComm1.Output = Mid(Buf, i, 1): TimeDelay PowerDelay
Next i
MSComm1.Output = Chr(13)
End Sub
''''''''''''''''''''''''''''''''''''''''''''''
'使用按钮控件
'结束系统
'''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command2_Click()
End
End Sub
''''''''''''''''''''''''''''''''''''''''''''''
'使用按钮控件
'选择波道,设置电压,并将设置的波道打开以输出
'数值的设置有一定的格式,此点必须注意
'''''''''''''''''''''''''''''''''''''''''''''
Private Sub Command3_Click()
Dim PowerDelay&
Dim SetVoltage!, Buf$, BufLen%
PowerDelay = 50
SetVoltage = Val(Text2.Text)
If SetVoltage = 0 Then
MSComm1.Output = "C": TimeDelay PowerDelay
MSComm1.Output = "H": TimeDelay PowerDelay
MSComm1.Output = "A": TimeDelay PowerDelay
MSComm1.Output = "N": TimeDelay PowerDelay
MSComm1.Output = "1": TimeDelay PowerDelay
MSComm1.Output = Chr(13)
TimeDelay 100
MSComm1.Output = "o": TimeDelay PowerDelay
MSComm1.Output = "u": TimeDelay PowerDelay
MSComm1.Output = "t": TimeDelay PowerDelay
MSComm1.Output = "0": TimeDelay PowerDelay
MSComm1.Output = Chr(13)
Exit Sub
End If
MSComm1.Output = "C": TimeDelay PowerDelay
MSComm1.Output = "H": TimeDelay PowerDelay
MSComm1.Output = "A": TimeDelay PowerDelay
MSComm1.Output = "N": TimeDelay PowerDelay
MSComm1.Output = "1": TimeDelay PowerDelay
MSComm1.Output = Chr(13)
TimeDelay 100
MSComm1.Output = "v": TimeDelay PowerDelay
MSComm1.Output = "s": TimeDelay PowerDelay
MSComm1.Output = "e": TimeDelay PowerDelay
MSComm1.Output = "t": TimeDelay PowerDelay
MSComm1.Output = "1": TimeDelay PowerDelay
MSComm1.Output = " ": TimeDelay PowerDelay
Buf = Trim(Format(SetVoltage, "00.00"))
BufLen = Len(Buf)
For i = 1 To BufLen
MSComm1.Output = Mid(Buf, i, 1): TimeDelay PowerDelay
Next i
MSComm1.Output = Chr(13)
TimeDelay 100
MSComm1.Output = "o": TimeDelay PowerDelay
MSComm1.Output = "u": TimeDelay PowerDelay
MSComm1.Output = "t": TimeDelay PowerDelay
MSComm1.Output = "1": TimeDelay PowerDelay
MSComm1.Output = Chr(13)
End Sub
''''''''''''''''''''''''''''''''''''''''''''''
'窗体的加载事件
'开放通信端口
'若打开错误亦通知用户
'''''''''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
Text1.Text = ""
On Error Resume Next
MSComm1.PortOpen = False
MSComm1.CommPort = Index + 1
If MSComm1.PortOpen Then
MsgBox "所选的串行端口已被其他设备所使用!", vbExclamation + vbOKOnly, "系统信息"
Exit Sub
Else
MSComm1.PortOpen = True
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''
'通信控件的OnComm事件程序
'引发事件后,将返回的字符串显示在显示区中
'''''''''''''''''''''''''''''''''''''''''''''
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
' 借着取代底下每一个 case 语句来处理每个事件与错误
' 事件
Case comEvCD ' CD 线的状态发生变化.
Case comEvCTS ' CTS 线的状态发生变化.
Case comEvDSR ' DSR 线的状态发生变化.
Case comEvRing ' Ring Indicator 变化.
Case comEvReceive ' 收到 RThreshold # of
Text1.Text = Text1.Text & MSComm1.Input
Case comEvSend ' 传输缓存区有 Sthreshold 个字符 '
End Select
End Sub
''''''''''''''''''''''''''''''''''''''''''''''
'使用Option控件
'让用户选择另外的通信端口,并打开它
'若无法打开,亦通知用户此情形
'''''''''''''''''''''''''''''''''''''''''''''
Private Sub optCom_Click(Index As Integer)
On Error Resume Next
MSComm1.PortOpen = False
MSComm1.CommPort = Index + 1
If MSComm1.PortOpen Then
MsgBox "所选的串行端口已被其他设备所使用!", vbExclamation + vbOKOnly, "系统信息"
Exit Sub
Else
MSComm1.PortOpen = True
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -