6
trends in analytical chemistry, vol. 9, no. 7,199O 217 Computer Conner Programming control and data acquisition routines for the IEEE-488 instrumentation interface Oliver Lee, Peter D. Wentzell*, David A. Boyd** and Adrian P. Wade*** Vancouver, Canada The IEEE-488 instrumentation interface is widely used both to control and acquire data from chemical instru- mentation and electronic test equipment. Research chemists sometimes require that communications with IEEE-488 compatible instruments be incorporated into their own data acquisition and analysis programs. High level languages such as Microsoft QuickBASIC and commercially available drivers greatly simplify this task. Example routines for triggered acquisition of transient waveforms at rates in excess of 2.5 MHz are adaptedfrom ongoing work in this laboratory. Introduction Recent articles in this column’92 have focussed on aspects of data acquisition using the IBM PC family of microcomputers. Such discussion would be incom- plete without coverage of high speed parallel inter- faces such as the IEEE-488, also known as the Hew- lett Packard Interface Bus (HP-IB) and the General Purpose Interface Bus (GPIB). The main advan- tages of the IEEE-488 are its ability to control and acquire data from multiple instruments/devices (a single IEEE-488 interface card can talk or listen to up to 15 devices), and its ability to transfer data at rates of up to 1 Mbyte/s. An excellent overview of its capabilities and use has been recently published by Gates and Becke?. IEEE-488 compatible instru- ments may be interconnected in daisy-chain and star fashion374: this allows for rapid, trouble-free inclu- sion and removal of devices. IEEE-488 interface * Present address: Department of Chemistry, Dalhousie Uni- versity, Halifax, N.S., B3H 453, Canada. ** Present address: Department of Chemical Engineering, University of British Columbia, Vancouver, B.C., V6T 1WS, Canada. l ** To whom correspondence should be addressed. 01659936/90/$03.00. OElsevier Science Pub1ishersB.V. cards for the IBM PC family occupy only a single short slot, which means that operation is possible even from portable computers. For reasons of brevi- ty, detailed discussion of IEEE-488 hardware must be left to other texts (see ref. 3 and refs. cited there- in). Commercial software for data acquisition and in- strument control across an IEEE-488 interface fre- quently fails to satisfy all of the needs of researchers and usually may not be incorporated into larger cus- tom-built programs. Since source code is considered proprietary, users cannot readily make their own modifications. In our experience, chemists who want to access IEEE-488 compatible devices from their own programs have been deterred by the ‘user-hos- tile’ instrument manuals, where these are available. While not entirely straightforward, the task may now be readily achieved in a high level language such as Microsoft’s QuickBASIC or C (Microsoft Cana- da, Mississauga, Canada), when coupled with com- mercially available libraries of language interface routines and drivers supplied by instrument manu- facturers4T5. This article concentrates on development of appli- cations of Microsoft QuickBASIC. Applications in this laboratory prior to the availability of appro- priate QuickBASIC drivers were written in Micro- soft’s GW-BASIC. The GPIB implementation is considered more general than the HP-IB, and thus the example routines given are for the PC-IIA GPIB interface adapter (National Instruments, Austin, TX, U.S.A.). Both GPIB and HP-IB based instru- ments are used in this laboratory, and are controlled from QuickBASIC programs. However, space re- strictions preclude inclusion of sample HP-IB code in this present article. Programming the IEEE-488 interface in Microsoft QuickBASIC Communication between the GPIB bus and com- puter is handled through a GPIB interface adapter

Programming control and data acquisition routines for the IEEE-488 instrumentation interface

Embed Size (px)

Citation preview

Page 1: Programming control and data acquisition routines for the IEEE-488 instrumentation interface

trends in analytical chemistry, vol. 9, no. 7,199O 217

Computer Conner

Programming control and data acquisition routines for the IEEE-488 instrumentation interface

Oliver Lee, Peter D. Wentzell*, David A. Boyd** and Adrian P. Wade*** Vancouver, Canada

The IEEE-488 instrumentation interface is widely used both to control and acquire data from chemical instru- mentation and electronic test equipment. Research chemists sometimes require that communications with IEEE-488 compatible instruments be incorporated into their own data acquisition and analysis programs. High level languages such as Microsoft QuickBASIC and commercially available drivers greatly simplify this task. Example routines for triggered acquisition of transient waveforms at rates in excess of 2.5 MHz are adaptedfrom ongoing work in this laboratory.

Introduction Recent articles in this column’92 have focussed on

aspects of data acquisition using the IBM PC family of microcomputers. Such discussion would be incom- plete without coverage of high speed parallel inter- faces such as the IEEE-488, also known as the Hew- lett Packard Interface Bus (HP-IB) and the General Purpose Interface Bus (GPIB). The main advan- tages of the IEEE-488 are its ability to control and acquire data from multiple instruments/devices (a single IEEE-488 interface card can talk or listen to up to 15 devices), and its ability to transfer data at rates of up to 1 Mbyte/s. An excellent overview of its capabilities and use has been recently published by Gates and Becke?. IEEE-488 compatible instru- ments may be interconnected in daisy-chain and star fashion374: this allows for rapid, trouble-free inclu- sion and removal of devices. IEEE-488 interface

* Present address: Department of Chemistry, Dalhousie Uni- versity, Halifax, N.S., B3H 453, Canada.

** Present address: Department of Chemical Engineering, University of British Columbia, Vancouver, B.C., V6T 1 WS, Canada.

l ** To whom correspondence should be addressed.

01659936/90/$03.00. OElsevier Science Pub1ishersB.V.

cards for the IBM PC family occupy only a single short slot, which means that operation is possible even from portable computers. For reasons of brevi- ty, detailed discussion of IEEE-488 hardware must be left to other texts (see ref. 3 and refs. cited there- in).

Commercial software for data acquisition and in- strument control across an IEEE-488 interface fre- quently fails to satisfy all of the needs of researchers and usually may not be incorporated into larger cus- tom-built programs. Since source code is considered proprietary, users cannot readily make their own modifications. In our experience, chemists who want to access IEEE-488 compatible devices from their own programs have been deterred by the ‘user-hos- tile’ instrument manuals, where these are available. While not entirely straightforward, the task may now be readily achieved in a high level language such as Microsoft’s QuickBASIC or C (Microsoft Cana- da, Mississauga, Canada), when coupled with com- mercially available libraries of language interface routines and drivers supplied by instrument manu- facturers4T5.

This article concentrates on development of appli- cations of Microsoft QuickBASIC. Applications in this laboratory prior to the availability of appro- priate QuickBASIC drivers were written in Micro- soft’s GW-BASIC. The GPIB implementation is considered more general than the HP-IB, and thus the example routines given are for the PC-IIA GPIB interface adapter (National Instruments, Austin, TX, U.S.A.). Both GPIB and HP-IB based instru- ments are used in this laboratory, and are controlled from QuickBASIC programs. However, space re- strictions preclude inclusion of sample HP-IB code in this present article.

Programming the IEEE-488 interface in Microsoft QuickBASIC

Communication between the GPIB bus and com- puter is handled through a GPIB interface adapter

Page 2: Programming control and data acquisition routines for the IEEE-488 instrumentation interface

218 trends in analytical chemistry, vol. 9, no. 7,199O

which, unlike the IEEE-488 bus itself, is not stan- dardized. This has left manufacturers free to imple- ment the GPIB bus specifications across this inter- face differently.

Programming of the interface at the adapter level gives the programmer direct control over all of the GPIB lines but requires a detailed knowledge of the hardware and GPIB bus protocols. Fortunately, it is possible to control the adapter from high level lan- guages such as Microsoft QuickBASIC by use of a language-specific interface and possibly a device driver (memory resident software loaded at comput- er boot-up). The main advantage of this approach is that much of the GPIB’s functionality is retained with a relatively small sacrifice in flexibility. Fur- thermore, the programmer no longer needs to worry about the details of the GPIB bus protocol and can concentrate on programming the device(s) used in the application. Programming at the ‘device level’ is relatively easy and is the most commonly used ap- . preach. It simplifies the programming task consider- ably.

The language interface425 contains a small number of general purpose library routines which allow con- trol of bus operations either via a device driver or, at the cost of some flexibility, directly. These routines can be used as if extensions to the high level lan- guage, and are listed in part in Table I.

The PC-IIA device driver used in this work4 is called GPIB.COM. The command, DEVICE=C:\ GPIB.COM, must be included in the computer’s CONFIG.SYS file so that the driver is installed each time the computer boots up (the above syntax as- sumes the driver file is located in the root directory of the ‘C:’ drive). This procedure is the same as for any device driver.

Drivers contain a table of user-defined device-spe-

TABLE I. Partial list of GPIB and HP-IB language interface routines for Microsoft QuickBASIC

GPIB” HP-IBb Description

ibclr ibcmd ibfind

ibrd ibrsp ibtmo ibtrg ibwait ibwrt

ioclear iosend -

Reset device (commonly to default state) Send interface commands from a string Return the identifier assigned to a device

for use by an application ioenters Get an ASCII string from a device iospoll Perform a serial poll iotimeout Set the time limit for operation iotrigger Trigger the device - Wait for the occurrence of a GPIB event iooutputs Send an ASCII string to a device

a National Instruments GPIB interface adapter, model PC- IIA4.

’ Equivalent for Hewlett Packard HP-IB command library5.

cific settings. Once the driver is installed, this table must be configured so that it ‘knows about’ the de- vice(s) presently attached to the bus. This is general- ly accomplished using a program supplied by the manufacturer. The primary address and any second- ary address of a device, the time limit for a GPIB op- eration, the message terminator used, and similar parameters for the interface adapter itself, must all be specified3. The PC-IIA driver uses a program named IBCONF to perform this task. After correct configuration the drivers are ready for use.

Program development with the QuickBASIC inter- preter

The PC-IIA language interface routines, supplied as object code file qbib4.obj, must first be linked with the QuickBASIC library, bqlb40lib, to form a Quick-library file, qbib4.qlb, before the QuickBASIC interpreter can access these routines.

link/q qbib4.obj,, , bqlb40.lib;

The /q option specifies that a Quick-library (.QLB) file is to be generated. The multiple commas are all necessary, as they delineate unused options of the link command. The file, bqlb40.lib, contains Quick- libary support routines. This can be accessed by a us- er’s program (here called gpibexpl.bas) as follows:

qb gpibexpl/l qbib4.qlb

Further details on switches and arguments for the link and qb programs are given in the language man- uals.

Using GPIB routines Six of the PC-IIA library functions described in

Table I are used in the example program. These are ibfind, ibrd, ibwrt, ibtmo, ibrsp and ibwait. The first three deserve close attention because they perform many of an application’s tasks. The others are docu- mented in the program listing. Ibfind determines if the device (here a fast digital storage oscilloscope) is configured on the interface adapter. If it is, the func- tion ‘opens’ the device and returns a value (called a unit descriptor) which the application uses to address the device. Ibfind must therefore be the first library function called. The functions ibwrt and ibrd respec- tively send commands (or queries) and retrieve re- sponses. These are passed as string data. New data retrieved with ibrd from the device destructively re- place the previous data in memory. One must ensure that the string space reserved is long enough to hold the contents of the response.

Page 3: Programming control and data acquisition routines for the IEEE-488 instrumentation interface

trends in analytical chemistry, vol. 9, no. 7,199O 219

GPIB interface error handling The PC-IIA language interface includes error

checking via status word, error and count variables. These error handling capabilities are essential for debugging GPIB interface code. After execution of a GPIB operation the status of the bus and of the adapter is returned as a 16-bit word and stored in the BASIC variable IBSTA%. The most significant bit indicates whether an error was encountered by the GPIB operation. If this bit is set, the error variable IBERR% will contain the appropriate error code. The count variable IBCNT% contains the number of bytes transferred during a GPIB ‘read’ or ‘write’ op- eration. These variables are usually declared as ‘COMMON SHARED’, and hence will be visible to all subprograms in the QuickBASIC file.

Creating executable image (. EXE) files Once development of an application program

(here gpibexpl.bas) is completed, the .BAS source code may be compiled and linked with required li- braries to produce an executable .EXE file which may then be run directly from DOS. First the appli- cation source code must be compiled into an object file:

bc gpibexpl. bas

Next the object codes for gpibexpl and the qbib4 driver are linked together as shown:

link gpibexpl.obj + qbib4.obj,, ,;

The above yields the executable file gpibexpl.exe, which also requires the presence of Microsoft’s brun40.exe standard QuickBASIC executable li- brary to run. A larger stand-alone executable file can be generated in a similar manner (refer to the QuickBASIC manuals for details).

Example: acquisition of fast transient signals across an IEEE-488 interface

Several branches of chemistry require acquisition of data at rates in excess of 2.5 MHz. This is beyond the capabilities of most data acquisition cards, but rates (from a few tens of Hz) to 100 MHz may readily be obtained with a digital storage oscilloscope. This is more cost-effective than purchase of a dedicated high speed transient digitizer, and is satisfactory so long as the limited record length available (normally 1024 or 4096 points) and the typical &bit resolution are not prohibitive. Applications include studies in fast chemical kinetics, fluorescence or phosphores- cence lifetime measurements, and chemical acoustic

emission. This last area is of particular interest to this research group6.

A chemical acoustic emission experiment may re- sult in rapid production of thousands of individual high-frequency short-duration signals. In order to capture chemically generated emissions for the pur- poses of waveform analysis, staff of this laboratory developed data acquisition systems based on digital storage oscilloscopes (Tektronix, Burnaby, Cana- da). Most of the functions on the Tektronix 2400 se- ries can be programmed across the GPIB bus, but the design of the 2200 series is more limited. All are microprocessor-based instruments which have a maximum digitizing rate of 100 Megasamples/s and support remote programming via a GPIB.

Tektronix supplies a command language for re- mote control of its oscilloscopes via the GPIB inter- face7. Commands take the following format:

command : header-[?] [argument]

Optional terms are enclosed in brackets. One or more space characters must separate the ‘header’ from its argument. This is not necessary for the ques- tion mark modifier which serves to change certain commands into queries (see below). Some com- mands exist only as queries. If a single argument is insufficient to define a task then further levels of ar- guments, separated from each other by a colon, are added as necessary. As an example, the commands VMODE CHl:OFF and VMODE CH2:ON turn off the display for channel 1 and turn on the display for channel 2 respectively. One can then query the scope for the status of the channel 1 display with VMODE? CHl. The response produced, VMODE CHl:OFF, has the same form as the command un- less the ‘path’ feature has been turned off, in which case, only OFF is returned. Multiple arguments can appear under the same header and are separated by commas. Employing the example above, one obtains VMODE CHl:OFF,CI-U:ON. Different commands, separated by semicolons, can be combined to form a message.

The program listed, AES-ACQ.BAS, transfers digitized waveforms captured by a Tektronix 2430A oscilloscope to an IBM PC/XT/AT/386 or compati- ble. This example illustrates the use of both the Na- tional Instruments PC-IIA language interface rou- tines and the Tektronix 2430A command language7. This application has two sub-programs, normalAcq and fastTransmit, which supply different acquisi- tion-data transfer rates. The first, normalAcq, ac- quires and transfer waveforms at the normal operat- ing speed of the oscilloscope and can also be used on 2200 series oscilloscopeS with very minor changes.

Page 4: Programming control and data acquisition routines for the IEEE-488 instrumentation interface

220 trenak in analytical chemistry, vol. 9, no. 7,199O

'NODULE AES_ACP.BAS Lenguage : Nicrosoft QuickBASIC 4.0

'Fast transient capture from Tektronix 2400 Series oscilloscopes, as used in

'chemical acoustic emissicm experiments. This code is provided "as is" and M)

'guarentees are given or msy be assuned. It nay bs freely copied for research

'and teaching use, but is not to be incorporeted into "for profit" software without

'the written permission of its authors (contact A.P. Uade, Chemistry Department,

'University of British Colurbie, Vencwver, B.C., V6T 116. Canada) - Dec. 1989

'Declare user defined sub-program and functions

DECLARE SUB fastlrensmit (de& fiLeYunX, swAcq%)

DECLARE SUB normalAcq (bd%. fileNun%, W&C&%)

DECLARE FUNCTION check4scopeX (id%)

DECLARE fUNCTION TimIt! (StartTim!)

'Declare National lnstrunents GPIB interface library sub-programs

DECLARE SUB ibfind (tiamef, bd%)

DECLARE SUB ibrd (Mx, rdS)

DECLARE SUB ibrsp (bd%, spr%)

DECLARE SUB ibtmo W%, VW

DECLARE SUB ibwait W%, mask%)

DECLARE SUE iiwrt (bd%. urtS)

‘Declare ConStantS

CONS, scopeLet.zl = "T243OA,"

CONST f10 = 17408

'Label of device on GPlB board

'Declare c~mr~n GPlB eww checking stews variables

COHHON SHARED ibstaX, ibWr%, ibcnt%

CLS

PRlN, "AES_ACP.BAS" : PRINT PRINT ~wx~rce: Laboratory for Autanated Chemical Analysis,"

PRINT "Chemistry Department, Univ. of British Colt&is,"

PRlNT "Vancouver, B.C., Canada, - Dece&er 1989." : PRINT PRINT "This program transfer waveforms captured with s Tektronix 243OA"

PRINT "digital storage oscilloscope to an IBM PC/XT/AT canprter."

PRINT : PRINT "Type 'N' for NormI data acquisition."

PRINT "Type anything else for fsst Transmit Mode."

INPUT "Your choice is: I'; AS : PRINT

SELECT CASE check4scopeX(devX) 'check for presence of scope

CASE 0

BEEP : PRINT "Scope found... Initializing"

CASE 1

BEEP : PRINT "DEVICE NOT CONNECTED" : SYSTEM CASE 2

BEEP : PRlN, "URONG DEVICE CONNECTED" : SYSTEH CASE 3

BEEP : PRINT "DEVICE NAFIE NOT FOUND ON GPIB BOARD"

PRlNT "PLEASE CHECK GPIB CONFIGURATION USING IlJCONF.EXE"

SYSTEM

CASE ELSE

END SELECT

nInitialize data acquisition settings and oscilloscope

iburt dev%, "path off" 'Turn path off

iburt dev%, "tie chl:w,chZ:off" 'Display channel 1 only

iburt de& "horizontal esecdiv:Ze-5" 'Select time base of 20 us per division

iburt dev%. "chl volts:le-1" 'Select a voltage of 100 mv

iburt dev%, "atrigger level:0.05" 'Set trigger level to 0.05 volts

maxAcq% = 20 'Set maxisun nu&er of acquisitions

fiLeNus% = 1 'Set output file nwnber

fitelamet = "signals.fls" 'Set output file name

OPEN fileNameS FOR OUTPUT AS #fileNus%

IF AS = "N" o,- AS = "n" T"EN 'Start acquisition ! normelAcq dev%, fileNun%, naxAcq%

ELSE

fastTransmit devX, fileNun%, nraxAcq%

ENDlf

iburt dev%. "path on"

CLOSE fileNun%

END

'turn path on

dev% - unit descriptor of oscilloscope on GPIE board.

fileNux%- BASIC file number to write signal to.

maxAcq% - Raximm d of acquisitions specified by user.

'On return, maxAcq% holds the ACTUAL number of acquisitions executed. Before

'this sub-prcgrem csn be called, i) both RqS and OPC rust be enabled on

'the oscilloscope; ii) the "path" portion of scope's response must be suppressed

'by the carmand: iburt dev%, "PATH OFF" (if this is not done, the procedure

'may not behave as expected); iii) a fiLe rmst elready have been OPENed

'for WTPUT es fileNun% to store the uaveforms.

buffers = SPACEf(l036)

ibw-t dev%, "acquire mcde:normal"

iburt dev%, "atrigger mcde:sglseq"

ilwrt dev%, "data source:chl,encdg:

ibwrt dev%, "init srq"

ibtmo &v%, 12

mask% = BH5000

WHILE IWKEYS 0 "": UEND

'Space to store transferred uaveforms

'Now make ready the oscilloscope

'Use normal acquisition mcde

'Acquire uith single weep mode

:rpbinary" 'Data fwn ch. 1 in fve binary

ICLear all service requests on scope

'Set GPlB TIMEOUT to 3 seconds

'Set mssk for timeout or service

1&H4000 = time Limit exceeded

'&ml000 = service req. by device

'Clear keyboard buffer

t = Tl"ER

WILE TimeIt -z .5: MND 'Delay for oscilloscope to react

BEEP 'Alert user to stwt of acquisition

count% = 0 'Initialize acquisition count

startlime = TIMER 'Get starting time oi acquisition

DO 'Main processing loop

iburt dev%, "run acquire" 'tansend scope to acquire waveform

DO Keep looking...

ibuait dev%, mssk% 'Usit for time out or service request

keyy% = CVI(lNKEYS + STRINGS(2, 0)) 'Get key code, if key pressed

IF keyy% = FlO THEN 'Wit if f10 pressed

mexAcq% = cowt% 'Transfer count% value to msXAcq%

ibtmo de+ 13 'Reset Tl"EWT to 10 seconds

EXIT SUB 'Exit sub program

END IF

LOOP WILE (ibsta% AND BH4000) 'Loop if timeout

currentTine = Timlt(startTime) 'Get elapsed time

ibrsp dev%. sprX 'Read serial poll response (necessary)

ibwt dev%, 'mevent?" 'Ask scope if service request has occurred

stats = SPACES(20) 'Initialize space for read

ibrd dev%, stats 'Read event Wte (a nuneric string)

stat% = VALWatt) 'COnvePt this to integer

IF stat% = 461 THEN 'Value of 461 = completed acquisition

ibwt de-&, "curve?" 'Get scope to send WavefOrm ibrd dev%, buffers 'Read waveform into buffer variable

signalRecf = MlDS(LwfferS, 4, 1024) 'Extrsct signal portion

indexl = RIGHTS(STRS(10000 + count%). 4)

tS = NKSS(currenrTime) 'Convert time to single precision binary

PRINT #fileNun%, indexf; tS; 'Write index (4 bytes), time of acqu.,

PRINT XfileNunZ, signalRecS; '(4 byte binary string), & uaveform to fil,

count% = count% + 1 'Incrnent acquisition count

ELSE

BEEP : PRINT "Event is: 'I; stat% 'Alert user to other event

END IF

LCOP WHILE count% ( mexAcq% 'Acquired enough?

END SUB

SUB fastTranSmit (dev%, fileNun%, msxAcq%)

'This acquires 1 Kg triggered signals from channel 1 of s Tektronix 2400 series

'oscilloscope using its FAST TRANSMIT capability.

!xfferS = SPACES(1036) 'Space to store input waveforms

ibtmo dev%, 0 'Shut off I/O timeout

UHILE INKEYS 0 '1*0: WEND 'Clear keyboard buffer

BEEP IALert user to start of acquisition

count% = 0 'Initialize signal count

startTime = TlNER 'Start time of acquisition

iburt dev%, "fastxmit l,normal:chl,encdg:rpbinary'~ 'Start acquisition

DO 'main acquisition Loop

ibrd dev%, buffers 'Read uaveform info buffer variable

currentTime = Timelt(starfTirne) 'Get elapsed time

SUB normalAcq (dev%, fiLeNunX, msxAcq%)

'This acquires 1 KB signals in triggered Rode at the normal data transmission speed

'frcm s Tektronix 2400 series scope.

tS = MKWcurrentTime) 'Convert its formet

keyy% = CVI(lNKEYS l STRINGS(2, 0,) 'Get key code, if key pressed

If ken,% = FlO THEN 'User wants to quit

msxAcq% = count% 'Transfer CcuWX value to maxacqr

EXIT DO 'Exit Loop

EN0 IF

'Parameters passed are:

Page 5: Programming control and data acquisition routines for the IEEE-488 instrumentation interface

trends in analyticalchemistry, vol. 9, no. 7,199O 221 .

signalRect = MlWbufferS, 4. 1024)

count% = count% + 1

in&x$ = RIGHTS(STRS(10000 + count.%),

PRINT Xl, indext; tt; sisnslRecS;

LOOP WILE count% < naxAcq%

iburt dev%, "fastxmit off"

t = TlllER

WILE tineIt < .l: YEND

ibtnm dev%. 13

END SUB

'Extract signal portion

'Increment acquisition count

4)

Write to file

'End of msin acquisition loop

'Shut down fast transmit

'Delay of 0.1 s for scope hardware reset

'Reset timecut to default

FUNCTIW check4scopeX (id%)

’ This confirms that the Tektronix 2430A scope is ccewnicating es the

’ configured device wss stored on the GPIE board. The scope is assuwd

’ to be in its factory default settings. The fwction returns one of:

0 = no problem 1 = device not cwected

2 = wrong device3 = scope label rot found

' If there ere no problems, the variable id% returns en identifier which

’ auick Basic uses in all future references to the scoce.

buffers = SPACES<401 'Initialize reed buffer

Program listing.

FastTransmit uses the fast transmit mode which is only available on the 2400 series models. In both cases triggering is internal to the scope, and occurs when a signal level greater than some preset thresh- old is detected at the input to channel No. 1. Any sig- nal that is below the user-selected trigger level is ig- nored. Table II indicates the hardware, software and non-default settings required to execute this code. In addition, the example assumes that the device driver has been configured so that the label ‘T2430A’ iden- tifies the oscilloscope. The main module code serves only to demonstrate the capabilities of the two sub- programs. For real applications the parameters set here and many others are handled through an exten- sive user interface. First, the program determines if the oscilloscope is attached to the bus. If so, it then initializes the scope to known settings (usually the

TABLE II. Hardware and software requirements for program listing given

Hardware equipment

IBM PC/XT/AT compatible (or 80386-based) computer Tektronix oscilloscope Model 2430A-this must be set as a Talk- er and Listener IEEE-488 cable

National Instruments GPIB interface adapter (model PC-IIA). Note: two adapter parameters must be changed from their de- fault settings:

Parameter Default Change to

Local lockout on all devices Disable auto serial polling

Software requirements

yes no

NO YES

Microsoft QuickBASIC 4.0 compiler and linker National Instruments GPIB driver (GPIB.COM) and language interface file (QBIB4.0BJ) for QuickBASIC 4.0

check4scopeX = 0 'Properly initialize setting

ibfird sclpeLebel, idX 'Open device L return id% if pass.

IF id% < 0 THEN

check4scopeX = 3 'Label not fwrd on GPlg board

ELSE

iburt id%, "IO?" 'Ask for the scope ID

IF ibsta% < 0 THEN 'Difficulty in c-icaticg with device

check4scopeX = 1 'Possible bad connection ?

ELSE

ibrd id%, buffers 'Check to see if wrong device or wcdel #

mcdelf = MlDf(buffers, 8, 5) 'Tektronix 2430A assured.

IF mOdeIt 0 "2430A" THEN checUscope% = 2

END IF

END IF

END FUNCTION

FUNCTION Tirsslt WertTisW

’ This cnpares BASIC's timer value with its parameter "stertlime~~ and calculates

’ the elapsed time (seconds). Initialize startlime prior to this function call.

TineIt = TIMER - startlime

IF Timelf < 0 THEN Timelt = TimIt + R&400

END FUNCTICtl

'Nocturnal chemistry...

'Tine integer hes recycled

factory default settings) to provide a reference point, and programs specific settings for data acqui- sition. Selectable oscilloscope parameters include the time base (which determines the digitizing rate) and the vertical (dynamic) range. Once these param- eters are set, signals from an acoustic transducer are fed to the input and digitized as 1024 point &bit records. The 2230 also supports 4096-point records.

The trigger mode can be set to either auto or segsql. The former mode causes the oscilloscope to self-trigger repeatedly and so is useful for acquisition of continuous waveforms. The latter results in a sin- gle triggered acquisition. Its completion causes the oscilloscope to assert the bus’s service request (SRQ) line. This provides a convenient way for an application to check if an acquisition has occurred; it can then transfer the signal, and rearm the oscillo- scope for a new acquisition.

The details of NormalAcq will now be reviewed. The TIMEOUT setting of the device is first reset from its default of 10 s to 3 s so that the routine may check for a user interrupt every 3 s. This becomes the maximum length of time a user must wait after a user-interrupt before the program aborts (check the National Instruments GPIB manual4 for codes and available time lengths). The sub-program then sends the scope a command to start an acquisition. The GPIB library sub-program, IBWAIT, is used here to trap both timeout and service requests. If the scope has acquired a waveform, it exerts a service request to the GPIB board. The oscilloscope is then polled for the latest ‘event’ stored in the oscilloscope’s event buffer. If the event code matches that gener- ated by the completion of an acquisition (code 461), the waveform is transferred, otherwise the event is ignored. In this manner waveforms can be digitized

Page 6: Programming control and data acquisition routines for the IEEE-488 instrumentation interface

222

and sent to a controller at a rate of about 30 waveforms/min and 120 waveforms/min for the 2200 and 2400 series models respectively.

FastTransmit takes advantage of the ability of the oscilloscope to execute the sequence ‘acquire wave- form-transfer-to-controller-rearm’ at a rate in ex- cess of 900 waveforms/min. Operation in this mode is very user unfriendly and error checking is difficult to implement. No polling is necessary to prompt the waveform transfer. The oscilloscope sends the data once acquisition has been requested by an ibrd func- tion and only when a signal has triggered an acquisi- tion. Note that the TIMEOUT on the GPIB must be turned off, otherwise the ibrd function will return the same waveform to the program if no trigger occurred during that time. When complete, the FASTXMIT function must be turned off. This command requires at least a 50-ms delay before another command can be sent to the scope.

The data returned by the oscilloscope are of un- signed binary integers and have the format

%xxd...dc

where % is the start of the record, xx is the byte count (1024 bytes of data and 1 check sum), d.. . d are the data values and c is the check sum. Each waveform is down-loaded to the output file along with the time it was acquired, and an index value (the current signal count). Records are transferred in binary rather than ASCII format to save storage space and increase transfer speeds. The program continues acquiring and transferring signals until either the required number have been collected or t:

. ,_“A. ,... . . . .

he user presses tne ‘l+ lu’ sortkey to stop acquisition.

trends in analytical chemistry, vol. 9, no. 7,199O

.

Acknowledgements The authors thank Alf J. Wiebe (Tektronix, Bur-

naby, Canada), David Hasman (Hewlett Packard, Richmond, Canada) and David Sibbald for their support and technical assistance.

This work was funded by the Institute for Chemi- cal Science and Technology (ICST) grant 580886 and the Natural Sciences and Engineering Research Council (NSERC) of Canada, grants 580246 and 5- 80389. O.L. acknowledges support from the B.C. Science Foundation G.R.E.A.T. program, and an NSERC Graduate Research Fellowship. P.D. W. ac- knowledges support from ICST and an NSERC Postdoctoral Fellowship. D.A.B. was supported by the Pulp and Paper Research Institute of Canada (PAPRICAN) through the UBC Chemical Engi- neering Department’s Co-Op Student Program.

References P. D. Wentzell, S. J. Vanslyke and A. P. Wade, Trends Anal. Chem., 9 (1990) 3-8. L. Bowman, M. Victor and S. R. Crouch, Trends Anal. Chem., 9 (1990) 111-118. S. C. Gates and J. Becker, Laboratory Automation Using the IBM PC, Prentice-Hall, Englewood Cliffs, NJ, 1989. GPIB-PC User Manual for the IBM Personal Computer and Compatibles, April 1988; GPIB PC-IIA Drivers, National In- struments, Austin, TX, Feb. 1989 ed.. HP-IB Command Library for MS-DOS, Hewlett Packard, Palo Alto, CA, June, 1986. P. D. Wentzell and A. P. Wade, Anal. Chem., 61 (1989) 2638-2642. Tektronix 2430A Programmers Reference Guide, Tektronix, Burnaby, October, 1988.

0. Lee, Dr. P. D. Wentzell, D. A. Boyd and Dr. A. P. Wade are at the Laboratory for Automated Chemical Analysis, Chemistry Department, University of British Columbia, Vancouver, B.C., Canada.

Computer Corner Contributions

Contributions of between 400 and 900 words are welcome in the following categories: hardware, software, chemical applications, mathematical tools and interfacing. Please send your papers either to:

TrAC Computer Comer, D. L. Massart, Vrije Universiteit Brussel, Fakulteit der Geneeskunde en der Farmacie, Farmaceutische Scheikunde, Laarbeeklaan 103, B-1090 Brussels, Belgium.

or

TrAC Computer Comer, A. P. Wade, Department of Chemistry, University of British Columbia, 2036 Main Mall, Vancouver, B.C. Canada V6T lY6.