Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Task De-initializes after instanciation.

So, currently I'm trying to re-write code that used to check in a timed loop into a ChangeDetection code. The focus of the code was always supposed to ensure the NI software was contained in its own library. Each instanciation is created through a static function and interfaced to another Library. I've been working on this for weeks. I had it working through a quick alteration, but not through the best practices technique I need.

 

After the instanciation, once the Task and the Reader is created and set, everything looks fine, when I peek at the object. As soon as the object leaves the instanciation, the Task and the reader nullify as if all I did was set the task to "new Task()".

 

Here is the instanciation:

public NniEventDigInputs(NgIoConfig config)
{
_Task = new Task();
bool first = true;
string address="";
foreach(var item in config.Inputs.Items)
{
_Channels.Add(item.Key, NniEventDigInChHw.Create(config.InputChannels.Device, config.InputChannels.PortIndex, item.ChannelIndex, ref _Task));
address+=first ? string.Format("{0}/port{1}/line{2}", config.InputChannels.Device,config.InputChannels.PortIndex,item.ChannelIndex.ToString()):
string.Format(",{0}/port{1}/line{2}", config.InputChannels.Device, config.InputChannels.PortIndex, item.ChannelIndex.ToString());
first = false;
}
_Task.DIChannels.CreateChannel(address, "", ChannelLineGrouping.OneChannelForAllLines);
_Task.Timing.ConfigureChangeDetection(address, address, SampleQuantityMode.ContinuousSamples, 1000);
_Task.SynchronizeCallbacks = true;
_Task.DigitalChangeDetection += new DigitalChangeDetectionEventHandler(OnHwChannelValueChanged);
_Reader = new DigitalSingleChannelReader(_Task.Stream);
foreach (var item in config.Inputs.Items)
{
_Channels[item.Key].SetReader(_Task, _Reader);
}
_Task.Start();

}

 

Here is the creation function:

public IEventDigInputs CreateEventDigInputs(NgIoConfig config)
{
return new NniEventDigInputs(config);
}

 

Here is the interface code for that function:

IEventDigInputs CreateEventDigInputs(NgIoConfig config);

I'm missing something easy I'm sure, but I can't figure it out.


The problem this creates, is when I try to detect the state of the input, like this:

public bool State
{
get
{
bool[] ret = _Reader.ReadSingleSampleMultiLine();
return ret[_Channel];
}
}

The task is empty and sends an NiDAQ exception.

0 Kudos
Message 1 of 2
(800 Views)

I figure I should give people the exception that happens when I do put a timeout into the Task.

 

  Name Value Type
  Message "Some or all of the samples requested have not yet been acquired.\nTo wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.\n\nProperty: NationalInstruments.DAQmx.DaqStream.ReadRelativeTo\nCorresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition\nProperty: NationalInstruments.DAQmx.DaqStream.ReadOffset\nCorresponding Value: 0\n\nTask Name: _unnamedTask<0>\n\nStatus Code: -200284" string

 

Update: I have changed from a ChangeDetectionEvent method of calling the read function to a DigitalCallback method of reading the function with the same result. I guess I'll add that All of the NI Examples for Change detection work fine on the system, so the PCIe card CAN perform the Change detection request.

0 Kudos
Message 2 of 2
(756 Views)