Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Java Native Access and arrays

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Java Native Access and arrays

    I plan to write an interface for a spectrometer in JAVA. The manufacturer provides a c-dll to access the spectrometer. Therefore I have written a JNA-wrapper.

    I could connect to the spectrometer and access simple methods of the dll. But I have problems to write appropriate functions, if the c-functions accept pointer-to-type arguments to return arrays.

    For example:

    c-header to access calibration data, from rcu1a.h:

    USHORT WINAPI RC_ReadCalibrationValue(
    	HANDLE DeviceHandle,
    	double *DataArray
    	);

    according function in rcu1a.java:

    short RC_ReadCalibrationValue(Pointer DeviceHandle, DoubleByReference DataArray);

    and the code snipplet from Spectrometer.java, the class to access the spectrometer data:

    private rcu1a lib = (rcu1a) Native.loadLibrary("rcu1a", rcu1a.class);
    private DoubleByReference  calibData = new DoubleByReference();
     
    //...
     
     public double [] calibrationData()
        {
     
           lib.RC_ReadCalibrationValue(DeviceHandle, calibData);
            return calibData.getPointer().getDoubleArray(0,6);
        }

    The function should return an array with 6 calibration parameters. Like this I get and array out of bounds exception:

    java.lang.IndexOutOfBoundsException: Bounds exceeds available space : size=8, offset=48
    if I change to calibData.getValue(); I get the value that should be in the first field of the array.

    Am I doing something substantially wrong in handling arrays?

    Thx Richard

  2. The Following User Says Thank You to p0llux For This Useful Post:

    morphtechnologies34a (September 25th, 2012)


Similar Threads

  1. calling native c code from java using JNI
    By ashok_jeev in forum Java Native Interface
    Replies: 3
    Last Post: November 20th, 2012, 05:28 AM
  2. Java web console with Java Native interface
    By rcbandit in forum Java Native Interface
    Replies: 1
    Last Post: August 22nd, 2011, 08:12 AM
  3. specify native library in java command line
    By major in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 14th, 2011, 06:45 AM
  4. Using JNA to access export native classes
    By sattu in forum Java Theory & Questions
    Replies: 1
    Last Post: May 9th, 2011, 04:24 AM
  5. Default Access (package access) confusion
    By gauravrajbehl in forum Java Theory & Questions
    Replies: 1
    Last Post: November 18th, 2009, 04:11 AM