📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.ComboBox Combo2
Height = 300
Left = 480
TabIndex = 2
Text = "com1"
Top = 480
Width = 1575
End
Begin VB.CommandButton Command2
Caption = "停止"
Height = 855
Left = 1920
TabIndex = 1
Top = 1560
Width = 975
End
Begin VB.CommandButton Command1
Caption = "开始"
Height = 855
Left = 480
TabIndex = 0
Top = 1560
Width = 975
End
Begin MSCommLib.MSComm MSComm1
Left = 3840
Top = 240
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
RThreshold = 2
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim startf As Long
Dim endf As Long
Dim frequency As Long
Dim buffer As String
Dim Phase() As String
Dim Voltage() As String
Dim Current() As String
Dim state As Integer
Dim F As Boolean
Dim n As Long
Private Sub Command1_Click()
Dim i As Long, j As Long
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
MSComm1.Output = "%STAR"
For i = 1 To 100
j = 1
Next i
If F = True Then
For frequency = startf To endf
MSComm1.Output = "%SETF"
For i = 1 To 100
j = 1
Next i
MSComm1.Output = "%GETP"
state = 1
For i = 1 To 100
j = 1
Next i
MSComm1.Output = "%GETV"
state = 2
For i = 1 To 100
j = 1
Next i
MSComm1.Output = "&GETC"
state = 3
For i = 1 To 100
j = 1
Next i
n = n + 1
Next frequency
End If
End Sub
Private Sub Command2_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
Private Sub Form_Load()
If Combo2.Text = "com1" Then
MSComm1.CommPort = 1
ElseIf Combo2.Text = "com2" Then
MSComm1.CommPort = 2
ElseIf Combo2.Text = "com3" Then
MSComm1.CommPort = 3
ElseIf Combo2.Text = "com4" Then
MSComm1.CommPort = 4
End If
MSComm1.Settings = "9600,N,8,1"
MSComm1.Handshaking = comNone
MSComm1.InputLen = 0
MSComm1.RThreshold = 2
MSComm1.InputMode = 0
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
F = False
state = 1
n = 1
ReDim Phase(1)
ReDim Voltage(1)
ReDim Current(1)
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
Case comEvReceive
buffer = MSComm1.Input
If buffer = "OK" Then
F = True
ElseIf buffer = "YS" Then
MSComm1.Output = frequency
Else
If (F = True And state = 1) Then
Phase(n) = buffer
ReDim Preserve Phase(UBound(Phase) + 1)
ElseIf (F = True And state = 2) Then
Voltage(n) = buffer
ReDim Preserve Voltage(UBound(Voltage) + 1)
ElseIf (F = True And state = 3) Then
Current(n) = buffer
ReDim Preserve Current(UBound(Current) + 1)
End If
End If
buffer = ""
MSComm1.InBufferCount = 0
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -