| |
program GPIB_CONSOLE_APP;
{* // gpib.pas : Sample project for Borland Delphi shows how to program the // GPIB-1, PCIGPIB and USB GPIB Modules // // Author: Michael Reimer, QUANCOM Informationssysteme GmbH, Germany // // Website: http://www.quancom.de // Product: // GPIB PCI Controller http://www.quancom.de/qprod01/eng/pb/pcigpib_1.htm // GPIB ISA Controller http://www.quancom.de/qprod01/eng/pb/GPIB_1.htm // GPIB USB Controller http://www.quancom.de/qprod01/eng/pb/usb_gpib_1.htm // Information: // // To use the QLIB Commands in your source, do the following: // // (1) Add statement {$INCLUDE QLIB.pas} to your source file. // (2) Copy QLIB.PAS from QLIB Installation Directory // d:\program files\quancom\qlib32\include to your // working directory *}
{$APPTYPE CONSOLE}
{$INCLUDE QLIB.pas}
{$X+}
var handle: longint; result: longint; listener: longint; talker: longint; buffer: string; s: string; serial_poll_byte: longint; device: longint;
begin
{* // The following sequence tries to find the // Bus Type ( PCI, ISA or USB ) of the // installed GPIB Controller *}
handle := QAPIExtOpenCard(PCIGPIB,0); if ( handle = 0 ) then begin handle := QAPIExtOpenCard(USBGPIB,0); if ( handle = 0 ) then begin handle := QAPIExtOpenCard(GPIB,0); end; end;
{* // The handle is <> NULL if there is a GPIB Controller installed *}
if ( handle = 0 ) then begin s := 'No QUANCOM GPIB Controller found!'; writeln(s); halt(0); end;
{* // Ok, we found a QUANCOM GPIB Controller Card
// Now we can send a string to the listner with address 3 // Change the address to the appropriate address for your // device ( normally set by DIP-Switches on the back side )
// --------------------------------------------------------------------------- // PART 1a: Writing a string to a IEEE 488, GPIB, HPIB Device // // Listener: A device capable of receiving data over the interface // when addressed to Listen by the active controller. Examples of such // devices are printers, programmable power supplies, or any other // programmable instrument. There can be up to 14 Listeners on the GPIB Bus // at one time. // ---------------------------------------------------------------------------
// Select the listener address, which is set by a DIP-Switch on the // back side of your instrument. *}
listener := 3;
// Send "z" to the listener 3, which resets the DMM to the initial settings.
s := 'z'#0;
if ( QAPIExtWriteString(handle, listener, Pchar(s), Length(s),0) = 0) then begin writeln('Writing to device ', listener, ' was successful.'); end else begin writeln('Writing to device ', listener, ' failed.'); end;
{* // --------------------------------------------------------------------------- // PART 1b: Reading a DMM or any other IEEE-488 device // // Talker: A device capable of transmitting data over the interface when // addressed to talk by the active controller. Examples of such devices // are voltmeters, data-acquisition systems, or any other programmable // instrument. There can be only one addressed talker on the GPIB Bus at one // time. // ---------------------------------------------------------------------------
// Select the talker address, which is set by a DIP-Switch on the // back side of your instrument. *}
talker := 3; SetLength(buffer,1024);
{* // Read value from DMM with talker address 3 *}
result := QAPIExtReadString(handle, talker, PChar(buffer), Length(buffer), 0);
if ( result <> 0 ) then begin writeln('Reading from device', talker, ' was ', buffer); end else begin writeln('Reading from device ', talker, ' failed.'); end;
{* // --------------------------------------------------------------------------- // PART2: Checking whether a device has requested service ( SRQ Service Request) // // A device can interrupt the active controller by asserting the SRQ line. The // SRQ is a single line, and if there are multiple devices on the GPIB Bus that // have been configured to assert an SRQ, the active controller will have // to "poll" the devices to figure out which one actually asserted the SRQ. // More than one device could in principle assert an SRQ at the same time. The // active controller can poll the devices in one of two ways: serial poll // or parallel poll. // --------------------------------------------------------------------------- *}
result := QAPIExtSpecial(handle, JOB_READSRQ, 0, 0);
if (result <> 0) then begin writeln('SRQ was asserted.'); end else begin writeln('SRQ was not asserted.'); end;
{* // --------------------------------------------------------------------------- // PART3: Reading Serial Poll Status from DMM // // In a serial poll, the active controller asks each device in turn to // send back a status byte that indicates whether the device has asserted // the SRQ. Bit 6 of this byte (where the bits are numbered 0 through 7) is set // if the device is requesting service. The definition of the other bits // is device dependent (under 488.1 at least; 488.2 provides a much more // concise definition of the status byte). // // The program has to perform this same sequence with every device // it needs to poll. // ---------------------------------------------------------------------------
// We poll all devices from 1 to 15 here. This is normally not nescessary and // very time consuming. Poll only valid devices on the GPIB Bus. *}
serial_poll_byte := 0;
for device := 1 to 15 do begin
result := QAPIExtSpecial(handle, JOB_SERIALPOLL, device, LongInt(@serial_poll_byte));
if ( result <> 0 ) then begin if ((serial_poll_byte and $40) = 0) then begin {* check for bit 6 = device requested service *} writeln('Device ', device, ' requested service and returned status byte ' , serial_poll_byte); end else begin writeln('Device ', device, ' no SRQ requested. Status is ', serial_poll_byte); end; end else begin writeln('No answer from device ', device); end; end;
{* // --------------------------------------------------------------------------- // PART4: Send a command to DMM // // The following commands are accepted by all devices on the GPIB Bus // simultaneously. The address part will be ignored. // // - JOB_DCL (Device Clear): The DCL command causes all devices to return to a device // dependent initial state. // // - JOB_LLO (Local Lockout): The LLO command disables the return-to-local front // panel key on the device. The user can no longer change the device settings // from its front panel. // // The following commands need an address and are only accepted by addressed // devices. Whether the devices are the listeners or the talkers depends on the // command. The three commands are as follows: // // - JOB_GET (Group Execute Trigger): The GET command tells all the addressed // listeners to perform some device-dependent function, like take a measurement. // GET allows for synchronizing a measurement function between multiple devices. // This is only used in specialized cases. // // - JOB_SDC (Selected Device Clear): The SDC command resets the addressed listeners // to a device-dependent state. It performs the same function as DCL, // but only resets the addressed listeners, not all the devices. // // - JOB_GTL (Go To Local): The GTL command sets the addressed listeners back to // local mode. // ---------------------------------------------------------------------------
// Send DCL to all devices
*}
result := QAPIExtSpecial(handle, JOB_DCL, 1, NULL);
if ( result = 0 ) then begin writeln('Command DCL failed\n'); end;
{* Send LLO to all devices *}
result := QAPIExtSpecial(handle, JOB_LLO, 1, NULL);
if ( result = 0 ) then begin writeln('Command LLO failed\n'); end;
{* Send GET to device 3 *}
result := QAPIExtSpecial(handle, JOB_GET, 3, NULL);
if ( result = 0 ) then begin writeln('Command GET failed\n'); end;
{* Send SDC to device 3 *}
result := QAPIExtSpecial(handle, JOB_SDC, 3, NULL);
if ( result = 0 ) then begin writeln('Command SDC failed\n'); end;
{* Send GTL to device 3 *}
result := QAPIExtSpecial(handle, JOB_GTL, 3, NULL);
if ( result = 0 ) then begin writeln('Command GTL failed\n'); end;
QAPIExtCloseCard(handle);
end.
|
|