Data Acquisition Toolbox
  Function/Property:
    Search    Help Desk 

Copying Device Objects and Channels

You can keep multiple versions of a device object or channels in the MATLAB workspace by copying them to a new MATLAB variable. Copying device objects and channels are discussed below.

Copying Device Objects

The example code below illustrates how to copy a device object. It is important to note that the copied object is identical to the original object. This can be seen by setting a property for the original object and returning the value of that property from the copied object.

The reason that myAI and newAI return the same property value is because both device objects reference the same data acquisition engine object as illustrated in the figure below.


Note:
Every data acquisition object that appears as a variable references an object in the data acquisition engine.

If you delete the original device object (or a copy), then the engine object is deleted. Any copies of the device object that remain in the workspace cannot be used to perform a data acquisition task since the object they referenced no longer exists in the engine. In other words, the copies are no longer associated with any hardware. Copied objects that do not reference an engine object are called invalid objects. The example code below illustrates this situation.

Note:
You cannot delete valid objects using the clear command. clear removes the variable from the MATLAB workspace but it does not remove objects from the engine. To remove objects from the engine, the delete command must be used.

Copying Channels

As shown on page 4-4, it is often useful to copy channels to a new variable with a short name and then reference the channels by that name. For example, to copy myAI's entire channel group to a new variable chans

Clearly, it is more convenient to type chans than myAI.Channel. When referencing chans, you can set only channel property values. To configure common property values, you must reference myAI or a copy of myAI.

You can copy the first channel contained by myAI to a new variable chan1 by indexing into the Channel property.

You can also copy the channel from chans.

If you delete one or more channels from the original device object (or a copy), then those channels are deleted from the engine object. Any copies of the channels that remain in the workspace cannot be used to perform a data acquisition task since the channels they referenced no longer exist in the engine. For example, channel 1 can be deleted from the engine using any of these commands

Deleting channels is discussed in detail on page 4-12.



[ Previous | Help Desk | Next ]