From fa9e9319c23f9a028aedfbd569a83b72ac4807f7 Mon Sep 17 00:00:00 2001 From: oopsbagel Date: Thu, 3 Apr 2025 16:07:54 -0700 Subject: [PATCH] fix(serial.enable_command_mode): claim usb device interface Windows does not support nusb::Device.control_out_blocking Claim the interface before writing as required on Windows. --- serial/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/serial/src/main.rs b/serial/src/main.rs index 115b614..812a499 100644 --- a/serial/src/main.rs +++ b/serial/src/main.rs @@ -107,7 +107,7 @@ fn enable_command_mode() -> Result<()> { let timeout = Duration::from_secs(1); - if let Some(interface) = open_device(0x05c6, 0xf626)? { + if let Some(device) = open_device(0x05c6, 0xf626)? { let enable_command_mode = Control { control_type: ControlType::Vendor, recipient: Recipient::Device, @@ -115,6 +115,9 @@ fn enable_command_mode() -> Result<()> { value: 0, index: 0, }; + let interface = device + .detach_and_claim_interface(1) + .context("detach_and_claim_interface(1) failed")?; if let Err(e) = interface.control_out_blocking(enable_command_mode, &[], timeout) { // If the device reboots while the command is still executing we // may get a pipe error here