Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem configuring 2 Digital Input Tasks at same time

I'm having a problem creating 2 tasks monitoring 2 different digital lines on the same DAQ 6513 card. I've attached a code sample that demonstrates the issue. When I run this code I get  the follwoing exception,

The specified resource is reserved. The operation could not be completed as specified.

Task Name: Task2

Status Code: -50103



but I can't find sufficient information to help me understand what I am not doing correctly.

using System;
using System.Diagnostics;
using NationalInstruments.DAQmx;

namespace DigitalIO
{
    class testClass
    {
       
        [STAThread]
        static void Main(string[] args)
        {
            testClass test = new testClass();
            test.runTest();
            System.Console.WriteLine("test");
           
        }
        public void runTest()
        {
            try
            {
                string lineAddress = @"Dev1/Port0/Line0";
                Task task = new Task("Task1");
                task.DIChannels.CreateChannel(lineAddress, "Channel1", ChannelLineGrouping.OneChannelForEachLine );
                task.Timing.ConfigureChangeDetection( lineAddress, lineAddress, SampleQuantityMode.ContinuousSamples);
                task.DigitalChangeDetection += new DigitalChangeDetectionEventHandler(this.OnDataChanged);

                task.Start();

                lineAddress = @"Dev1/Port0/Line1";
                task = new Task("Task2");
                task.DIChannels.CreateChannel(lineAddress, "Channel2", ChannelLineGrouping.OneChannelForEachLine );
                task.Timing.ConfigureChangeDetection( lineAddress, lineAddress, SampleQuantityMode.ContinuousSamples);
           
                task.DigitalChangeDetection += new DigitalChangeDetectionEventHandler(this.OnDataChanged);
                task.Start();
            }
            catch(DaqException ex)
            {
                Trace.Write(((Exception)ex).Message);
                Trace.Flush();
                System.Console.WriteLine(ex.StackTrace);
            }
        }
        public void OnDataChanged(object sender, DigitalChangeDetectionEventArgs e)
        {
            System.Console.WriteLine("test");
        }
    }
}

0 Kudos
Message 1 of 6
(3,655 Views)

Hello Bruce,

The reason you are seeing that error is that you are configuring digital input lines to do change detection on a board this is digital output only.  A digital output board cannot do change detection.  You may want to consider the PCI-6515 instead of the 6513 because it has 32 digital input and 32 digital output lines and can do change detection. 

Thanks,

Laura

 
0 Kudos
Message 2 of 6
(3,632 Views)
Hi Laura

Thanks for the reply.

I have to apologize... I made a typo in my original message. I am using a PCI-6514

Bruce


0 Kudos
Message 3 of 6
(3,625 Views)

Hi Bruce,

I thought that may have happened.  The trouble with what you are trying to do is that you cannot run two change detection tasks at the same time.  Instead, just add both lines that you want to do change detection on to the same task.  Your syntax would be "Dev1/Port0/Line0:1" You should not see that error once you do this.

Thanks,

Laura

0 Kudos
Message 4 of 6
(3,619 Views)
Hi Laura

Thanks again! I'l glad that I was able to get a definitive answer on this question.

Did I miss something in the documentation? Is there anything in the NI documentation that states that only one change detection task can run at a time or is it just hard won experience ?

Best regards,

Bruce
0 Kudos
Message 5 of 6
(3,614 Views)

Hi Bruce,

I do not see anything specifically in the documentation about running these sorts of tasks.  If you have missed it, the documentation installs at Start >> Programs >> National Instruments >> NI-DAQ.  There is a general NI-DAQmx help file and also a C Reference help file.  Usually, the number of tasks that can be performed at once depends on the number of DMA channels and also the type of task, so it can be very device-specific.  Your device uses interrupts to transfer data.  If you were doing simple digital input, then two tasks could be run at once.  According to the DIO Help, with change detection an interrupt is generated for a change but it is not line specific.  The line states are probed after the interrupt is generated to see which line has changed.  From this description, It makes sense to put all lines doing change detection into the same task.

I hope this helps!
Laura
0 Kudos
Message 6 of 6
(3,582 Views)