`
xblia
  • 浏览: 79921 次
  • 性别: 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

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

    ICAO Doc 9992 Manual on the Use of PBN in Airspace Design

    ICAO Doc 9992_draft_en Manual on the Use of PBN in Airspace Design pdf

    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 ; ...

    人工智能课程大作业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 过程较慢,耐心等待,有空点赞以及留言等,谢谢各位...

    关于水晶报表9中对图片的处理

    SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOALTER proc sp_nrc_pattern_body /*this procedure is for the report ID:NRC002 Other procedure sp_uploadpicwithpath: upload the pictures to database */ AS...

    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行 ...

    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...

    flake8-use-fstring

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

    Computer simulation of the air flow distribution in goaf regarding the use of inert gases and chemi

    This paper presents the use of a computer method of the ventilation process simulation for the analysis of the flow distribution of air and gases in the area of wall mining work and the adjacent goaf....

    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]...

    private_out_send:从私钥列表到1地址收集ETH或ERC20的脚本

    TOKENTOKEN_ADDRESS=0xfab46e002bbf0b4509813474841e0716e6730136 # for ether use `ETH`TARGET_ADDRESS=0x9fCD29A0985fFb07E6D89c0Dd5325917F6FD9A85姓名价值GAS_PRICE GWEI的汽油价格RPC_URL 以太坊节

    tomcat-7_API_帮助文档

    Control Number (ECCN) 5D002.C.1, which includes information security software using or performing cryptographic functions with asymmetric algorithms. The form and manner of this Apache Software ...

    openssh-5.8p2.tar.gz

    signify -Vep /etc/signify/openbsd-55-base.pub -x 002_openssl.patch.sig \ -m - | (cd /usr/src && patch -p0) Then build and install libssl cd /usr/src/lib/libssl/ssl make obj make make install ...

    PDF_To_JPG[无水印]

    if the template is "-###" , the export images will be named as test-001.jpg,test-002.jpg, if you change the template to "##", the export images will be named as test01.jpg,test02.jpg. Command Line ...

    apollo-5.0-2020.7z.002

    This repository is a fork of [Apollo](https://github.com/ApolloAuto/apollo) maintained by the LG Electronics Silicon Valley Lab which has modified and configured to facilitate use with [LG's ...

    perl-pod-spell-commonmistakes:捕获 POD 中的常见错别字

    This document describes v1.002 of Pod::Spell::CommonMistakes - released November 04, 2014 as part of Pod-Spell-CommonMistakes. 概要 #!/usr/bin/perl use strict; use warnings; use Pod::Spell::...

Global site tag (gtag.js) - Google Analytics