无法通过从 ITLSSPProc.dll 调用 Native 方法打开端口 [英] Unable to open the port by calling Native method from ITLSSPProc.dll
问题描述
这是来自 ITLSSPProc.dll 的本地方法
NOMANGLE int CCONV OpenSSPComPort (SSP_COMMAND * cmd);
<块引用>
这里,SSP_COMMAND 是 C++ 中 ITLSSPProc.dll 中的结构语言.
struct SSP_COMMAND{无符号长波特率;无符号字符端口号;};
<块引用>
所以,我必须使用 java 访问 OpenSSPComPort (SSP_COMMAND * cmd)JNI.这是我写的代码,
public class Main {公共接口 ITLSSPProc 扩展库 {ITLSSPProc INSTANCE = (ITLSSPProc) Native.loadLibrary((Platform.isWindows() ? "ITLSSPProc" : "simpleDLLWindowsPort"), ITLSSPProc.class);int OpenSSPComPort(指针参数);int CloseSSPComPort();}public static void main(String[] args)throws IOException {ITLSSPProc sdll = ITLSSPProc.INSTANCE;内存 intMem = 新内存(10);//分配空间intMem.setLong(0,9600);intMem.setString(1,"com7");if(sdll.OpenSSPComPort(intMem)==1){//使用 int 参数和结果调用函数System.out.println("连接");}别的{System.out.println("失败");}}}输出:失败
<块引用>
端口号是我们正在使用的 COM7.所以,当我运行这个应用程序,当我手动传递波特率时,如用户所给手动,如果端口号正确,则必须在其上打印已连接"安慰.所以,有人知道我哪里出错了,我不明白实际问题在哪里..
基本类型的 JNA 文档(long
、char
).
聚合类型的 JNA 文档(struct
, struct *
).
//tl;博士类 SSP_COMMAND 扩展结构 {公共 NativeLong BaudRate;公共字节端口号;}int OpenSSPComPort(SSP_COMMAND 参数)
This is native method from ITLSSPProc.dll
NOMANGLE int CCONV OpenSSPComPort (SSP_COMMAND * cmd);
Here, SSP_COMMAND is structure in ITLSSPProc.dll which is in C++ Language.
struct SSP_COMMAND
{
unsigned long BaudRate;
unsigned char PortNumber;
};
So, I have to access OpenSSPComPort (SSP_COMMAND * cmd) in java using JNI. Here is a code i have written,
public class Main {
public interface ITLSSPProc extends Library {
ITLSSPProc INSTANCE = (ITLSSPProc) Native.loadLibrary(
(Platform.isWindows() ? "ITLSSPProc" : "simpleDLLWindowsPort"), ITLSSPProc.class);
int OpenSSPComPort(Pointer param);
int CloseSSPComPort();
}
public static void main(String[] args)throws IOException {
ITLSSPProc sdll = ITLSSPProc.INSTANCE;
Memory intMem = new Memory(10); // allocating space
intMem.setLong(0,9600);
intMem.setString(1,"com7");
if(sdll.OpenSSPComPort(intMem)==1)
{// calling function with int parameter&result
System.out.println("connected");
}
else
{
System.out.println("failed");
}
}
}
Output : failed
Port number is COM7 on which we are working. So, when i run this application and as i passing baud rate as manually as given in user manual and if port number is correct it has to print "connected" on console. So, anybody know where i am going wrong, i dont understand where is actual problem..
JNA documentation for basic types (long
, char
).
JNA documentation for aggregate types (struct
, struct *
).
// tl;dr
class SSP_COMMAND extends Structure {
public NativeLong BaudRate;
public byte PortNumber;
}
int OpenSSPComPort(SSP_COMMAND param)
这篇关于无法通过从 ITLSSPProc.dll 调用 Native 方法打开端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!