JNA调用dll时crash了。求教大牛
这个dll是解调仪厂商给的。
isCorrect和发送命令都正常,可以判断是DataReadPD的问题
文档中的DataReadPD描述如下
DataReadPD(byte ArrayOfData[], int NumberOfBytes) – this function reads the
data returned on port 55000 by the sm125 in response to a command issued with
the SendCommandPD function. The function performs both of the reads
necessary to fully interpret the data returned from the sm125. The function returns
a pointer to an array of bytes, ArrayOfData[], containing the data returned, and an
integer, NumberOfBytes, which indicates the size of the data array. The function
returns a value of 0 on successful completion. The function returns an integer
error code if an error occurs. Integer error codes and their descriptions are listed
later in this document
错误日志
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0b0e1c4b, pid=176, tid=4000
#
# Java VM: Java HotSpot(TM) Client VM (11.3-b02 mixed mode windows-x86)
# Problematic frame:
# C [sm125_Comm_Dll.dll+0x1c4b]
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
JNA代码如下
import java.nio.ByteBuffer;
import com.sun.jna.Native;
import com.sun.jna.win32.StdCallLibrary;
public interface sm125_Comm_Dll extends StdCallLibrary
{
sm125_Comm_Dll INSTANCE = (sm125_Comm_Dll)Native.loadLibrary("sm125_Comm_Dll",sm125_Comm_Dll.class);
public int sm125_Connect(String IPAddress);
public int sm125_Disconnect();
public int SendCommandPD(String command);
// public int DataReadPD(byte[] ArrayOfData , int NumberOfBytes);
public int DataReadPD(ByteBuffer ArrayOfData , int NumberOfBytes);
}
测试的代码如下:
import java.nio.ByteBuffer;
public class Test
{
public static void main(String[] args)
{
int isConnect = 1;//0代表建立成功,1代表连接失败。
String str = "10.0.0.122";
isConnect = sm125_Comm_Dll.INSTANCE.sm125_Connect(str);
System.out.println("isConnect:" + isConnect);//已测试建立连接
String peaks = "#GET_PEAKS_AND_LEVELS";
String convert = null;
// convert = new String(peaks.getBytes("ASCII"));
if(sm125_Comm_Dll.INSTANCE.SendCommandPD("#GET_PEAKS_AND_LEVELS") != 0)
{
System.out.println("SendCommandPD命令运行失败");
return ;
}
else{
System.out.println("发送命令成功");