,Java   工具软件   办公软件   操作系统   网络安全   设计在线   程序开发   教程宝典   软件下载   软件论坛,Java
您的位置:Yesky > 软件 > 开发者网络 > 正文
在 Java 应用程序中访问USB设备
[文章信息]
作者:羽斌
时间:2005-05-28
出处:Java研究组织
责任编辑:方舟
[文章导读]
在本文通过提供使Java 应用程序可以使用 USB 设备的 API 而使这个过程变得更容易
advertisement
热点推荐
· 图文详解:黑客入侵方式演示
· Java异常处理的陋习展播
· 多媒体系列教程:网页设计制作
· Powerpoint动画演示教程连载
· 光盘刻录手册:禁忌与技巧(下)
[正文]

上一页  1 2 3 4  下一页

  清单 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<total_interface; 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<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();
   }
   // 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  下一页

发表评论推荐给朋友我想参加相关培训打印我对此感兴趣订阅电子杂志
,Java相关内容,Java焦点新闻
  • Hibernate 3新增XML关系持久性介绍
  • 深入研究Servlet线程安全性问题
  • 基于WebSphere MQ的收发消息程序
  • Java压缩文件/目录成ZIP包最新技巧
  • Eclipse插件开发之添加简单的GUI元素
  • FVD刺激高清碟机加速商业化 抢占商机最重要
  • 3家搜索引擎集体诉讼8848 吕春维未敢出席
  • 杨元庆:没有准备不会获批的备用方案
  • 军队信息化诞生新领域 电子军务呼之欲出
  • 世界经济论坛公布信息化程度全球最新排名
  • 2004政务绩效评估:政府门户尚处于发展阶段
  • 甲骨文出资5.15亿美元 意图收购RetekInc
  • 技术并购:帮你突破传统增长的“天花板”
  • ,JavaAdvertisement