📄 frmgetwfm.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmGetWfm
Caption = "Get Waveform"
ClientHeight = 2325
ClientLeft = 60
ClientTop = 345
ClientWidth = 4200
LinkTopic = "Form1"
ScaleHeight = 2325
ScaleWidth = 4200
StartUpPosition = 3 '窗口缺省
Begin MSCommLib.MSComm MSComm1
Left = 0
Top = 960
_ExtentX = 794
_ExtentY = 794
_Version = 393216
DTREnable = -1 'True
RThreshold = 1
End
Begin VB.Timer Timer1
Enabled = 0 'False
Left = 120
Top = 360
End
Begin VB.Frame Frame1
Caption = "Select COMM port"
Height = 732
Left = 600
TabIndex = 2
Top = 240
Width = 3012
Begin VB.OptionButton CommPort
Caption = "COM2"
Height = 252
Index = 1
Left = 1800
TabIndex = 4
Top = 240
Width = 1092
End
Begin VB.OptionButton CommPort
Caption = "COM1"
Height = 252
Index = 0
Left = 240
TabIndex = 3
Top = 240
Width = 1212
End
End
Begin VB.CommandButton cmdEnd
Caption = "Done"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 2400
TabIndex = 1
Top = 1320
Width = 1212
End
Begin VB.CommandButton cmdStart
Caption = "Start"
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 600
TabIndex = 0
Top = 1320
Width = 1212
End
End
Attribute VB_Name = "frmGetWfm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SelectedCommPort As Integer
Private Sub cmdEnd_Click()
End
End Sub
Private Sub cmdStart_Click()
'
' GetWfm - program to get a waveform from an oscilloscope,
' convert its data values to absolute voltage measurements,
' and store these values in an Excell compatible file.
'
' Version 1.0.
'
'
' Initialize the arrays.
'
Dim IARR%()
Dim WFARR%()
Dim VOLTARR!()
Dim TIMEARR!()
Dim P As Integer
'
' Disable the start button until we are done.
'
cmdStart.Enabled = False
' Set up the comm port
' Set the comm port to generate an event on every character
' received.
' Then open the port.
MSComm1.CommPort = SelectedCommPort
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
'
' Turn off the header from query responses.
'
Call RS232WRITE(MSComm1, "HEADER OFF")
'
' Set up the data source to be channel 1.
'
DATSRC$ = "CH1"
WRT$ = "DATA:SOURCE " + DATSRC$
Call RS232WRITE(MSComm1, WRT$)
'
' Set up data encoding to be ribinary and data width to 1.
'
Call RS232WRITE(MSComm1, "DATA:ENCDG RIBINARY;WIDTH 1")
' Print a message on the screen instructing the user to connect
' Channel 1 to the front-panel PROBE COMPENSATION SIGNAL.
'
MSG = " Connect the PROBE COMPENSATION SIGNAL to channel 1" ' Define message.
Style = vbOKOnly + vbInformation ' Define buttons.
Title = "Probe Connection" ' Define title.
RESPONSE = MsgBox(MSG, Style, Title)
'
'
' Set up the recordlength, and the data start and data stop positions.
' In this example, the entire waveform is obtained so data start and
' data stop are 1 and 500 respectively.
'
RL% = 500
WRT$ = "HORIZONTAL:RECORDLENGTH " + Str$(RL%)
Call RS232WRITE(MSComm1, WRT$)
DSTART% = 1
DSTOP% = RL%
WFPOINTS% = DSTOP% - DSTART% + 1
MsgBox "Number of waveform points is " & WFPOINTS%
'Print " Number of waveform points is "; WFPOINTS%
'Print
WRT$ = "DATA:START " + Str$(DSTART%)
Call RS232WRITE(MSComm1, WRT$)
WRT$ = "DATA:STOP " + Str$(DSTOP%)
Call RS232WRITE(MSComm1, WRT$)
WRT$ = "HEADER OFF"
Call RS232WRITE(MSComm1, WRT$)
'
'
' Make sure setup changes have taken effect and a new waveform is acquired
'
Call RS232WRITE(MSComm1, "ACQUIRE:STATE RUN")
'
' Wait for the scope to acquire the waveform.
'
Call RS232WAITCOM(MSComm1, 14)
'
' Send the scope a curve query to get waveform data.
'
Call RS232WRITE(MSComm1, "CURVE?")
'
'
' Read waveform data.
'
' The waveform is formatted as #<x><yyy><data><newline> where
' <x> is the number of y bytes; for example if yyy = 500, then
' x = 3
' <yyy> is the number of bytes to transfer including checksum;
' if width is 1 then all bytes on bus are single data
' points; if width is 2 then bytes on bus are
' 2-byte pairs; this program uses width of 1
' <data> is the curve data
' <newline> is a single byte newline character at the end of the data
'
' RLPREAM$ = Space$(WFPOINTS%)) + 1)
' Read the waveform data
Call RS232Read(MSComm1, RLPREAM$)
Print "123"
'
'
' Transfer data an array that will have one data element per data
' point. Handle the conversion to signed data.
'
ReDim WFARR%(WFPOINTS%) ' set up the waveform output array
For i% = 1 To WFPOINTS%
P = Asc(Mid(RLPREAM$, i%, 1))
If P > 128 Then
P = -(256 - P)
End If
WFARR%(i% - 1) = P
Next i%
'
'
' Read the waveform preamble.
' Get the vertical offset and scale multiplier,
' the trigger point, the horizontal sampling interval
' and the horizontal units to convert the data points to
' time and voltage values.
'
WRT$ = "WFMPRE:" + DATSRC$ + ":YOFF?"
Call RS232WRITE(MSComm1, WRT$)
rd$ = Space$(20)
Call RS232Read(MSComm1, rd$)
YOFF! = Val(rd$)
WRT$ = "WFMPRE:" + DATSRC$ + ":YMULT?"
Call RS232WRITE(MSComm1, WRT$)
rd$ = Space$(20)
Call RS232Read(MSComm1, rd$)
YMULT! = Val(rd$)
WRT$ = "WFMPRE:" + DATSRC$ + ":YUNIT?"
Call RS232WRITE(MSComm1, WRT$)
YUNIT$ = Space$(20)
Call RS232Read(MSComm1, YUNIT$)
WRT$ = "WFMPRE:" + DATSRC$ + ":PT_Off?"
Call RS232WRITE(MSComm1, WRT$)
rd$ = Space$(20)
Call RS232Read(MSComm1, rd$)
PtOff! = Val(rd$)
WRT$ = "WFMPRE:" + DATSRC$ + ":XINCR?"
Call RS232WRITE(MSComm1, WRT$)
rd$ = Space$(20)
Call RS232Read(MSComm1, rd$)
XINCR! = Val(rd$)
WRT$ = "WFMPRE:" + DATSRC$ + ":XUNIT?"
Call RS232WRITE(MSComm1, WRT$)
XUNIT$ = Space$(20)
Call RS232Read(MSComm1, XUNIT$)
'
' Output header (x-, y-units, date, time and source)
' Write out the data to a file called "WFM_DATA.PRN".
WAVEFL$ = "C:\WFM_DATA.PRN" ' set up an output file for the data time and voltages
Open WAVEFL$ For Output As #1
Print #1, USING; "\\"; XUNIT$; " ";
Print #1, USING; "\ \"; YUNIT$; " ";
Print #1, "CH1"
'
'
' Process waveform data.
' Write out the data to a file called "WFM_DATA.PRN".
'
ReDim VOLTARR!(WFPOINTS%) ' set up the voltage output array
ReDim TIMEARR!(WFPOINTS%) ' set up the time output array
For i% = 0 To WFPOINTS% - 1
TIMEARR!(i%) = (i% - PtOff!) * XINCR!
VOLTARR!(i%) = (WFARR%(i%) - YOFF!) * YMULT!
Print #1, TIMEARR!(i%), ",", VOLTARR!(i%)
Next i%
' Display the name of the file
SMSG = "Waveform time and voltage points are in file " & WAVEFL$
MsgBox SMSG
'
' Close the file and comm port.
'
Close #1
MSComm1.PortOpen = False
cmdStart.Enabled = True
End Sub
'
' Save the users select of a COMM port.
'
Private Sub CommPort_Click(Index As Integer)
If Index = 0 Then
SelectedCommPort = 1
Else
SelectedCommPort = 2
End If
End Sub
Private Sub Form_Load()
SelectedCommPort = 2
CommPort(1).Value = True
End Sub
Private Sub Timer1_Timer()
Call MsgBox("Time out occurred!")
Stop
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -