Create a Session

This example shows how to create a session and add channels to the session and use the session to acquire and generate data. You can also configure session and channel properties needed for your operation.

Step 1. Create a data acquisition session.

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

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

Once you create a session object, add channels using addAnalogInputChannel, addAnalogOutputChannel, addCounterInputChannel, and addCounterOutputChannel functions.

Step 2. Configure session properties.

Change the sessions duration to 10 seconds:

s.DurationInSeconds = 10
s = 

Data acquisition session using National Instruments hardware:
   Will run for 10 seconds (10000 scans) at 1000 scans/second.
   No channels have been added.

Step 3. Add channels to the session.

Add an analog input channel to the session:

s.addAnalogInputChannel('cDAQ1Mod1','ai0', 'Voltage')
ans =

Data acquisition session using National Instruments hardware:
   Will run for 10 seconds (10000 scans) at 1000 scans/second.
   Number of channels: 1
      index Type  Device   Channel MeasurementType      Range       Name
      ----- ---- --------- ------- --------------- ---------------- ----
      1     ai   cDAQ1Mod1 ai0     Voltage (Diff)  -10 to +10 Volts

Step 4. Change channel properties.

Examine the channel properties.

s.Channels
ans = 

Data acquisition analog input voltage channel 'ai0' on device 'cDAQ1Mod1':

       Coupling: DC
      InputType: Differential
          Range: -10 to +10 Volts
           Name: empty
             ID: 'ai0'
         Device: [1x1 daq.ni.CompactDAQModule]
MeasurementType: 'Voltage'

Change the InputType property to 'SingleEnded'.

s.Channels.InputType='SingleEnded'
s = 

Data acquisition session using National Instruments hardware:
   Will run for 10 seconds (10000 scans) at 1000 scans/second.
   Number of channels: 1
      index Type  Device   Channel   MeasurementType        Range       Name
      ----- ---- --------- ------- ------------------- ---------------- ----
      1     ai   cDAQ1Mod1 ai0     Voltage (SingleEnd) -10 to +10 Volts

Related Examples

Was this topic helpful?