简体   繁体   English

使用JNAerator和ftd2xx库的JNA / Java

[英]JNA/Java using JNAerator and ftd2xx Libraries

I'm relatively new to using JNA, and found the JNAerator tool. 我对使用JNA比较陌生,并找到了JNAerator工具。 I thought it would be an easy way to get going, however, how I have generated my interfaces and various files I'm finding it hard to debug or understand why it might not be working. 我以为这是一个简单的方法,但是,如何生成接口和各种文件却使我很难调试或理解为什么它可能无法正常工作。 Windows programming isn't my forte, hence the attempt with JNA to make life easy for myself... Windows编程不是我的专长,因此JNA尝试使自己的生活变得轻松...

The Header file is here: http://www.ftdichip.com/Support/Knowledgebase/index.html?ftd2xx_h.htm 头文件在这里: http : //www.ftdichip.com/Support/Knowledgebase/index.html?ftd2xx_h.htm

And it generated the following Java JNA File here: http://pastebin.com/hpJgSRMk 并且在此处生成了以下Java JNA文件: http : //pastebin.com/hpJgSRMk

Now my sample App is simply trying to list those connected devices, which i can then iterate around and manipulate etc.. 现在,我的示例应用程序只是在尝试列出那些已连接的设备,然后我可以对其进行迭代和操作等。

import com.sun.jna.NativeLong;

import ft2xx.Ftd2xxLibrary;
import ft2xx.Ftd2xxLibrary.LPDWORD;

public class Test {
    public static void main(String[] args){
        LPDWORD lpd = new LPDWORD();
        NativeLong nl = Ftd2xxLibrary.INSTANCE.FT_CreateDeviceInfoList(lpd);
        System.out.println("Call State: " + nl);
    }
}

This following what i have read here: http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer's_Guide(FT_000071).pdf which details how to list the connected devices, which can then be iterated around etc.. 以下是我在这里阅读的内容: http : //www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer's_Guide( FT_000071).pdf,其中详细列出了如何列出连接的设备,然后可以对其进行迭代等。

So, my method returns a 6, which is indicative of an invalid parameter, but given that I auto-generated the code, and it doesn't stack, I'm a little clueless as to how to proceed. 因此,我的方法返回一个6,表示一个无效的参数,但是鉴于我自动生成了代码,并且该代码没有堆叠,因此我对如何进行操作一无所知。

I used JNAerator given the sheer number of methods that I needed to implement and use, and was le to believe that JNA, and such generated code would be easy enough to make work for this particular purpose. 考虑到我需要实现和使用的大量方法,我使用了JNAerator,并且相信JNA和这样生成的代码将很容易实现此特定目的。

Any clues, or should I head back to the basics? 有什么线索,还是我应该回到基础上?

I'm on Windows 7, using Eclipse (Mars), and the webstarted version of JNAerator. 我在Windows 7上,使用Eclipse(Mars)和JNAerator的网络启动版本。

If you don't have a decent understanding of pointers, you're in for a world of confusion. 如果您对指针没有足够的了解,那么您将陷入一片混乱。 Your call expects a pointer to a DWORD (Java int ). 您的呼叫需要一个指向DWORD (Java int )的指针。 You're passing one in, but it has a default value of zero, which is the same as a NULL pointer. 您正在传入一个,但是它的默认值为零,它与NULL指针相同。 If you use IntByReference , you can at least use IntByReference.getValue() after the call to see what the native method "returned" to you in the memory buffer you passed it. 如果使用IntByReference ,则至少可以在调用之后使用IntByReference.getValue() ,以查看传递给它的内存缓冲区中的本机方法“返回”给您的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM