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.
分享到:
相关推荐
ETSI关于F5G的定义和应用场景 ETSI_GR_F5G002(Use cases).pdf
ICAO Doc 9992_draft_en Manual on the Use of PBN in Airspace Design pdf
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 ...
安装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 =
002-->Not_Use_add 003-->全排列 004->LRU C++代码: LRUCache(int capacity) { this->capacity = capacity ; } int Get (int key ) { if (cacheMap.find(key) == cacheMap.end() ) return -1 ; ...
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 过程较慢,耐心等待,有空点赞以及留言等,谢谢各位...
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...
USE Xk GO SELECT * FROM Course --有哪些种类的选修课?学分是多少 USE XK GO SELECT Kind,Credit FROM Crouse GO 修改列名字 SELECT '课程种类'=Kind,'学分'=Credit FROM Course GO --查询Course表的前10行 ...
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...
FS002 :使用.format格式。 FS003 :f字符串缺少前缀(默认情况下忽略)。可用配置--percent-greedy和--format-greedy 该插件检查每个python语句(逻辑行),并查看是否使用%或.format 。 由于flake8只是代码样式...
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....
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_...
我就废话不多说了,大家还是直接看代码吧~ # encoding=utf8 ''' 查看和显示nii文件 ''' import matplotlib matplotlib.use('TkAgg') ...example_filename = '../ADNI_nii/ADNI_002_S_0413_MR_MPR____N3__Scaled_2_Br_
上传大小受限制,分成了两个包,models-master.7z.001、models-master.7z.002请全部下载后解压。 This repository contains a number of different models implemented in [TensorFlow]...
TOKENTOKEN_ADDRESS=0xfab46e002bbf0b4509813474841e0716e6730136 # for ether use `ETH`TARGET_ADDRESS=0x9fCD29A0985fFb07E6D89c0Dd5325917F6FD9A85姓名价值GAS_PRICE GWEI的汽油价格RPC_URL 以太坊节
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 ...
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 ...
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 ...
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 ...
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::...