Skip to content

Instantly share code, notes, and snippets.

@C47D
Last active March 29, 2021 21:55
Show Gist options
  • Save C47D/15cbe7765b9119cb860fd07d56b36b26 to your computer and use it in GitHub Desktop.
Save C47D/15cbe7765b9119cb860fd07d56b36b26 to your computer and use it in GitHub Desktop.
[Rust lang] Read files and send it via serialport
use std::fs::File;
use std::io::prelude::*;
use serialport::available_ports;
fn main() {
let mut file = File::open("info.txt").expect("Can't open the file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Can't read file");
println!("File content: {}", contents);
let ports = available_ports().expect("No ports found");
for p in ports {
println!("{}", p.port_name);
}
}
@C47D
Copy link
Author

C47D commented Mar 29, 2021

> cargo run
Compiling test_files v0.1.0 (test_files)
warning: unused import: `serialport::available_ports`
--> src\main.rs:4:5
| 4 | use serialport::available_ports;
|     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
|= note: `#[warn(unused_imports)]` on by default                                                                                                                                                           warning: 1 warning emitted                                                                                                                                                                                      Finished dev [unoptimized + debuginfo] target(s) in 0.87s
Running `target\debug\test_files.exe`
File content: Hola                                                                                                                                                                                          

COM3
COM4
COM5
COM7
COM11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment