Discussion:
[gphoto-devel] gp_camera_wait_for_event and JNA - no data returned
unclebob
2016-04-19 07:16:27 UTC
Permalink
I'm attempting to write a tether in Java, but while the new file event is
triggered correctly, I can't seem to get any data back from it, neither the
eventtype nor the eventdata.

Here's what my JNA binding looks like:

int gp_camera_wait_for_event(Camera camera, int timeout, IntBuffer
eventtype, PointerByReference eventdata, Gphoto2Library.GPContext context);

The code using it looks as follows:

PointerByReference eventdata = new PointerByReference();
IntBuffer eventtype = IntBuffer.allocate(1);

int result = gphoto2.gp_camera_wait_for_event(camera, 1000000000,
eventtype, eventdata, context); //result is always 0, OK
int test = eventtype.get(); //just testing what I got back. test is
always 0, with which it was initialised

CameraFilePath filepath = new CameraFilePath(eventdata.getValue());
//filepath never contains anything


And for completeness, the CameraFilePath Structure (which works without a
hitch when used with gp_camera_capture):


public class CameraFilePath extends Structure
{
/**
* < \brief Name of the captured file.<br>
* C type : char[128]
*/
public byte[] name = new byte[128];
/**
* < \brief Name of the folder of the captured file.<br>
* C type : char[1024]
*/
public byte[] folder = new byte[1024];

public CameraFilePath()
{
super();
}

@Override
protected List getFieldOrder()
{
return Arrays.asList(new String[]{"name", "folder"});
};

/**
* @param name < \brief Name of the captured file.<br>
* C type : char[128]<br>
* @param folder < \brief Name of the folder of the captured file.<br>
* C type : char[1024]
*/
public CameraFilePath(byte name[], byte folder[]) {
super();
if (name.length != this.name.length)
throw new IllegalArgumentException("Wrong array size !");
this.name = name;
if (folder.length != this.folder.length)
throw new IllegalArgumentException("Wrong array size !");
this.folder = folder;
}

public CameraFilePath(Pointer pointer)
{
super(pointer);
}

public static class ByReference extends CameraFilePath implements
Structure.ByReference {

};
public static class ByValue extends CameraFilePath implements
Structure.ByValue {

};
}


I'm still somwhat clumsy in JNA, but for all I know, this should work... ?

Test Camera is Nikon D5300, just in case that might have an influence.





--
View this message in context: http://gphoto-software.10949.n7.nabble.com/gp-camera-wait-for-event-and-JNA-no-data-returned-tp16144.html
Sent from the gphoto-devel mailing list archive at Nabble.com.
Marcus Meissner
2016-04-23 18:15:37 UTC
Permalink
Post by unclebob
I'm attempting to write a tether in Java, but while the new file event is
triggered correctly, I can't seem to get any data back from it, neither the
eventtype nor the eventdata.
int gp_camera_wait_for_event(Camera camera, int timeout, IntBuffer
eventtype, PointerByReference eventdata, Gphoto2Library.GPContext context);
PointerByReference eventdata = new PointerByReference();
IntBuffer eventtype = IntBuffer.allocate(1);
I would try to use com.sun.jna.ptr.IntByReference for eventtype.
Post by unclebob
int result = gphoto2.gp_camera_wait_for_event(camera, 1000000000,
eventtype, eventdata, context); //result is always 0, OK
int test = eventtype.get(); //just testing what I got back. test is
always 0, with which it was initialised
CameraFilePath filepath = new CameraFilePath(eventdata.getValue());
//filepath never contains anything
Can you print out eventdata.getValue() ... Here i think the data converter in
the Structure constructor might not work.

Ciao, MArcus
Post by unclebob
And for completeness, the CameraFilePath Structure (which works without a
public class CameraFilePath extends Structure
{
/**
* < \brief Name of the captured file.<br>
* C type : char[128]
*/
public byte[] name = new byte[128];
/**
* < \brief Name of the folder of the captured file.<br>
* C type : char[1024]
*/
public byte[] folder = new byte[1024];
public CameraFilePath()
{
super();
}
@Override
protected List getFieldOrder()
{
return Arrays.asList(new String[]{"name", "folder"});
};
/**
* C type : char[128]<br>
* C type : char[1024]
*/
public CameraFilePath(byte name[], byte folder[]) {
super();
if (name.length != this.name.length)
throw new IllegalArgumentException("Wrong array size !");
this.name = name;
if (folder.length != this.folder.length)
throw new IllegalArgumentException("Wrong array size !");
this.folder = folder;
}
public CameraFilePath(Pointer pointer)
{
super(pointer);
}
public static class ByReference extends CameraFilePath implements
Structure.ByReference {
};
public static class ByValue extends CameraFilePath implements
Structure.ByValue {
};
}
I'm still somwhat clumsy in JNA, but for all I know, this should work... ?
Test Camera is Nikon D5300, just in case that might have an influence.
--
View this message in context: http://gphoto-software.10949.n7.nabble.com/gp-camera-wait-for-event-and-JNA-no-data-returned-tp16144.html
Sent from the gphoto-devel mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Gphoto-devel mailing list
https://lists.sourceforge.net/lists/listinfo/gphoto-devel
unclebob
2016-04-25 06:18:19 UTC
Permalink
First let me note that I did solve the problem differently, I wrote a tether
that just checks the file system of the camera for new files at an interval
and downloads them. So I'm not actively solving this problem anymore, but I
did the tests you suggested and post the results here in case it is helpful
for gphoto development.

JNAerator actually produced a method overload of gp_camera_wait_for_event
using IntByReference, but marked it as deprecated.
I can now confirm both ways as working. After initialising the eventtype to
-1, I could confirm that it does indeed change. A timeout event is also
correctly returned as 1.

I can also confirm that the eventdata pointer has indeed been initialised
(it's not null anymore after the call).

The essential problem then seems that I get a GP_EVENT_UNKNOWN back when
pressing the trigger on the camera (eventdata == 0), while I would have been
expecting a GP_EVENT_FILE_ADDED.
This would of course also explain why I was unable to use eventdata to
initialise a CameraFilePath with the received eventdata pointer: If it's not
a GP_EVENT_FILE_ADDED, I'm not getting the data back I thought I should be
getting.

So I assumed that there might be other events triggered in case of a camera
trigger, events that might not be implemented. So I did the following:

do
{
int result = gphoto2.gp_camera_wait_for_event(camera, 1000000,
eventtype, eventdata, context);

System.out.println(eventtype.getValue());
System.out.println(eventdata.getValue().toString());
}
while (eventtype.getValue() == 0);

And sure enough, the GP_EVENT_FILE_ADDED got passed after 7 unknown events
in short order... So basically everything is working properly, but the
documentation could be improved a little (some sort of hint that the
function will return the next event occuring, and that it's very probable
that this will be an as of yet unimplented event. I know it's logical
behaviour after you mull it over some, but it's not /intuitive/).
Or it might be good to change the gp_camera_wait_for_event function in a way
that you can subscribe to a specific event by passing a valid event type
(That's how I interpreted the method right at the beginning before reading
the documentation very carefully).



--
View this message in context: http://gphoto-software.10949.n7.nabble.com/gp-camera-wait-for-event-and-JNA-no-data-returned-tp16144p16161.html
Sent from the gphoto-devel mailing list archive at Nabble.com.

Loading...