Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Get DaqMX.Channel instance from virtual channel

Hi

 

I am doing some tests with the DaqMX API for .NET. Please note that I am not using Measurement Studio but only the .NET API (see the references below).

daqmx1.PNG

 

I am an experienced programmer but completely new to National Instruments products (hardware and software).

 

The issue

I have used MAX (Measurement and Automation Explorer) to set up a few virtual (global) channels.

In my .NET application i wish to:

  • List all virtual channels
  • From a specific virtual channel name obtain a DaqMX.Channel instance for that specific channel.

daqmx.PNG

 

Listing the channels is easy (the DAQmx.DaqSystem.Local.GlobalChannels string array), but the second one is harder.

The only way I have found so far is:

  • Create a dummy task (DaqMX.Task)
  • Add the virtual channel to the task by its name (Task.AddGlobalChannel(channelName) )
  • Configure timing
  • Verify the task
  • Use the channel object returned by AddGlobalChannel
Public Function getVirtualChannelByName(channelName As String) As DAQmx.Channel
    Try
        Dim dummyTask As New DAQmx.Task
        Dim ch As DAQmx.Channel = dummyTask.AddGlobalChannel(channelName)
        dummyTask.Timing.ConfigureSampleClock("", 100, DAQmx.SampleClockActiveEdge.Falling, DAQmx.SampleQuantityMode.ContinuousSamples)
        dummyTask.Control(DAQmx.TaskAction.Verify)
        Return ch
    Catch ex As Exception
        Throw ex
    End Try
End Function

Is there a better way of doing this? Or are there maybe any logical limitations which prevents the API from retrieving the channel information without it being added to a task? Clearly MAX can do it, so I think this would be possible.

Linus Nilsson
0 Kudos
Message 1 of 1
(3,758 Views)