首页 | 互联网 | IT动态 | IT培训 | Cisco | Windows | Linux | Java | .Net | Oracle | 软件测试 | C/C++ | 嵌入式开发 | 存储世界 | 服务器
网络设备 | IDC | 安全 | 求职招聘 | 数字网校 | 网页设计 | 平面设计 | 技术专题 | 电子书下载 | 教学视频 | 源码下载 | 搜索 | 博客 | 论坛
中国IT实验室Linux频道
中国IT教育
Google
首页 资讯动态 认证考试 新手入门 核心技术 高级技术 J2EE J2ME Java&XML 开源技术 其他技术 RSS订阅 论坛 专题
您现在的位置: 中国IT实验室 >> Java >> 核心技术 >> 网络编程 >> 正文

教你如何在java应用程序中访问usb设备


  清单 2 展示了在应用程序成功地找到了 Device 的条件下,如何与 Interface 和 EndPoint 进行批量 I/O。 这个代码段也可以修改为执行控制或者中断 I/O。它对应于上述步骤 5。

  清单 2. 用 jUSB API 执行批量 I/O

  if (device != null)
  {
  // 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  {
  // Access the currently 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  {
   // 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();
   }
   // If the Endpoint is and output Endpoint, obtain its
   // OutputStream and write out data.
   else
   {
    OutputStream out;
    out = ep.getOutputStream();
    // Write out data here.
    out.close();
   }
  }
  }
  }

   jUSB 项目在 2000年 6月到 2001年 2月期间非常活跃。该 API 的最新的版本 0.4.4发表于 2001年 2月 14日。从那以后只提出了很少的改进,原因可能是 ibm 小组成功地成为了 Java 语言的候选扩展标准。不过,基于 jUSB 已经开发出一些第三方应用程序,包括 JPhoto 项目(这是一个用 jUSB 连接到数码照相机的应用程序)和 jSyncManager 项目(这是一个用 jUSB 与使用 Palm 操作系统的 PDA 同步的应用程序)。

上一页  [1] [2] [3] [4] [5] [6] [7] 下一页

【责编:Ken】

中国IT教育

相关产品和培训
文章评论
 友情推荐链接
 认证培训
 专题推荐

 ·关于Java框架技术专题
 ·XML全攻略技术专题
 ·JAVA开源技术介绍专题
 ·Java嵌入式开发之J2ME技术专题
 ·超前体验 Oracle 11g的5个新特性…
 ·揭密使用VB.NET的五个实用技巧
 ·Oracle和SQL Server常用函数对比专题…
 ·展现C#世界 C#程序设计专题…
 ·Java入门 Tomcat的配置技巧精华专题…
 ·Oracle RMAN物理备份技术详解…
 今日更新
 社区讨论
 博客论点
 频道精选
 Java 频道导航