01-12-2007 05:11 AM - edited 01-12-2007 05:11 AM
Dear friends since I had problems using NI API’s in Borland
C++ Bulder I had to write a DLL in VC++ and then call it in Borland C++
builder.
Although it is working I’m only able to read 1 value at a time I want to read the values continuously.I don’t know weather I’m doing something wrong .
Name of the DLL is ni.dll and the function used is getdata() my device is USB-6009 I’m trying to read the analog inputs continuously.
Below is the attachment containing the source code of both the DLL and the Borland Program.Can somebody Please help me.
Message Edited by perk_bud on 01-12-2007 04:14 PM
Message Edited by perk_bud on 01-12-2007 04:16 PM
01-12-2007 10:12 PM - edited 01-12-2007 10:12 PM
DLL source -------->
#include <stdAfx.h>
#include <NIDAQmx.h>
#include <stdio.h>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
float64 getdata(void)
{
int32 error=0,taskisrunning=1;
TaskHandle taskHandle=0;
char errBuff[2048]={'\0'};
static int totalRead=0;
int32 read=0;
float64 data[1000];
/*********************************************/
// DAQmx Configure Code
/*********************************************/
DAQmxCreateTask("",&taskHandle);
DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000);
/*********************************************/
// DAQmx Start Code
/*********************************************/
DAQmxStartTask(taskHandle);
printf("Acquiring samples continuously. Press Enter to interrupt\n");
DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL);return data[0];
fflush(stdout);
}
Message Edited by perk_bud on 01-13-2007 09:13 AM
01-12-2007 10:14 PM - edited 01-12-2007 10:14 PM
Borland Source----------->
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "stdio.h"
#pragma package(smart_init)#pragma resource "*.dfm"
#define add_dll "ni.dll"
typedef float(CALLBACK* GETDATA)();
GETDATA getdata;
Tcancel *cancel;
HINSTANCE dll=NULL;
__fastcall Tcancel::Tcancel(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall Tcancel::Button2Click(TObject *Sender)
{
Close();
}
void __fastcall Tcancel::addClick(TObject *Sender)
{
dll = LoadLibrary(add_dll);
if(dll==NULL)
{
char msg[255]={0};
sprintf(msg,"The library : %s could not be loaded. Please make sure this file is in the C:\\windows\\system32\\ folder or in the forder this program is being run from.",add_dll);
MessageBox(NULL,msg,"ERROR",MB_OK | MB_ICONERROR);
Application->Terminate();
}
getdata=(GETDATA)GetProcAddress(dll,"getdata");
float c;
while(1)
{
c=getdata();
data->Text=FloatToStr(c);
}
}
Message Edited by perk_bud on 01-13-2007 09:14 AM
01-12-2007 10:15 PM
01-13-2007 01:45 AM
01-13-2007 04:59 AM
01-13-2007 06:14 AM
01-15-2007 02:27 PM
01-15-2007
02:36 PM
- last edited on
11-22-2025
05:13 PM
by
Content Cleaner
Hi perk_bud,
The error you are receiving is due to an overflow of the circular buffer of the device, and it is caused because data cannot be transferred fast enough from the device to PC memory. A couple of options to try and overcome this overflow error are to increase the buffer size as you already attempted and also to decrease the sample rate. When the error specifies "reading the data more frequently" this means reading the data already sampled into the buffer. Increasing the sample rate actually speeds up the process of causing the buffer to overflow. If there is any timing in your application that delays transfer of data from the device buffer to PC memory, this should be reduced as well.
There is a KnowledgeBase article here that addresses the -200279 error. This KB is speaking in terms of LabVIEW, but the equivalent C call would be DAQmxGetReadAvailSampPerChan. Information about this property can be found in the NI-DAQmx C Reference Help.
Regards,
Andrew W
National Instruments
01-16-2007 12:26 AM - edited 01-16-2007 12:26 AM
Message Edited by perk_bud on 01-16-2007 11:30 AM