Instrument Control Toolbox 2.9
Accessing Instruments Using Interface Objects
Contents
Overview
In this demo, you will learn how to create and obtain information about instrument objects with the Instrument Control Toolbox and MATLAB.
An instrument object in MATLAB represents the connection between MATLAB and an instrument. The Instrument Control Toolbox supports two types of instrument objects: interface objects and device objects.
An interface object represents a direct connection between MATLAB and an instrument using one of the supported interfaces,
such as the serial port, GPIB, a VISA protocol, or TCP and UDP. The object uses functions such as fprintf, fscanf, fread,
and fwrite to exchange low-level commands and data with the instrument.
A device object represents a connection between MATLAB and an instrument by way of an instrument driver. A device object provides high level properties and functions that map to high-level settings and functionality of the instrument and does not expose low-level commands or data.
Creating an Interface Instrument Object
To create an interface object, use one of the interface object constructors.
g = gpib('iotech', 0, 1)
GPIB Object Using IOTech Adaptor : GPIB0-1
Communication Address
BoardIndex: 0
PrimaryAddress: 1
SecondaryAddress: 0
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
s = serial('COM1')
Serial Port Object : Serial-COM1
Communication Settings
Port: COM1
BaudRate: 9600
Terminator: 'LF'
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
v = visa('ni', 'GPIB0::1::INSTR')
VISA-GPIB Object Using NI Adaptor : VISA-GPIB0-1
Communication Address
BoardIndex: 0
PrimaryAddress: 1
SecondaryAddress: 0
Communication State
Status: closed
RecordStatus: off
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
Accessing an Interface Object's Properties
Each interface object provides a list of general and interface specific properties.
get(g)
ByteOrder = littleEndian
BytesAvailable = 0
BytesAvailableFcn =
BytesAvailableFcnCount = 48
BytesAvailableFcnMode = eosCharCode
BytesToOutput = 0
ErrorFcn =
InputBufferSize = 512
Name = GPIB0-1
ObjectVisibility = on
OutputBufferSize = 512
OutputEmptyFcn =
RecordDetail = compact
RecordMode = overwrite
RecordName = record.txt
RecordStatus = off
Status = closed
Tag =
Timeout = 10
TimerFcn =
TimerPeriod = 1
TransferStatus = idle
Type = gpib
UserData = []
ValuesReceived = 0
ValuesSent = 0
GPIB specific properties:
BoardIndex = 0
BusManagementStatus = [1x1 struct]
CompareBits = 8
EOIMode = on
EOSCharCode = LF
EOSMode = none
HandshakeStatus = [1x1 struct]
PrimaryAddress = 1
SecondaryAddress = 0
get(s)
ByteOrder = littleEndian
BytesAvailable = 0
BytesAvailableFcn =
BytesAvailableFcnCount = 48
BytesAvailableFcnMode = terminator
BytesToOutput = 0
ErrorFcn =
InputBufferSize = 512
Name = Serial-COM1
ObjectVisibility = on
OutputBufferSize = 512
OutputEmptyFcn =
RecordDetail = compact
RecordMode = overwrite
RecordName = record.txt
RecordStatus = off
Status = closed
Tag =
Timeout = 10
TimerFcn =
TimerPeriod = 1
TransferStatus = idle
Type = serial
UserData = []
ValuesReceived = 0
ValuesSent = 0
SERIAL specific properties:
BaudRate = 9600
BreakInterruptFcn =
DataBits = 8
DataTerminalReady = on
FlowControl = none
Parity = none
PinStatus = [1x1 struct]
PinStatusFcn =
Port = COM1
ReadAsyncMode = continuous
RequestToSend = on
StopBits = 1
Terminator = LF
get(v)
ByteOrder = littleEndian
BytesAvailable = 0
BytesAvailableFcn =
BytesAvailableFcnCount = 48
BytesAvailableFcnMode = eosCharCode
BytesToOutput = 0
ErrorFcn =
InputBufferSize = 512
Name = VISA-GPIB0-1
ObjectVisibility = on
OutputBufferSize = 512
OutputEmptyFcn =
RecordDetail = compact
RecordMode = overwrite
RecordName = record.txt
RecordStatus = off
Status = closed
Tag =
Timeout = 10
TimerFcn =
TimerPeriod = 1
TransferStatus = idle
Type = visa-gpib
UserData = []
ValuesReceived = 0
ValuesSent = 0
VISA-GPIB specific properties:
Alias =
BoardIndex = 0
EOIMode = on
EOSCharCode = LF
EOSMode = none
PrimaryAddress = 1
RsrcName = GPIB0::1::0::INSTR
SecondaryAddress = 0
Cleanup
When an instrument object is no longer needed, remove it from memory and clear the MATLAB workspace of the associated variable.
delete([g s v]); clear g s v
Store