Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Acquire Data from Multiple Channels using MCC Devices

This example shows how to acquire data from multiple analog input channels with MCC devices using the session-based interface.

Hardware Setup

This example uses a Measurement Computing USB-1608GX-2AO device to log data from analog input channels 0 and 9, which are connected to the outputs of a function generator.

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. If the device does not support multiple terminal configurations across channels, ensure that the terminal configuration of the added channels are the same.

  4. 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 adds an analog input channel to the session. You can add more than one channel to a session.

ch1 = addAnalogInputChannel(s,'Board1',0,'Voltage');
ch2 = addAnalogInputChannel(s,'Board1',9,'Voltage');
Warning: Vendor Driver command failed and returned
Status code: 33031
Diagnostic: 'To perform any operation on this device, all channels in this
subsystem must have the same terminal configuration setting'
. 

Certain devices do not allow the setting of terminal configuration for each channel. In these cases, set the terminal configuration of all channels added from that device to be the same, as described in the warning above.

s
s = 

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

If the device does not support the setting of terminal configuration per channel, ensure that the terminal configuration of the added channels are the same.

ch1.TerminalConfig = 'SingleEnded'
ch1 = 

Data acquisition analog input voltage channel 'Ai0' on device 'Board1':

       Coupling: DC
 TerminalConfig: SingleEnded
          Range: -10 to +10 Volts
           Name: ''
             ID: 'Ai0'
         Device: [1x1 daq.sdk.DeviceInfo]
MeasurementType: 'Voltage'


The session should now look as follows:

s
s = 

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

The startForeground function starts the acquisition and returns the results.

[data, timestamps] = startForeground(s);

The session has acquired 1000 scans. Plot the acquired data:

plot(timestamps, data)
xlabel('Time (s)')
ylabel('Voltage (V)')

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: 2
      index Type Device Channel   MeasurementType        Range       Name
      ----- ---- ------ ------- ------------------- ---------------- ----
      1     ai   Board1 Ai0     Voltage (SingleEnd) -10 to +10 Volts
      2     ai   Board1 Ai9     Voltage (SingleEnd) -10 to +10 Volts
   

Run the acquisition and plot the acquired data:

data = startForeground(s);
plot(data)
xlabel('Time (s)')
ylabel('Voltage (V)')

Was this topic helpful?