NullMember / maxhidapi

Max MSP wrapper for the hidapi: cross platform USB and BLE HID API
MIT License
2 stars 0 forks source link

Connecting with vendor and product ID does not work via Bluetooth #1

Open zetenynagy opened 3 years ago

zetenynagy commented 3 years ago

I'm trying to connect to a DualShock 4 via an "open vendor-id product-id" message. When doing so via USB, everything works perfectly. If I try the same message when the controller is connected via Bluetooth, I get an "open -1" error. The "enumerate" message tells me that the vendor and product ID-s stay the same regardless of the connection type.

Is this an actual issue, or am I just missing something?

zetenynagy commented 3 years ago

Also, Max's CPU usage hits 100% when sending a "read 128" message every 10 milliseconds. Is that normal?

NullMember commented 3 years ago

I'm trying to connect to a DualShock 4 via an "open vendor-id product-id" message. When doing so via USB, everything works perfectly. If I try the same message when the controller is connected via Bluetooth, I get an "open -1" error. The "enumerate" message tells me that the vendor and product ID-s stay the same regardless of the connection type.

Is this an actual issue, or am I just missing something?

I think I was not tested "open vendor-id product-id" for bluetooth devices. I'm always using "open vendor-id product-id serial-number" for them. Could you try using serial-number or index option? Maybe It's how hidapi work, I don't know. Sorry.

Also, Max's CPU usage hits 100% when sending a "read 128" message every 10 milliseconds. Is that normal?

No, it's not normal. When you open a device, maxhidapi will set set_nonblocking to 1. Nonblocking setting make sure object will not wait next message from connected device. Because, if device do not send any message max will wait that message forever. Same rule applies for devices who sending message but slower than expected. If you request a message every 10 ms but device send messages in 20 ms period max will wait 10 ms for every message. This will lock cpu resources for 10 ms frame (and probably crash application to free these resources but sometimes not). Maybe (because of bug in maxhidapi or hidapi itself) opening a device will not set nonblocking to 1. Please try to set nonblocking to 1 after connecting to device.

zetenynagy commented 3 years ago

Thanks for responding!

Could you try using serial-number or index option?

Well, I could, but my patcher is supposed to work with any connected controller, and the serial number is unique to the one I own. So if someone else tries my patcher, the serial numbers won't match. I'm looking for a universal solution, if possible. I'll try the serial number or index solution later today.

Same rule applies for devices who sending message but slower than expected.

This device sends messages faster than every 10ms. When using Max's built-in [hi] object and polling every 10ms, CPU usage is normal, 3-5%. I'll try manually setting nonblocking to 1 later today.

zetenynagy commented 3 years ago

Update:

Problems on Bluetooth:

If I use the serial number I get from the enumerate command, "open vendor-id product-id serial-number" does not work, results in error.

If I use the index I get from the enumerate command, "open index" works, but "read" command does not output any values at all, no matter the parameters.

If I use get_serial_number_string after "open index", I get a different serial number than the one that is displayed when using enumerate.

If I use the different serial number I got from get_serial_number_string, "open vendor-id product-id serial-number" still does not work, still results in error.

Problems on USB:

Manually setting nonblocking to either 1 or 0 does not change anything. CPU usage is still the same, 50-100%. Max didn't crash, no matter how many times I set nonblocking to 1 or 0.

Also, there is some latency (around 250ms) that isn't present with [hi].