1 个回答
该问题已解决,如下
3、jna封装为
interface MotorDllLibrary extends Library {
String fileName = "CH375DLL.DLL";
String filePath = MotorDllLibrary.class.getResource("").getPath().replaceFirst("/", "").replaceAll("%20", " ") + fileName;
MotorDllLibrary motor = (MotorDllLibrary) Native.loadLibrary(filePath, MotorDllLibrary.class);
/**
* 读取设备描述符
*
* @param index 指定CH375设备序号
* @param buff 指向一个足够大的缓冲区,用于保存描述符
* @param length 指向长度单元,输入时为准备读取的长度,返回后为实际读取的长度
* @return 0,失败;其他,成功
*/
int CH375GetDeviceDescr(int index, byte[] buff, int[] length);
}
4、调用如下
public static void main(String[] args) {
try {
byte[] s = new byte[100];
int[] l = new int[1];
l[0] = 100;
int deviceDescr = MotorDllLibrary.motor.CH375GetDeviceDescr(0,s,l);
System.out.println("deviceDescr:" + deviceDescr);
} catch (Exception e) {
e.printStackTrace();
}
}
核心问题即为指针问题