

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
5 messages in net.java.dev.jna.usersRe: [jna-users] Contiguous Structure ...| From | Sent On | Attachments |
|---|---|---|
| Thinner | Dec 12, 2008 1:11 pm | |
| Timothy Wall | Dec 12, 2008 4:22 pm | |
| Thinner | Dec 12, 2008 5:30 pm | |
| Timothy Wall | Dec 12, 2008 6:45 pm | |
| Thinner | Dec 13, 2008 2:45 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Contiguous Structure array | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Dec 12, 2008 4:22:54 pm | |
| List: | net.java.dev.jna.users | |
On Dec 12, 2008, at 4:11 PM, Thinner wrote:
Hello.
I'm trying to connect a fingerprint device to a Java app using libfprint (http://reactivated.net/fprint/). I've come a long way but have now hit a roadblock. I'm new to JNA, so please excuse any obvious errors.
I have a C function, enroll(), that returns the fingerprint data as a struct fp_print_data to my Java app that stores this data in a fp_print_data object, this object is then stored for later identification. Function, struct and object definitions are listed below. This part works fine, I think :)
Now I want to take this stored print and compare this to a freshly scanned print. This is done by sending an array of fp_print_data Structures to a C function called identify(). identify() then returns the index of the print in the array that matched the freshly scanned print. The problem is that I get a segmentation fault. If I pass empty fp_print_data objects to the function I don't get the seg fault so I guess I have a problem with my fp_print_data Structure. It also works fine if I leave out the Java app all together and let a C program do all the work. My guess is that the array of Structures I send to idenfity() is not allocated correctly. I'd appreciate any help I can get :)
C: struct fp_print_data { uint16_t driver_id; uint32_t devtype; enum fp_print_data_type type; size_t length; unsigned char data[0]; };
struct fp_print_data* enroll (void){ // print_data is a globally defined struct fp_print_data* fp_enroll_finger(sel_dev, &print_data); }
size_t* identify(struct fp_print_data **print_gallery, int prints){ size_t *match_offset = -1; int result = -1; print_gallery[prints] = NULL; // The list must be NULL terminated fp_identify_finger(sel_dev, print_gallery, &match_offset); return match_offset; }
Java: public class fp_print_data extends Structure {
public static class ByReference extends fp_print_data implements Structure.ByReference { }
public int driver_id; public int devtype; public int type; public int length; public IntByReference data; }
driver_id is probably 16 bits, not 32. data is an inline array of bytes, so you'll have to initialize it yourself. you can default to byte[4]. If you don't have to read/ write the data, then you don't have to do anything further.
The function is expecting an array of pointer to struct, not an array of struct, so you'll need to pass an array of Structure.ByReference.
public static void main(String[] args){ fp_print_data enrolledPrint = myLibrary.INSTANCE.enroll(); // The array must be NULL-terminated, thus I need to allocate one extra element Structure[] printGallery = enrolledPrint.toArray(2); myLibrary.INSTNCE.identify(printGallery, printGallery.length-1); }
-- There is no knife either







