Note: forwarded message attached.
                                 
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com

----- Message from amit deshpande <[EMAIL PROTECTED]> on Mon, 24 Oct 2005 23:29:04 -0700 (PDT) -----
To:
amit deshpande <[EMAIL PROTECTED]>
Subject:
Re: Fw: Help On USB Ports

Hi,
Iam using javax.usb package in my project i am little
bit stuck up here can i get help its urgent.the
problem is i detect usb ports on a pc,i detect usb
device to a port,i send some command to this device
but iam getin same command in return and not the data
which iam expecting.Can u help Here is my code .Iam
communicating
with a RFID feig reader through usb to serial
converter
device========================
import java.util.*;
import javax.usb.*;
import javax.usb.event.*;
import javax.usb.util.*;
import java.io.*;
public class detectusb
{

  UsbServices services = null;
  UsbHub virtualRootUsbHub = null;
  public static void main(String argv[])
  {
       try
       {
             detectusb d =new detectusb();
             UsbServices services =
UsbHostManager.getUsbServices();
             UsbHub rootHub =
services.getRootUsbHub();
             List ports=rootHub.getUsbPorts();
             for(int i=0;i<ports.size();i++)
             {
                               
System.out.println("port:"+ports.get(i));
             }
             d.traverse(rootHub);
             //System.out.println("after traverse");
         }
                 catch (Exception e) {}
  }


       public  void traverse(UsbDevice device)
   {
         if (device.isUsbHub())
 {
            List attachedDevices =
                ((UsbHub)
device).getAttachedUsbDevices();
            for (int i=0; i<attachedDevices.size();
i++)
            {
              traverse((UsbDevice)
attachedDevices.get(i));
            }
         }
         else
         {
               System.out.println("Device
found:"+device);
           
//System.out.println(device.getUsbDeviceDescriptor());
               communicate(device);
         }
      }

          public void communicate(UsbDevice device)
      {
           UsbConfiguration
config=device.getActiveUsbConfiguration();

           UsbInterface interf = null;
           UsbEndpoint endptIn = null;
           UsbEndpoint endptOut = null;
           UsbEndpoint ep = null;
           if(config!=null) // if conf is null get
the interface
           {
             
interf=config.getUsbInterface((byte)0);
               System.out.println("INTERFACE
FOUND:"+interf);
           }
           else
           {
               System.out.println("Error");
}

            try {
                       interf.claim(new policy()); //
if interface found claim that
                }
               catch (Exception ue)
               {
                   System.out.println("Exception of
claiming interface:"+ue);
               }

               List eps=interf.getUsbEndpoints();
//get the endpts of interface
               for(int j=0;j<eps.size();j++)
               {
                 ep = (UsbEndpoint)eps.get(j);
               //  System.out.println("End
point:"+ep);
                 int t=ep.getType();
                 //System.out.println("TYPE==="+t);
                 if(t == UsbConst.ENDPOINT_TYPE_BULK
&& ep.getDirection()==UsbConst.ENDPOINT_DIRECTION_IN )
//to read endpt direction should be IN
               {

                 endptIn = ep;
                 System.out.println("direction is IN"
+endptIn);
               }
               else{System.out.println("not found any
end pt");}
               }
               UsbPipe pipe=endptIn.getUsbPipe();
               System.out.println("PIPE:"+pipe);
               try
                {
                  pipe.open();
                }
catch (UsbException ue)
               {
                       System.out.println("pipe open
exception:"+ue.toString());
               }
               UsbIrp transfer=pipe.createUsbIrp();
byte [] buffer =
{0x07,(byte)0xFF,(byte)0xB0,0x01,0x00,(byte)0x1C,(byte)0x56};
       //      byte [] buffer =
{0x05,(byte)0xFF,(byte)0x65,(byte)0xE5,(byte)0xCB};
               //byte[] buffer = new
byte[UsbUtil.unsignedInt(pipe.getUsbEndpoint().getUsbEndpointDescriptor().wMaxPacketSize())];
               try
               {
               transfer.setData(buffer);
               //transfer.setLength(64);
               //transfer.setOffset(0);
               // transfer.complete();
               //transfer.waitUntilComplete();
               System.out.println("after setting
buffer::"+transfer.isComplete());
               }catch(Exception
e){System.out.println("exception of send command"+e);}

               try
               {
               byte[] data1=transfer.getData();
             
System.out.println("----GETLength-----:"+transfer.getLength());
               for(int i=0;i<data1.length;i++){
               System.out.println("received data"+
javax.usb.util.UsbUtil.toHexString(data1[i]));        
       }
               }catch(Exception
e){System.out.println("Exception in receiving
data"+e);}
      }
The output
is+++++++++++++++++++++++++++++++++++++++++++
port:[EMAIL PROTECTED]
port:[EMAIL PROTECTED]
port:[EMAIL PROTECTED]
port:[EMAIL PROTECTED]
Device found:[EMAIL PROTECTED]
INTERFACE FOUND:[EMAIL PROTECTED]
not found any end pt
not found any end pt
direction is [EMAIL PROTECTED]
PIPE:[EMAIL PROTECTED]
after setting buffer::false
----GETLength-----:7
received data07
received dataff
received datab0
received data01
received data00
received data1c
received data56
Thanks& Regards,
Amit D

--- amit deshpande <[EMAIL PROTECTED]> wrote:

> Hi,
> I just wanted to know one more thing I TRIED USING
> JUSB
> .But I was Unable even to run the simple basic code
> AS
> it started giving HostSupport Unavailable.
> Can u help.
> Regards ,
> Amit
>
> --- [EMAIL PROTECTED] wrote:
>
> >
> > Hello,
> >
> > You can send commands to your device using the
> > asyncSubmit and syncSubmbit
> > methods.  However maybe you are asking not _how_
> to
> > send commands but
> > _what_ commands to send?  In that case I can't
> help
> > you, the commands are
> > specific to your device's protocol which isn't
> part
> > of the USB spec.  You
> > need to get the specification for your device to
> > know how to talk to
> > it...many devices are "proprietary" and their
> > specification isn't publicly
> > available.  Your only choice then is to reverse
> > engineer the protocol by
> > "sniffing" the communication when an existing
> driver
> > is talking to the
> > device.
> >
> > You should also try joining the mailing list and
> > posting questions there.
> >
> > Thanks.
> >
> >
> >
> > > amit deshpande <[EMAIL PROTECTED]>
> > > 10/01/2005 06:50 AM                
> > >                  
> > >                  To
> > >                  [EMAIL PROTECTED]
> > >                  cc
> > >                  
> > >                  Subject
> > >                  Help On USB Ports
> > >                  
> > >                  
> > >                  
> > >                  
> > >                  
> > >
> > >
> > > Hi,
> > > i am trying to communicate with usb port using
> > > javax.usb,
> > > i have successfully implemented a code which
> > > continously monitors usb port for a device. My
> > > question i have detected a usb pen drive device
> > and
> > > opened pipe for communication.But how do i send
> > > commands to the port .Any Help would be
> > appreciated &
> > > Can it be done.
> > > Regards ,
> > > Amit
> > >
> > >
> > >      
> > > __________________________________
> > > Yahoo! Mail - PC Magazine Editors' Choice 2005
> > > http://mail.yahoo.com
> > >
> >
>
>
>
>                                  
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
>



                                 
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

Reply via email to