我是靠谱客的博主 妩媚自行车,最近开发中收集的这篇文章主要介绍libusb java_求教usb的操作方法 关于 java.libusb-win32.jar包的问题,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

为什么我正确打开了usb设备之后,一写数据就会报错

ccc0d1c8d1f2ff9f9a565182c5155691.png

————————————————以下是完整代码—————————————————

package usb2;

import ch.ntb.usb.Device;

import ch.ntb.usb.LibusbJava;

import ch.ntb.usb.USB;

import ch.ntb.usb.USBException;

import ch.ntb.usb.Usb_Bus;

import ch.ntb.usb.Utils;

public class A {

/**

* 输出接收的数据

* @param data

*/

private static void logData(byte[] data)

{

System.out.print("Data: ");

for (int i = 0; i < data.length; i++) {

System.out.println("0x" + Integer.toHexString(data[i]&0xff) + " ");

}

}

private static void ReadData() throws USBException

{

Device dev = USB.getDevice((short) 0x10c4, (short) 0xea60);

try

{

byte[] data = new byte[] { 0x07,0x04 ,0x03, 0x03, 0x01, 0x04};

byte[] readData = new byte[data.length];

dev.open(1, 0,-1);

System.out.println("port open or not : "+dev.isOpen());

int altinterface=dev.getAltinterface();

int pid=dev.getIdProduct();

int vid=dev.getIdVendor();

int psize= dev.getMaxPacketSize();

int interfac = dev.getInterface();

int config = dev.getConfiguration();

int xx=dev.hashCode();

System.out.println("Device pid : "+pid); //pid

System.out.println("Device vid : "+vid); //vid

System.out.println("Device psize : "+psize);

System.out.println("Device hashcode : "+xx);

System.out.println("Device Configuration : "+config); //配置信息

System.out.println("Device Altinterface : "+altinterface); // 备用接口

System.out.println("Device interface : "+interfac); //接口

dev.writeBulk(0x01, data, data.length, 1000, false);//写出去

dev.readBulk(0x81, readData, readData.length, 1000, false);

//System.out.println("ReadData value:"+readData.toString());

//dev.readInterrupt(0x81, readData, readData.length, 100000, true);

logData(readData);

dev.close();

} catch (USBException e){

e.printStackTrace();

dev.close();

}

}

private static boolean LogBus(){

boolean islogged =false;

try{

LibusbJava.usb_init();

LibusbJava.usb_find_busses();

LibusbJava.usb_find_devices();

// 检索设备

Usb_Bus bus = LibusbJava.usb_get_busses();

Utils.logBus(bus);

islogged=true;

}

catch(Exception e){

e.printStackTrace();

}

// 输出显示设备

return islogged;

}

public static void main(String[] args) throws USBException

{

boolean islog=LogBus();

if (islog)

{

ReadData();

}else

System.out.println("Is Bus Logged Succesfully :"+islog);

}

}

————————————————输出信息是

sb_Bus bus-0

Usb_Device \.libusb0-0001--0x093a-0x2510

Usb_Device_Descriptor idVendor: 0x93a, idProduct: 0x2510

Usb_Config_Descriptor bNumInterfaces: 0x1

Usb_Interface num_altsetting: 0x1

Usb_Interface_Descriptor bNumEndpoints: 0x1

Usb_Endpoint_Descriptor bEndpointAddress: 0x81

Usb_Device \.libusb0-0002--0x04f2-0x0112

Usb_Device_Descriptor idVendor: 0x4f2, idProduct: 0x112

Usb_Config_Descriptor bNumInterfaces: 0x1

Usb_Interface num_altsetting: 0x1

Usb_Interface_Descriptor bNumEndpoints: 0x1

Usb_Endpoint_Descriptor bEndpointAddress: 0x81

Usb_Device \.libusb0-0003--0x04f2-0x0112

Usb_Device_Descriptor idVendor: 0x4f2, idProduct: 0x112

Usb_Config_Descriptor bNumInterfaces: 0x1

Usb_Interface num_altsetting: 0x1

Usb_Interface_Descriptor bNumEndpoints: 0x1

Usb_Endpoint_Descriptor bEndpointAddress: 0x82

Usb_Device \.libusb0-0011--0x10c4-0xea60

Usb_Device_Descriptor idVendor: 0x10c4, idProduct: 0xea60

Usb_Config_Descriptor bNumInterfaces: 0x1

Usb_Interface num_altsetting: 0x1

Usb_Interface_Descriptor bNumEndpoints: 0x2

Usb_Endpoint_Descriptor bEndpointAddress: 0x81

Usb_Endpoint_Descriptor bEndpointAddress: 0x1

port open or not : true

Device pid : -5536

Device vid : 4292

Device psize : 64

Device hashcode : 19224790

Device Configuration : 1

Device Altinterface : -1

Device interface : 0

ch.ntb.usb.USBTimeoutException: LibusbJava.usb_bulk_write: libusb0-dll:err [_usb_reap_async] timeout error

at ch.ntb.usb.Device.writeBulk(Device.java:338)

at usb2.ca.ReadData(ca.java:47)

at usb2.ca.main(ca.java:85)

——————————————求吧里大神指导。。。。

最后

以上就是妩媚自行车为你收集整理的libusb java_求教usb的操作方法 关于 java.libusb-win32.jar包的问题的全部内容,希望文章能够帮你解决libusb java_求教usb的操作方法 关于 java.libusb-win32.jar包的问题所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部