I am building a Java application that communicates with a particular manufacturer's API using JNA. I have a ton of function calls mapped and already working, but there are a pair of functions that have been giving me some grief.
Both of these functions pass a data structure back and forth to configure the device. This structure has a nested array of data structures within it. The functions are declared in the native header like so:
VISION_API_DECL BOOL VISION_API SetDeviceParameters( DWORD DeviceID, DeviceParameters DeviceParam );
VISION_API_DECL BOOL VISION_API GetDeviceParameters( DWORD DeviceID, DeviceParameters *DeviceParam );
These function calls seem to work. JNA does not throw an exception when I call either of those functions. When I call the GetDeviceParameters
method and print out the struct, I see most of it filled with data from what I would assume is the device's default configuration. However, when I call the SetDeviceParameters
method using the same data just returned from the get call, the device returns an error saying the parameters are wrong.
How do I know if I have mapped the structure correctly?
Native:
typedef struct _DeviceParameters
{
BOOL bMICREnable;
UINT nMICRFont;
BOOL bMICRSaveSamples;
UINT nMICRSpaces;
char cRejectSymbol;
UINT nReserved;
BOOL bReserved;
IMAGE_PROPERTIES ImagePropertiesFront1;
IMAGE_PROPERTIES ImagePropertiesFront2;
IMAGE_PROPERTIES ImagePropertiesRear1;
IMAGE_PROPERTIES ImagePropertiesRear2;
SNIPPET_PROPERTIES SnippetProperties[10];
BOOL bPrintEnable;
BOOL bOneDoc;
UINT nFeedingMode;
} DeviceParameters;
typedef struct _SnippetProperties
{
BOOL Enable;
BOOL Front;
Snippet Properties;
} SNIPPET_PROPERTIES;
typedef struct _Snippet
{
UINT Xposition;
UINT Yposition;
UINT Width;
UINT Height;
UINT Orientation;
UINT Color;
UINT Compression;
BOOL Millimeters;
} Snippet;
typedef struct _ImageProperties
{
UINT Format;
UINT Paging;
UINT Resolution;
UINT ColorDepth;
UINT Threshold;
} IMAGE_PROPERTIES;
Java:
public class DEVICE_PARAMETERS extends Structure {
public boolean bMICREnable;
public int nMICRFont;
public boolean bMICRSaveSamples;
public int nMICRSpaces;
public byte cRejectSymbol;
public int nReserved;
public boolean bReserved;
public IMAGE_PROPERTIES ImagePropertiesFront1;
public IMAGE_PROPERTIES ImagePropertiesFront2;
public IMAGE_PROPERTIES ImagePropertiesRear1;
public IMAGE_PROPERTIES ImagePropertiesRear2;
public SNIPPET_PROPERTIES[] SnippetProperties = new SNIPPET_PROPERTIES[10];
public boolean bPrintEnable;
public boolean bOneDoc;
public int nFeedingMode;
@Override
protected List getFieldOrder() {
return Arrays.asList(
"bMICREnable"
, "nMICRFont"
, "bMICRSaveSamples"
, "nMICRSpaces"
, "cRejectSymbol"
, "nReserved"
, "bReserved"
, "ImagePropertiesFront1"
, "ImagePropertiesFront2"
, "ImagePropertiesRear1"
, "ImagePropertiesRear2"
, "SnippetProperties"
, "bPrintEnable"
, "bOneDoc"
, "nFeedingMode"
);
}
}
public class IMAGE_PROPERTIES extends Structure {
public int Format;
public int Paging;
public int Resolution;
public int ColorDepth;
public int Threshold;
@SuppressWarnings("RedundantArrayCreation")
@Override
protected List getFieldOrder() {
return Arrays.asList(
new String[]{
"Format"
, "Paging"
, "Resolution"
, "ColorDepth"
, "Threshold"
}
);
}
}
public class SNIPPET_PROPERTIES extends Structure {
public boolean Enable;
public boolean Front;
public SNIPPET Properties = new SNIPPET();
@Override
protected List getFieldOrder() {
return Arrays.asList("Enable", "Front", "Properties");
}
}
public class SNIPPET extends Structure {
public int Xposition;
public int Yposition;
public int Width;
public int Height;
public int Orientation;
public int Color;
public int Compression;
public boolean Millimeters;
@Override
protected List getFieldOrder() {
return Arrays.asList("Xposition"
, "Yposition"
, "Width"
, "Height"
, "Orientation"
, "Color"
, "Compression"
, "Millimeters"
);
}
}
Output:
DEVICE_PARAMETERS(auto-allocated@0x16a25938 (520 bytes)) {
boolean bMICREnable@0=false
int nMICRFont@4=1
boolean bMICRSaveSamples@8=false
int nMICRSpaces@c=2
byte cRejectSymbol@10=3f
int nReserved@14=0
boolean bReserved@18=false
IMAGE_PROPERTIES ImagePropertiesFront1@1c=IMAGE_PROPERTIES(allocated@0x16a25954 (20 bytes) (shared from auto-allocated@0x16a25938 (520 bytes))) {
int Format@0=0
int Paging@4=0
int Resolution@8=0
int ColorDepth@c=0
int Threshold@10=0
}
IMAGE_PROPERTIES ImagePropertiesFront2@30=IMAGE_PROPERTIES(allocated@0x16a25968 (20 bytes) (shared from auto-allocated@0x16a25938 (520 bytes))) {
int Format@0=0
int Paging@4=0
int Resolution@8=0
int ColorDepth@c=0
int Threshold@10=0
}
IMAGE_PROPERTIES ImagePropertiesRear1@44=IMAGE_PROPERTIES(allocated@0x16a2597c (20 bytes) (shared from auto-allocated@0x16a25938 (520 bytes))) {
int Format@0=0
int Paging@4=0
int Resolution@8=0
int ColorDepth@c=0
int Threshold@10=0
}
IMAGE_PROPERTIES ImagePropertiesRear2@58=IMAGE_PROPERTIES(allocated@0x16a25990 (20 bytes) (shared from auto-allocated@0x16a25938 (520 bytes))) {
int Format@0=0
int Paging@4=0
int Resolution@8=0
int ColorDepth@c=0
int Threshold@10=0
}
SNIPPET_PROPERTIES SnippetProperties[10]@6c=[Lpanini.data.SNIPPET_PROPERTIES;@fb642f
boolean bPrintEnable@1fc=false
boolean bOneDoc@200=false
int nFeedingMode@204=1
}
memory dump
[00000000]
[01000000]
[00000000]
[02000000]
[3f000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[00000000]
[01000000]
Device Error: Wrong device parameters <-- this is where I try to set params
Aucun commentaire:
Enregistrer un commentaire