Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Simultaneous Digital Write and Read w. Interval Measurement

Solved!
Go to solution

Hi all,

For the past couple days, I've been wracking my brain trying to get a program to work.

 

I'm trying to generate a 4-bit digital output while simulatanously counting the rising edges on its LSB up to an arbitary number set by the program's operator, at which point, the program would make a measurement.

 

I'm noticing, though, that, over a certain rising edge count number (~950 or so), the program crashes. The problem persists even when I remove the function that reads the LSB, although, in that case, the crashes occur at a much higher number. What might cause this? Is there any way I can work around this problem?

 

Below is my code:

 

arraySizeInBytes2 = 8
bufferSize = 255

ReDim readArray(arraySizeInBytes2)


publicLifetime = 100 ' use this to control the length of time the task takes
numSamplesToWrite = 10 * publicLifetime * numSample * 5
numSamplesInArray = 5 * 10 * numSample

'code that defines the digital and analog output signals

j = 0
  k = -1
    Do While j < numSamplesInArray
        If j Mod SampPerCycle = 0 Then k = k + 1 Else k = k  
        For m = 0 To 3
        If ((k) And (2 ^ m)) = (2 ^ m) Then writeArray(m, j) = 1 Else: writeArray(m, j) = 0 
        Next m
        j = j + 1
        Loop

    publicStatus = DAQmxCreateTask("", taskHandleDigitalOut)
    publicStatus = DAQmxCreateTask("", taskHandleAnalog)
    publicStatus = DAQmxCreateTask("", taskHandleDigitalIn)
    taskIsRunning = True
    
     publicStatus = DAQmxCreateDOChan(taskHandleDigitalOut, "Dev2/port0/line0:3", "", DAQmx_Val_ChanForAllLines)
     publicStatus = DAQmxCfgSampClkTiming(taskHandleDigitalOut, "Ctr0InternalOutput", 1000000#, DAQmx_Val_Falling, DAQmx_Val_AcquisitionType_FiniteSamps, numSamplesToWrite)
     publicStatus = DAQmxCreateAOVoltageChan(taskHandleAnalog, "dev2/ao0", "", -10, 10, DAQmx_Val_VoltageUnits2_Volts, "")
     publicStatus = DAQmxCfgSampClkTiming(taskHandleAnalog, "Ctr0InternalOutput", 1000000#, DAQmx_Val_Falling, DAQmx_Val_AcquisitionType_FiniteSamps, numSamplesToWrite)
     publicStatus = DAQmxCreateDIChan(taskHandleDigitalIn, "dev2/port0/line7", "", DAQmx_Val_ChanPerLine)
     publicStatus = DAQmxCfgChangeDetectionTiming(taskHandleDigitalIn, "dev2/port0/line7", "", DAQmx_Val_AcquisitionType_ContSamps, 8)
     publicStatus = DAQmxWriteBinaryI16(taskHandleAnalog, DACwaveFormSize, False, -1, DAQmx_Val_GroupByScanNumber, buffer(0), sampsPerChanWritten, ByVal 0&)
     publicStatus = DAQmxWriteDigitalLines(taskHandleDigitalOut, numSamplesInArray, False, -1, DAQmx_Val_GroupByScanNumber, writeArray(0, 0), sampsPerChanWritten, ByVal 0&)
         
     publicStatus = DAQmxStartTask(taskHandleDigitalIn)
     publicStatus = DAQmxStartTask(taskHandleAnalog)
     publicStatus = DAQmxStartTask(taskHandleDigitalOut)
     publicStatus = DAQmxStartTask(publicCounterHandle)

r = 0
Do While r < (publicLifetime * numSample)
publicStatus = DAQmxReadDigitalLines(taskHandle, 1, 5, DAQmx_Val_GroupByScanNumber, readArray(0), arraySizeInBytes2, SampsPerChanRead, numBytesPerSamp, ByVal 0&)
If publicStatus = 0 Then r = r + 1
If r Mod publicMeasurementInterval= 0 Then 'Measurement Code here
Loop

publicStatus = DAQmxStopTask(taskHandleDigitalIn)

 publicStatus = DAQmxWaitUntilTaskDone(taskHandleDigitalOut, -1)
 publicStatus = DAQmxClearTask(taskHandleDigitalOut)
 publicStatus = DAQmxStopTask(taskHandleAnalog)
 publicStatus = DAQmxClearTask(taskHandleAnalog)
 publicStatus = DAQmxStopTask(publicCounterHandle)
 publicStatus = DAQmxStopTask(taskHandleDigitalIn)
 publicStatus = DAQmxClearTask(taskHandleDigitalIn)   
 taskIsRunning = False

   

 

 

Thank you.

0 Kudos
Message 1 of 9
(8,397 Views)

FWIW, I'm using an PCI-6259 connected to an SCB-68.

0 Kudos
Message 2 of 9
(8,378 Views)

Do you receive any type of error message or code when this occurs?

Applications Engineer
National Instruments
0 Kudos
Message 3 of 9
(8,372 Views)

Just an overflow error.

 

For what it's worth, I've been able to get the maximum number of cycles up to 2047 by changing the line

 

publicStatus = DAQmxCfgChangeDetectionTiming(taskHandleDigitalIn, "dev2/port0/line7", "", DAQmx_Val_AcquisitionType_ContSamps, 8)

 

 

to

 

publicStatus = DAQmxCfgChangeDetectionTiming(taskHandleDigitalIn, "dev2/port0/line7", "", DAQmx_Val_AcquisitionType_FiniteSamps, publicLifetime * numSample)

 

 

What do you think that might mean?

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

Specifically what error are you getting, and does it give you a code?

Applications Engineer
National Instruments
Message 5 of 9
(8,350 Views)

You may need to read more samples from your device. It sounds like you could possibly have a buffer overflow.

Applications Engineer
National Instruments
Message 6 of 9
(8,347 Views)

I get the 6 error. I'm currently trying to expand the read array size. I'll let you know how that goes.

 

Thank you for your help, by the way.

0 Kudos
Message 7 of 9
(8,339 Views)

Still having difficulty. I tried increasing the buffer size (which I'm presuming is for the DAQmxReadDigitalLines command) but to no avail. For what it's worth, I used the error line feature of VB and found that the program crashes on the line

 

"If publicStatus = 0 Then r = r + 1" 

 

I can get the program to write however many samples I want. The problem is entirely within that read loop.

0 Kudos
Message 8 of 9
(8,330 Views)
Solution
Accepted by topic author Armando83

You were right: it was a buffer overflow. I was using integer numbers when I should have been using doubles.

 

Thank you for your help.

Message 9 of 9
(8,319 Views)