I am developing a tool for biometric recognition using the SDK provided in DLL format, developed in Delphi. For DLL access from Java, I'm using JNA.
The digital template (the most important part) is an object that refers to this section (in Delphi):
type
CIS_Digital = packed record
intSize: integer;
pDigital: Pointer
end;
pCIS_Digital = ^CIS_Digital;
How to develop something equivalent in Java?
Basically, I need to call the following DLL functions:
SDK_CIS_Iniciar(int cnpj, int detectaFake);
SDK_CIS_LerDigital(pCIS_Digital digital);
SDK_CIS_CompararDigital(pCIS_Digital amostra1, pCIS_Digital amostra2);
SDK_CIS_Finalizar();
Looking at the example provided, developed in Delphi , I saw that the pCIS_Digital
object, which is passed in the SDK_CIS_LerDigital()
and SDK_CIS_CompararDigital()
functions, is of type ( type
) declared in code snippet above.
In the same example, before calling the SDK_CIS_LerDigital()
method, the pCIS_Digital
object is instantiated and goes empty where it is then "populated" through the function.
The reader is the Techmag BioFlex , which is based on the Futronic (FS-80) readers.
Searching, I saw that the object pCIS_Digital
(of the code snippet) accesses the memory to read the information the reader writes to it writes.
After much research, I think that I should develop some equivalent Java object, extending from the Structure
or Memory
classes,
Update:MyCodeInformation
IreadandstoremydigitalnumbertwiceusingtheSDK_CIS_LerDigital
method,thencomparethetwousingtheSDK_CIS_CompararDigital
method,whichalwaysreturns0
(commandnotexecuted).
"I have printed the objects intSize
and pDigital
after reading digital, intSize
returns 0
and pDigital
returns null
."
Interface to DLL methods:
public interface SDK_CIS extends StdCallLibrary {
static SDK_CIS INSTANCE = (SDK_CIS) Native.loadLibrary("SDK_CIS", SDK_CIS.class);
public String SDK_CIS_Versao();
public String SDK_CIS_Retorno(int resposta);
public int SDK_CIS_Iniciar(long cnpj, int fake);
public int SDK_CIS_Finalizar();
public int SDK_CIS_LerDigital(CIS_Digital.ByReference digital);
public int SDK_CIS_CancelarLeitura();
public int SDK_CIS_CompararDigital(CIS_Digital.ByReference pAmostra1, CIS_Digital.ByReference pAmostra2);
}
Class that extends Structure, referring to the CIS_Digital object:
public class CIS_Digital extends Structure {
public static class ByReference extends CIS_Digital implements Structure.ByReference {}
public int intSize;
public Pointer pDigital;
@Override
protected List<String> getFieldOrder() {
return Arrays.asList("intSize", "pDigital");
}
}
Method responsible for double-reading any digital and comparing them:
public void leEcomparaDigitais() {
SDK_CIS leitor = SDK_CIS.INSTANCE;
try {
// TROQUEI MEU CNPJ POR ZEROS, PARA NÃO EXPOR MINHA LICENÇA
leitor.SDK_CIS_Iniciar(Long.parseLong("00000000000000"), 0);
CIS_Digital.ByReference amostra1 = new CIS_Digital.ByReference();
leitor.SDK_CIS_LerDigital(amostra1);
try {
// AGUARDA 1 SEGUNDO PARA LER PELA SEGUNDA VEZ
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
CIS_Digital.ByReference amostra2 = new CIS_Digital.ByReference();
leitor.SDK_CIS_LerDigital(amostra2);
int resp = leitor.SDK_CIS_CompararDigital(amostra1, amostra2);
// EXIBE RESPOSTA
// 0 -> COMANDO NAO EXECUTADO
// 1 -> COMANDO EXECUTADO COM SUCESSO
System.out.println(resp);
} finally {
leitor.SDK_CIS_Finalizar();
}
}