/
private static void ReadData() throws USBException
{
Device dev = USB.getDevice((short) 0x5131, (short) 0x2007);
try
{
byte[] readData = new byte[20];
// open the device with configuration 1, interface 0 and without
// altinterface
// this will initialise Libusb for you
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);
System.out.println("Device 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);
// retrieve a object tree representing the bus with its devices and
// descriptors
Usb_Bus bus = LibusbJava.usb_get_busses();
Utils.logBus(bus);
islogged=true;
}
catch(Exception e){
e.printStackTrace();
}
// log the bus structure to standard out
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);
}
OUTPUT
Usb_Bus bus-0
Usb_Device .\libusb0-0002--0x5131-0x2007
Usb_Device_Descriptor idVendor: 0x5131, idProduct: 0x2007
Usb_Config_Descriptor bNumInterfaces: 0x1
Usb_Interface num_altsetting: 0x1
Usb_Interface_Descriptor bNumEndpoints: 0x2
Usb_Endpoint_Descriptor bEndpointAddress: 0x82
Usb_Endpoint_Descriptor bEndpointAddress: 0x2
Usb_Device .\libusb0-0003--0x5131-0x2007
Usb_Device_Descriptor idVendor: 0x5131, idProduct: 0x2007
Usb_Config_Descriptor bNumInterfaces: 0x1
Usb_Interface num_altsetting: 0x1
Usb_Interface_Descriptor bNumEndpoints: 0x1
Usb_Endpoint_Descriptor bEndpointAddress: 0x81
port open or not : true
Device pid : 8199
Device vid : 20785
Device psize : 64
Device hashcode : 216072924
Device Configuration : 1
Device Altinterface : -1
Device interface : 0
ch.ntb.usb.USBTimeoutException: LibusbJava.usb_bulk_read: libusb0-dll:err [_usb_reap_async] reaping request failed, win error: The I/O operation has been aborted because of either a thread exit or an application request.
at ch.ntb.usb.Device.readBulk(Device.java:398)
at TestCardReadingClass.ReadData(TestCardReadingClass.java:63)
at TestCardReadingClass.main(TestCardReadingClass.java:114)
}
Thanks in advance.....
Last edit: bhuvan 2013-02-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 TestCardReadingClass
{
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();
}
/
@param args
* @throws USBException
/
private static void ReadData() throws USBException
{
Device dev = USB.getDevice((short) 0x5131, (short) 0x2007);
try
{
byte[] readData = new byte[20];
// open the device with configuration 1, interface 0 and without
// altinterface
// this will initialise Libusb for you
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);
System.out.println("Device 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);
} catch (USBException e)
{
// if an exception occures during connect or read/write an exception
// is thrown
}
}
private static boolean LogBus(){
boolean islogged =false;
try{
LibusbJava.usb_init();
LibusbJava.usb_find_busses();
LibusbJava.usb_find_devices();
// retrieve a object tree representing the bus with its devices and
// descriptors
Usb_Bus bus = LibusbJava.usb_get_busses();
Utils.logBus(bus);
islogged=true;
}
catch(Exception e){
e.printStackTrace();
}
// log the bus structure to standard out
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);
}
OUTPUT
Usb_Bus bus-0
Usb_Device .\libusb0-0002--0x5131-0x2007
Usb_Device_Descriptor idVendor: 0x5131, idProduct: 0x2007
Usb_Config_Descriptor bNumInterfaces: 0x1
Usb_Interface num_altsetting: 0x1
Usb_Interface_Descriptor bNumEndpoints: 0x2
Usb_Endpoint_Descriptor bEndpointAddress: 0x82
Usb_Endpoint_Descriptor bEndpointAddress: 0x2
Usb_Device .\libusb0-0003--0x5131-0x2007
Usb_Device_Descriptor idVendor: 0x5131, idProduct: 0x2007
Usb_Config_Descriptor bNumInterfaces: 0x1
Usb_Interface num_altsetting: 0x1
Usb_Interface_Descriptor bNumEndpoints: 0x1
Usb_Endpoint_Descriptor bEndpointAddress: 0x81
port open or not : true
Device pid : 8199
Device vid : 20785
Device psize : 64
Device hashcode : 216072924
Device Configuration : 1
Device Altinterface : -1
Device interface : 0
ch.ntb.usb.USBTimeoutException: LibusbJava.usb_bulk_read: libusb0-dll:err [_usb_reap_async] reaping request failed, win error: The I/O operation has been aborted because of either a thread exit or an application request.
at ch.ntb.usb.Device.readBulk(Device.java:398)
at TestCardReadingClass.ReadData(TestCardReadingClass.java:63)
at TestCardReadingClass.main(TestCardReadingClass.java:114)
}
Thanks in advance.....
Last edit: bhuvan 2013-02-14