Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

What causes the "Specified operation cannot be performed when the are no devices in the task

Solved!
Go to solution
        using (NationalInstruments.DAQmx.Task task = new NationalInstruments.DAQmx.Task())
        {
          task.Timing.ConfigureSampleClock("", 1000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 2);
          task.DIChannels.CreateChannel("PXI1Slot6/Port2/Line3", "", ChannelLineGrouping.OneChannelForAllLines);
          //task.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(triggerLine, DigitalEdgeStartTriggerEdge.Rising);

          DigitalSingleChannelReader reader = new DigitalSingleChannelReader(task.Stream);
          reader.ReadSingleSampleSingleLine();
        }

Why does the above code throw a DAQmx exception with message:

"Specified operation cannot be performed where there are no devices in the task.

 

task name:_unnamedTask<2>

 

Status Code:-200477"

 

There IS a device in the task.  I'm trying to PXI1Slot6 (the 6535 IO card) to grab 2 samples off of Port 2 Line 3.  

0 Kudos
Message 1 of 4
(9,659 Views)

The problem arises from attempting to configure the sample clock before setting the channel.  This code works fine:

 

        using (NationalInstruments.DAQmx.Task task = new NationalInstruments.DAQmx.Task())
        {
//NOTE: These two lines have been switched! task.DIChannels.CreateChannel("PXI1Slot6/Port2/Line3", "", ChannelLineGrouping.OneChannelForAllLines); task.Timing.ConfigureSampleClock("", 1000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 2); //task.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(triggerLine, DigitalEdgeStartTriggerEdge.Rising); DigitalSingleChannelReader reader = new DigitalSingleChannelReader(task.Stream); reader.ReadSingleSampleSingleLine(); }

 

This one is a definite whiskey-tango-foxtrot.

0 Kudos
Message 2 of 4
(9,658 Views)

CurtisHx,

 

The reason that the second code that you posted works and the first one doesn’t is that you have to create a channel before you are able to set the timing. Even though you have a card in the slot, you have to create the channel which verifies what channel you are accessing in the code first.

 

If you are interested as well there are examples which will be show you how to do a read digital channel. The following path is where those examples are located:

C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DotNET4.5.1\Digital\Read Values\ReadDigChan\CS.

 

Also below is an example of the set up for setting up a digital input, the code below is LabVIEW; however the steps should be the same in Measurement Studios.

 

 

DI LabVIEW.PNG

 

Hope this helps!

Sarina
Applications Engineering
National Instruments
Message 3 of 4
(9,625 Views)
Solution
Accepted by topic author CurtisHx

Hi CurtisHx

 

Thanks for reporting this. I agree that the error message returned by the driver is not very clear and fails to provide an API user enough information to determine the cause of error in code. In addition to that, it seems we do not document the correct order of operations for setting up a task well (the best thing we could find was the Tasks in NI-DAQmx topic, which actually seems to imply that configuration of channels and their timing can be done in any order). We are in the process of filing several bug reports aimed at fixing / improving the following:

  • The error message returned to the API from the driver. 
  • The help topic for Tasks in NI-DAQmx.
  • The specific method documentation provided with the NI-DAQmx .NET API.

 

To clarify the error, it seems that "device" in "Specified operation cannot be performed when the are no devices in the task" is actually referring to channels configured in the task. At this point, I am unsure whether "device" can be applied to other software entities in the DAQmx driver, but I will post back when I have an improved error message created by the development team working on it. 

 

 Warm regards,

Daniel Dorroh
National Instruments
Message 4 of 4
(9,557 Views)