02-04-2016 10:54 AM
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.
Solved! Go to Solution.
02-04-2016 11:05 AM
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.
02-05-2016 06:05 PM
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.
Hope this helps!
02-10-2016 04:27 PM
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:
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,