Hardware Reference
In-Depth Information
Commands can be sent to instruments using simple single lines of code. As
an example, the following BASIC call is used to send a command string ( cmd$ )
to a specified board ( board% ):
CALL ibcmd (board%, cmnd$)
The alternative in C/C ++ would be:
ibcmd (int board, char cmnd[], long bytecount)
where board is an integer containing the board handle, cmnd is the com-
mand string to be sent, and bytecount is the number of command bytes to
be transferred.
The following code fragment shows how a standard IEEE-488.2 library can
be used for board level I/O from BASIC:
const METER_ADR = 3
const BOARD_NUM = 0
buffer$ = space$(100) ' Reserve space for returned data
DevClear (BOARD_NUM, METER_ADR) ' Clear the device
Send (BOARD_NUM, METER_ADR, "*RST", DABend)
Send (BOARD_NUM, METER_ADR, "VDC", DABend)
Send (BOARD_NUM, METER_ADR, "VAL?", DABend)
Receive (BOARD_NUM, METER_ADR, buffer$, 100, STOPend)
PRINT "Voltage = "; buffer$
' Display the returned reading
The equivalent in C/C ++ would be:
#define METER_ADR 3
#define BOARD_NUM 0
int board;
char buffer[100]; // Reserve space for returned data
DevClear (BOARD_NUM, METER_ADR); // Clear the device
Send (BOARD_NUM, METER_ADR, "*RST", DABend);
Send (BOARD_NUM, METER_ADR, "VDC", DABend);
Send (BOARD_NUM, METER_ADR, "VAL?", DABend);
Receive (BOARD_NUM, METER_ADR, buffer, STOPend);
printf ("Voltage = %s\n", buffer);
// Display the returned reading
Alternatively, the same results can be obtained using device level I/O and the
IEEE-488.1 from BASIC:
buffer$ = space$(100)
' Reserve space for returned data
CALL ibfind ("VoltMeter", device%)
' First open the voltmeter device
CALL ibclr (device%)
' and then clear the device
CALL ibwrt (device%, "*RST")
' Send the command to reset the meter
CALL ibwrt (device%, "VDC")
' and then select the DC voltage range
CALL ibwrt (device%, "VAL?")
' Request the current voltage reading
CALL ibrd (device%, buffer$)
' and read the value into the buffer
PRINT "Voltage = "; buffer$;
' Now display the returned reading
Search WWH ::




Custom Search