How to use GPIB-Tcl

 

GPIB-Tcl adds a new command, gpib, to Tcl. Before you use this command, make sure you’ve loaded the library:

package require gpib


Commands for Instrument I/O

gpib open -address addrnum

          [-secondary secondnum]

          [-sendeoi true|false]

          [-sendcr true|false]

          [-sendlf true|false]

          [-expect cr|lf|none]

          [-timeout numseconds]

          [-buffer numbytes]


The only required parameter is the GPIB address. (Example: gpib open -address 8). "secondnum" is the optional secondary address. "sendeoi" tells your GPIB card whether or not to send the EOI signal on the bus. "sendcr" and "sendlf" control sending of carriage return and linefeed, respectively. "expect" controls whether or not your computer will stop reading when it sees a carriage return or line feed. "timeout" is the number of seconds to allow for a read. "buffer" is the size of the transmit/receive buffer in bytes--the default of 2048 is good enough for most simple applications.

gpib open returns an integer you use to refer to the device.

gpib close [-device devnum|all]


With no parameters, "gpib close" closes the last device you controlled with a Tcl command. With a device number (returned from the open command), it closes that device. With "-device all", it closes all open devices.

gpib list


Lists all open devices.

gpib select -device devnum


Selects an open device for subsequent reading, writing, or closing.

gpib read [-device devnum] [-mode ascii|binary|mixed]


Reads from the specified device (or the last device used, if none is specified). "mode" formats the output exactly as read ("ascii"), as hex values ("binary") or with all printable characters as read and all nonprintable characters as hex values ("mixed").

gpib write [-device devnum] -message messagetext


Writes to the specified device (or the last device used, if none is specified). "messagetext" is the string message to send. GPIB-Tcl does not yet support sending binary data.

gpib clear [-device devnum]


Causes the GPIB board to perform a Selected Device Clear (SDC) action on the specified device (or the last device used, if none is specified).

gpib serialpoll [-device devnum]


Causes the GPIB board to perform a serial poll on the specified device (or the last device used, if none is specified).

gpib wait [-device devnum] [-event srq|mask]


Causes the GPIB board to wait for an event on the specified device (or the last device used, if none is specified). "event" can either be "srq" (default) or an integer representing a bit mask of the event(s) for which you want to wait. The bit fields are defined in your GPIB adapter's documentation.

Commands to Control the GPIB Board

gpib interface status


Returns the board's GPIB status register.

gpib interface error


Returns the board's GPIB error string.

gpib interface clear


Causes the GPIB board to perform an Interface Clear (IFC) action on the bus.

gpib interface exceptions off|on


If exceptions are off (default), failed GPIB operations will simply return no data. If exceptions are on, failed GPIB operations will throw an exception and return detailed information.

gpib interface testsrq


Returns 0 or 1 based on the current state of the board's SRQ line.

General Commands

gpib version


Returns the version number of GPIB-Tcl.

gpib about


Gives a brief description of GPIB-Tcl.