Skip to Main Content

JNI and call by reference

860915May 10 2011 — edited May 11 2011
Hello,

In my Java - code I have to use native C - code. The native C - function I use has got the reference parameter “read”.

DAQmxBaseReadAnalogF64(...,&read,...);

I do need the information the reference points on on the java layer.

How do I pass the reference via JNI to Java – code?

I am already returning data.

Here is my code:

JNIEXPORT jfloatArray JNICALL Java_JavaWrapper_readAnalog(JNIEnv *env, jobject obj, jfloat timeout, jint arraySizeInSamps)
{

int32 read;
float64 dataArray[1000]; //Größe sollte ausreichen!

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;
}
env->ReleaseFloatArrayElements(ret,returnArray,0);

return ret;

}

Edited by: 857912 on 10.05.2011 12:59
Comments
Post Details
Added on May 10 2011
2 comments
473 views