From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Buffer too small(DAQ with VB6)

I write a programm with VB6 for M series PCI DAQ card 6220.
here is the brief code:
'create a task
DAQmxErrChk DAQmxCreateTask(TaskName, hTask)
'create a channel
DAQmxErrChk DAQmxCreateAIVoltageChan(hTask, pChnANum, "", DAQmx_Val_RSE, -5, 5, DAQmx_Val_Volts, "")
'define sampleClock timing
DAQmxErrChk DAQmxCfgSampClkTiming(hTask, "", sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, PointNum)
'start test
DAQmxErrChk DAQmxStartTask(hTask)
'read result
DAQmxErrChk DAQmxReadAnalogF64(hTask, 1000, timeout, DAQmx_Val_GroupByScanNumber, Data, PointNum, ReadNum, 0)
'stop test
DAQmxErrChk DAQmxStopTask(hTask)
'clear task
DAQmxErrChk DAQmxClearTask(hTask)

test parameters are : sample point per chan=1000 (as PointNum)
sample rate = 10000 (as sampleRate)
result Data count =1000 (as Data(1000) )

but when I run the propgram ,I got a error "buffer is too small for reading data."what's the problem?
^_^^_^
0 Kudos
Message 1 of 6
(3,279 Views)
Hello,

How many channels are in this task? Keep in mind that if you have more than one channels, than a buffer will be created that is Number of Sampels * Number of Channels. Also try changing
DAQmxErrChk DAQmxReadAnalogF64(hTask, 1000, timeout, DAQmx_Val_GroupByScanNumber, Data, PointNum, ReadNum, 0)

to

DAQmxErrChk DAQmxReadAnalogF64(hTask, -1, timeout, DAQmx_Val_GroupByScanNumber, Data, PointNum, ReadNum, 0)

The "-1" tells the command to read whatever is in the buffer.

Let me know your results.

Sean C.
0 Kudos
Message 2 of 6
(3,266 Views)
thank you for reply.
I've tried the method you said,but the problem is the same.:(
^_^^_^
0 Kudos
Message 3 of 6
(3,261 Views)
Hi,

Since you are using DAQmx with VB6, you need to declare you function prototypes (either at the top of the program or in a .BAS file). When you declare DAQmxConfigSmpClkTiming, how did you account for the 64 bit datatype?

int32 DAQmxCfgSampClkTiming (TaskHandle taskHandle, const char source[], float64 rate, int32 activeEdge, int32 sampleMode, uInt64 sampsPerChanToAcquire);

You see that sampsPerChanToAcquire is a uInt64 datatype. This datatype is not supported in VB6 so you need a way around it. If you are using the wrong datatype you will pass an unexpected value for that parameter.

Check out my attached example. It shows how to take care of the 64 bit datatype.

-Sal
0 Kudos
Message 4 of 6
(3,253 Views)
thank you for reply!! I've seen your answer at "Measurement Studio for VB6" area. I rewrite the prototype of DAQmxCfgSampClkTiming and other fbunctions that have int64 type parameters. I successfully acquired the data to the array I defined.But there's still a problem.
After I call the data reading function , I want caculate the average data of data(n). then "overflow" error occured like this:
sub GetData() 'Get the data and caculate the average. the data I Acquired stored in : data(10)
....... 'call data Reading function....
for I=0 to 10
val1=val1+data(i) <---- overflow at this point
next I
aver=val1/11
end sub

but when I write caculate process in another function, the "overflow" error disappeared. Like this:

sub Getdata()'Get the data
....... 'call data Reading function....
end sub

sub Caculate() 'caculate the average
for I=0 to 10
val1=val1+data(i) <---- not overflow
next I
aver=val1/11
end sub

I don't know why?
^_^^_^
0 Kudos
Message 5 of 6
(3,245 Views)
Hi,

That is indeed very strange. It looks like you have a working solution to this. I'm not exactly sure what the problem is however. It looks like your data is a global variable so passing it by reference versus value doesn't seem to be the issue.

very odd...

-Sal
0 Kudos
Message 6 of 6
(3,226 Views)