Detailed instructions for use are in the User's Guide.
[. . . ] Data Acquisition ToolboxTM Adaptor Kit 2 User's Guide
How to Contact The MathWorks
Web Newsgroup www. mathworks. com/contact_TS. html Technical Support
www. mathworks. com comp. soft-sys. matlab suggest@mathworks. com bugs@mathworks. com doc@mathworks. com service@mathworks. com info@mathworks. com
Product enhancement suggestions Bug reports Documentation error reports Order status, license renewals, passcodes Sales, pricing, and general information
508-647-7000 (Phone) 508-647-7001 (Fax) The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site. Data Aquisition ToolboxTM Adaptor Kit User's Guide © COPYRIGHT 20002010 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. [. . . ] For a discussion of the important properties for SetDaqHwInfo, consult Appendix D, "Sample Property and daqhwinfo Tables. "
Step 5. 5
Modify the SetPortDirection Method
The SetPortDirection method is used to set up the read or write status of each line in each port. The calling syntax of the method is as follows:
HRESULT ::SetPortDirection(LONG Port, ULONG DirectionValues)
The first argument is the port number, and the second argument is a masked list of directions for that particular port. A 0 in any bit position means that the particular line should be an input (reading), while a 1 in any bit position means that the line must be configured for output (writing).
Note For port-configurable devices, the DirectionValues variable is always set to 0 for input, or 255 for output, regardless of the size of the port.
A typical example of the SetPortDirection method is given below for the Measurement Computing adaptor:
HRESULT CDio::SetPortDirection(LONG Port, ULONG DirectionValues) { if (PortNum[Port]==AUXPORT) return S_OK; if (DirectionValues==0) { CBI_CHECK(cbDConfigPort(_BoardNum, PortNum[Port], DIGITALIN)); } else { CBI_CHECK(cbDConfigPort(_BoardNum, PortNum[Port], DIGITALOUT));
3-57
3
Step-by-Step Instructions for Adaptor Creation
} return S_OK; }
Step 5. 6
Implement the ReadValues Method
The ReadValues method is used to read data from a number of digital lines. The ReadValues method is called whenever the user requests digital input using the getvalue function in MATLAB (see "Reading Line Values" in Chapter 2 for more information on the getvalue function). A typical implementation of this method is shown for the Measurement Computing adaptor:
HRESULT CDio::ReadValues(LONG NumberOfPorts, LONG * PortList, ULONG * Data) { if (Data == NULL) return E_POINTER; USHORT val; for (int i=0;i<NumberOfPorts;i++) { CBI_CHECK(cbDIn(_BoardNum, PortNum[PortList[i]], &val)); Data[i]=val; } return S_OK; }
The data is always returned to MATLAB as unsigned long data.
Note Some boards allow lines on a given port to be configured separately. In this case, ReadValues still assumes that the whole port will be read. However, the values obtained from the lines configured for output are meaningless, because they reflect values latched from a previous write operation. The engine returns only the requested line information to the user.
3-58
About the Demo Adaptor Software
Testing the ReadValues Method
Once you have written the ReadValues method, you can test your device. The code given in "Reading Line Values" in Chapter 2 provides example code to test your adaptor.
Step 5. 7
Implement the WriteValues Method
The WriteValues method is used to write data to a number of digital lines. The WriteValues method is called whenever the user sends digital input data using the putvalue function in MATLAB (see "Writing Line Values" in Chapter 2 for more information on the putvalue function). A typical implementation of this method is shown for the Measurement Computing adaptor:
HRESULT CDio::WriteValues(LONG NumberOfPorts, LONG * PortList, ULONG * Data, ULONG * Mask) { for (int i=0;i<NumberOfPorts;i++) { CBI_CHECK(cbDOut(_BoardNum, PortNum[PortList[i]], Data[i])); } return S_OK; }
Testing the WriteValues Method
Once you have written the WriteValues method, you can test your device. The code given in "Writing Line Values" in Chapter 2 provides example code to test your adaptor.
3-59
3
Step-by-Step Instructions for Adaptor Creation
3-60
4
Working with Properties
Overview . 4-14
4
Working with Properties
Overview
This chapter contains information on dealing with Data Acquisition Toolbox properties in your adaptor. This information provides you with techniques for using the Adaptor Kit templates for · Accessing properties from your adaptor · Attaching to properties to monitor property changes (or for frequent interaction with the property) · Creating adaptor-specific properties Once you have created a reference to the property (using one of the preceding techniques), this chapter also provides you with information on · Setting values, defaults, and ranges · Adding and removing items from enumerated lists The Data Acquisition Toolbox uses properties of data acquisition objects to control how the object behaves in response to user requests. Any action taken by a data acquisition object should be due to specific property values, or combinations of values of many properties. MATLAB users interact with properties by using the get and set methods on the data acquisition object. Properties have defined types, and can have defined ranges or enumerated lists from which the user can select a value. Property methods are generally called from within · The adaptor's Open method, when creating an adaptor-specific property · The adaptor's Open method, when changing the characteristics of an existing property · The adaptor's SetProperty method, when the user modifies a property that affects the characteristics of other properties or requires special attention because of hardware limitations (for example, quantization of sampling rates) · The adaptor's SetChannelProperty method, when modifying one channel property affects the characteristics of another property
4-2
Overview
· The adaptor's Start method, when accessing values of a property that are needed to set up the acquisition task Note This chapter should be used as a reference for techniques, and not as a reference for the Adaptor Kit ATL code. The Adaptor Kit ATL code does not need to be understood in order for you to use the ATL templates.
4-3
4
Working with Properties
Accessing Properties from Your Adaptor
The data acquisition engine provides property management functions, exposing a number of methods to your adaptor through the IPropRoot, IPropValue, and IPropContainer interfaces. Although you can use these interface methods directly, the Adaptor Kit includes some helper functions to allow you to interact with properties more easily. The first requirement for interacting with a property is to be able to access that specific property. Some properties require frequent interaction from the adaptor, and those should be accessed using the ATTACH_PROP macro. [. . . ] Attach to implement possible range changes for Internal to/from Software transition. Almost always attached for an adaptor, to quantize values and/or check channel skew. Might need to attach if hardware triggering is used.
ChannelSkew
ChannelSkewMode
ClockSource
InputType
SampleRate
TriggerChannel
D-7
D
Sample Property and daqhwinfo Tables
Table D-5: Analog Input Properties for propinfo Table (Continued) Property TriggerCondition Typical Adaptor Interaction
Can change depending on TriggerType. Typically, if hardware triggering is supported, TriggerCondition changes depending on the types of triggers implemented. [. . . ]