09-23-2015 01:07 PM
I create output tasks with several DigitalSingleChannelWriters for my USB-6525 device. I can execute writer.WriteSingleSampleSingleLine(true, state); statements to change the output states. That works fine. However I created an input task as well to detect edge changes on port1. When I launch the DigitalMultiChannelReader with a BeginReadMultiSamplePortUInt32(...), I can't change the outputs any more. Can I run input and output tasks at the same time? Should I suspend the input task while changing the outputs? How do I handle this in C#?
The exception:
"Requested operation could not be performed, because the specified digital lines are either reserved or the device is not present in NI-DAQmx. \n\nIt is possible that these lines are reserved by another task, the device is being used through the Traditional NI-DAQ interface, or the device is being reset. You might also get the error if the specified resource is currently in use by LabVIEW network variables bound to the DAQ Channel, or if the DAQ Channel is being used in any OPC Client software.\n\nIf you are using these lines with another task, wait for the task to complete. If you are using the device through the Traditional NI-DAQ interface, and you want to use it with NI-DAQmx, reset (initialize) the device using the Traditional NI-DAQ interface. If you are resetting the device, wait for the reset to finish.\n\nDevice: Dev1\n\nTask Name: _unnamedTask<1B>\n\nStatus Code: -200587"
Partial init code:
digitalOutTask0.DOChannels.CreateChannel(deviceName + "/port0/line0", "TestChannelOut0", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask1.DOChannels.CreateChannel(deviceName + "/port0/line1", "TestChannelOut1", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask2.DOChannels.CreateChannel(deviceName + "/port0/line2", "TestChannelOut2", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask3.DOChannels.CreateChannel(deviceName + "/port0/line3", "TestChannelOut3", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask4.DOChannels.CreateChannel(deviceName + "/port0/line4", "TestChannelOut4", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask5.DOChannels.CreateChannel(deviceName + "/port0/line5", "TestChannelOut5", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask6.DOChannels.CreateChannel(deviceName + "/port0/line6", "TestChannelOut6", ChannelLineGrouping.OneChannelForEachLine);
digitalOutTask7.DOChannels.CreateChannel(deviceName + "/port0/line7", "TestChannelOut7", ChannelLineGrouping.OneChannelForEachLine);
digiWriter0 = new DigitalSingleChannelWriter(digitalOutTask0.Stream);
digiWriter1 = new DigitalSingleChannelWriter(digitalOutTask1.Stream);
digiWriter2 = new DigitalSingleChannelWriter(digitalOutTask2.Stream);
digiWriter3 = new DigitalSingleChannelWriter(digitalOutTask3.Stream);
digiWriter4 = new DigitalSingleChannelWriter(digitalOutTask4.Stream);
digiWriter5 = new DigitalSingleChannelWriter(digitalOutTask5.Stream);
digiWriter6 = new DigitalSingleChannelWriter(digitalOutTask6.Stream);
digiWriter7 = new DigitalSingleChannelWriter(digitalOutTask7.Stream);
digitalMultiInAsyncTask.DIChannels.CreateChannel(deviceName + "/port1/line0", "DigitalInChannel0", ChannelLineGrouping.OneChannelForEachLine);
digitalMultiInAsyncTask.DIChannels.CreateChannel(deviceName + "/port1/line1", "DigitalInChannel1", ChannelLineGrouping.OneChannelForEachLine);
digitalMultiInAsyncTask.DIChannels.CreateChannel(deviceName + "/port1/line2", "DigitalInChannel2", ChannelLineGrouping.OneChannelForEachLine);
digitalMultiInAsyncTask.DIChannels.CreateChannel(deviceName + "/port1/line3", "DigitalInChannel3", ChannelLineGrouping.OneChannelForEachLine);
digitalMultiInAsyncTask.Timing.ConfigureChangeDetection(deviceName + "/port1", deviceName + "/port1", SampleQuantityMode.ContinuousSamples, 1);
digitalMultiInAsyncTask.Stream.Timeout = -1;
digi_reader_multi_async = new DigitalMultiChannelReader(digitalMultiInAsyncTask.Stream);
digi_reader_multi_async_handle = digi_reader_multi_async.BeginReadMultiSamplePortUInt32(1, new AsyncCallback(OnMultiDataReady), digitalMultiInAsyncTask);
09-23-2015 01:15 PM
I don't understand why you think you could simply change from reading to writing a DIO line at whim.
09-23-2015 02:22 PM
My USB6525 NI device has one output port with 8 outputs and one input port with 8 inputs. There are no bidrectional IOs on this device. What I need to do is generate a sequence of output changes on port0 that are connected to a machine and read back the machine (output) behaviour via the inputs on port1.
The app is receiving a public void OnMultiDataReady(IAsyncResult i) call event when any of the inputs of port1 have changed. But while the inputs are being scanned (started with BeginReadMultiSamplePortUInt32(..)), a different thread will set the individual outputs via a WriteSingleSampleSingleLine call on the corresponding DigitalSingleChannelWriter object. The outputs are handled in a different task then the inputs. When an output is changed, the exception is thrown.
How can I prevent that or what am I doing wrong?
09-23-2015 02:31 PM
I think I understand now.
You have 8 lines that are to be inputs and 8 that are suppose to be outputs.
Did you get your code from the NI examples? If so, which one?
Can you post your entire code including the variable declations, etc?
I am guessing that you have all your code in Form1.
I am thinking that OOP may be tripping you up.
09-23-2015 03:05 PM
I can't say from which example I once started.
The code is not running under Form1. This NI code controller runs in a thread parallel to a scenario engine thread. The scenario engine executes a serie of output sequences and sends OutputCommands to the NI controller engine to set the outputs on port0. The outputs on port0 could for example power up a machine. When the machine power up sequence is cpmplete, it lights up a 'machine good' indicator. This indicator is connectect to input port1. The input levels on port1 change, the OnMultiDataReady method is called and the NI controller delegates the status info back. The info is captured by the scenario engine (and GUI) which can verify if a predefined condition is met.
I attached the NI controller code.
09-23-2015 03:20 PM - edited 09-23-2015 03:26 PM
You have
Task digitalOutTask0 = new Task(); Task digitalOutTask1 = new Task(); Task digitalOutTask2 = new Task(); Task digitalOutTask3 = new Task(); Task digitalOutTask4 = new Task(); Task digitalOutTask5 = new Task(); Task digitalOutTask6 = new Task(); Task digitalOutTask7 = new Task(); Task digitalMultiInAsyncTask = new Task(); Task digitalInSycTask = new Task();
and then you have
digitalOutTask0 = new Task(); digitalOutTask1 = new Task(); digitalOutTask2 = new Task(); digitalOutTask3 = new Task(); digitalOutTask4 = new Task(); digitalOutTask5 = new Task(); digitalOutTask6 = new Task(); digitalOutTask7 = new Task(); digitalMultiInAsyncTask = new Task(); digitalInSycTask = new Task();
What I would do is declare at the top
Task digitalOutTask0; Task digitalOutTask1; Task digitalOutTask2; Task digitalOutTask3; Task digitalOutTask4; Task digitalOutTask5; Task digitalOutTask6; Task digitalOutTask7; Task digitalMultiInAsyncTask; Task digitalInSycTask;
Also, at the top only have
NI_USB6525_EventArg m_eventArgs;
Also, I am not sure what you are doing in InitStop() with
digitalInSycTask = new Task(); digitalMultiInAsyncTask = new Task();
09-24-2015 12:06 AM - edited 09-24-2015 12:08 AM
I cleaned that up. Attached you may find the updated file.
09-24-2015 08:51 AM
@MeasurementStudioFan wrote:
I cleaned that up. Attached you may find the updated file.
Have you tried the program with the changes?
09-24-2015 09:27 AM
Yes.
I think the real question is; can the device run more than one Task at same time?
09-24-2015 02:55 PM
Why do you have two tasks -- digitalMultiInAsyncTask and digitalInSycTask -- for port1 ?