Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Encounter division by zero on call of DAQmxStartTask

I am programming in Borland Builder 5 (C++) for data acquisition with a USB-6009 board.
 
When the DAQmx ANSI C example program, Acq-IntClk, is compiled and run, the program encounters a division by zero error during the DAQmxStartTask(taskHandle) call.  The only change in the code which I made was 'DEV1' to 'QNWDAQ' to match a device name change I had made with the NI 'MAX' utility.
 
I had previously encountered the same problem in an instrument control program I was writing.  I was successfully doing digital output before adding the analog input code.
 
Has this problem been encountered before?  Is there a solution?
0 Kudos
Message 1 of 8
(4,566 Views)
I have not had such an experience. I program DAQmx using VC++.net, using ANSII C++.

Perhaps post the problem code; maybe there's a problem in your code.

I have encountered a crash with NI-DAQmx if I try to add a non-existent analog input channel to a task *if* I have configured a CB-68LP accessory on the DAQ device. (Non-existent channel means, for instance, trying to add channel 32 on a DAQ device with 32 analog input channels.)
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 2 of 8
(4,559 Views)

The code resulting in the divide by zero is listed below.  The line where the divide by zero error occurs is marked by

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 

 

#include <stdio.h>
#include "NIDAQmx.h"

#define DAQmxErrChk(functionCall) { if( DAQmxFailed(error=(functionCall)) ) { goto Error; } }

int main(int argc, char *argv[])
{
 int32       error=0;
 TaskHandle  taskHandle=0;
 int32       read;
 float64     data[1000];
 char        errBuff[2048]={'\0'};

 /*********************************************/
 /*/ DAQmx Configure Code
 /*********************************************/
 DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
 DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"USBDAQ/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
 DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000));

 /*********************************************/
 /*/ DAQmx Start Code
 /*********************************************/
 DAQmxErrChk (DAQmxStartTask(taskHandle));//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

 /*********************************************/
 /*/ DAQmx Read Code
 /*********************************************/
 DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL));

 printf("Acquired %d points\n",read);

Error:
 if( DAQmxFailed(error) )
  DAQmxGetExtendedErrorInfo(errBuff,2048);
 if( taskHandle!=0 )  {
  /*********************************************/
  /*/ DAQmx Stop Code
  /*********************************************/
  DAQmxStopTask(taskHandle);
  DAQmxClearTask(taskHandle);
 }
 if( DAQmxFailed(error) )
  printf("DAQmx Error: %s\n",errBuff);
 printf("End of program, press Enter key to quit\n");
 getchar();
 return 0;
}

 

 

 

0 Kudos
Message 3 of 8
(4,555 Views)
Looks like pretty standard code. But then I've overlooked pretty obvious bugs in my own code 🙂 The only possible thing I see might be:

DAQmxCfgSampClkTiming(taskHandle,"",

The documentation for DAQmxCfgSampClkTiming says to pass NULL or "OnboardClock" for the source. Try replacing "" with NULL.

Other than that, I'm not sure Borland is a supported development environment. Any possibility you could try it on VC?

Added later:
It just occurred to me that divide by zero in my code doesn't cause a problem. I think you have to do something special to catch the divide-by-zero signal, so it's possible that the driver has some sort of asymptomatic bug that causes a benign divide by zero that doesn't cause a problem with VC++. Maybe you could look for a way in Borland to turn off the divide-by-zero notification.

Message Edited by WM John Weeks on 09-16-2005 09:37 AM

John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 4 of 8
(4,552 Views)
I have the same problem in Borland Delphi 2005. I wrote a DLL to wrap the c-library. But when I use the DLL in Delphi the program throws a "divide by zero" exception.
Is there a new version of the lib or any other resolution for this problem?
0 Kudos
Message 5 of 8
(4,421 Views)
Whether to throw an exception on divide-by-zero is often a compiler option. Can you find such an option (perhaps set through a #pragma?) to get around it?

Naturally, it would be nice of NI could get rid of the divide by zero, but in the meantime I bet that would solve the problem.
John Weeks

WaveMetrics, Inc.
Phone (503) 620-3001
Fax (503) 620-6754
www.wavemetrics.com
0 Kudos
Message 6 of 8
(4,402 Views)

Hi Pallaeon,

DAQmx with Borland Delphi is not officially supported. However, I found a knowledgebase with information that should help you with the "divide by zero" exception: Can I Make NI-DAQmx Calls From Borland Delphi?

LouisJL: I think that John Weeks has provided a viable workaround to the problem. You can also try upgrading to a newer version of the DAQmx driver and running some shipping examples to see if you still receive the error.

Regards,
Hal L.

0 Kudos
Message 7 of 8
(4,391 Views)
Thanks for the link.
I found no compiler option to deactivate this exception but  it's possible with the order "Set8087CW($133f);" to change the behavior of Delphi.

For all Delphi users: put this function into the create-methode (needs unit system) and the wrapper dll works fine. Smiley Happy
0 Kudos
Message 8 of 8
(4,382 Views)