MCPcopy Index your code
hub / github.com/FrameworkComputer/inputmodule-rs / find_serialdevs

Function find_serialdevs

inputmodule-control/src/inputmodule.rs:102–151  ·  view source on GitHub ↗
(args: &crate::ClapCli, wait_for_device: bool)

Source from the content-addressed store, hash-verified

100}
101
102pub fn find_serialdevs(args: &crate::ClapCli, wait_for_device: bool) -> (Vec<String>, bool) {
103 let mut serialdevs: Vec<String>;
104 let mut waited = false;
105 loop {
106 let ports = serialport::available_ports().expect("No ports found!");
107 if args.list || args.verbose {
108 for p in &ports {
109 match &p.port_type {
110 SerialPortType::UsbPort(usbinfo) => {
111 println!("{}", p.port_name);
112 println!(" VID {:#06X}", usbinfo.vid);
113 println!(" PID {:#06X}", usbinfo.pid);
114 if let Some(sn) = &usbinfo.serial_number {
115 println!(" SN {}", sn);
116 }
117 if let Some(product) = &usbinfo.product {
118 // TODO: Seems to replace the spaces with underscore, not sure why
119 println!(" Product {}", product);
120 }
121 }
122 _ => {
123 //println!("{}", p.port_name);
124 //println!(" Unknown (PCI Port)");
125 }
126 }
127 }
128 }
129 serialdevs = match_serialdevs(
130 &ports,
131 &args.serial_dev,
132 args.command.as_ref().map(|x| x.to_pid()),
133 );
134 if serialdevs.is_empty() {
135 if wait_for_device {
136 // Waited at least once, that means the device was not present
137 // when the program started
138 waited = true;
139
140 // Try again after short wait
141 thread::sleep(Duration::from_millis(100));
142 continue;
143 } else {
144 return (vec![], waited);
145 }
146 } else {
147 break;
148 }
149 }
150 (serialdevs, waited)
151}
152
153/// Commands that interact with serial devices
154pub fn serial_commands(args: &crate::ClapCli) {

Callers 2

mainFunction · 0.85
serial_commandsFunction · 0.85

Calls 2

match_serialdevsFunction · 0.85
to_pidMethod · 0.80

Tested by

no test coverage detected