use lager::{LagerBox, UsbDeviceFilter};use std::time::{Duration, Instant};let lager = LagerBox::from_env()?;let port = lager.usb("usb3");port.disable()?;std::thread::sleep(Duration::from_millis(500));port.enable()?;// Poll the bus until the DUT reappears. usb_devices() is cheap and takes no// exclusive access, so this loop is safe.let filter = UsbDeviceFilter { vid: Some("0483".into()), ..Default::default() };let deadline = Instant::now() + Duration::from_secs(10);loop { if !lager.usb_devices_matching(&filter)?.is_empty() { break; } assert!(Instant::now() < deadline, "DUT did not re-enumerate"); std::thread::sleep(Duration::from_millis(200));}
在 Plugable 扩展坞上,已断电端口上的设备在供电恢复之前仍然列在总线上。于是上面那个循环可能立刻匹配到旧条目,而被测设备其实还没有重新枚举。在 Plugable 扩展坞上,请用 CLI 的 lager usb NET cycle,它会等待集线器报告重新连接。