最近一个项目需要用c#设置示波器并获取示波器的波形数据,使用了TekScope,文档看了一段时间,但是毫无起色,希望有大神们能给个实例程序 谢谢啦。
------解决思路----------------------
这是初始化的代码,其中包括所有的参数设置,包括采集的刻度,采集的记录长度,频率,采集通道这些的, 你可以对照着示波器开发文档看看. 这个是用VB写的, 跟C#差别不大.
Private Sub Initialize() Implements IScopeClass.Initialize
_Scope.Descriptor = _DevHandle
_Scope.YMult = 1 / 250
_Scope.YOffset = _Yoffset
_Scope.YZero = _Yzero
'Send RCL command
_Scope.WriteString("*RST") '将在示波器重置为出厂默认值
_Scope.WriteString("ACQ:MOD SAM") '设置采用模式,SAM默认模式,在示例模式下,所有波形数据有 8 位的精度
'scope.WriteString("HEAD ON")
_Scope.WriteString("HEAD OFF")
_Scope.YModelEnabled = False
'HOR record lenth
_Scope.WriteString("HOR:DEL:MOD ON")
_Scope.WriteString("HOR:DEL:TIM" + Str(OffsetTime)) '设置或返回用于延迟时的水平的延迟时间
_Scope.WriteString("HOR:SCA " + Str(_HScale)) '设置或返回时间基本水平缩放
_Scope.WriteString("HOR:RECO " + Str(_RecordLen)) '设置水平的记录长度。此命令的查询表返回,当前水平的记录长度。
'VER record lenth
Dim VScale As Single = _VScale / 1000
_Scope.WriteString("CH1:BAN FUL;COUP AC;TER MEG;OFFS 0;SCA " + Str(VScale))
'BANdwidth Sets or returns the bandwidth of the specified TWEnty sets the upper bandwidth limit of channel <x> to 20 MHz.
'COUPling Sets or returns the coupling setting for the specified(CHANNEL) AC sets channel <x> to AC coupling. DC sets channel <x> to DC coupling. GND sets channel<x> to ground. Only a flat, ground-level waveform will be displayed
'TERmination Sets the connected-disconnected status of a 50 ?resistor, which may be connected between the specified channel’s coupled input and oscilloscope ground.MEG sets the channel <x> input resistance to 1 M?
'OFFSet Sets or returns the vertical offset for channel
'Scale Sets or returns the vertical scale for the channel specified by <x>, where x is the channel number.
_Scope.WriteString("CH2:COUP DC;TER MEG;OFFS 1.5;SCA 5E-1")
'Set up data source and format
_Scope.WriteString("DAT:SOU CH1;ENC RIB;WIDTH 2")
'DATa:SOUrce Sets or returns the location of the waveform data transferred from the oscilloscope by the CURVe? query.
'DATa:ENCdg Sets or returns the format of outgoing waveform data. This command is equivalent to setting WFMOutpre:ENCdg, WFMOutpre:BN_Fmt, andWFMOutpre:BYT_Or.Setting the DATa:ENGdg value causes the corresponding WFMOutpre values to be updated and conversley. RIBINARY specifies signed integer data point representation with the most significant byte transferred first.
'WIDTH 2 When the byte width is two, the values range from -32768 to 32767. and positive integer values range from 0 to 65,535
'Set up data format
_Scope.WriteString("WFMO:ENCDG BIN")
'WFMO:ENCDG Sets and queries the type of encoding for outgoing waveforms.
'BINary specifies that outgoing data is to be in a binary format whose further specification is determined by WFMOutpre:BYT_Nr, WFMOutpre:BIT_Nr, WFMOutpre:BN_Fmt and WFMOutpre:BYT_Or.
_Scope.WriteString("WFMO:BN_FMT RI")
'Sets or returns the format of binary data for outgoing waveforms specified by the DATa:SOUrce command. Changing the value of WFMOutpre:BN_Fmt also changes the value of DATa:ENCdg.
'RI specifies signed integer data point representation.
'_Scope.WriteString("WFMOutpre:NR_Pt 100000")
'This query returns the number of data points in the waveform record that will
'be transmitted in response to a CURVe? query. This value is the adjusted
'range specified by DATA:START and DATA:STOP commands.
'TRIGGER
_Scope.WriteString("TRIG:A:EDGE:SOU CH2;SLO RIS;COUP DC")
'TRIG:A:EDGE:SOU Sets or returns the source for the A edge trigger.
'CH1–CH4 specifies an analog input channel as the A edge trigger source.
'SLO Sets or returns the slope for the A edge trigger.
'RISe specifies to trigger on the rising or positive edge of a signal.
'COUP Sets or returns the type of coupling for the A edge trigger.
'DC specifies DC trigger coupling, which passes all input signals to the trigger circuitry.
_Scope.WriteString("TRIG:A:MOD NORM;TYP EDG")
'TRIG:A:MOD Sets or returns the A trigger mode.
'NORMal waits for a valid trigger event.
'Sets or returns the type of A trigger. Once you have set the trigger type, you may also need to identify the associated trigger class. For details on selecting Logic and Pulse trigger classes, see TRIGger:A:LOGIc:CLAss and TRIGger:A:PULse:CLAss respectively.
'EDGe is the default trigger. A trigger event occurs when a signal passes through a specified voltage level in a specified direction and is controlled by the TRIGger:A:EDGE? commands.
_Scope.WriteString("TRIG:A:LEV 2.5")
'TRIG:A:LEV Sets or returns the trigger level for the A trigger.
'2.5 specifies the trigger level in user units (usually volts)
System.Threading.Thread.Sleep(1000)
'setup the acq mode
_Scope.WriteString("ACQ:MOD AVE;NUMAV" + Str(2))
_Scope.WriteString("ACQ:STOPA RUNST")
_Scope.WriteString("ACQ:STATE RUN")
End Sub