📄 vbtest.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "300"
ClientHeight = 6315
ClientLeft = 60
ClientTop = 435
ClientWidth = 8850
LinkTopic = "Form1"
ScaleHeight = 6315
ScaleWidth = 8850
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "结束"
Height = 375
Left = 7680
TabIndex = 19
Top = 4080
Width = 1095
End
Begin VB.TextBox Text6
Height = 270
Left = 120
TabIndex = 15
Text = "0ms,0V"
Top = 5760
Width = 2295
End
Begin VB.HScrollBar HScroll2
Height = 150
Left = 1200
TabIndex = 14
Top = 5400
Width = 6495
End
Begin VB.Frame Frame2
Caption = "V"
Height = 1215
Left = 240
TabIndex = 8
Top = 1080
Width = 1095
Begin VB.OptionButton Option12
Caption = "625"
Height = 180
Left = 120
TabIndex = 17
Top = 240
Width = 855
End
Begin VB.OptionButton Option6
Caption = "800"
Height = 150
Left = 120
TabIndex = 11
Top = 960
Width = 855
End
Begin VB.OptionButton Option5
Caption = "625"
Height = 150
Left = 120
TabIndex = 10
Top = 720
Width = 855
End
Begin VB.OptionButton Option4
Caption = "200"
Height = 180
Left = 120
TabIndex = 9
Top = 480
Width = 855
End
End
Begin VB.Frame Frame1
Caption = "S"
Height = 1935
Left = 240
TabIndex = 5
Top = 2760
Width = 1095
Begin VB.OptionButton Option16
Caption = "64ms"
Height = 180
Left = 120
TabIndex = 22
Top = 1560
Width = 735
End
Begin VB.OptionButton Option15
Caption = "32ms"
Height = 180
Left = 120
TabIndex = 21
Top = 1320
Width = 735
End
Begin VB.OptionButton Option14
Caption = "1ms"
Height = 180
Left = 120
TabIndex = 20
Top = 480
Width = 735
End
Begin VB.OptionButton Option13
Caption = "4ms"
Height = 255
Left = 120
TabIndex = 18
Top = 240
Width = 735
End
Begin VB.OptionButton Option3
Caption = "4ms"
Height = 150
Left = 120
TabIndex = 12
Top = 720
Width = 735
End
Begin VB.OptionButton Option2
Caption = "16ms"
Height = 180
Left = 120
TabIndex = 7
Top = 1080
Width = 735
End
Begin VB.OptionButton Option1
Caption = "8ms"
Height = 255
Left = 120
TabIndex = 6
Top = 840
Width = 735
End
End
Begin VB.PictureBox Picture1
Height = 4815
Left = 1440
Picture = "vbtest.frx":0000
ScaleHeight = 4755
ScaleWidth = 5955
TabIndex = 4
Top = 600
Width = 6015
End
Begin VB.CommandButton Command4
Caption = "信息清除"
Height = 375
Left = 7680
TabIndex = 3
Top = 1920
Width = 1095
End
Begin MSCommLib.MSComm MSComm1
Left = 5520
Top = 0
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
InputLen = 750
RThreshold = 1
BaudRate = 57600
InputMode = 1
End
Begin VB.CommandButton Command2
Caption = "串口连接"
Height = 375
Left = 7680
TabIndex = 2
Top = 3120
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "采样开始"
Height = 375
Left = 7680
TabIndex = 1
Top = 2520
Width = 1095
End
Begin VB.TextBox Text2
Height = 375
Left = 7680
TabIndex = 0
Text = "Text2"
Top = 1080
Width = 1095
End
Begin VB.Label Label4
Caption = "坐标"
Height = 255
Left = 120
TabIndex = 16
Top = 5280
Width = 495
End
Begin VB.Label Label1
BackColor = &H00C0FFFF&
Caption = "Label1"
Height = 615
Left = 4680
TabIndex = 13
Top = 5640
Width = 2535
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim j As Integer
Dim i As Integer
Dim n As Integer
Dim time_scale As Integer
Dim v_scale As Integer
Dim data(3200) As Integer
Dim set_falg As Boolean
Dim now_value As Integer
Dim pre_value As Integer
'Dim close_falg As Boolean
'Dim in_byte() As Byte
Private Sub Command1_Click()
If MSComm1.PortOpen Then
If set_falg = False Then
set_falg = True
HScroll2.Enabled = False
Command1.Caption = "采样停止"
Label1.Caption = "信息发送成功!"
MSComm1.Output = Chr(111)
'out_byte(1) = 111
'out_byte(2) = 253
'MSComm1.Output = out_byte
Else
set_falg = False
HScroll2.Enabled = True
HScroll2.Value = 0
Command1.Caption = "采样开始"
Label1.Caption = "系统已停止"
'close_falg = True
MSComm1.Output = Chr(100) '上下位机应达成同步协议
'out_byte(1) = 100
'out_byte(2) = 253
'MSComm1.Output = out_byte
End If
Else
Label1.Caption = "串口未打开!"
MsgBox "操作错!请连接串口!"
End If
End Sub
Private Sub Command2_Click()
If MSComm1.PortOpen Then
'out_byte(1) = 100
'out_byte(2) = 253
' MSComm1.Output = out_byte
MSComm1.Output = Chr(100)
MSComm1.PortOpen = False
Command2.Caption = "串口连接"
Label1.Caption = "串口已断开!"
Else
i = 0
MSComm1.PortOpen = True
MSComm1.Output = Chr(100)
'out_byte(1) = 111
'out_byte(2) = 253
'MSComm1.Output = out_byte
Command2.Caption = "串口断开"
Label1.Caption = "串口接通成功!"
End If
End Sub
Private Sub Command3_Click()
If MSComm1.PortOpen = False Then
End
Else
MsgBox "操作错!请断开串口连接!"
End If
End Sub
Private Sub Command4_Click()
Text2.Text = ""
Picture1.Cls
End Sub
Private Sub Form_Load()
'close_falg = False
Option13.Value = True
Option12.Value = True
'HScroll1.Min = 3
'HScroll1.Max = 90
'HScroll1.Value = 3
HScroll2.Max = 400
HScroll2.Value = 0
i = 0
'MSComm1.Handshaking = comRTS
MSComm1.RTSEnable = True
MSComm1.DTREnable = True
MSComm1.Settings = "19200,n,8,1" '单片机与上位机的最高波特率单速19200
MSComm1.InputLen = 750 '串行读入的字符长度相当于缓冲区
MSComm1.RThreshold = 1 '设置1个字节才引发事件接收放到缓冲区里
time_scale = 400
v_scale = 250
Picture1.Scale (0, v_scale)-(time_scale, 0)
Picture1.DrawWidth = 1
Picture1.DrawStyle = 0
End Sub
Private Sub HScroll2_Change()
Picture1.DrawStyle = 1
Picture1.Cls
Text6.Text = Trim(Str(HScroll2.Value * 0.04)) + "ms," + Trim(Str(data(HScroll2.Value) * 5 / 255)) + "V"
Picture1.Line (HScroll2.Value, 0)-(HScroll2.Value, 5000), vbWhite
For j = 0 To i
If j = 0 Then
Picture1.PSet (0, data(j))
Else
Picture1.Line -(j, data(j)), vbRed
End If
Next j
End Sub
Private Sub MSComm1_OnComm()
Dim buf() As Byte
Select Case MSComm1.CommEvent
'通过取代底下每一个 case 表达式来处理每个事件与错误
'事件
Case comEvCD ' CD 线的状态发生变化
Case comEvCTS ' CTS 线的状态发生变化
Case comEvDSR ' DSR 线的状态发生变化
Case comEvRing ' Ring Indicator 变化
Case comEvReceive ' 收到 RThreshold # of
buf = MSComm1.Input '单片机有时发送快,传输缓冲区数据错误
'可能是缓冲区已满而重新装入
For j = LBound(buf) To UBound(buf)
now_value = buf(j)
now_value = Abs(now_value)
Text2.Text = Str(now_value)
Picture1.DrawStyle = 0
Picture1.Scale (0, v_scale)-(time_scale, 0)
If i < time_scale Then
If i = 0 Then
Picture1.Cls
Picture1.PSet (0, now_value)
data(0) = now_value
Else
n = (pre_value + now_value) / 2 '中间插值法补偿波形失真
data(i - 1) = n
data(i) = now_value
' n = (6 * pre_value + 4 * now_value) / 10 '数字一阶惯性虑波
Picture1.Line -(i, data(i)), vbRed
pre_value = now_value
End If
Else
i = 0
Picture1.Cls
End If
i = i + 2
Next j
'If (close_falg = 1 & i > 1500) Then
'MSComm1.Output = Chr(100) '上下位机应达成同步协议
'End If
Case comEvSend ' 传输缓冲区有 Sthreshold 个字符 '
End Select
End Sub
Private Sub Option1_Click()
time_scale = 500
Picture1.Scale (0, v_scale)-(time_scale, 0)
HScroll2.Max = 500
HScroll2.Value = 0
End Sub
Private Sub Option14_Click()
time_scale = 50
Picture1.Scale (0, v_scale)-(time_scale, 0)
HScroll2.Max = 50
HScroll2.Value = 0
End Sub
Private Sub Option15_Click()
time_scale = 1500
HScroll2.Max = 1500
HScroll2.Value = 0
Picture1.Scale (0, v_scale)-(time_scale, 0)
End Sub
Private Sub Option16_Click()
time_scale = 3000
HScroll2.Max = 3000
HScroll2.Value = 0
Picture1.Scale (0, v_scale)-(time_scale, 0)
End Sub
Private Sub Option2_Click()
time_scale = 750
HScroll2.Max = 750
HScroll2.Value = 0
Picture1.Scale (0, v_scale)-(time_scale, 0)
End Sub
Private Sub Option3_Click()
time_scale = 250
Picture1.Scale (0, v_scale)-(time_scale, 0)
HScroll2.Max = 250
HScroll2.Value = 0
End Sub
Private Sub Option4_Click()
v_scale = 150
Picture1.Scale (0, v_scale)-(time_scale, 0)
End Sub
Private Sub Option5_Click()
v_scale = 250
Picture1.Scale (0, v_scale)-(time_scale, 0)
End Sub
Private Sub Option6_Click()
v_scale = 300
Picture1.Scale (0, v_scale)-(time_scale, 0)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -