Callbacks not working

Issues dealing with Java interfacing to Canon SDK

Callbacks not working

Postby mattp » Mon Oct 12, 2009 7:59 pm



I've written a Java wrapper (JNA + JNAerator) that works beautifully except for the callbacks. From what I gather from other posts, Canon's documentation for callbacks sucks. I've tried a few different things with threads but nothing seems to work. Usually my callbacks are never called. Very rarely, one will be called and then the JVM crashes. Has anybody had any success with callbacks and Java?


mattp
Canon SDK Professional
 
Posts: 22
Joined: Thu Oct 08, 2009 7:08 pm

Re: Callbacks not working

Postby clem » Fri Oct 23, 2009 8:02 pm

Hi!
Happy to see that i'm not the only one on JNA/JAVA.
I'm beginning in PSREC . I succeed to take a picture but I have some problems to retrieve the picture data.
I created the callback function (myGetFileDataCB) and registered it with PR_RC_GetReleasedData
Code: Select all
returnedMessage = library.PR_RC_GetReleasedData(cameraHandle, 0, JNAPsrec.prPTP_FULL_VIEW_RELEASED, 1024*1024, 0, myGetFileDataCB);


But I have an odd error code : 3145815
In hexa it is 300057 .
If I have correctly understood , it is a problem of WIA and the error code is 0057 but I didn't find what it means...
clem
 
Posts: 1
Joined: Fri Oct 23, 2009 7:52 pm

Re: Callbacks not working

Postby bmmoody » Sun Oct 25, 2009 10:52 pm

Hey matt - if you poke around on this forum, you'll find that the callback mechanism is implemented as a windows message. As a result you have to run a windows message pump in order for callbacks to work.
bmmoody
Site Admin
 
Posts: 21
Joined: Mon Mar 31, 2008 9:03 pm

Re: Callbacks not working

Postby mattp » Tue Nov 03, 2009 4:01 pm

I haven't yet attempted to implement a windows message pump in Java (via JNA). If anybody has, would you mind posting some code or pointing us Java guys in the correct direction?

I haven't looked into it thoroughly but does anybody know how callbacks work under the Mac version of the SDK? Maybe I'm naive but wouldn't it be nice if Canon actually implemented both versions as stated in the documentation (that being a new thread per callback)?
mattp
Canon SDK Professional
 
Posts: 22
Joined: Thu Oct 08, 2009 7:08 pm

Re: Callbacks not working

Postby mattp » Wed May 05, 2010 8:00 pm

Just a little update for those of you wanting to communicate with Canon cameras via Java. I ended up scrapping my JNA work. I built a C application that is basically a command line app that my Java programs pass parameters to and get data back from. I've implemented live view, image capturing, reading/writing settings, etc. It ended up being much easier and straight forward to write in C. If you can do it with JNI or JNA then more power to you.
mattp
Canon SDK Professional
 
Posts: 22
Joined: Thu Oct 08, 2009 7:08 pm

Re: Callbacks not working

Postby kritzikratzi » Tue Jul 27, 2010 10:46 pm

Hey all!

I have no idea how it would work on mac, but on windows it looks like i'm getting it to work with this command:

Code: Select all
   public static void dispatchMessages() {
      // This bit never returns from GetMessage

      int result;
      MSG msg = new MSG();
      final User32 lib = User32.INSTANCE;
      HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);

      while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {

         if (result == -1) {
            System.err.println("error in get message");
            break;
         }

         else {
            lib.TranslateMessage(msg);
            lib.DispatchMessage(msg);
         }
      }

   }



At the end of my code, just after connecting to the camera and opening the session, i just call dispatchEvent() which will obviously run forever.

This code is just copied from the jna list:
http://www.java-forum.org/647697-post14.html#_


Hopefully i'll soon be able to post more on this, but i'm confident.
kritzikratzi
 
Posts: 1
Joined: Tue Jul 27, 2010 10:42 pm


Return to Canon SDK in Java

Who is online

Users browsing this forum: No registered users and 2 guests