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 using VISA
 

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 Excel VBA using VISA-COM

Private Sub cmd_trig_sing_vcom_Click()

    

    '*** The variables of the resource manager and the instrument I/O are declared

    Dim ioMgr As VisaComLib.ResourceManager

    Dim Age507x As VisaComLib.FormattedIO488

    '*** The memory area of the resource manager and the instrument I/O are acquired

    Set ioMgr = New VisaComLib.ResourceManager

    Set Age507x = New VisaComLib.FormattedIO488

    '*** Open the instrument

    Set Age507x.IO = ioMgr.Open("GPIB0::17::INSTR")

    Age507x.IO.timeout = 100000   ' TimeOut time should be greater than the measurement time.

    

    '*** Variable declaration

    Dim ContMode(4) As String

    Dim Result As String * 10

    Dim Stat As String

    Dim i As Integer

    ' Store the settings of continuous initiation mode for each channel

    ' (ON for channels 1 and 2; OFF for channels 3 and 4)

    ' into the array variable ContMode().

    ContMode(1) = "ON"

    ContMode(2) = "ON"

    ContMode(3) = "OFF"

    ContMode(4) = "OFF"

    '

    ' Turn ON or OFF continuous initiation mode for each channel

    ' depending on the value of ContMode(*).

    Age507x.WriteString ":DISP:SPL D12_34" & vbLf, True

    Age507x.WriteString ":SENS1:SWE:TIME:AUTO OFF" & vbLf, True

    Age507x.WriteString ":SENS1:Swe:TIME 5" & vbLf, True

    Age507x.WriteString ":SENS2:SWE:TIME:AUTO OFF" & vbLf, True

    Age507x.WriteString ":SENS2:SWE:TIME 3" & vbLf, True

    Age507x.WriteString ":SENS3:SWE:TIME:AUTO OFF" & vbLf, True

    Age507x.WriteString ":SENS3:SWE:TIME 1" & vbLf, True

    Age507x.WriteString ":SENS4:SWE:TIME:AUTO OFF" & vbLf, True

    Age507x.WriteString ":SENS4:SWE:TIME 3" & vbLf, True

    For i = 1 To 4

        Age507x.WriteString ":INIT" & CStr(i) & ":CONT " & ContMode(i) & vbLf, True

    Next i

    ' Set the trigger source to Bus Trigger.

    Age507x.WriteString ":TRIG:SOUR BUS" & vbLf, True

    '

    ' Trigger the instrument to start a sweep cycle.

    Age507x.WriteString ":TRIG:SING" & vbLf, True

    '

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

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

    Age507x.WriteString "*OPC?" & vbLf, True

    Result = Age507x.ReadString

    '

    ' Display a measurement completion message.

    Stat = MsgBox("Measurement complete", vbOKOnly)

    Age507x.IO.Close

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