Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting a null task stream handle SOMETIMES using DAQmx 8.6

I'm doing a triggered read on some analog inputs. Periodically, I have to terminate and restart the task because i'm changing the trigger line between "up" and "down" (pfi8 and pfi9).

 

Here's the code that (re)sets up the read:

if (null != _psdTask)

{

   _psdTask.Control(
TaskAction.Abort);

   _psdTask.Dispose();

}

_psdTask = new Task();

//Create a virtual channel

_psdTask.AIChannels.CreateVoltageChannel(GetSampleLines(), string.Empty,

     AITerminalConfiguration.Differential, -10.0, 10.0, AIVoltageUnits.Volts);

//Configure the timing parameters & set it to retrieve exactly N samples

_psdTask.Timing.ConfigureSampleClock(string.Empty, SAMPLE_RATE,

SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, SAMPLES_PER_CHANNEL);

switch (_trigger)

{

case PSDTriggerSource.Continuous:

   _psdTask.Triggers.StartTrigger.ConfigureNone();

   _psdTask.Triggers.StartTrigger.Delay = 1.0 / SAMPLES_PER_SECOND_POLLING;

   _psdTask.Triggers.StartTrigger.DelayUnits =
StartTriggerDelayUnits.Seconds;

break;

case PSDTriggerSource.DownSensor:

   _psdTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(GetDownTriggerLine(),

      DigitalEdgeStartTriggerEdge.Rising);

break;

case PSDTriggerSource.UpSensor:

   _psdTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(GetUpTriggerLine(),

      DigitalEdgeStartTriggerEdge.Rising); break;

}

//Verify the Task

_psdTask.Control(TaskAction.Verify);

// make it never time out

_psdTask.Stream.Timeout = -1; // This is the line with the null reference

The last line sometimes throws a NullReferenceException, and the stack trace ends in my code. I'm assuming the Stream property returns NULL.

 

Any idea what can cause this (or how to work around it)? I was expecting that Verify() would have reported any issues, but it never throws an exception.

 

Thanks!

 

John Duddy

0 Kudos
Message 1 of 3
(3,011 Views)

Hello,

 

Please do some more probing.  Lets setup a breakpoint prior to the _psdTask.Stream.Timeout line and run the code.  When the code stops due to the breakpoint, navigate back to the code and find _psdTask.  Right click and Add Watch.  Please check if _psdTask is null and then expand out to check if Stream or Timeout is null.  Just looking for more insight.

 

 

Samantha
National Instruments
Applications Engineer
0 Kudos
Message 2 of 3
(2,999 Views)

Many thanks for the reply.

 

Because the NullReferenceException happens only when I access the Stream, and because I access members of the task, and because new() cannot fail in C# without throwing an OutOfMemoryException, I think it's safe to assume that the task is not null.

 

I can set a conditional breakpoint that stops if Stream is null. As I mentioned, it is very intermittent. It may take me some days to get this done, since the equipment is under heavy use at the moment - I'll keep you posted.

 

 

0 Kudos
Message 3 of 3
(2,986 Views)