Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxDigWrite in VB6

I've downloaded the DAQmxDigWrite.zip file, but encounter a run-time error 6 'Overflow' when
run as a compiled .exe file.
0 Kudos
Message 1 of 6
(6,788 Views)
Hi Neil,

Unfortunately, you are running into one of the problems with DAQmx and VB6. The major issue is the fact that VB 6 does not support the uInt64 datatype. The DAQmxCfgSampClkTiming function (as well as many others) use this datatype. When attempting to call this function in VB6 is is possible that a completely wrong value can be passed to the function for the number of samples. In this case you can get buffer errors (I have seen this first hand). There is a way around it and that is to use the "currency" datatype in VB6 which is 64 bits.

I have included a program that shows how to do this.

-Sal
0 Kudos
Message 2 of 6
(6,763 Views)
DO you know which function is generating the overflow error?
Bilal Durrani
NI
0 Kudos
Message 3 of 6
(6,754 Views)
Yes, it's the following:

DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, 1, -1#, DAQmx_Val_GroupByChannel, writeArray(0), sampsPerChanWritten, ByVal 0&)

==============================================================================
Public Declare Function DAQmxWriteDigitalLines Lib "nicaiu.dll" (ByVal taskHandle As Long, ByVal numSampsPerChan As Long, ByVal autoStart As Long, ByVal timeout As Double, ByVal dataLayout As DAQmxValGroup, ByRef writeArray As Byte, ByRef sampsPerChanWritten As Long, ByVal reserved As Long) As Long
0 Kudos
Message 4 of 6
(6,741 Views)
This seems to be related to some general VB weirdness. It seems that if I step thru the code as it runs, I dont get the overflow, while if I just run the code ( and only the first time), i get this overflow. The culprit seems to be the timeout value. Im not sure why its causing an overflow, but try changing the timeout in the above mentioned function to 10#. Hence a 10 second timeout, instead of infinite. If the data is not written within 10 seconds, something wrong anyway, right?

So the final result will be

DAQmxErrChk DAQmxWriteDigitalLines(taskHandle, 1, 1, 10#, DAQmx_Val_GroupByChannel, writeArray(0), sampsPerChanWritten, 0)

Hope this helps. I'll make sure the example is updated to reflect this.
Bilal Durrani
NI
0 Kudos
Message 5 of 6
(6,727 Views)
I had the same experience with calling the funcion the first time, so I put it
in a loop until the function returned '0', along with a preceeding
On Error Resume Next statement to trap the buffer overflow error.
A workaround at best, your fix is the way to go.
Thanks.
0 Kudos
Message 6 of 6
(6,719 Views)