1

私はこのネイティブ関数を持っており、デバイスをシステムに接続すると JNA で null 値を取得します。JNA との LPVOID マッピングに問題があると思います。

CP210x_GetProductString( DWORD DeviceNum,LPVOID DeviceString,DWORD Options)
  1. DeviceNum— 製品説明文字列、シリアル番号、またはフル パスが必要なデバイスのインデックス。
  2. DeviceStringCP210x_DEVICE_STRING— NULL で終わるシリアル番号、デバイスの説明、またはフル パス文字列を返す型の変数。
  3. OptionsDeviceString—製品説明、シリアル番号、またはフルパス文字列が含まれているかどうかを判断するフラグ

JNA コード:

public class Helloworld {

    public interface CLibrary extends Library{
        CLibrary INSTANCE = (CLibrary) Native.loadLibrary(
            (Platform.isWindows() ? "CP210xManufacturing.dll" : "c"),
            CLibrary.class);

        int CP210x_GetProductString(int dn,String [] ds,int op);
    }

    public static void main(String[] args) {
        int dn=0;
        String dsc = new String[100];
        if(CLibrary.INSTANCE.CP210x_GetProductString(dn, dsc,
               CP210x.CP210x_RETURN_SERIAL_NUMBER) == CP210x.CP210x_SUCCESS){
        {
            for(int i=0;i<dsc.length;i++)
                System.out.print(dsc[i]);
            }

        }
    }
}
4

1 に答える 1

0

これが機能するかどうかはわかりませんが、CP210x_GetProductString のこの説明から、長さ 256 の byte[] を関数 (文字列で埋めるバッファー) に渡す必要があると思います。

 int CP210x_GetProductString(int dn,byte[] ds,int op);

 //use it like this
 byte[] rawString = new byte[256];
 int dn = ...;
 int op = ...;
 CP210x_GetProductString(dn,rawString,op);
 //You might have to choose a different Charset here
 //since I don't know what encoding the string uses I used the default
 String product = new String(rawString,Charset.defaultCharset());
于 2011-01-08T20:11:54.813 に答える