Digital I/O Objects

Creating a Digital I/O Object

You create a digital I/O (DIO) object with the digitalio function. digitalio accepts the adaptor name and the hardware device ID as input arguments. For parallel ports, the device ID is the port label (LPT1, LPT2, or LPT3). For data acquisition boards, the device ID refers to the number associated with the board when it is installed. Note that some vendors refer to the device ID as the device number or the board number. When using NI-DAQmx, this is usually a string such as 'Dev1'.) Use the daqhwinfo function to determine the available adaptors and device IDs.

Each DIO object is associated with one parallel port or one subsystem. For example, to create a DIO object associated with a National Instruments board:

dio = digitalio('nidaq','Dev1');

The digital I/O object dio now exists in the MATLAB workspace. You can display the class of dio with the whos command.

whos dio
  Name      Size         Bytes  Class

  dio       1x1           1308  digitalio object

Grand total is 40 elements using 1308 bytes

Once the object is created, the properties listed below are automatically assigned values. These general purpose properties provide descriptive information about the object based on its class type and adaptor.

Table 8-1. Descriptive Digital I/O Properties

Property Name

Description

Type

Indicate the device object type.

Name

Specify a descriptive name for the device object.

You can display the values of these properties for dio with the get function.

get(dio,{'Name','Type'})
ans = 
    'nidaq1-DIO'    'Digital IO'

The Parallel Port

The PC supports up to three parallel ports that are assigned the labels LPT1, LPT2, and LPT3. You can use any of these standard ports as long as they use the usual base addresses, which are (in hex) 378, 278, and 3BC, respectively. The port labels and addresses are typically configured through the PC's BIOS. Additional ports, or standard ports not assigned the usual base addresses, are not accessible by the toolbox.

Most PCs that support the MATLAB software will include a single parallel port with label LPT1 and base address 378. To create a DIO object for this port,

parport = digitalio('parallel','LPT1');

Administrator Privileges for Parallel Port Pins

Accessing the individual pins of the parallel port under Windows 2000 and Windows XP is a privileged operation. The Data Acquisition Toolbox software installs a driver called winio.sys that provides access to the parallel port pins. Normally, only users with administrator privileges can do this.

To allow users without administrator privileges to use the parallel port from the Data Acquisition Toolbox software:

  1. Log in to your machine as the administrator.

  2. Start the MATLAB software.

  3. At the MATLAB Command Window, type

      daqhwinfo('parallel');
  4. Minimize the MATLAB Command Window.

  5. On the desktop, select My Computer and right-click. Choose Properties from the menu that appears.

  6. In the dialog box that appears, click the Hardware tab, and click the Device Manager button.

  7. In the window that appears, select View > Show Hidden Devices, and expand the Non-Plug and Play Drivers item in the list.

  8. Find the WINIO item near the bottom of the list. Double-click it, and click the Driver tab in the window that appears.

  9. Expand the Startup Type drop-down list and change the entry from Demand to Boot. This causes the WINIO driver to start up every time the machine is rebooted.

  10. Close all the open windows, including MATLAB, and restart your machine.

Users with standard or power-user privileges can now access the parallel port pins.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS