usb4java_usb4java USB错误4:无法打开USB设备:-程序员宅基地

技术标签: usb4java  

我正在尝试与PS3的DS3控制器连接.我已经设法在C#中使用libusb的实现,但决定将我的实现移动到java.不幸的是,我转向java并不是那么顺利.该设备似乎在设备列表中找到,但当我尝试打开它时,我收到以下错误“USB错误4:无法打开USB设备:没有这样的设备(可能已断开连接)”

public class Main {

private static final short VID = 0x054c;

private static final short PID = 0x0268;

Context context;

public Main() {

context = new Context();

int result = LibUsb.init(context);

if (result != LibUsb.SUCCESS) {

throw new LibUsbException("Unable to initialize libusb.", result);

}

ByteBuffer data = ByteBuffer.allocate(49);

DeviceHandle ds3Handle = getDeviceHandle(findDevice(VID, PID));

LibUsb.controlTransfer(ds3Handle, (byte)0xa1, (byte)0x1, (short)0x101, (short)0, data, 1000L);

LibUsb.exit(context);

}

private Device findDevice(int vid, int pid) {

Device UsbDevice = null;

DeviceList list = new DeviceList();

int result = LibUsb.getDeviceList(context, list);

if (result < 0) {

throw new LibUsbException("Unable to get device list", result);

}

try {

for(Device device: list) {

DeviceDescriptor descriptor = new DeviceDescriptor();

result = LibUsb.getDeviceDescriptor(device, descriptor);

if (result != LibUsb.SUCCESS) {

throw new LibUsbException("Unable to read device descriptor", result);

}

if (descriptor.idVendor() == vid && descriptor.idProduct() == pid) {

UsbDevice = device;

System.out.println("found");

}

}

} finally {

LibUsb.freeDeviceList(list, true);

}

return UsbDevice;

}

private DeviceHandle getDeviceHandle(Device device) {

DeviceHandle handle = new DeviceHandle();

int result = LibUsb.open(device, handle);

if (result != LibUsb.SUCCESS) {

throw new LibUsbException("Unable to open USB device", result);

}

return handle;

}

public static void main(String [] args){

new Main();

}

}

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_36199904/article/details/114402988

智能推荐

OpenCV错误(-215:Assertion failed) npoints > 0 in function_error: (-215:assertion failed) npoints > 0 in func-程序员宅基地

文章浏览阅读3k次,点赞7次,收藏3次。在使用OpenCV绘图函数时容易遇到(-215:Assertion failed) npoints > 0 错误。代码如下:import numpyimport cv2mask = numpy.zeros([4000, 4000, 3])cnt=[[ 1626. 360.] [ 1776. 3108.] [ 126. 3048.] [ 330. 486.]]cv2.drawContours(mask, [cnt], 0, (0, 255, 0), -1)出错._error: (-215:assertion failed) npoints > 0 in function 'cv::drawcontours

【OpenGL手册17】数据输入工具Assimp_opengl assimp-程序员宅基地

文章浏览阅读1k次,点赞8次,收藏20次。我们一直都在用一个破木箱渲染,但时间久了甚至是我们最好的朋友也会感到无聊。在日常的图形程序中,通常都会使用非常复杂且好玩的模型,它们比静态的箱子要好看多了。然而,和箱子对象不同,我们不太能够对像是房子、汽车或者人形角色这样的复杂形状手工定义所有的顶点、法线和纹理坐标。我们想要的是将这些模型(Model)导入(Import)到程序当中。模型通常都由3D艺术家在Blender、3DS Max或者Maya这样的工具中精心制作。_opengl assimp

【CodeForces - 988C 】Equal Sums (思维,STLmap,STLset,tricks)_小a有 n 个整数数列 a1,a2,…an ,每个数列的长度为li。 请你找出两个编号不同的数列,并-程序员宅基地

文章浏览阅读294次。题干:You are given kk sequences of integers. The length of the ii-th sequence equals to nini.You have to choose exactly two sequences ii and jj (i≠ji≠j) such that you can remove exactly one element ..._小a有 n 个整数数列 a1,a2,…an ,每个数列的长度为li。 请你找出两个编号不同的数列,并从这两个数列中各恰好删除一个数,使得这两个数列的和相等。

API与EDI的区别?_api和edi指的什么-程序员宅基地

文章浏览阅读3.2k次。从下图可以看出,有时EDI和API都是基于Http通过互联网进行安全可靠的数据交换。从上图看出,API缺少EDI特定的传输协议,如OFTP,AS2。另外也没有任何定义的消息类型,例如EDIFACT,X12。EDI消息类型和特定的传输协议是EDI的重要组成部分,而且EDI消息类型几乎覆盖了供应链领域所有业务,使得其对于增长的对接需求更加友好。而API呢?通俗的说就是:API实际上就是..._api和edi指的什么

运维工程师(Operations)-程序员宅基地

文章浏览阅读329次。运维工程师(Operations)在国内又称为运维开发工程师(Devops),在国外称为 SRE(Site Reliability Engineering)。负责维护并确保整个服务的高可用性,同时不断优化系统架构、提升部署效率、优化资源利用率提高整体的ROI(指通过投资而应返回的价值,即企业从一项投资活动中得到的经济回报)。运维工程师最基本的职责都是负责服务的稳定性,确保服务可以7..._运维的高大上叫法

@PathVariable为空时指定默认值_pathvariable默认值-程序员宅基地

文章浏览阅读6.4k次,点赞3次,收藏6次。@PathVariable为空时指定默认值,可以指定多个匹配路径,然后设置参数非必要的,就可以了,例子如下@RequestMapping(value = {"/timeline/{uid}", "/timeline/{uid}/{size}"})public ModelAndView getTimeline(@PathVariable(value="uid" ) String articleUserId,@PathVariable(value="size" , required = false_pathvariable默认值

随便推点

Android - WebView 全面干货指南_android webview-程序员宅基地

文章浏览阅读643次。前言总结 Android WebView 常用的相关知识点,令包含以下干货内容分析:Js注入漏洞、WebView 遇到的坑、JsBridge 原理以及框架使用(JsBridge,DSBridge-Android)、缓存机制应用、性能优化、腾讯开源框架 VasSonic (之后会进行代码分析)。目录一、简介这部分主要介绍下 WebView,WebView 是一个用来显示 Web ..._android webview

使用eclipse遇到问题:the-package-collides-with-a-type-程序员宅基地

文章浏览阅读743次。相似问题:http://stackoverflow.com/questions/12236909/the-package-collides-with-a-type_the package com.csii.pe.action.twophase collides with a type

Spring Boot 接口使用rome实现RSS 订阅_rometools-程序员宅基地

文章浏览阅读1.3k次。Spring Boot 入门 接口使用rome实现RSS 订阅首次接口实现RSS订阅RSS是什么环境参考博客版本问题遇到的坑正文实现结果首次接口实现RSS订阅公司数据对接国内某知名股票机构,需要提供接口按Rss方式返回结果,开始首次尝试实现。RSS是什么Really Simple Syndication 简易信息聚合(也叫聚合内容)是一种基于XML的标准。简单来说就是网站提供按Rss方式返回结果的接口,方便RSS订阅器订阅;将一些自己关注的信息整合在一起【个人理解】环境SpringBoot 2._rometools

LoadRunner12使用教程(五)——关联的使用_loadrunner12关联函数后后面请求怎么引用-程序员宅基地

文章浏览阅读1.1k次。LoadRunner12使用教程(一)——如何进行参数化LoadRunner12使用教程(二)——回放与录制LoadRunner12使用教程(三)——Action迭代LoadRunner12使用教程(四)——事务与集合点LoadRunner12使用教程(五)——关联的使用 下载最新版loadrunner12>>很多时候,一个项目的请求所以带的参数会来源于前面请求返回的结_loadrunner12关联函数后后面请求怎么引用

什么是Kdump?_kdump是什么意思-程序员宅基地

文章浏览阅读3k次。什么是Kdump?Kdump 是一种的新的crash dump捕获机制,用来捕获kernel crash时候产生的crash dump。Kdump需要配置两个不同目的的kernel,其中一个我们在这里称作standard(production) kernel;另外一个称之为Crash(capture)kernel。standard(production)kernel,是指我正在使用_kdump是什么意思

MySQL-python安装遇到的各种问题_mysql-python(联网安装经常会安装不上,建议打包下载到电脑上安装-程序员宅基地

文章浏览阅读3.2k次。项目场景:提示:这里简述项目相关背景:例如:项目场景:示例:通过蓝牙芯片(HC-05)与手机 APP 通信,每隔 5s 传输一批传感器数据(不是很大)问题描述提示:这里描述项目中遇到的问题:Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gzTraceback (most recent call last): File "setup.py", line 7, in &_mysql-python(联网安装经常会安装不上,建议打包下载到电脑上安装

推荐文章

热门文章

相关标签