IM 253401-01E
App2-40
Appendix 2.5 Sample Program
Appendix 2.5 Sample Program
This section describes sample programs for a IBM PC/AT and compatible system with National
Instruments AT-GPIB/TNTIEEE-488.2 board. Sample programs in this manual are written in
Quick BASIC version 4.0/4.5.
‘*********************************************************************
‘* WT110/WT130 *
‘* After having set the measurement conditions/measurement range, *
‘* output the following data:voltage(V),current(A),active power(W), *
‘* voltage frequency(VHz) of element 1. *
‘* Microsoft QuickBASIC 4.0/4.5 Version *
‘*********************************************************************
REM $INCLUDE: ‘qbdecl4.bas’
N = 4
DIM D$(N) ‘ Array D$(4) is prepared for receiving data
BORD$ = “GPIB0”: CALL IBFIND(BORD$, BD%)
IF BD% < 0 THEN GOTO ERRDISP
CALL IBSIC(BD%): GOSUB ERRCHK
DEVICE$ = “WT”: CALL IBFIND(DEVICE$, WT%)
IF WT% < 0 THEN GOTO ERRDISP
CALL IBCLR(WT%): GOSUB ERRCHK
V% = 1: CALL IBSRE(BD%, V%)
CLS
‘ Setting measurement conditions
‘ Hold OFF, Measurement mode = RMS, Filter OFF, Scaling OFF, Averaging OFF
CMD$ = “SAMPLE:HOLD OFF”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “MODE RMS”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “FILTER OFF”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “SCALING OFF”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “AVERAGING OFF”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
‘ Setting measurement range(150V/5A)
CMD$ = “VOLTAGE:RANGE 150V;:CURRENT:RANGE 5A”
CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
‘ Sets display C to VHz1 in order to measure the voltage frequency of element 1
CMD$ = “DISPLAY3:FUNCTION VHZ;ELEMENT 1”
CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
‘ Sets the communication output items.(V1,A1,W1,VHz1 ON, all others OFF)
CMD$ = “MEASURE:ITEM:PRESET CLEAR”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “MEASURE:ITEM:V:ELEMENT1 ON”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “MEASURE:ITEM:A:ELEMENT1 ON”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “MEASURE:ITEM:W:ELEMENT1 ON”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “MEASURE:ITEM:VHZ:ELEMENT1 ON”: CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
‘ Sets the filter to detect the end of data updating
CMD$ = “STATUS:FILTER1 FALL” ‘ bit0(UPD)
CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
BUF$ = SPACE$(200)
‘ Reads the measurement data and displays them (10 times)
FOR I = 1 TO 10
CMD$ = “STATUS:EESR?” ‘ Clears the extended event register
CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CALL IBRD(WT%, BUF$): GOSUB ERRCHK
‘ Waiting until data are finished updating
CMD$ = “COMMUNICATE:WAIT 1”
CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CMD$ = “MEASURE:VALUE?” ‘ Requests output of measurement data
CALL IBWRT(WT%, CMD$): GOSUB ERRCHK
CALL IBRD(WT%, BUF$): GOSUB ERRCHK ‘ Reads measurement data
K = 1
FOR J = 1 TO N
IF J < N THEN S = INSTR(K, BUF$, “,”) ELSE S = INSTR(K, BUF$, CHR$(10))
D$(J) = MID$(BUF$, K, S - K)
K = S + 1
NEXT J
‘ Shows the measurement data per function
PRINT “V1”, D$(1) ‘V1
PRINT “A1”, D$(2) ‘A1
PRINT “W1”, D$(3) ‘W1
PRINT “VHz1”, D$(4) ‘VHz1
NEXT I
PRGEND:
CALL IBLOC(WT%)
END ‘ End
‘
‘ When IBFIND call failed
ERRDISP:
PRINT “ ===== No such board or device name ===== “
GOTO PRGEND
‘
‘ GP-IB error check
ERRCHK:
IF IBSTA% >= 0 THEN RETURN
PRINT “ ===== Error ===== “
GOTO PRGEND