无法通过从ITLSSPProc.dll调用Native方法来打开端口 [英] Unable to open the port by calling Native method from ITLSSPProc.dll
问题描述
这是来自ITLSSPProc.dll的本地方法
This is native method from ITLSSPProc.dll
NOMANGLE int CCONV OpenSSPComPort (SSP_COMMAND * cmd);
这里,SSP_COMMAND是ITLSSPProc.dll中的结构,它是C ++
语言
Here, SSP_COMMAND is structure in ITLSSPProc.dll which is in C++ Language.
struct SSP_COMMAND
{
unsigned long BaudRate;
unsigned char PortNumber;
};
所以,我必须在java中访问OpenSSPComPort(SSP_COMMAND * cmd)使用
JNI。这是我写的代码,
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
端口号是我们正在工作的COM7。所以,当我运行这个
应用程序,并且我通过手动通过波特率在用户
手册中给出,如果端口号正确,它必须在
控制台上打印连接。所以,任何人都知道我在哪里错了,我不明白
哪里是实际的问题..
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文档( long
, char
)
聚合类型的JNA文档( struct
, struct *
)。
// tl;dr
class SSP_COMMAND extends Structure {
public NativeLong BaudRate;
public byte PortNumber;
}
int OpenSSPComPort(SSP_COMMAND param)
这篇关于无法通过从ITLSSPProc.dll调用Native方法来打开端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!