04-19-2013 03:49 PM
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.
Solved! Go to Solution.
04-22-2013 01:34 PM
FWIW, I'm using an PCI-6259 connected to an SCB-68.
04-22-2013 02:59 PM
Do you receive any type of error message or code when this occurs?
04-23-2013 04:39 PM
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?
04-24-2013 04:49 PM
Specifically what error are you getting, and does it give you a code?
04-24-2013 04:57 PM
You may need to read more samples from your device. It sounds like you could possibly have a buffer overflow.
04-25-2013 12:23 PM
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.
04-26-2013 03:50 PM - edited 04-26-2013 03:50 PM
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.
04-29-2013 04:34 PM
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.