Skip to content
Snippets Groups Projects
Commit 572e90ca authored by Federico Lolli's avatar Federico Lolli
Browse files

removed comments

parent 725917aa
No related branches found
No related tags found
No related merge requests found
//! Duplex example
//!
//! This example tests the ability to clone a serial port. It works by creating
//! a new file descriptor, and therefore a new `SerialPort` object that's safe
//! to send to a new thread.
//!
//! This example selects the first port on the system, clones the port into a child
//! thread that writes data to the port every second. While this is running the parent
//! thread continually reads from the port.
//!
//! To test this, have a physical or virtual loopback device connected as the
//! only port in the system.
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::time::Duration; use std::time::Duration;
use std::{io, thread}; use std::{io, thread};
fn main() { fn main() {
// let mut s = String::new();
// let mut f = std::fs::File::open("mavlink.csv").expect("Unable to open file");
// f.read_to_string(&mut s).expect("Unable to read string");
// let values = s
// .trim()
// .split(',')
// .map(|s| s.parse::<f64>().unwrap())
// .collect::<Vec<_>>();
// dbg!(&values);
// Open the first serialport available. // Open the first serialport available.
let port_name = "/dev/tty.usbmodem143203"; let port_name = "/dev/tty.usbmodem143203";
let mut port = serialport::new(port_name, 115200) let mut port = serialport::new(port_name, 115200)
...@@ -46,17 +22,6 @@ fn main() { ...@@ -46,17 +22,6 @@ fn main() {
} }
mavlink_buffer[152..158].fill(100u8); mavlink_buffer[152..158].fill(100u8);
// mavlink_buffer[158] = b'\n';
// let mut send_buffer = [0u8; 316];
// for i in 0..316 {
// if i % 2 == 0 {
// send_buffer[i] = mavlink_buffer[i / 2];
// } else {
// send_buffer[i] = b'\n';
// }
// }
clone clone
// .write_all(&send_buffer) // .write_all(&send_buffer)
.write_all(&mavlink_buffer) .write_all(&mavlink_buffer)
...@@ -69,14 +34,6 @@ fn main() { ...@@ -69,14 +34,6 @@ fn main() {
match port.read(&mut buffer) { match port.read(&mut buffer) {
Ok(t) => { Ok(t) => {
io::stdout().write_all(&buffer[..t]).unwrap(); io::stdout().write_all(&buffer[..t]).unwrap();
// let mut read = 0;
// for chunk in buffer[..bytes].chunks(4) {
// read += 4;
// let mut utfbuf = [0u8; 4];
// utfbuf[0..chunk.len()].copy_from_slice(chunk);
// let value = String::from_utf8_lossy(&utfbuf);
// print!("{}", value);
// }
} }
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (), Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
Err(e) => eprintln!("{:?}", e), Err(e) => eprintln!("{:?}", e),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment