Creating an Enumerated Property
This example creates a property that will select and display
the Tektronix TDS 210 oscilloscope's cursor. The oscilloscope
allows two types of cursor. It supports a horizontal cursor that measures
the vertical units in volts, divisions, or decibels, and a vertical
cursor that measures the horizontal units in time or frequency. In
the MATLAB instrument driver editor,
Select the Properties node
in the tree.
Enter the property name, CursorType,
in the Name text field and click
the Add button. The new property's name CursorType appears
in the Property Name table.
Expand the Properties node
to display all the defined properties.
Select the CursorType node
from the properties displayed in the tree.
Select the Code tab
to define the set and get commands
for the CursorType property.
Select Instrument Commands in the Property style field.
Enter CURSor:FUNCtion? in the Get Command text field.
Enter CURSor:FUNCtion in the Set Command text field.
Select the Property
Values tab to define the allowed property values.
Select String in the Data Type field.
Select Enumeration in the Constraint field.
Enter none in the New property value text field and click the Add button.
Then enter OFF in the Instrument
Value table field.
Similarly add the property value voltage,
with instrument value HBArs.
Similarly add the property value time,
with instrument value VBArs.
Select the Help
tab to finish defining the property behavior.
Enter none in the Default value text field.
Select never in the Read only field.
In the Help text field, enter
Specifies the type of cursor.
Click the Save button.
Verifying the Behavior of the Property.This procedure verifies the behavior of the property. In this
example, the driver name is tektronix_tds210_ex.mdd.
Communication with the Tektronix TDS 210 oscilloscope at primary
address 2 is done via a Measurement Computing Corporation GPIB
board at board index 0. From the MATLAB command line,
Create the device object, obj,
using the icdevice function.
g = gpib('mcc',0,2);
obj = icdevice('tektronix_tds210_ex.mdd',g);
View the CursorType property's
current value. Calling get on the object lists
all its properties.
get(obj)
ConfirmationFcn =
DriverName = tektronix_tds210_ex.mdd
DriverType = MATLAB interface object
InstrumentModel =
Interface = [1x1 gpib]
LogicalName = GPIB0-2
Name = scope-tektronix_tds210_ex
ObjectVisibility = on
RsrcName =
Status = closed
Tag =
Timeout = 10
Type = scope
UserData = []
SCOPE specific properties:
CursorType = none
DisplayContrast = 50
Calling get on the CursorType property
lists its current value.
obj.CursorType
ans =
'none'
View acceptable values for the CursorType property.
Calling set on the object lists all its settable
properties.
set(obj)
ConfirmationFcn: string -or- function handle -or- cell array
Name:
ObjectVisibility: [ {on} | off ]
Tag:
Timeout:
UserData:
SCOPE specific properties:
CursorType: [ {none} | voltage | time ]
DisplayContrast: [ 1.0 to 100.0 ]
Calling set on the CursorType property
lists the values to which you can set the property.
set(obj,'CursorType')
[ {none} | voltage | time ]
Try setting the property to valid and
invalid values.
obj.CursorType = 'voltage';
obj.CursorType
ans =
'voltage'
obj.CursorType = 'horizontal'
There is no enumerated value named 'horizontal'.
View the help you wrote.
instrhelp(obj,'CursorType')
CURSORTYPE [ {none} | voltage | time ]
Specifies the type of cursor.
List the CursorType
characteristics that you defined in the Property Values and Help tabs.
info = propinfo(obj,'CursorType')
info =
struct with fields:
Type: 'string'
Constraint: 'enum'
ConstraintValue: {3×1 cell}
DefaultValue: 'none'
ReadOnly: 'never'
InterfaceSpecific: 1
info.ConstraintValue
ans =
3×1 cell array
{'none' }
{'voltage'}
{'time' }
Connect to your instrument to verify the set and get code.
connect(obj)
When you issue the set function in the MATLAB software,
the tektronix_tds210_ex.mdd driver actually sends
the CURSor:FUNCtion VBArs command to the instrument.
obj.CursorType = 'time';
When you issue the get function in the MATLAB software,
the tektronix_tds210_ex.mdd driver actually sends
the CURSor:FUNCtion? command to the instrument.
obj.CursorType
ans =
'time'
Finally disconnect from the instrument
and delete the objects.
disconnect(obj)
delete([obj g])