Java 问题的根本原因是什么;USB主机支持不可用“;消息

Java 问题的根本原因是什么;USB主机支持不可用“;消息,java,usbserial,jusb,Java,Usbserial,Jusb,我正在尝试使用jUSB库通过USB到串行电缆发送数据。我正在Windows上的NetBeans IDE中编码 以下代码中的“USB主机支持不可用”消息背后的问题是什么: package usb.core; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.List; import usb.core.*; public class M

我正在尝试使用jUSB库通过USB到串行电缆发送数据。我正在Windows上的NetBeans IDE中编码

以下代码中的“USB主机支持不可用”消息背后的问题是什么:

package usb.core;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;    
import usb.core.*;

public class Main {
    public static void main(String[] args) throws IOException {
        try {
            // Bootstrap by getting the USB Host from the HostFactory.
            Host host = HostFactory.getHost();

            // Obtain a list of the USB buses available on the Host.
            Bus[] bus = host.getBusses();
            int total_bus = bus.length;
            System.out.println(total_bus);
            // Traverse through all the USB buses.
            for (int i = 0; i < total_bus; i++) {
                // Access the root hub on the USB bus and obtain the
                // number of USB ports available on the root hub.
                Device root = bus[i].getRootHub();
                int total_port = root.getNumPorts();

                // Traverse through all the USB ports available on the 
                // root hub. It should be mentioned that the numbering 
                // starts from 1, not 0.
                for (int j = 1; j <= total_port; j++) {
                    // Obtain the Device connected to the port.
                    Device device = root.getChild(j);
                    if (device != null) {
                        // USB device available, do something here.
                        // Obtain the current Configuration of the device
                        // and the number of interfaces available under the
                        // current Configuration.
                        Configuration config = device.getConfiguration();
                        int total_interface = config.getNumInterfaces();

                        // Traverse through the Interfaces
                        for (int k = 0; k < total_interface; k++) {
                            // Access the current Interface and obtain the 
                            // number of endpoints available on the Interface 
                            Interface itf = config.getInterface(k, 0);
                            int total_ep = itf.getNumEndpoints();

                            // Traverse through all the endpoints.
                            for (int l = 0; l < total_ep; l++) {
                                // Access the endpoint and
                                // obtain its I/O type
                                Endpoint ep = itf.getEndpoint(l);
                                String io_type = ep.getType();
                                boolean input = ep.isInput();

                                // If the endpoint is an input endpoint,
                                // obtain its InputStream and read in data.
                                if (input) {
                                    InputStream in;
                                    in = ep.getInputStream();
                                    // Read in data here
                                    in.close();
                                }
                                else {
                                    // If the Endpoint is an output Endpoint,
                                    // obtain its OutputStream and
                                    // write out data.
                                    OutputStream out;
                                    out = ep.getOutputStream();
                                    // Write out data here.
                                    out.close();
                                }
                            }
                        }
                    }
                }
            }

        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
封装usb.core;
导入java.io.IOException;
导入java.io.InputStream;
导入java.io.OutputStream;
导入java.util.List;
导入usb.core.*;
公共班机{
公共静态void main(字符串[]args)引发IOException{
试一试{
//通过从HostFactory获取USB主机进行引导。
Host Host=HostFactory.getHost();
//获取主机上可用的USB总线列表。
总线[]总线=host.getBusses();
int total_bus=总线长度;
系统输出打印LN(总总线);
//穿过所有的USB总线。
对于(int i=0;i对于(int j=1;j我在谷歌上搜索了该错误消息,发现:

  • 2005年的一篇论坛帖子说,在Linux上,这可能是由于USB控制器的独家使用引起的:

  • 的联机副本,表示如果getHost尝试创建(特定于平台的)HostFactory失败,则会发生这种情况。不幸的是,代码会出现意外异常(*),因此您需要使用Java调试器来找出真正的代码


(*代码在
maybeGetHost
和其他地方捕获
Exception
,并丢弃诊断!这是一个重大的“不”字,也是对库的总体代码质量的一个重大警告。如果我是你,我会寻找一个质量更好的库来使用。)

一个选项可能是让操作系统为电缆安装驱动程序,然后将其用作串行端口而不是usb设备。可能是这样的驱动程序妨碍了您的工作,或者您的安装中缺少启用原始usb访问所需的代理驱动程序。