Advice needed after an attempt to create a Java (JNA) wrapper of ArduCamLib.dll

Published by muth on

Home Forums Arducam USB Camera Shields Advice needed after an attempt to create a Java (JNA) wrapper of ArduCamLib.dll

Viewing 12 reply threads
  • Author
    • #13190

      Hi ArduCam team,

      First of all, thanks a lot for your work here on the USB shields. Some context : I have a USB2 shield (UC-391 rev.D), working like a charm with the USB test GUI on windows. I’m using it with the AR0134 sensor for its good the sensitivity. My hope is to have a live stacking program for astro photos.

      I’m quite use to Java, so before switching to unknown territories with python or C++, I’m trying to access the ArduCamLib with JNA. Which seems to work:

      I can scan and autoopen the device, I can write to sensor register and re-read them correctly. This by using the functions defined in ArduCamLib.h

      If I understood correctly the C and python code, I proceed as the following :

      – ArduCam_autoopen
      – ArduCam_getUsbType (get dev 2 and inf 2)
      – ArduCam_setboardConfig (according the cfg file entries, 6 settings on 0xD7 and one array[3] on 0xF6)
      – ArduCam_writeReg_16_16 (according the cfg file entries)(16bit as it is the AR0134)
      – ArduCam_setMode (continuous, 0x02)

      Then I create 2 threads.

      Capture thread with:
      – ArduCam_beginCaptureImage (once)
      – ArduCam_captureImage (repeatedly)
      – ArduCam_endCaptureImage (to end)

      Reading thread with:
      – ArduCam_availableImage
      – ArduCam_readImage (if available image is >0)

      It goes all through with no error coming on the return of the ArduCam functions. I can even read correctly the sensor register I set with Java, on the USBtest program.

      However, I always get zero on ArduCam_availableImage, and the ArduCam_captureImage function returns 0xFF26, which means USB_CAMERA_USB_TIMEOUT_ERROR according common.h.

      Here is the code I wrote so far. It’s really draft and settings are static.

      Do you think I should pursue on this direction ? I would love to use the camera with Java, but there is maybe an obstacle I ignore.

      Thanks for reading.


    • #13214
      Lee Jackson


      Thanks for your interests in our camera, our engineer will investigate your problem and get back to you soon. please be patient.

    • #13216

      Thanks a lot!

      I’ve added the output of my draft program on the repository (

      If we manage to have a Java access, I hope it can serve you as well. I’ll try to make a Jar as close as possible to your SDK libs, and examples using the same configuration files.

      Thanks again for your fast reply.

    • #13238

      Hi @muth

      You are very close to success, I made a little modification to

      line 65:

      – pu8Buf1.setByte(0, (byte) 0x85);
      + pu8Buf1.setByte(0, (byte) 0x05);

      line 108:

      – answer += arduCamSDKlib.ArduCam_writeReg_16_16(useHandle.getValue(), i2cAddr, 0x3012, 0xDEAD);
      + answer += arduCamSDKlib.ArduCam_writeReg_16_16(useHandle.getValue(), i2cAddr, 0x3012, 0x0200);

      line 192:

      – System.out.println(new Date().getTime()+” CaptureImageThread: ArduCam_captureImage returned: “+Utils.intToHex(answer));
      + /*System.out.println(new Date().getTime()+” CaptureImageThread: ArduCam_captureImage returned: “+Utils.intToHex(answer));^M

      try {
      } catch (InterruptedException e) {
      – }
      + }*/


      The complete file is as follows:


    • #13291

      Oh wow, this is it! Thanks a lot really !
      My mistakes were :
      Line 65: Confusing with the 12 bits and 8 bits configuration files (0x85 -> 0x05)
      Line 108: Register 0x3012 is the integration time, it was too large
      Line 192: And of course I should NOT have put a sleep() on the CaptureImage thread ! (I was worried about saturating a thread).

      I will now work on correctly use ArduCam_readImage() and not just dump the bytes.
      Thank you very much for your efficient support! I will update with my progress.
      Have a very nice day!

    • #13298

      Hi @muth
      What you are doing is great, can you submit it to the ArduCAM_USB_Camera_Shield repository when you are done?

    • #13408

      Sure, I would be glad to.
      For the moment I should spend a bit of time to better understand the pointer/reference of structures on the JNA side. I can somehow see image data, but I’m making a mistake with ArduCamOutData* &pstFrameData.
      But I’m close, and looking forward to write a proper example:

    • #13409

      Sorry if I’m a bit too enthusiastic, but I found my mistake and got nice images:
      I used a wrong type, so it shifted the value of the image byte array pointer value, thus the incoherent data.
      I’m now more confident to continue with config files and raw to color conversion.

    • #13507

      No, this is fine, I’m just a bit busy and can’t reply to you in time. I’m glad you solved the problem, and sorry again I can’t reply to you in time.

      • This reply was modified 1 year ago by wong.
      • This reply was modified 1 year ago by wong.
    • #13540

      Oh, my post was not against you, I knew I did a mistake somewhere. I was very happy to get images and could not resist to share it here 😉
      You yet helped me a lot, and in only few a days! I’m really thankful !
      I will try to make progress on a proper example. Have a nice day!

    • #26074

      Sorry for  missing your post. Have you made any progress?

    • #26591


      I must admit it’s been few months I didn’t worked on the code. I made some nice progress, bellow is the status.

      The main problem I have is to include the .dll files into an executable Jar, in order to have an easy demo program.


      I run everything from Eclipse.

      – I have the program ( which allows you to load the CFG file and launch the capture. It displays continuously the camera output, and can naively ‘decode’ the raw to color.

      –  Then I have a couple of test programs to use open CV for the decoding and processing. But a lot of hard coded values specific to the AR0134. (

      I paused the work on it, but not gave up. I was trying to use the AR0134 sensor for astro-photography due to his high pixel sensitivity. I mounted the board on an adapter to use Canon EF prime lens, everything mounted on an equatorial motorized mount. As the aim is to make picture stacking, I then realize how bad my cheap mount is when I tried to integrate pictures for more than 5 minutes. So I need a better hardware setup, however the camera board works like a charm. If I put the integration time to the maximum (around 2 seconds if I remember correctly), I can display in real time the Andromeda galaxy.


    • #26596

      Bellow is my setup, and I will try to capture the program output.

Viewing 12 reply threads
  • You must be logged in to reply to this topic.