Waiting for Trigger (OPC?)

Other topics about Sample Programs

Overview

This sample program demonstrates how to use the :TRIG:SING command to wait until the measurement cycle is completed.

The sample program uses the :TRIG:SING command to start a sweep (measurement) cycle, uses the *OPC command to wait until the measurement cycle is completed, then prints a message and exits.

See Waiting for the End of Measurement for this programming.

Sample Program in Excel VBA
 

Sub trg_sing_Click()

    Dim defrm As Long

    Dim vi As Long

    Dim ContMode(9) As String

    Dim Result As String * 10

    Dim i 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)

    '

    ' Trigger the instrument to start a sweep cycle.

    Call viVPrintf(vi, ":TRIG:SING" & vbLf, 0)

    '

    ' Execute the *OPC? command and wait until the command

    ' returns 1 (i.e., the measurement cycle is completed).

    Call viVPrintf(vi, "*OPC?" & vbLf, 0)

    Call viVScanf(vi, "%t", Result)

    '

    ' Display a measurement completion message.

    Stat = MsgBox("Measurement complete", vbOKOnly)

    Call viClose(vi)

    Call viClose(defrm)

End Sub

Sample Program in HT Basic (trg_sing.htb)

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;":TRIG:SING"

220 OUTPUT @Agte507x;"*OPC?"

230 ENTER @Agte507x;Buff$

240 !

250 PRINT "Measurement complete"

260 END