Hi Guys
Iam Using Operating System UBUNTU 9.05
MY PC is 32 BIT.
I also logged in as root in my system.
Iam using following standard I/o code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import com.ibm.jusb.*;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;
import javax.usb.*;
import javax.usb.event.UsbPipeListener;
import java.util.List;
public class USBIO {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{// Access the system USB services, and access to the root
// hub. Then traverse through the root hub.
System.out.println("Application started");
UsbServices services = UsbHostManager.getUsbServices();
UsbHub rootHub = services.getRootUsbHub();
System.out.println("The root hub: "+rootHub);
System.out.println("The Root hub status"+rootHub.isRootUsbHub());
System.out.println("The Root Configured
status"+rootHub.isConfigured());
traverse(rootHub);
//listDevices(rootHub);
boolean isLinux = isUnix();
} catch (Exception e) {
System.out.println("The Exception occured"+e.getMessage());
}
}
public static void traverse(UsbDevice device) throws
UnsupportedEncodingException, UsbDisconnectedException, UsbException
{
System.out.println("Iam in traverse");
if (device.isUsbHub())
{
// This is a USB Hub, traverse through the hub.
System.out.println("The device is a HUB");
List attachedDevices = ((UsbHub)
device).getAttachedUsbDevices();
System.out.println("The attached devices size is
"+attachedDevices.size());
//System.out.println("The Manufacturer
String"+device.getManufacturerString());
for (int i=0; i<attachedDevices.size(); i++)
{
System.out.println("The Manufacturer
String"+device.getManufacturerString());
traverse((UsbDevice) attachedDevices.get(i));
}
}
else
{
System.out.println("Iam in else traverse ");
// This is a USB function, not a hub.
if("USBest Technology".equals(device.getManufacturerString()))
{
//testIO(device);
}
}
}
public static void testIO(UsbDevice device) throws UsbClaimException,
UsbNotActiveException, UsbDisconnectedException, UsbException{
System.out.println("Iam in testIo");
try
{
// Access to the active configuration of the USB device,
obtain
// all the interfaces available in that configuration.
UsbConfiguration config = device.getActiveUsbConfiguration();
if(config !=null)
{
System.out.println("The Configuration String:
"+config.getConfigurationString());
UsbConfigurationDescriptor
objdescp=config.getUsbConfigurationDescriptor();
if(objdescp!=null)
{
System.out.println("The iConfiguration:
"+objdescp.iConfiguration());
System.out.println("The Configuration Value:
"+objdescp.bConfigurationValue());
System.out.println("The Descriptor type:
"+objdescp.bDescriptorType());
System.out.println("The Decrriptor:
"+objdescp.bLength());
System.out.println("The Attributes:
"+objdescp.bmAttributes());
System.out.println("The Maxium power:
"+objdescp.bMaxPower());
System.out.println("The number interfaces:
"+objdescp.bNumInterfaces());
}
}
List totalInterfaces = config.getUsbInterfaces();
// Traverse through all the interfaces, and access the
endpoints
// available to that interface for I/O.
System.out.println("The Total interface size:
"+totalInterfaces.size());
for (int i=0; i<totalInterfaces.size(); i++)
{
UsbInterface interf = (UsbInterface)
totalInterfaces.get(i);
UsbInterfacePolicy uiP = new UsbInterfacePolicy()
{
public boolean forceClaim()
{
return true;
}
@Override
public boolean forceClaim(UsbInterface usbInterface) {
// TODO Auto-generated method stub
return true;
}
};
if(interf.isClaimed())
{
System.out.println("This Devoice Is Claimed");
interf.claim(uiP);
}
else
{
interf.claim();
}
if(interf!=null)
{
System.out.println("The Interface string:
"+interf.getInterfaceString());
System.out.println("The Active settting number:
"+interf.getActiveSettingNumber());
System.out.println("The Number Setting:
"+interf.getNumSettings());
System.out.println("The Active Setting:
"+interf.getActiveSetting());
}
List totalEndpoints = interf.getUsbEndpoints();
System.out.println("**************The endpoints
size:"+totalEndpoints.size());
for (int j=0; j<totalEndpoints.size(); j++)
{
// Access the particular endpoint, determine the
direction
// of its data flow, and type of data transfer, and
open the
// data pipe for I/O.
UsbEndpoint ep = (UsbEndpoint) totalEndpoints.get(i);
int direction = ep.getDirection();
int type = ep.getType();
System.out.println("Endpoint direction
:"+direction+"Endpoint type: "+type);
UsbPipe pipe = ep.getUsbPipe();
UsbIrp irp=pipe.createUsbIrp();
byte[] input=new byte[64];
System.out.println("Pipe Status : " + pipe.isOpen());
int offsetd =irp.getOffset();
int dataLength =irp.getLength();
irp.setData(input,offsetd,dataLength);
System.out.println("Offset :"+offsetd+"DataLength:
"+dataLength+"The actual length : "+irp.getActualLength());
pipe.open();
// Perform I/O through the USB pipe here.
System.out.println("pipe read start\n");
int loop=0;
outer:while (true) {
loop++;
System.out.println("loop= "+loop);
pipe.syncSubmit(irp);
System.out.println("input 0= "+input[0]);
System.out.println("input 1= "+input[1]);
if (loop==10)
break outer;
irp.setComplete(false);
}
System.out.println("pipe read end\n");
pipe.abortAllSubmissions();
pipe.close();
}
interf.release();
}
} catch (Exception e)
{
System.out.println("Exception occured:"+e.getMessage());
e.printStackTrace();
}
}
public static void listDevices(UsbHub hub) {
List devices = hub.getAttachedUsbDevices( );
System.out.println("The attached device size: "+devices.size());
Iterator iterator = devices.iterator( );
while (iterator.hasNext( )) {
UsbDevice device = (UsbDevice) iterator.next( );
System.out.println(device);
if (device.isUsbHub( )) {
listDevices((UsbHub) device);
}
}
}
public static boolean isUnix(){
String os = System.getProperty("os.name").toLowerCase();
//linux or unix
System.out.println("The Operating System is"+os);
return (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0);
}
}
_________________________________________________________________________________________________________________
But it shows me the Attached device size as 0.
but when i execute above same code on other Linux machine
Who's OS is fedora core 9
and it is also 32 bit.
iam getting the appropriate list of the attached devices.
so what the extra setting i have to do for UBUNTU so that above code works
fine.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
javax-usb-devel mailing list
javax-usb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel