Other topics about Sample Programs
This sample program demonstrates how to use an SRQ to detect the end of measurement.
This sample program correctly runs when the maximum number of channels/traces is set to 9 channels/9 traces.
The sample program sets up the trigger system, configures the instrument to properly generate an SRQ, and then triggers the instrument. When the instrument has generated an SRQ that indicates the end of measurement, the program exits after printing a measurement completion message.
See Waiting for the End of Measurement for this programming.
Sub srq_meas_Click()
Dim defrm As Long
Dim vi As Long
Dim ContMode(9) As String
Dim Result As String * 10
Dim i As Integer, StbStatus As Integer
Const TimeOutTime = 100000 ' TimeOut time should be greater than the measurement time.
'
' Assign a GPIB address to the I/O pass.
Call viOpenDefaultRM(defrm)
Call viOpen(defrm, "GPIB0::17::INSTR", 0, 0, vi)
Call viSetAttribute(vi, VI_ATTR_TMO_VALUE, TimeOutTime)
'
' Store the settings of continuous initiation mode for eachchannel
' (on for channels 1 and 2; off for channels 3 through 9)
' into the array variable ContMode().
ContMode(1) = "ON"
ContMode(2) = "ON"
For i = 3 To 9
ContMode(i) = "OFF"
Next i
'
' Turn on or off continuous initiation mode for each channel
' depending on the value of ContMode(*).
For i = 1 To 9
Call viVPrintf(vi, ":INIT" & CStr(i) & ":CONT " & ContMode(i) & vbLf, 0)
Next i
'
' Set the trigger source to Bus Trigger.
Call viVPrintf(vi, ":TRIG:SOUR BUS" & vbLf, 0)
'
' .
Call viVPrintf(vi, ":STAT:OPER:PTR 0" & vbLf, 0) 'Set 0 at all bits of Position Transition Filter
Call viVPrintf(vi, ":STAT:OPER:NTR 16" & vbLf, 0) 'Set 1 at bit 4 of Negative Transition Filter
Call viVPrintf(vi, ":STAT:OPER:ENAB 16" & vbLf, 0) 'Set 1 at bit 4 of Operation status enable
Call viVPrintf(vi, "*SRE 128" & vbLf, 0) 'Set 1 at bit 7 of Service Request Enable Register
Call viVPrintf(vi, "*CLS" & vbLf, 0) ' Clear Register.
'
Call viVPrintf(vi, "*TRG" & vbLf, 0) 'Make a trigger
' Wait until Status Byte Register became 192
Do
Call viReadSTB(vi, StbStatus) ' Read Status Byte Register
Range("B5").Value = StbStatus
Loop Until StbStatus = 192
'
' Display a measurement completion message.
Stat = MsgBox("Measurement complete", vbOKOnly)
' Close IO
Call viClose(vi)
Call viClose(defrm)
End Sub
10 DIM Cont_mode$(1:9)[9],Buff$[9]
20 INTEGER I
30 !
40 ASSIGN @Agte507x TO 717
50 !
60 Cont_mode$(1)="ON"
70 Cont_mode$(2)="ON"
80 Cont_mode$(3)="OFF"
90 Cont_mode$(4)="OFF"
100 Cont_mode$(5)="OFF"
110 Cont_mode$(6)="OFF"
120 Cont_mode$(7)="OFF"
130 Cont_mode$(8)="OFF"
140 Cont_mode$(9)="OFF"
150 !
160 FOR I=1 TO 9
170 OUTPUT @Agte507x;":INIT"&VAL$(I)&":CONT "&Cont_mode$(I)
180 NEXT I
190 OUTPUT @Agte507x;":TRIG:SOUR BUS"
200 !
210 OUTPUT @Agte507x;":STAT:OPER:PTR 0"
220 OUTPUT @Agte507x;":STAT:OPER:NTR 16"
230 OUTPUT @Agte507x;":STAT:OPER:ENAB 16"
240 OUTPUT @Agte507x;"*SRE 128"
250 OUTPUT @Agte507x;"*CLS"
260 OUTPUT @Agte507x;"*OPC?"
270 ENTER @Agte507x;Buff$
280 !
290 ON INTR 7 GOTO Meas_end
300 ENABLE INTR 7;2
310 OUTPUT @Agte507x;"*TRG"
320 PRINT "Waiting..."
330 Meas_wait: GOTO Meas_wait
340 Meas_end: OFF INTR 7
350 PRINT "Measurement Complete"
360 END
Line 40
Assigns a GPIB address to the I/O pass.
Lines 60 to 140
These lines store the settings of continuous initiation mode for each channel (on for channels 1 and 2; off for channels 3 through 9) into the array variable Cont_mode$(*).
Lines 160 to 180
These lines turn on or off continuous initiation mode for each channel depending on the value of Cont_mode$(*).
Line 190
Sets the trigger source to "Bus Trigger".
Lines 210 to 220
These lines configure the instrument so that operation status event register's bit 4 is set to 1 only when the operation status condition register's bit 4 is changed from 1 to 0 (negative transition).
Lines 230 to 240
These lines enable the operation status event register's bit 4 and status byte register's bit 7.
Lines 250 to 270
These lines clear the status byte register and operation status event register.
Lines 290 to 300
These lines set the branch target for an SRQ interrupt to enable SRQ interruptions.
Lines 310 to 320
These lines trigger the instrument and wait until the measurement cycle finishes.
Line 350
Displays a measurement completion message.