11-07-2007 11:08 AM
11-08-2007
10:52 PM
- last edited on
10-29-2025
08:11 PM
by
Content Cleaner
Hello mjcatt,
I would recommend that you use the ReadMultiSample method to read your data in a call back that occurs asynchronously. As stated in the documentation for this method in the NI-DAQmx .NET Framework 2.0 Help (Start>>All Programs>>National Instruments>>NI-DAQ😞
"If you set samplesPerChannel (parameter) to -1 for a finite acquisition, the read behavior is set by the ReadAllAvailableSamples property of the DaqStream you are reading from."
By setting the ReadAllAvailableSamples property to true, you can read all the available samples during your finite acquisition and plot the data dynamically as you are acquiring. An example of this use can be found in the example called ContAcqVoltageSamples_IntClk. This example performs a continuous acquisition, so you would need to change the ConfigureSampleClock method to set the SampleQuantityMode to FiniteSamples and set the ReadAllAvailableSamples property as described above. This would allow you to read 1000 samples on your channels at whatever rate you wanted (approximately 17 Hz should give you just over 1000 samples in 60 seconds). This document describes where to find .NET examples for NI-DAQmx, NI-VISA and NI-488.2.
11-12-2007 09:59 AM
Matt,
Thanks for your comments. I had reviewed the examples, which are somewhat misleading. The NI example asynchronous code is as follows:
Public Sub New(ByVal t As Task)
'Create the reader
reader = New AnalogSingleChannelReader(t.Stream)
'Acquire 100 samples
Dim handle As IAsyncResult
handle = reader.BeginReadMultiSample(100,AddressOf OnDataReady,Nothing)
End Sub
Public Sub OnDataReady(i As IAsyncResult)
'Retrieve the data that was read.
'At this point, any exceptions that occurred during the asynchronous read are thrown
Dim data As Double()
data = reader.EndReadMultiSample(i)
'You can call the BeginReadMultiSample method here again
End Sub
This lead me to believe that a call to BeginReadMultiSample initiates a measurement sequence (which apparently it does) - it was unclear if every call to BeginReadMultiSample would want to initiate a new measurement sequence in addition to reading samples.
In fact the code I needed was (this is just a very simplified example), which now seems obvious:
mytask.Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, NSamp)Thanks again. Regards,
Mark
11-13-2007 07:36 PM
12-18-2007 04:34 PM - edited 12-18-2007 04:35 PM
TaskAB.Stream.ReadRelativeTo = ReadRelativeTo.FirstSample
'New: configure clock to acquire finite number of samplesTaskAB.Timing.ConfigureSampleClock(ClockOutSrcAB, Convert.ToDouble(TRANSFER_HZ), SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples,
CType(CMB_NUMPOINTS.Text, Integer)) 'Configure task to be Burst Handshake Timing protocol:TaskAB.Timing.ConfigureHandshakingBurstExportClock(ClockOutSrcAB, Convert.ToDouble(TRANSFER_HZ), DigitalLevelPauseTriggerCondition.Low, ReadyForTransferEventLevelActiveLevel.ActiveHigh, SampleClockPulsePolarity.ActiveHigh, SampleQuantityMode.FiniteSamples,
CType(CMB_NUMPOINTS.Text, Integer)).
.
.
ReaderAB.BeginReadMultiSamplePortInt32(DataMult *
CType(CMB_NUMPOINTS.Text, Integer), asyncDigitalCallbackAB, TaskAB).
.
.
M_Buffer = ReaderAB.EndReadMultiSamplePortInt32(async_req) <== this is where it sends the exception -200278
Do you have any ideas why this is happening? I need to collect, say, 128 samples from my DIO at 20 MHz. Then get this data to a vector of long integers. Thank you for any suggestions.
12-19-2007 01:26 PM
Hello,
Two things can be happening here … either way the error code related to trying to get samples that are not available. One you are trying to pull samples that are not there, since the number you are trying to read in the callback is larger than the amount currently acquired / available. As Matt stated above in post 2, you can read all the available samples using the ReadAllAvailableSamples and setting it to true. Try enabling the ReadAllAvailableSamples property.
In addition, the error could also be accruing if all the samples specified in the finite acquisition have already been acquire and now the callback task cannot link to an acquisition in process. This is more likely the case given the 20 MHz rate and only 128 samples needed. You might want to consider using continuous mode, increasing the 128 number, or using post processing instead of using a callback.
12-19-2007 01:33 PM
12-20-2007
05:35 PM
- last edited on
10-29-2025
08:12 PM
by
Content Cleaner
Hello,
For post processing, I would suggest writing the data to a file and reading from it at a later point in time. I do however think that running in continuous mode would be a better option, if possible. Or I also see from your description of the application that I can recommend some examples. The DAQmx .Net examples download to two different locations mattering what version of Drivers you have downloaded. Please refer to the Knowledge Base linked below for the path locations. The examples on my computer are located at C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET2.0 and I have DAQmx 8.6. I opened up the example titled ContReadDigitalChan_ExtClk.2005. I modified the example to take an internal clock by referencing the ReadDigChan_IntClk_PatternMatchStart and changed it from continuous to finite. I hope this helps. Please note that when you posted that you were using VB 5, I assumed you were using 2005 since this was initially a .NET post and you stated you have a similar issue.
NI-DAQmx, NI-VISA and NI-488.2 .NET Example Locations