instrumentação suportada em computadores pessoais · instituto superior tÉcnico universidade...

14
INSTITUTO SUPERIOR TÉCNICO Universidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS 1ºsem 2008/ 09 Instrumentação Suportada em Computadores Pessoais GPIB under MATLAB A. Lopes Ribeiro [email protected]

Upload: lytu

Post on 17-Dec-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Instrumentação Suportada em Computadores Pessoais

GPIB under MATLAB

A. Lopes [email protected]

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Using the GPIB Interface under MATLAB Control

IEEE 488

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

Equipment

• GPIB adaptor board or GPIB-USB adaptor• GPIB cables• Instruments with the GPIB interface• MATLAB with the “Instrument Control Toolbox”

installed

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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'

>>

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Communicate with One InstrumentTo 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

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Communicate with One Instrument>> oscil=gpib('ni',0,18)

GPIB Object Using NI Adaptor : GPIB0-18

Communication Address BoardIndex: 0PrimaryAddress: 18SecondaryAddress: 0

Communication State Status: closedRecordStatus: off

Read/Write State TransferStatus: idleBytesAvailable: 0ValuesReceived: 0ValuesSent: 0

>>

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Obtain Information on The Object Created

Double click

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

To Obtain Information on The Object Created

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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'>>

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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.Statusans =Open>> ………………………>> ………………………>> fclose(oscil)>> oscil.Statusans =closed>>

We can check the Status property of the object oscil with the command above

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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…….>>

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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>>

INSTITUTO SUPERIOR TÉCNICOUniversidade Técnica de Lisboa INSTRUMENTAÇÃO SUPORTADA EM COMPUTADORES PESSOAIS

1ºsem 2008/ 09

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)