Here is an abbreviated example. Note that I have removed from this, all 
checks, error handling, and such.
It is just the logic of creating two pipes for two endpoints. One IN and 
one OUT. Then using them to do a write and a read.
It assumes that endpoint 2 is an OUT and endpoint 4 is an IN.
Note also that the name of an IN endpoint is OR'd with 0x80:
--------------------------------------------------------------------------

import javax.usb.*;

public class Example {

  public static void main(String[] args) throws Exception {
    UsbDevice usbDevice = ...getUsbDevice by matching vID, pID, knowing 
the path... or whatever works for you...
    usbDevice.getUsbConfigurations();
    UsbConfiguration config = usbDevice.getActiveUsbConfiguration();
    UsbInterface xface = config.getUsbInterface((byte)0);
    xface.claim();

    UsbEndpoint endPt2 = xface.getUsbEndpoint((byte)2);            //OUT 
endpoint
    UsbEndpoint endPt4 = xface.getUsbEndpoint((byte)(4  | 0x80) ); //IN 
endpoint

    UsbPipe pipe2 = endPt2.getUsbPipe();
    pipe2.open();
    UsbPipe pipe4 = endPt4.getUsbPipe();
    pipe4.open();
   
    //Use the pipes:
    byte[] bytesToSend = new byte[] {1,2,3}; //Going to send out these 3 
bytes
    UsbIrp irpSend = pipe2.createUsbIrp();
    irpSend.setData(bytesToSend);
    pipe2.asyncSubmit(irpSend); //Send out some bytes
    irpSend.waitUntilComplete(1000); //Wait up to 1 second

    byte[] bytesToRead = new byte[3]; //Going to read 3 bytes into here
    UsbIrp irpRead = pipe2.createUsbIrp();
    irpRead.setData(bytesToRead);
    pipe4.asyncSubmit(irpRead); //Read some bytes
    irpRead.waitUntilComplete(1000); //Wait up to 1 second
  }
}
--------------------------------------------------------------------------


Xie, Ric wrote:
> I know what you said. One endpoint with one pipe. I just want to know how to 
> open two pipes of two endpoints in the same time. So I can receive and send 
> data synchronously.
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL 
> PROTECTED]
> Sent: Saturday, December 15, 2007 2:43 AM
> To: javax-usb-devel@lists.sourceforge.net
> Subject: Re: [javax-usb-devel] how to read while writing with the usbPipe!
>
>
> You can only open one pipe on a given endpoint. That pipe has to be either an 
> IN or an OUT, depending on how that endpoint is defined. To do IN and OUT, 
> you need two separate endpoints.
>
>
> ---- "Xie wrote:
>   
>> Dan,
>>
>> I have been trapped in a problem recently. That is, when I use an USBPipe of 
>> BULK-OUT type to write something to the device, how can I read some reply 
>> from the device?
>>
>> I tried to open an usbpipe of BULK-IN type, but I got an exception said that 
>> it cannot open two usbpipes.
>>
>> However, if I close the out usbpipe, the data transferring will be 
>> interrupted, which will cause an error.
>>
>> So what's your opinion? And is there a way to read from and write to the 
>> device in the same time?
>>
>> Or, how to tell the device that the data transferring is not over when the 
>> usbpipe is closed?
>>
>> In additional, another question: when I use "UsbPipe.syncSubmit(buffer);", 
>> how can I know that the all the submissions are over and the UsbPipe can be 
>> closed? (Sometimes when close the pipe, I get an exception that cannot close 
>> the pipe because there are some pending submissions)
>>
>> Thanks.
>> Yours,
>> Sincerely,
>> Ric
>> Best Regards!
>>     


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
javax-usb-devel mailing list
javax-usb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/javax-usb-devel

Reply via email to