Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Clear what one has written to a DAQ between subsequent calls to WriteMultiSample(bool autoStart, double[,] data) function?

Solved!
Go to solution

Hello,

 

I would like to have my application call the WriteMultiSample(bool autoStart, double[,] data) function whenever the user changes a parameter on the UI that influences how the sample sequence to be delivered out of the analog output is generated. The problem is that this function may end up getting called multiple times without starting it's associated task which inevitably leads to DAQ exceptions being thrown. In between subsequent calls to WriteMultiSample(), I would like to clear what was written to the DAQ device. Is this possible?

0 Kudos
Message 1 of 3
(2,112 Views)

Adding some more information that may be of use. If I do not start a writer's associated task between subsequent WriteMultiSample(false, _myData) calls the function call will eventually throw the following exception...

NationalInstruments.DAQmx.DaqException
  HResult=0x80131501
  Message=DAQmx Write failed, because a previous DAQmx Write automatically configured the output buffer size. The buffer size is equal to the original number of samples written per channel, so no more data can be written prior to starting the task.

Start the generation before the second DAQmx Write, or set Auto Start to true in all occurences of DAQmx Write. To incrementally write into the buffer prior to starting the task, call DAQmx Configure Output Buffer before the first DAQmx Write.

Task Name: UptAnalogOutputTask

Status Code: -200547
  Source=NationalInstruments.DAQmx
  StackTrace:
   at nNIMSSAIL100.StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >.CheckWithName(StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* , tCaseInsensitiveBasicString<unsigned short\,_STL::char_traits<unsigned short>\,_STL::allocator<unsigned short>\,nNIDMXS100::tLocaleConsideringWideStringComparitor\,nNIDMXS100::tLocaleConsideringWideStringCaseForcer>* pName)
   at nNIMSSAIL100.StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >.Check(StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* )
   at nNIMSSAIL100.StatusObserverWrapperT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >.Check(StatusObserverWrapperT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* )
   at nNIMSSAIL100.Write<class nNIMSSAIL100::ApiTraits<class nNIMSSAIL100::DotNetApi>,class nNIMSSAIL100::AnalogWrite,double>(tTask* , Double* , UInt32 , UInt32 , UInt32 , Double , Boolean , Boolean , tScaledDataFormat , StatusObserverT<nNIMSSAIL100::ApiTraits<nNIMSSAIL100::DotNetApi> >* )
   at nNINETAI2005100.Write2D<class nNIMSSAIL100::ApiTraits<class nNIMSSAIL100::DotNetApi>,class nNIMSSAIL100::AnalogWrite,double,double,cli::array<double ,2>^>(Task task, Double[,] buffer, UInt32 numChannels, UInt32 numSamples, UInt32 lines, Double timeout, Boolean autoStart, Boolean interleaved)
   at NationalInstruments.DAQmx.Internal.AnalogMultiChannelWriterImpl.WriteMultiSample(Boolean autoStart, Double[,] data)
   at NationalInstruments.DAQmx.AnalogMultiChannelWriter.WriteMultiSample(Boolean autoStart, Double[,] data)
   at Cess.Upt.UptAnalogOutput.Handle(UptDeliverableSamplesAvailableEvent message) in C:\projects\Cardialen\Cess\Software\Cess\Upt\UptAnalogOutput.cs:line 107

Unfortunately, setting AutoStart to true for me is not an option. It would be ideal if I could clear the output buffer it is talking about.

 

I have found that if I dispose of the writer's associated task and reconfigure it between subsequent writes, then no exception is every thrown. This behavior makes sense but is not a viable solution to my problem, because disposing and reconfiguring the task introduces unnecessary overhead.

0 Kudos
Message 2 of 3
(2,093 Views)
Solution
Accepted by topic author b!tmaster

I found the following info in an exception message.

The following actions can empty the buffer: changing the size of the buffer, unreserving a task, setting the Regeneration Mode property, changing the Sample Mode, or configuring retriggering. 

I did some testing to verify as much of this as I could.

 

Changing the size of the buffer

Results: Clears the buffer

 

Unreserving the task

Results: Clears the buffer

 

Set regeneration mode property

Results: Changing the regeneration mode property clears the buffer, setting the regeneration mode to itself does not clear the buffer. This should be interpreted as Change regeneration mode property.

 

Change sample mode

Results: Does not clear the buffer.

 

Configure retriggering

Results: Not exactly sure how to test, unsure!

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