Measurement Studio for .NET Languages

취소
다음에 대한 결과 표시 
다음에 대한 검색 
다음을 의미합니까? 

DigitalSingleChannelWriter vs DigitalMultiChannelReader

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);

0 포인트
1/14 메시지
7,623 조회수

I don't understand why you think you could simply change from reading to writing a DIO line at whim.

 

 

0 포인트
2/14 메시지
7,621 조회수

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?

0 포인트
3/14 메시지
7,614 조회수

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.

 

 

0 포인트
4/14 메시지
7,610 조회수

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.

0 포인트
5/14 메시지
7,601 조회수

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();
0 포인트
6/14 메시지
7,598 조회수

I cleaned that up. Attached you may find the updated file.

0 포인트
7/14 메시지
7,584 조회수

@MeasurementStudioFan wrote:

I cleaned that up. Attached you may find the updated file.


Have you tried the program with the changes?

0 포인트
8/14 메시지
7,572 조회수

Yes.

 

I think the real question is; can the device run more than one Task at same time?

0 포인트
9/14 메시지
7,568 조회수

Why do you have two tasks -- digitalMultiInAsyncTask and digitalInSycTask -- for port1 ?

 

0 포인트
10/14 메시지
7,561 조회수