2012-04-28 14 views
3

jUSBライブラリを使用してUSB経由でシリアルケーブル経由でデータを送信しようとしています。私はWindowsのNetBeans IDEでコーディングしています。次のコードでは「USBホストのサポートは利用できません」:私はそのエラーメッセージをGoogleで検索し、私が見つけた"USB Host support is unavailable"メッセージの根本原因は何ですか?

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()); 
     } 
    } 
} 
+0

オプションは、osがケーブルのドライバをインストールし、USBデバイスとしてではなくシリアルポートとして使用できるようにするオプションかもしれません。そのようなドライバが途中で入っている可能性があります。あるいは、あなたのインストールでraw USBアクセスを有効にするために必要なプロキシドライバが見つからない可能性があります。 –

答えて

1

  • フォーラムの投稿をメッセージの背後にある問題は何

    2005年にはがLinuxのであることが判明しました。これは、USBコントローラを独占的に使用したことが原因です。http://bytes.com/topic/java/answers/16736-jusb

  • the source codeのオンライン・コピー。これは、(プラットフォーム固有の)HostFactoryを作成するgetHostの試行が失敗した場合に発生することを示します。残念なことに、このコードでは予期しない例外(*)が発生するため、Javaデバッガを使用して実際のコードを把握する必要があります。

(コードがmaybeGetHostExceptionをキャッチし、他の場所との診断を捨て*!これは、ライブラリの全体的なコードの品質上のノーノー主要な、そして大きな赤い旗である。私があなただったら、

関連する問題