Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

C# NI USB-6255 Analog Reader Doesn't Issue a Callback

Hello everyone,

 

I am currently experiencing an issue in which my callback supplied to AnalogMultiChannelReader.BeginReadMultiSample isn't being called after stopping a collection task and recreating / starting it. In both cases the activity light indicates activity on the NI USB-6255 A/D. I have spent the last couple of hours trying to figure this out and I am at a complete loss now.

 

Here is the code I use to start collecting analog data:

 

collectionTask = new Task(configuration.Name);

ConfigureChannels();

collectionTask.Timing.ConfigureSampleClock(
	signalSource: "",
	rate: configuration.Rate,
	activeEdge: SampleClockActiveEdge.Rising,
	sampleMode: SampleQuantityMode.ContinuousSamples);
collectionTask.Timing.AIConvertRate = configuration.Rate * configuration.Channels.Length;

collectionReader = new AnalogMultiChannelReader(collectionTask.Stream) {
	SynchronizeCallbacks = true
};

collectionTask.Control(TaskAction.Verify);

collectionTask.Start();

collectionReader.BeginReadMultiSample(
	samplesPerChannel: (int)Math.Round(configuration.Rate * configuration.BufferTime),
	callback: DataReceived,
	state: null);

 

 

Here is the callback:

 

private void DataReceived(IAsyncResult asyncResult) {
	log.Info("Data Received");
	try {
		if (collectionTask == null)
			return;

		var waveform = collectionReader.EndReadMultiSample(asyncResult);
		queue.Add(waveform);
					
		collectionReader.BeginReadMultiSample(
			samplesPerChannel: (int)Math.Round(configuration.Rate * configuration.BufferTime),
			callback: DataReceived,
			state: null);
	}
	catch (Exception exception) {
		// Exception Logged (not shown)
	}
}

 

Here is how I stop the collection:

collectionTask.Stop();
collectionTask.Dispose();
collectionTask = null;

 

Any thoughts on possible debugging paths would be greatly appretiated. I have spent the last 4 hours trying to figure this out.

 

Thank you

 

0 Kudos
Message 1 of 4
(4,109 Views)

Hello CanisUrsa,

 

I just wanted to know if you could go a little bit further in you explanation of the error. 

 

Do you get any error codes?

Do the code stops running at some specific time?

Or it is jsut that you run the code and dont get a responce as you want?

 

Thanks for the information!! 🙂


Regards,
Daniel M.
Applications Engineering
National Instruments
www.ni.com/support
0 Kudos
Message 2 of 4
(4,071 Views)

Thank you for the response Daniel,

 

No exceptions occur. The task verifies properly. The code stops working after the second time I start collecting A/D data.

 

I traced the issue to the following:

collectionReader = new AnalogMultiChannelReader(collectionTask.Stream) {
	SynchronizeCallbacks = true
};

I changed SynchronizeCallbacks to false and the code functions as I expect (works). I do not know the impact this has or what kind of trade offs this creates.

0 Kudos
Message 3 of 4
(4,062 Views)

Hey CanisUrsa,

 

Maybe you can take a look to these articles:

 

http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/eventscallbacksthreadsafety/

http://zone.ni.com/reference/en-XX/help/370473H-01/mstudiowebhelp/html/6a98728/

 

 

Let me know if you are still having some questions!! 


Regards,
Daniel M.
Applications Engineering
National Instruments
www.ni.com/support
0 Kudos
Message 4 of 4
(4,055 Views)