Unable to open the port by calling Native method from ITLSSPProc.dll

戏子无情 提交于 2019-12-17 20:45:43

问题


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..


回答1:


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)


来源:https://stackoverflow.com/questions/14521284/unable-to-open-the-port-by-calling-native-method-from-itlsspproc-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!