Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read out the parameter reference &pointsRead of the function DAQmxBaseReadAnalogF64() via JNI in Java using read out data array as return value

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

 

 

 

 

0 Kudos
Message 1 of 1
(3,241 Views)