mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-25 15:16:53 +01:00
port listing
This commit is contained in:
parent
999dd244c7
commit
98f37af879
@ -1,7 +1,7 @@
|
||||
pub struct DeviceInfo {
|
||||
pub port: String,
|
||||
pub description: String,
|
||||
pub serial: String,
|
||||
pub port: String,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
@ -97,15 +97,23 @@ impl Wrapper {
|
||||
)
|
||||
};
|
||||
|
||||
let description = unsafe { std::ffi::CStr::from_ptr(description.as_ptr()) }
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
let serial = unsafe { std::ffi::CStr::from_ptr(serial.as_ptr()) }
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
let port = if list.binary_search_by(|d| d.serial.cmp(&serial)).is_ok() {
|
||||
format!("i:0x{vendor:04X}:0x{product:04X}:{index}")
|
||||
} else {
|
||||
format!("s:0x{vendor:04X}:0x{product:04X}:{serial}")
|
||||
};
|
||||
|
||||
if result == 0 {
|
||||
list.push(DeviceInfo {
|
||||
port: format!("i:0x{vendor:04X}:0x{product:04X}:{index}"),
|
||||
description: unsafe { std::ffi::CStr::from_ptr(description.as_ptr()) }
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
serial: unsafe { std::ffi::CStr::from_ptr(serial.as_ptr()) }
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
description,
|
||||
serial,
|
||||
port,
|
||||
});
|
||||
}
|
||||
|
||||
@ -113,6 +121,8 @@ impl Wrapper {
|
||||
index += 1;
|
||||
}
|
||||
|
||||
list.sort_by(|a, b| a.serial.cmp(&b.serial));
|
||||
|
||||
Ok(list)
|
||||
} else {
|
||||
match devices {
|
||||
|
@ -1,7 +1,7 @@
|
||||
pub struct DeviceInfo {
|
||||
pub port: String,
|
||||
pub description: String,
|
||||
pub serial: String,
|
||||
pub port: String,
|
||||
}
|
||||
|
||||
pub struct SerialDevice {
|
||||
@ -43,14 +43,16 @@ impl SerialDevice {
|
||||
if let serialport::SerialPortType::UsbPort(info) = port.port_type {
|
||||
if info.vid == vendor && info.pid == product {
|
||||
devices.push(DeviceInfo {
|
||||
port: port.port_name,
|
||||
description: info.product.unwrap_or_default(),
|
||||
serial: info.serial_number.unwrap_or_default(),
|
||||
port: port.port_name,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
devices.sort_by(|a, b| a.serial.cmp(&b.serial));
|
||||
|
||||
Ok(devices)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user