Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...