Hi,
I want to implement continuous reading in Java using the Java Native Interface.
In the NI-DAQmx Base Documentation I found the C example "contAcquireNChan.c". In this example the parameter reference &pointsRead of ReadAnalogF64 is read out to count the total points read.
while( time(NULL)<startTime+10) {
DAQmxErrChk(DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByScanNumber,data,bufferSize*2,&pointsRead,NULL));
totalRead += pointsRead;
printf("Acquired %d samples. Total %d\n",pointsRead,totalRead);
// Just print out the first 10 points of the last data read
for (i = 0; i < 10; ++i)
printf ("data0[%d] = %f\tdata1[%d] = %f\n",i,data[2*i],i,data[2*i+1]);
} //Ende while
The native function is implemented in C. In the following function the read out data is returned via array. How can I pass the parameter reference &pointsRead to the Java layer.
JNIEXPORT jfloatArray JNICALL Java_JavaWrapper_readAnalog(JNIEnv *env, jobject obj, jfloat timeout, jint arraySizeInSamps)
{
int32 read;
float64 dataArray[1000];
DAQmxBaseReadAnalogF64(taskHandle, arraySizeInSamps, timeout, DAQmx_Val_GroupByScanNumber,dataArray,arraySizeInSamps*2,&read,NULL);
int i=0;
jfloatArray ret = env->NewFloatArray(1000);
jfloat* returnArray = env->GetFloatArrayElements(ret,NULL);
for(i=0;i<1000;i++){
returnArray[i] = dataArray[i];
}
env->ReleaseFloatArrayElements(ret,returnArray,0);
return ret;
}
Kind Regards,
Bernd