`
xblia
  • 浏览: 83136 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

use_002

 
阅读更多
ReadWrite.java  
/* 
 * Java libusb wrapper
 * Copyright (c) 2005-2006 Andreas Schläpfer <spandi at users.sourceforge.net>
 *
 * http://libusbjava.sourceforge.net
 * This library is covered by the LGPL, read LGPL.txt for details.
 */
package ch.ntb.usb.demo;

import ch.ntb.usb.Device;
import ch.ntb.usb.USB;
import ch.ntb.usb.USBException;

/**
 * Demo class to demonstrate simple read and write operations to an USB device.<br>
 * 
 * @author schlaepfer
 * 
 */
public class ReadWrite {

  private static void logData(byte[] data) {
    System.out.print("Data: ");
    for (int i = 0; i < data.length; i++) {
      System.out.print("0x" + Integer.toHexString(data[i] & 0xff) + " ");
    }
    System.out.println();
  }

  public static void main(String[] args) {
    // get a device instance with vendor id and product id
    Device dev = USB.getDevice((short) 0x8235, (short) 0x0222);
    try {
      // data to write to the device
      byte[] data = new byte[] { 0, 1, 2, 3 };
      // data read from the device
      byte[] readData = new byte[data.length];

      // open the device with configuration 1, interface 0 and without
      // altinterface
      // this will initialise Libusb for you
      dev.open(1, 0, -1);
      // write some data to the device
      // 0x03 is the endpoint address of the OUT endpoint 3 (from PC to
      // device)
      dev.writeInterrupt(0x03, data, data.length, 2000, false);
      // read some data from the device
      // 0x84 is the endpoint address of the IN endpoint 4 (from PC to
      // device)
      // bit 7 (0x80) is set in case of an IN endpoint
      dev.readInterrupt(0x84, readData, readData.length, 2000, false);
      // log the data from the device
      logData(readData);
      // close the device
      dev.close();
    } catch (USBException e) {
      // if an exception occures during connect or read/write an exception
      // is thrown
      e.printStackTrace();
    }
  }
}  

Examples

The first example (LogBus) uses the libusb share library directly to initialize libusb, get an object tree which represents the bus with associated devices and descriptors and print it to standard out.

The second example (ReadWrite) demonstrates how to get a device instance, read from and write to the device using the ch.ntb.usb.Device class. This class hides libusb specific methods and implements exceptions in case of error.

 

分享到:
评论
1 楼 无奈的漂泊 2011-11-28  
dev.open(1, 0, -1);  到这一步打不开,为什么

相关推荐

    ETSI关于F5G的定义和应用场景 ETSI_GR_F5G002(Use cases).pdf

    F5G Use Cases》(GR F5G 002 V1.1.1,2021-02版)中详细阐述了F5G(第五代固定网络)的定义以及各种应用场景。这份报告由ETSI的第五代固定网络产业规格小组(ISG)制定,体现了参与ISG成员的观点,但并不一定代表...

    SQL sever 实训

    USE Xk GO SELECT * FROM Course --有哪些种类的选修课?学分是多少 USE XK GO SELECT Kind,Credit FROM Crouse GO 修改列名字 SELECT '课程种类'=Kind,'学分'=Credit FROM Course GO --查询Course表的前10行 ...

    2157_stm8ef_DoYou_stm8_

    The results are: x wafer: 0x001B y wafer: 0x800D n wafer: 0x00 lot n: 0x00312C28706431 and: x wafer: 0x001C y wafer: 0x002A n wafer: 0x00 lot n: 0x002C2870643129 is ''y wafer 0x800D'' a sign-abs ...

    churchsys:教会系统

    安装S3驱动器 / mnt / s3-drive -o use_cache = / tmp -o allow_other -o uid = 1001 -o mp_umask = 002 -o multireq_max = 5 -o use_path_request_style -o url =

    leetcodepushfront-Leetcode_Interview_Collection:收藏采访示例

    002--&gt;Not_Use_add 003--&gt;全排列 004-&gt;LRU C++代码: LRUCache(int capacity) { this-&gt;capacity = capacity ; } int Get (int key ) { if (cacheMap.find(key) == cacheMap.end() ) return -1 ; ...

    002-FreeRTOS202212-4001-链表头节点(根节点)初始化

    这些字段的初始化取决于配置选项`configUSE_MINI_LIST_ITEM`的值。 在链表头节点的初始化过程中,还需要写入链表结构的其余字段,以便在链表结构中存储和管理链表项。这些字段包括链表项的数量`uxNumberOfItems`和...

    Chinese Entity Linking Comprehensive

    TAC KBP Chinese Entity Linking Comprehensive Training and Evaluation Data 2011-2014 LDC2015E17 March 20, 2015 Linguistic Data Consortium 1. Overview Text Analysis Conference (TAC) is a series...

    MFC.rar_MFC 销毁窗口_mfc non client_mfc 创建窗口

    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, AfxGetInstanceHandle(), NULL); ``` 接下来,我们讨论**销毁窗口**。在MFC中,窗口的销毁通常是通过`DestroyWindow()`函数来完成的...

    人工智能课程大作业python基于深度学习的英文文本分类源码+项目说明+详细注释(含数据集).zip

    step 950, loss 0.002 step 960, loss 0.001 step 970, loss 0.000 the acc in the test set is 0.783 ``` 预测过程展示: ``` 预测结果保存路径: save_pre.txt 过程较慢,耐心等待,有空点赞以及留言等,谢谢各位...

    Phase 2 Use Cases and Requirements (MEC).pdf

    首先,文件标题“Phase 2 Use Cases and Requirements (MEC)”指向文档内容涉及MEC技术的第二阶段发展,重点在于用例和需求分析。这一阶段的目标是根据第一阶段的技术实现,进一步细化并明确在边缘计算领域中所需...

    002.zip_Windows编程_Perl_

    7. **错误处理和调试**:学习如何使用`die`、`warn`函数进行错误处理,以及使用`use strict`和`use warnings`等提示来提升代码质量。 8. **Windows特定的API调用**:通过Win32::API模块,Perl程序员可以在Windows...

    ftp相关内容的配置

    4. `local_umask=002`:设置umask为002,意味着新创建的文件和目录的默认权限将是775(rwxrwxr-x),这样同组用户也能有读写权限。 5. `userlist_enable=YES` 和 `userlist_deny=YES`:启用用户列表,并禁止列表中的...

    MTK ccache脚本的使用

    export CCACHE_UMASK=002 然后,执行source .bashrc命令使设置生效。 检查ccache版本 使用以下命令检查ccache版本: ccache --version 设置ccache大小 ccache的大小是一个动态的值,可以使用以下命令设置: ...

    flake8-use-fstring

    FS002 :使用.format格式。 FS003 :f字符串缺少前缀(默认情况下忽略)。可用配置--percent-greedy和--format-greedy 该插件检查每个python语句(逻辑行),并查看是否使用%或.format 。 由于flake8只是代码样式...

    T6 5.1升级T66.2报错

    USE [UFDATA_002_2004] GO /****** Object: Table [dbo].[JustInVouchs] Script Date: 06/12/2014 14:09:57 ******/ drop table JustInVouchs drop table IA_Subsidiary SET ANSI_NULLS ON GO SET QUOTED_...

    python 读取.nii格式图像实例

    我就废话不多说了,大家还是直接看代码吧~ # encoding=utf8 ''' 查看和显示nii文件 ''' import matplotlib matplotlib.use('TkAgg') ...example_filename = '../ADNI_nii/ADNI_002_S_0413_MR_MPR____N3__Scaled_2_Br_

    tensorflow models-master.7z.002

    上传大小受限制,分成了两个包,models-master.7z.001、models-master.7z.002请全部下载后解压。 This repository contains a number of different models implemented in [TensorFlow]...

Global site tag (gtag.js) - Google Analytics