Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

sampsperchantoacquire =1 gives error -200077

using either DAQmxCfgSampClkTiming or DAQmxCfgImplicitTiming and setting SampsPerChantoAcquire to 1 gives error code -200077

I want to sample 6 channels exactly once as fast as possible - how should I do this?

Thanks!
0 Kudos
Message 1 of 8
(9,132 Views)

Hello Britt,

You would want to use the DAQmxCfgSampClkTiming function for this application.  If you set the sample mode parameter to finite acquisition, then the minimum number of samples that it will acquire is two.  If you set the sample mode parameter to Hardware Timed Single Point acquisition, then one sample will be read every time that the DAQmx Read is called.  The Samples Per Channel To Acquire parameter will let the driver know how many samples to acquire. 

For you application it sounds that you would want to set the sample mode parameter to Hardware Timed Single Point acquisition and the Samples Per Channel To Acquire to one.  The sample rate parameter would depend on your device.  Most DAQ boards will have a maximum sample rate for one channel.  Since you are reading from 6 channels, you might need to divide the maximum sampling rate by 6.  The reason for this is there is usually only one ADC.  All the analog input channels are then multiplexed into that ADC. 

I could only tell you the maximum sample rate for 6 analog input channels after I know which device you are going to use.

Respectfully,

Rob F
Test Engineer
Condition Measurements
National Instruments
Message 2 of 8
(9,118 Views)
thanks a lot!  I am using both a USB-6009 and a USB-6218 OEM.  A few follow up questions. . . \

1) I am using Visual Basic and I can't figure out how to set Hardware Timed Single Point.  In the C documentation, the values to set sampleMode to Finite Samples or Hardware Timed Single Point are:
DAQmx_Val_FiniteSamps
DAQmx_Val_HWTimedSinglePoint
but in the one Visual Basic example provided, the value used for Finite Samples is slightly different:
DAQmx_Val_AcquisitionType_FiniteSamps
If I try to use DAQmx_Val_HWTimedSinglePoint I again get a -200077 error.  I manually searched nidaqmx.tlb to try to find what the value should be for Hardware Timed Single Point, and found:
DAQmx_Val_AcquisitionType_HWTimedSinglePoint
but this too gives -200077. 

2) Assuming I can sample these channels at kHz rates but only really need to at ~ 100Hz, is sampling at 10 kHz and averaging 100 values the same as sampling one value at 100 Hz (or by setting the Rate to 100 Hz do I only get a spot sample every 0.01 seconds)?

Thanks again!

0 Kudos
Message 3 of 8
(9,115 Views)

hello my english is no godd, i write because i work whit the PCI 6132 and when i open de exsample for visual basic for Analogo in always  "error 10459-interface Erro" i do the many thing tha are in the page of NI but  to be the error , I wil be crazy because this is part of my  tesis, please help me, o tell me what i do for the error dont to be.

 

thanks  

0 Kudos
Message 4 of 8
(9,108 Views)

Hello All,

carlinedanrii,

We prefer that you post new questions to a new forum so that we do not get the two subjects confused. I would recommend that you post your question to a Multifunction DAQ forum here. You may also want to check out this KnowledgeBase online. If you are still having problems I would recommend that you post to the DAQ forum. Specifically, you should also mention if you are using any ComponentWorks controls.

 

britt,

Let me try to address your questions in order:

1) The three valid parameters for the DAQmxAcquisitionType in Visual Basic are:

- NIDAQmxCAPI.DAQmxAcquisitionType.DAQmx_Val_AcquisitionType_ContSamps

- NIDAQmxCAPI.DAQmxAcquisitionType.DAQmx_Val_AcquisitionType_FiniteSamps

- NIDAQmxCAPI.DAQmxAcquisitionType.DAQmx_Val_AcquisitionType_HWTimedSinglePoint

You can determine these parameters by looking up the NIDAQmxCAPI.DAQmxAcquisitionType enumeration in Visual Basic 6.0. However, neither the USB-6009 nor the USB-6218 OEM devices support Hardware Timed Single Point analog acquisition, due to the high latency in the USB interface. That is why you are receiving the errors when you try to use that acquisition type with your devices. I would recommend that you examine the example called OneSample.vbp for a demonstration of how to take a single sample using software timing. This example is installed to the following location by default:

C:\Program Files\National Instruments\NI-DAQ\Examples\Visual Basic 6.0\Analog In\Measure Slow Varying Signal\One Sample

2) The fact that you are sampling so slowly may make the first point irrelevant. Software timed acquisition accuracy is dependant on the overhead of your code and the accuracy of your system clock. However, in general, this operation is accurate down to the millisecond range. So, instead of sampling your signal using hardware timing on the device to get into the kHz range, you could use software timing to take a single sample at intervals in the 100 Hz range. Forgive my pseudo code, but software timing would look something like this:

while(!done){

  acquire data //code from the example program

  Sleep(waitTime) //where waitTime is in milliseconds

}

 


Matt Anderson

Hardware Services Marketing Manager
National Instruments
Message 5 of 8
(9,096 Views)
Thanks a lot Matt!  That is very helpful information.

I had looked at OneSample but because I want to scan 6 channels it did not look appropriate - do you happen to know if starting and stopping 6 tasks sequentially as in OneSample can be done as fast as scanning 6 channels using the DAQmxCfgSampClkTiming?  I currently have a kluge in place where I set DAQmxCfgSampClkTiming up for 2 sampsperchannel and then only collect 1 sample per channel when I call DAQmxReadAnalogF64  - that seems to work, but I'm unclear whether I am losing data.

Also, if I set the rate to 100 Hz in
DAQmxCfgSampClkTiming am I getting something like a 0.01 second average measurement or is it more like a spot sample collected every 0.01 seconds?

Thanks again!
Britt
0 Kudos
Message 6 of 8
(9,094 Views)
Hello Britt,

You can use the basic structure of OneSample as a guideline and simply add on however many more channels you require (in this case 5 more). You would do this using the DAQmxCreateAIVoltageChan() function. The NI-DAQmx C Reference Help describes this function as follows:


DAQmxCreateAIVoltageChan

int32 DAQmxCreateAIVoltageChan (TaskHandle taskHandle, const char physicalChannel[], const char nameToAssignToChannel[], int32 terminalConfig, float64 minVal, float64 maxVal, int32 units, const char customScaleName[]);

Purpose

Creates channel(s) to measure voltage and adds the channel(s) to the task you specify with taskHandle. If your measurement requires the use of internal excitation or you need the voltage to be scaled by excitation, call DAQmxCreateAIVoltageChanWithExcit.




You would simply call this function with the same taskHandle you are already using and list whatever channels you want as the physicalChannel[] input parameter. Also, as noted in the NI-DAQmx Help, the physical channel syntax can be used for a single channel or a range of channels. As described in this manual:


Physical Channel Syntax

<script type="text/javascript"> </script>

Use this syntax to refer to physical channels and groups of physical channels in NI-DAQmx.

Physical Channel Names

Physical channel names consist of a device identifier and a slash (/) followed by a channel identifier. For example, if the physical channel is Dev0/ai1, the device identifier is Dev0, and the channel identifier is ai1. MAX assigns device identifiers to devices in the order they are installed in the system, such as Dev0 and Dev1. You also can assign arbitrary device identifiers with MAX.

For analog I/O and counter I/O, channel identifiers combine the type of the channel, such as analog input (ai), analog output (ao), and counter (ctr), with a channel number such as the following:

ai1

ctr0

For digital I/O, channel identifiers specify a port, which includes all lines within a port:

port0

Or, the channel identifier can specify a line within a port:

port0/line1

All lines have a unique identifier. Therefore, you can use lines without specifying which port they belong to. For example, line31—is equivalent to port3/line7 on a device with four 8-bit ports.

Physical Channel Ranges

To specify a range of physical channels, use a colon between two channel numbers or two physical channel names:

Dev0/ai0:4


For digital I/O, you can specify a range of ports with a colon between two port numbers:

Dev0/port0:1

You also can specify a range of lines:

Dev0/port0/line0:4

Dev0/line0:31

You can specify channel ranges in reverse order:

Dev0/ai4:0


Dev0/port1/line3:0

Physical Channel Lists

Use commas to separate physical channel names and ranges in a list as follows:

Dev0/ai0, Dev0/ai3:6

Dev0/port0, Dev0/port1/line0:2



The implementation in which you specify 2 samples per channel in DAQmxCfgSampleClkTiming is probably not the best implementation. If you continue to specify 2 samples to read and then only pull 1 sample from the buffer in DAQmxReadAnalogF64 you will eventually overflow the buffer on the device. Also, you will not "lose" data, but I don't think you are getting the data you expect. The DAQmxReadAnalogF64 function will read the oldest available sample from the device; this isn't a problem when you are reading all the data that is in the buffer every time. However, in your implementation, you will be getting old data when you expect more recent. The figure below should demonstrate the problem with this scheme. The arrows represent the data that you are reading with the DAQmxReadAnalogF64.



This behavior is the default setting for the NI-DAQmx driver, but you can change it using the RelativeTo property. The description of this property is as follows:



RelativeTo

Data Type: int32
Description: Specifies the point in the buffer at which to begin a read operation. If you also specify an offset with Offset, the read operation begins at that offset relative to the point you select with this property. The default value is DAQmx_Val_CurrReadPos unless you configure a Reference Trigger for the task. If you configure a Reference Trigger, the default value is DAQmx_Val_FirstPretrigSamp.


Valid values

DAQmx_Val_FirstSample 10424 Start reading samples relative to the first sample acquired.
DAQmx_Val_CurrReadPos 10425 Start reading samples relative to the last sample returned by the previous read. For the first read operation, this position is the first sample acquired or the first pretrigger sample if you configured a reference trigger for the task.
DAQmx_Val_RefTrig 10426 Start reading samples relative to the first sample after the reference trigger occurred.
DAQmx_Val_FirstPretrigSamp 10427 Start reading samples relative to the first pretrigger sample. You specify the number of pretrigger samples to acquire when you configure a reference trigger.
DAQmx_Val_MostRecentSamp 10428 Start reading samples relative to the next sample acquired. For example, use this value and set Offset to -1 to read the last sample acquired.



You can get/set/reset this property using:

  DAQmxGetReadRelativeTo

  DAQmxSetReadRelativeTo

  DAQmxResetReadRelativeTo




However, in your implementation, you would still face problems with overflowing the buffer. Instead, I would recommend that you read all available samples and either average the data or just discard the samples that are not applicable.

Finally, to address your question regarding the sample rate in DAQmxCfgSampClkTiming, the sample rate is accurate down to the specifications of the device you are using. The USB-6008/6009 User Guide here provides the following specification:


Timing accuracy..................................... 100 ppm of actual sample rate


The NI USB-621x Specifications here indicates:


Timing accuracy..................................... 100 ppm of actual sample rate




Message Edited by Matt A on 07-11-2007 10:39 AM


Matt Anderson

Hardware Services Marketing Manager
National Instruments
Download All
Message 7 of 8
(9,082 Views)
thank you!  extremely helpful, saved me going way down a wrong path
Britt
0 Kudos
Message 8 of 8
(9,069 Views)