Instrumentação Suportada em Computadores Pessoais GPIB under MATLAB A. Lopes Ribeiro arturlr@ist.utl.pt
Using the GPIB Interface under MATLAB Control IEEE 488
Equipment GPIB adaptor board or GPIB-USB adaptor GPIB cables Instruments with the GPIB interface MATLAB with the Instrument Control Toolbox installed
MATLAB information about drivers To get information about the available drivers to the GPIB interface use the MATLAB function instrhwinfo( gpib ) instrhwinfo('gpib') ans = InstalledAdaptors: {'advantech' 'ni'} JarFileVersion: 'Version 2.3' There are drivers for GPIB from the manufacturers Advantech and National Instruments
MATLAB information about the adaptor board To get information about the GPIB board installed use the MATLAB function instrhwinfo( gpib, manufacturer ) instrhwinfo('gpib','ni') ans = AdaptorDllName: [1x87 char] AdaptorDllVersion: 'Version 2.3' AdaptorName: 'ni' InstalledBoardIds: [??????????] ObjectConstructorName: 'gpib('ni',<bid>,<pr>) ' VendorDllName: 'gpib-32.dll' VendorDriverDescription: 'NI-488'
To Communicate with One Instrument To communicate with one instrument, we need to create one variable of the type object in MATLAB. At this time MATLAB already told us how to construct it: ObjectConstructorName: 'gpib('ni',<bid>,<pr>) ' Example: We want to communicate with one oscilloscope. The board adaptor number is <BID>=0 and the Oscilloscope Primary Address is <PR>=18. The virtual object to create will have the name oscil : We must use the MATLAB command oscil=gpib('ni',0,18) MATLAB will respond as follows
To Communicate with One Instrument oscil=gpib('ni',0,18) GPIB Object Using NI Adaptor : GPIB0-18 Communication Address BoardIndex: 0 PrimaryAddress: 18 SecondaryAddress: 0 Communication State Status: closed RecordStatus: off Read/Write State TransferStatus: idle BytesAvailable: 0 ValuesReceived: 0 ValuesSent: 0
To Obtain Information on The Object Created Double click
To Obtain Information on The Object Created
To Obtain Information on The Object Created Some information about the object oscil just created is also available with the function instrhwinfo(object_name) instrhwinfo(oscil) ans = AdaptorDllName: [1x87 char] AdaptorDllVersion: 'Version 2.3' AdaptorName: 'NI' VendorDllName: 'gpib-32.dll' VendorDriverDescription: 'NI-488'
Connecting and Disconnecting Instruments To connect to the oscilloscope we must open the object using the function fopen(object_name). To disconnect it we use the function fclose(object_name). fopen(oscil) oscil.status ans = Open fclose(oscil) oscil.status ans = closed We can check the Status property of the object oscil with the command above
Sending and Receiving Data We send data to the instrument with the function fprintf(instrument_name, data_string ), but to read answers we use the function fscanf(.) with the instrument logic name as argument. Example: fprintf(oscil, *IDN? ) Osc_name=fscanf(oscil) Osc_name= TEKTRONIX TDS 2014,0,CF:91.
Sending and Receiving Data In the next example we wish to read data from the channel 1 of the oscilloscope. We send one command to set CH1 as the data source and next we confirm the command execution by sending a query and reading the answer, that is put in a variable: fprintf(oscil, MEASUREMENT:IMMED:SOURCE CH1 ) fprintf(oscil, MEASUREMENT:IMMED:SOURCE? ) Source_channel=fscanf(oscil) Source_channel= CH1
Sending and Receiving Data If we wish to read a peak to peak voltage from the current source channel: fprintf(oscil, MEASUREMENT:MEAS1:TYPE PK2PK ) fprintf(oscil, MEASUREMENT:MEAS1:VALUE? ) Vx_p2p=fscanf(oscil) Vx_p2p= 3.0017668678E0 If we want to disconnect the instrument definitely we must close the object, delete it and clear the MATLAB workspace: fclose(oscil) delete(oscil) clear(oscil)