📄 form1.frm
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form Form1
Caption = "虚拟示波器"
ClientHeight = 10230
ClientLeft = 60
ClientTop = 360
ClientWidth = 12450
LinkTopic = "Form1"
ScaleHeight = 10230
ScaleWidth = 12450
StartUpPosition = 3 'Windows Default
Begin VB.CheckBox Check2
Caption = "Fre"
Height = 255
Left = 11640
TabIndex = 34
Top = 3840
Width = 735
End
Begin VB.CheckBox Check1
Caption = "Inv"
Height = 255
Left = 10920
TabIndex = 14
Top = 3840
Width = 615
End
Begin VB.TextBox Text1
Height = 495
Index = 3
Left = 10800
TabIndex = 12
Text = "0"
Top = 3240
Width = 735
End
Begin VB.CommandButton Command5
Caption = "存盘"
Height = 495
Left = 10320
TabIndex = 11
Top = 5400
Width = 2055
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 10680
Top = 9720
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command4
Caption = "颜色"
Height = 495
Left = 10320
TabIndex = 10
Top = 4800
Width = 2055
End
Begin VB.CommandButton Command3
Caption = "复位"
Height = 495
Left = 10320
TabIndex = 9
Top = 4200
Width = 2055
End
Begin VB.TextBox Text1
Height = 495
Index = 2
Left = 10800
TabIndex = 8
Text = "0"
Top = 2640
Width = 735
End
Begin VB.TextBox Text1
Height = 495
Index = 1
Left = 10800
TabIndex = 6
Text = "1"
Top = 2040
Width = 735
End
Begin VB.TextBox Text1
Height = 495
Index = 0
Left = 10800
TabIndex = 4
Text = "1"
Top = 1440
Width = 735
End
Begin VB.CommandButton Command2
Caption = "停止"
Height = 495
Left = 10320
TabIndex = 2
Top = 720
Width = 2055
End
Begin VB.Timer Timer1
Left = 10200
Top = 9720
End
Begin VB.PictureBox Picture1
BackColor = &H00000000&
Height = 10060
Left = 120
ScaleHeight = 10005
ScaleWidth = 10005
TabIndex = 1
Top = 120
Width = 10060
End
Begin VB.CommandButton Command1
Caption = "采集"
Height = 495
Left = 10320
TabIndex = 0
Top = 120
Width = 2055
End
Begin VB.Label Label6
Caption = "avg:"
Height = 255
Index = 4
Left = 10320
TabIndex = 33
Top = 7560
Width = 375
End
Begin VB.Label Label7
Alignment = 1 'Right Justify
Caption = "0"
Height = 255
Index = 4
Left = 10800
TabIndex = 32
Top = 7560
Width = 1215
End
Begin VB.Label Label8
Caption = "V"
Height = 255
Index = 4
Left = 12120
TabIndex = 31
Top = 7560
Width = 135
End
Begin VB.Label Label8
Caption = "V"
Height = 255
Index = 3
Left = 12120
TabIndex = 30
Top = 7200
Width = 135
End
Begin VB.Label Label7
Alignment = 1 'Right Justify
Caption = "0"
Height = 255
Index = 3
Left = 10800
TabIndex = 29
Top = 7200
Width = 1215
End
Begin VB.Label Label6
Caption = "min:"
Height = 255
Index = 3
Left = 10320
TabIndex = 28
Top = 7200
Width = 375
End
Begin VB.Label Label8
Caption = "V"
Height = 255
Index = 2
Left = 12120
TabIndex = 27
Top = 6840
Width = 255
End
Begin VB.Label Label7
Alignment = 1 'Right Justify
Caption = "0"
Height = 255
Index = 2
Left = 10800
TabIndex = 26
Top = 6840
Width = 1215
End
Begin VB.Label Label6
Caption = "max:"
Height = 255
Index = 2
Left = 10320
TabIndex = 25
Top = 6840
Width = 375
End
Begin VB.Label Label6
Caption = "freq:"
Height = 255
Index = 1
Left = 10320
TabIndex = 24
Top = 6480
Width = 375
End
Begin VB.Label Label7
Alignment = 1 'Right Justify
Caption = "0"
Height = 255
Index = 1
Left = 10800
TabIndex = 23
Top = 6480
Width = 1215
End
Begin VB.Label Label8
Caption = "Hz"
Height = 255
Index = 1
Left = 12120
TabIndex = 22
Top = 6480
Width = 255
End
Begin VB.Label Label8
Caption = "us"
Height = 255
Index = 0
Left = 12120
TabIndex = 21
Top = 6120
Width = 255
End
Begin VB.Label Label7
Alignment = 1 'Right Justify
Caption = "0"
Height = 255
Index = 0
Left = 10800
TabIndex = 20
Top = 6120
Width = 1215
End
Begin VB.Label Label6
Caption = "time:"
Height = 255
Index = 0
Left = 10320
TabIndex = 19
Top = 6120
Width = 375
End
Begin VB.Label Label5
Caption = "V"
Height = 255
Left = 11760
TabIndex = 18
Top = 3360
Width = 375
End
Begin VB.Label Label4
Caption = "V"
Height = 255
Left = 11760
TabIndex = 17
Top = 2760
Width = 255
End
Begin VB.Label Label3
Caption = "* 5ms/Div"
Height = 255
Left = 11640
TabIndex = 16
Top = 2160
Width = 735
End
Begin VB.Label Label2
Caption = "By 1V/Div"
Height = 375
Left = 11640
TabIndex = 15
Top = 1560
Width = 735
End
Begin VB.Label Label1
Caption = "Y触发"
Height = 255
Index = 3
Left = 10320
TabIndex = 13
Top = 3360
Width = 615
End
Begin VB.Label Label1
Caption = "Y位移"
Height = 255
Index = 2
Left = 10320
TabIndex = 7
Top = 2760
Width = 615
End
Begin VB.Label Label1
Caption = "X时基"
Height = 255
Index = 1
Left = 10320
TabIndex = 5
Top = 2160
Width = 615
End
Begin VB.Label Label1
Caption = "Y增益"
Height = 255
Index = 0
Left = 10320
TabIndex = 3
Top = 1560
Width = 615
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim dly
Dim tm
Dim linecolor As ColorConstants
Private taskHandle As Long
Dim sampsPerChanRead As Long
Private data() As Double
Dim sz As Long
Dim j
Dim td
Dim tdtm(10)
Dim tdposi
Dim screendata(20000)
Private Sub Command1_Click()
tm = 0
Timer1.Interval = 30
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
tm = 0
Timer1.Enabled = False
End Sub
Private Sub Command3_Click()
Text1(0).Text = "1"
Text1(1).Text = "1"
Text1(2).Text = "0"
Text1(3).Text = "0"
linecolor = RGB(0, 255, 0)
End Sub
Private Sub Command4_Click()
CommonDialog1.ShowColor
If CommonDialog1.Color <> 0 Then linecolor = CommonDialog1.Color
End Sub
Private Sub Command5_Click()
If Timer1.Enabled = True Then Exit Sub
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then Exit Sub
Open CommonDialog1.FileName For Output As #1
For i = 1 To 10000
If screendata(i) < 10 Then Print #1, screendata(i)
Next i
Close #1
End Sub
Private Sub Form_Load()
Picture1.AutoRedraw = True
sz = 0
For Y = 0 To 10000 Step 100
Picture1.Line (0, Y)-(10000, Y), RGB(0, 32, 32)
Next Y
For X = 0 To 10000 Step 100
Picture1.Line (X, 0)-(X, 10000), RGB(0, 32, 32)
Next X
For Y = 0 To 10000 Step 1000
Picture1.Line (0, Y)-(10000, Y), RGB(0, 64, 0)
Next Y
For X = 0 To 10000 Step 1000
Picture1.Line (X, 0)-(X, 10000), RGB(0, 64, 0)
Next X
Picture1.Line (0, 5000)-(10000, 5000), RGB(64, 64, 0)
Picture1.Line (5000, 0)-(5000, 10000), RGB(64, 64, 0)
Picture1.AutoRedraw = False
linecolor = RGB(0, 255, 0)
For i = 1 To 10000
screendata(i) = 10
Next i
End Sub
Private Sub Timer1_Timer()
On Error GoTo sube
dly = 1
sz = 40000
DAQmxErrChk DAQmxCreateTask("", taskHandle)
DAQmxErrChk DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "", DAQmx_Val_InputTermCfg_RSE, -5#, 5#, DAQmx_Val_VoltageUnits1_Volts, "")
DAQmxErrChk DAQmxCfgSampClkTiming(taskHandle, "OnboardClock", 200000, DAQmx_Val_Rising, DAQmx_Val_AcquisitionType_FiniteSamps, sz)
ReDim data(sz)
DAQmxErrChk DAQmxReadAnalogF64(taskHandle, sz, 10#, DAQmx_Val_GroupByScanNumber, data(0), sz, sampsPerChanRead, ByVal 0&)
DAQmxErrChk DAQmxStopTask(taskHandle)
DAQmxErrChk DAQmxClearTask(taskHandle)
j = 0
tdposi = 0
yvlu = CDbl(Text1(0).Text)
yofs = CDbl(Text1(2).Text)
xamp = CDbl(Text1(1).Text)
ytrg = CDbl(Text1(3).Text) * 4
kk = 40000 - xamp * 5000
If kk < 15000 Then kk = 15000
If kk > 35000 Then kk = 35000
For i = 5000 To kk Step 1
If data(i) + data(i - 1) + data(i - 2) + data(i - 3) < ytrg And data(i + 1) + data(i + 2) + data(i + 3) + data(i + 4) >= ytrg And Check1.Value = 0 Then
'If data(i) < ytrg And data(i + 1) >= ytrg And Check1.Value = 0 Then
tdtm(0) = tdtm(1)
tdtm(1) = tdtm(2)
tdtm(2) = tdtm(3)
tdtm(3) = tdtm(4)
tdtm(4) = tdtm(5)
tdtm(5) = tdtm(6)
tdtm(6) = tdtm(7)
tdtm(7) = tdtm(8)
tdtm(8) = tdtm(9)
tdtm(9) = tdtm(10)
tdtm(10) = i
For ii = 0 To 9
If i - tdtm(ii) > 20 Then
td = i - tdtm(ii)
tdposi = ii
End If
Next ii
j = i
End If
If data(i) + data(i - 1) + data(i - 2) + data(i - 3) > ytrg And data(i + 1) + data(i + 2) + data(i + 3) + data(i + 4) <= ytrg And Check1.Value = 1 Then
'If data(i) > ytrg And data(i + 1) <= ytrg And Check1.Value = 1 Then
tdtm(0) = tdtm(1)
tdtm(1) = tdtm(2)
tdtm(2) = tdtm(3)
tdtm(3) = tdtm(4)
tdtm(4) = tdtm(5)
tdtm(5) = tdtm(6)
tdtm(6) = tdtm(7)
tdtm(7) = tdtm(8)
tdtm(8) = tdtm(9)
tdtm(9) = tdtm(10)
tdtm(10) = i
For ii = 0 To 9
If i - tdtm(ii) > 20 Then
td = i - tdtm(ii)
tdposi = ii
End If
Next ii
j = i
End If
Next i
Label7(0).Caption = td * 5
If td > 0 Then Label7(1).Caption = CSng(200000 / td)
If j = 0 And Check2.Value = 1 Then j = 35000
If j > 0 Then
If tm Mod dly = 0 Then Picture1.Cls
tm = (tm + 1) Mod 1000
Max = -5
Min = 5
For i = 1 To 10000
If j + (i - 5000) * xamp > 1 And j + (i - 5000) * xamp < sz Then
Picture1.Line (i, 5000 - 1000 * yvlu * (data(j + (i - 5001) * xamp) + yofs))-(i + 1, 5000 - 1000 * yvlu * (data(j + (i - 5000) * xamp) + yofs)), linecolor
screendata(i) = data(j + (i - 5000) * xamp)
If Max < data(j + (i - 5000) * xamp) Then Max = data(j + (i - 5000) * xamp)
If Min > data(j + (i - 5000) * xamp) Then Min = data(j + (i - 5000) * xamp)
Else
screendata(i) = 10
End If
Next i
If Max > Min Then
Label7(2).Caption = CSng(Max)
Label7(3).Caption = CSng(Min)
End If
End If
iii = 0
sss = 0
For kkk = tdtm(tdposi) To tdtm(10)
sss = sss + data(kkk)
iii = iii + 1
Next kkk
If iii <> 0 Then Label7(4).Caption = CSng(sss / iii)
If tdposi = 0 Then
Label7(0).Caption = "--"
Label7(1).Caption = "--"
End If
sube:
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -