簡體   English   中英

找不到功能JNA + SiUSBXp

[英]Function not found JNA + SiUSBXp

我正在嘗試將JNA與SiLabs的USBXPRESS庫(siusbxp.dll)配合使用,並且基本功能正常運行時,SI_GetDeviceProductString函數存在問題。

public class usbxpress 
{

public interface SiUSBXp extends StdCallLibrary 
{
SiUSBXp INSTANCE = (SiUSBXp) Native.loadLibrary("SiUSBXp", SiUSBXp.class);

byte SI_GetNumDevices (IntByReference lpdwNumDevices);
byte SI_GetProductString( int dwDeviceNum, byte[] lpvDeviceString, int dwFlags);
byte SI_Open (int dwDevice, HANDLEByReference cyHandle);
byte SI_GetPartNumber (HANDLE cyHandle, ByteByReference lpbPartNum);        
byte SI_GetDeviceProductString (HANDLE cyHandle, PointerByReference lpProduct, ByteByReference lpbLength, int bConvertToASCII);
//byte SI_GetDeviceProductString (HANDLE cyHandle, LPVOID lpProduct, LPBYTE lpbLength, BOOL bConvertToASCII = TRUE); //original c function
}

public static void main(String[] args) 
{
//checking number of connected devices  
IntByReference lpdwNumDevices = new IntByReference();
SiUSBXp.INSTANCE.SI_GetNumDevices (lpdwNumDevices);        
System.out.println(lpdwNumDevices.getValue());

//opening the device
HANDLEByReference dev_handle_ref = new HANDLEByReference();
byte status = SiUSBXp.INSTANCE.SI_Open(0, dev_handle_ref);
System.out.printf("Status %d\n", status);

HANDLE device_handle = dev_handle_ref.getValue();

//checking part number
ByteByReference lpbPartNum = new ByteByReference();
SiUSBXp.INSTANCE.SI_GetPartNumber(device_handle, lpbPartNum);
System.out.printf("Part number is CP210%d\n", lpbPartNum.getValue());      

//checking product string - does not work
PointerByReference lpProduct = new PointerByReference();
ByteByReference lpbLength = new ByteByReference();
SiUSBXp.INSTANCE.SI_GetDeviceProductString(device_handle, lpProduct, lpbLength, 1);
}}

當我嘗試運行它時,出現以下錯誤:

> Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'SI_GetDeviceProductString': at com.sun.jna.Function.<init>(Function.java:179) 
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:391) 
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:371) 
at com.sun.jna.Library$Handler.invoke(Library.java:205) 
at $Proxy0.SI_GetDeviceProductString(Unknown Source)

感覺像是C函數的默認參數有問題。 我嘗試使用int作為參數,並嘗試省略它,但是這些都沒有幫助。 我什至沒有到達SI_Write(HANDLE cyHandle,LPVOID lpBuffer,DWORD dwBytesToWrite,LPDWORD lpdwBytesWritten,OVERLAPPED * o = NULL); 功能,這有望引起更多問題:)

可以請任何人建議我如何處理JNA中的默認函數參數嗎?

更新:SI_Write函數可以通過以下方式正常工作:

byte SI_Write (HANDLE cyHandle, PointerByReference lpBuffer, int dwBytesToWrite, IntByReference lpdwBytesWritten, Pointer o);
...
SiUSBXp.INSTANCE.SI_Write (device_handle, lpBuffer, message.length, lpdwBytesWritten, null);

因此,問題是由其他原因引起的,但仍然存在。

我已經設法通過使用Internet上的較舊版本的SiUSBXp庫解決了該問題。 從SiLabs網站下載的較新版本的行為很奇怪-有時在Dependency Walker中可以看到SI_GetDeviceProductString函數,有時則看不到,而較舊的版本就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM