Hi maybe anyone can read he garmin sdk :
http://www8.garmin.com/support/pdf/IOSDK.zip

I don't know what I do wrong but I only get zeros :(

Here is my Code:

public void IODevices(UsbDevice device){
        try{
                device.getActiveUsbConfiguration();
                UsbConfiguration config = device.getActiveUsbConfiguration();
                UsbInterface interf = config.getUsbInterface((byte)0);
                interf.claim(new UsbInterfacePolicy() {
                        public boolean forceClaim(UsbInterface usbInterface) {
                                return true;
                        }
                });
                List totalEndpoints = interf.getUsbEndpoints();
                UsbEndpoint ep = null;
//Endpoints
                UsbEndpoint pipeInEndP = (UsbEndpoint) totalEndpoints.get(0);
                UsbEndpoint pipeOutEndP = (UsbEndpoint) totalEndpoints.get(2);
                                
                //Pipes
                UsbPipe pipeIn = pipeInEndP.getUsbPipe();
                pipeIn.open();
                UsbPipe pipeOut = pipeOutEndP.getUsbPipe();
                pipeOut.open();

                short mReserved2 = 0;
                short mPacketId = 254;
                int mDataSize = 0;
                byte[] bytesToSend = new byte[12];
                bytesToSend[0] = 20;
                bytesToSend[1] = 0;
                bytesToSend[2] = (byte) (mReserved2 & 0xFF); //Short to Byte
                bytesToSend[3] = (byte) ((mReserved2 & 0xff00 ) >> 8); //Short 
to Byte
                bytesToSend[4] = (byte) (mPacketId & 0xFF); //Short to Byte
                bytesToSend[5] = (byte) ((mPacketId & 0xff00 ) >> 8); //Short 
to Byte
                bytesToSend[6] = (byte) (mReserved2 & 0xFF); //Short to Byte
                bytesToSend[7] = (byte) ((mReserved2 & 0xff00 ) >> 8); //Short 
to Byte
                bytesToSend[8] = (byte) (mDataSize >>24); //unsigned long to 
Byte
                BytesToSend[9] = (byte) ((mDataSize << 8) >> 24);
                BytesToSend[10] = (byte) ((mDataSize << 16) >> 24);
                bytesToSend[11] = (byte) ((mDataSize << 24) >> 24);
                                
                UsbIrp irpSend = pipeOut.createUsbIrp();
                IrpSend.setData(bytesToSend);
                pipeOut.asyncSubmit(irpSend);
                irpSend.waitUntilComplete(1000);
                                
                byte[] bytesToRead = new byte[255];
                UsbIrp irpRead = pipeIn.createUsbIrp();
                irpRead.setData(bytesToRead);
                pipeIn.asyncSubmit(irpRead);
                irpRead.waitUntilComplete(1000);
                pipeIn.abortAllSubmissions();
                pipeOut.abortAllSubmissions();
                pipeIn.close();
                pipeOut.close();
                interf.release();
                                
                int pid,sv;
                pid =(bytesToRead[0] & 0xff);
                sv =(bytesToRead[1] & 0xff);
                pid= bytes_to_int(bytesToRead);
                sv= bytes_to_int(bytesToRead, 4);
                System.out.println("pid: " + pid + "; sv: " + sv);
                                
                System.out.println(bytesToRead);
        }catch(Exception ex){
                ex.printStackTrace();
        }               
}

int bytes_to_int(byte b[], int start) {
        int i = ((b[start + 3] & 0xff) << 24) + ((b[start + 2] & 0xff) << 16) +
((b[start + 1] & 0xff) << 8) + (b[start] & 0xff);
                   return i;
}
int bytes_to_int(byte b[]) {
                    /* as above, but start == 0 */
                    return bytes_to_int(b, 0);
}


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
javax-usb-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to