Recovering from keyboard disconnection

Christopher Stawarz's Avatar

Christopher Stawarz

10 Nov, 2021 03:18 PM

Hi Yasmine & Jack,

I've made some changes to MWorks' USBHID interface that should allow it to recover from device removal and reconnection (e.g. the spurious Bluetooth keyboard dropouts you've experienced) without requiring the experiment to be stopped or reloaded.

If the selected device is removed, MWorks will report the removal via an error message. For example:

ERROR: HID device "keyboard" was removed

This will happen irrespective of whether the experiment is currently running. If the device is subsequently reconnected, MWorks will report this, too, and indicate whether it was able to reestablish communication:

Attempting to reconnect to HID device "keyboard"...
HID device "keyboard" reconnected successfully

Again, this will happen even if the experiment isn't running. After a successful reconnection, I/O from the device will once again be received and handled as per usual.

Note that, in order for an actual USB device to be recognized correctly upon reconnection, it must be plugged in to the same USB port as before disconnection. For a Bluetooth keyboard or mouse, this shouldn't be an issue.

Also, I've observed that, after turning my Bluetooth keyboard off and back on to simulate disconnection, the device doesn't actually reconnect until I press a key on it. I don't know if this will be the case with spontaneous disconnects, but it's something to keep in mind.

These changes will be in tonight's nightly build.

Cheers,
Chris

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac