MATLAB Examples

Getting Started with Session-Based Interface Using MCC Devices

This example shows how to get started with MCC devices from the command line using the session-based interface.

Contents

Discover Available Devices

Use the daq.getDevices function to display a list of devices available to your machine and MATLAB®.

devices = daq.getDevices
devices = 

Data acquisition devices:

index Vendor Device ID                 Description                
----- ------ --------- -------------------------------------------
1     ni     Dev1      National Instruments USB-6255
2     mcc    Board0    Measurement Computing Corp. USB-1208FS-Plus
3     mcc    Board1    Measurement Computing Corp. USB-1608GX-2AO
4     mcc    Board2    Measurement Computing Corp. USB-1604HS-2AO
5     mcc    Board3    Measurement Computing Corp. USB-1608FS-Plus
6     mcc    Board4    Measurement Computing Corp. USB-1616FS


Learn Device Details

To learn more about an individual device, click the name of the device in the list in the Command window, or access the device in the array returned by the daq.getDevices function.

devices(3)
ans = 

mcc: Measurement Computing Corp. USB-1608GX-2AO (Device ID: 'Board1')
   Analog input subsystem supports:
      4 ranges supported
      Rates from 0.1 to 500000.0 scans/sec
      16 channels ('Ai0' - 'Ai15')
      'Voltage' measurement type
   
   Analog output subsystem supports:
      -10 to +10 Volts range
      Rates from 0.1 to 500000.0 scans/sec
      2 channels ('Ao0','Ao1')
      'Voltage' measurement type
   


Acquire Data

To acquire data:

  1. Create a session describing the operation to perform
  2. Add input channels to the session
  3. Start the acquisition

The daq.createSession function creates a session. The session contains information describing the hardware, scan rate, duration, and other properties associated with the acquisition. Create a session, and assign it to a variable.

s = daq.createSession('mcc')
s = 

Data acquisition session using Measurement Computing Corp. hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   No channels have been added.
   

By default, the session is configured for 1000 scans per second and a duration of one second. For this example, accept these defaults.

The addAnalogInputChannel function attaches an analog input channel to the session. You can add more than one channel to a session. For this example, add only one.

addAnalogInputChannel(s,'Board1',0,'Voltage');
s
s = 

Data acquisition session using Measurement Computing Corp. hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Number of channels: 1
      index Type Device Channel MeasurementType      Range       Name
      ----- ---- ------ ------- --------------- ---------------- ----
      1     ai   Board1 Ai0     Voltage (Diff)  -10 to +10 Volts
   

The startForeground function starts the acquisition and returns the results.

data = startForeground(s);

The session has acquired 1000 scans. Plot a portion of the acquired data:

plot(data)

Change Default Properties of the Acquisition

By default, sessions run for one second at 1000 scans per second. To acquire at a higher rate for a longer time, change the Rate and DurationInSeconds properties.

s.Rate = 5000;
s.DurationInSeconds = 2;
s
s = 

Data acquisition session using Measurement Computing Corp. hardware:
   Will run for 2 seconds (10000 scans) at 5000 scans/second.
   Number of channels: 1
      index Type Device Channel MeasurementType      Range       Name
      ----- ---- ------ ------- --------------- ---------------- ----
      1     ai   Board1 Ai0     Voltage (Diff)  -10 to +10 Volts
   

Run the acquisition and plot the acquired data:

data = startForeground(s);
plot(data)