Skip to content

Use bus_id() instead of busnum() when constructing/matching on DeviceArg - #60

Open
dingari wants to merge 3 commits into
collabora:mainfrom
genkiinstruments:device-arg-bus-id
Open

Use bus_id() instead of busnum() when constructing/matching on DeviceArg#60
dingari wants to merge 3 commits into
collabora:mainfrom
genkiinstruments:device-arg-bus-id

Conversation

@dingari

@dingari dingari commented May 26, 2026

Copy link
Copy Markdown
Contributor

busnum() is only available on Linux. The cross-platform equivalent is bus_id().

  • Linux: String version of the busnum (e.g. "001")
  • MacOS: Top byte of the location ID (e.g. "01")
  • Windows: Unsure

In any case, it should be consistent with the output of the list command in the example.

…ching on DeviceArg

busnum() is only available on Linux. The cross-platform equivalent is
bus_id().

* Linux: String version of the busnum (e.g. \"001\")
* MacOS: Top byte of the location ID (e.g. \"01\")
* Windows: Unsure

In any case, it should be consistent with the output of the `list`
command  in the example

@sjoerdsimons sjoerdsimons left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes seems fine; If you could fix the libusb example so CI succeeds then this should be ready to merge

@dingari
dingari force-pushed the device-arg-bus-id branch from f053ba1 to 3db3a72 Compare June 16, 2026 22:21
.iter()
.find(|d| match d {
Ok(device) => {
device.bus_number() == dev.bus_number && device.address() == dev.address

@dingari dingari Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know which is better...

let bus_number = dev.bus_id.parse().unwrap();
device.bus_number() == bus_number && device.address() == dev.address

or

let bus_id = format!("{:03}", device.bus_number());
bus_id == dev.bus_id && device.address() == dev.address

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the examples’ device listing/selection logic to use bus_id() (a cross-platform identifier) instead of Linux-only busnum()/numeric bus numbers, aligning device selection with the output of the list command.

Changes:

  • Update rockusb (nusb) example to print and match devices using bus_id().
  • Update rockusb-libusb example to match against the new DeviceArg.bus_id.
  • Change CLI DeviceArg parsing from bus_number: u8 to bus_id: String.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
rockusb/examples/rockusb.rs Switches list output and device matching to bus_id() and prints VID/PID as hex.
rockusb/examples/rockusb-libusb.rs Updates device matching to compare against the new string-based bus_id.
rockusb/examples/common.rs Changes DeviceArg to store bus_id: String and updates parsing accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 35 to 37
devices
.find(|d| d.busnum() == dev.bus_number && d.device_address() == dev.address)
.find(|d| d.bus_id() == dev.bus_id && d.device_address() == dev.address)
.ok_or_else(|| anyhow!("Specified device not found"))?
Comment on lines 555 to 562
let mut parts = device.split(':');
let bus_number = parts
let bus_id = parts
.next()
.ok_or_else(|| anyhow!("No bus number: use <bus>:<address>"))?
.parse()
.map_err(|_| anyhow!("Bus should be a number"))?;
.ok_or_else(|| anyhow!("No bus id: use <bus>:<address>"))?
.to_string();
let address = parts
.next()
.ok_or_else(|| anyhow!("No address: use <bus>:<address>"))?
Comment on lines 32 to 43
devices
.iter()
.find(|d| match d {
Ok(device) => {
device.bus_number() == dev.bus_number && device.address() == dev.address
let bus_id = format!("{:03}", device.bus_number());
bus_id == dev.bus_id && device.address() == dev.address
}
Err(DeviceUnavalable { device, .. }) => {
device.bus_number() == dev.bus_number && device.address() == dev.address
let bus_id = format!("{:03}", device.bus_number());
bus_id == dev.bus_id && device.address() == dev.address
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants