MacOSX: Accessing multiple interfaces of the same device at once

View: New views
5 Messages — Rating Filter:   Alert me  

MacOSX: Accessing multiple interfaces of the same device at once

by Emmanuel Blot-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I was wondering what is the recommended way, on Mac OS X (10.5/10.6),
to access multiple interfaces of the same device, from the same process ?

It seems that opening the same device twice or more is not allowed,
as the libusb_open() call silently fails:

The call sequence looks like the following:
usb_open
  libusb_open
    darwin_open
      USBDeviceOpenSeize

fails with the kIOReturnExclusiveAccess error.
darwin_open silently discards the error, and resume execution.

Then the following call sequence is executed to perform a USB reset

usb_control_msg
  libusb_control_transfer
    libusb_submit_transfer
      darwin_submit_transfer
        submit_control_transfer
          DeviceRequestAsyncTO

which fails with kIOUSBNoAsyncPortErr as the CreateDeviceAsyncEventSource()
never got called in the previous darwin_open() invokation.

So what would be the proper way to open a single device and use several
interfaces at once ?

Thanks in advance,
Manu

(using the latest libusb release, 1.0.4)

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libusb-devel mailing list
Libusb-devel@...
https://lists.sourceforge.net/lists/listinfo/libusb-devel

Re: MacOSX: Accessing multiple interfaces of the same device at once

by Peter Stuge-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Emmanuel Blot wrote:
> The call sequence looks like the following:
> usb_open
>   libusb_open
>     darwin_open
>       USBDeviceOpenSeize
>
> fails with the kIOReturnExclusiveAccess error.
> darwin_open silently discards the error, and resume execution.

That seems like a bug to me.


//Peter

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libusb-devel mailing list
Libusb-devel@...
https://lists.sourceforge.net/lists/listinfo/libusb-devel

Re: MacOSX: Accessing multiple interfaces of the same device at once

by Emmanuel Blot-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>> fails with the kIOReturnExclusiveAccess error.
>> darwin_open silently discards the error, and resume execution.
>
> That seems like a bug to me.

The silent error, or the exclusive access ?

The silent error is made on purpose, if I believe the comments:
"
 switch (kresult) {
    case kIOReturnExclusiveAccess:
      /* it is possible to perform some actions on a device that is
not open so do not return an error */
      priv->is_open = 0;
...
"

I'm a newbie in USB so I'm not sure how the stack is supposed to work:

Should the device be open once, and usb_claim_interface() called on
the same device for each requested interface, or should it be possible
to open the same device several times?

The USBDeviceOpenSeize does not seem to allow the latter case.

Maybe the 'Seize' call variant should be performed on the interface
(USBInterfaceOpenSeize) rather than on the device itself (in this
case, the device would be open with USBDeviceOpen rather than
USBDeviceOpenSeize)?

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libusb-devel mailing list
Libusb-devel@...
https://lists.sourceforge.net/lists/listinfo/libusb-devel

Re: MacOSX: Accessing multiple interfaces of the same device at once

by Nathan Hjelm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 12, 2009, at 7:28 AM, Emmanuel Blot wrote:

>>> fails with the kIOReturnExclusiveAccess error.
>>> darwin_open silently discards the error, and resume execution.
>>
>> That seems like a bug to me.
>
> The silent error, or the exclusive access ?
>
> The silent error is made on purpose, if I believe the comments:
> "
> switch (kresult) {
>    case kIOReturnExclusiveAccess:
>      /* it is possible to perform some actions on a device that is
> not open so do not return an error */
>      priv->is_open = 0;
> ...
> "

Yup. It is a feature, not a bug.

> I'm a newbie in USB so I'm not sure how the stack is supposed to work:
>
> Should the device be open once, and usb_claim_interface() called on
> the same device for each requested interface, or should it be possible
> to open the same device several times?

It should be possible to call open the device several times within the same process space (different threads). I did not write the backend with this case in mind and it is unsupported at this time. When I get the chance I will add support for multiple opens of the same device (sometime this week I hope).

> The USBDeviceOpenSeize does not seem to allow the latter case.
>
> Maybe the 'Seize' call variant should be performed on the interface
> (USBInterfaceOpenSeize) rather than on the device itself (in this
> case, the device would be open with USBDeviceOpen rather than
> USBDeviceOpenSeize)?
>

Nothing in the documentation suggests the Seize variant won't allow the device to be opened multiple times. From my understanding the Seize variant can claim devices which other programs/drivers are willing to release. If the other program is unwilling to release the device then the call behaves exactly like USBDeviceOpen. Note, libusb will not release a device on request from the OS.

-Nathan

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libusb-devel mailing list
Libusb-devel@...
https://lists.sourceforge.net/lists/listinfo/libusb-devel

Re: MacOSX: Accessing multiple interfaces of the same device at once

by Emmanuel Blot-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> It should be possible to call open the device several times within the same process space (different threads). I did not write the backend with this case in mind and it is unsupported at this time. When I get the chance I will add support for multiple opens of the same device (sometime this week I hope).

Ok, if you need some beta testers, I'm in.

Here is my use case:
I'm using FTDI devices (2232H, 4232H) which contain, to sum up, two
(four) identical UART/USRT USB-to-serial gateways. Each feature block
is driven with 2 endpoints (bulk-in, bulk-out), and all feature blocks
are independent from each others.

For now, as soon as a UART is open and used (usb_open,
usb_claim_interface, ...), any other attempt to open another UART
fails (which defeats the purpose of the multiple UARTs in a single
chip).

> Nothing in the documentation suggests the Seize variant won't allow the device to be opened multiple times. From my understanding the Seize variant can claim devices which other programs/drivers are willing to release. If the other program is unwilling to release the device then the call behaves exactly like USBDeviceOpen. Note, libusb will not release a device on request from the OS.

I did read the documentation too fast, /me bad.

Thanks,
Manu

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Libusb-devel mailing list
Libusb-devel@...
https://lists.sourceforge.net/lists/listinfo/libusb-devel