pub struct SerialPortSettings { /* private fields */ }
Expand description
Serial port settings
Implementations§
Source§impl SerialPortSettings
impl SerialPortSettings
Sourcepub fn baud(self, baud: u32) -> Self
pub fn baud(self, baud: u32) -> Self
Set baud rate
Examples found in repository?
examples/port_list.rs (line 46)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
Sourcepub fn read_timeout(self, timeout: Option<u128>) -> Self
pub fn read_timeout(self, timeout: Option<u128>) -> Self
Examples found in repository?
examples/port_list.rs (line 47)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
pub fn byte_size(self, byte_size: ByteSize) -> Self
Sourcepub fn write_timeout(self, timeout: Option<u128>) -> Self
pub fn write_timeout(self, timeout: Option<u128>) -> Self
Examples found in repository?
examples/port_list.rs (line 48)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
pub fn parity(self, parity: Parity) -> Self
pub fn stop_bits(self, stop_bits: StopBits) -> Self
Sourcepub fn set_flow_control(self, method: FlowControl) -> Self
pub fn set_flow_control(self, method: FlowControl) -> Self
Examples found in repository?
examples/port_list.rs (line 49)
11fn main() {
12
13 #[cfg(windows)]
14 {
15 let mut scanner = port_lister::COMPortLister{};
16 for port in scanner.list_devices().unwrap() {
17 println!("Found port:");
18 println!("\tPort: {}", port.get_port());
19 println!("\tDescription: {}", port.get_desc());
20 println!("\tManufacturer: {}", port.get_manufacturer());
21 }
22 }
23
24 #[cfg(unix)]
25 {
26 let mut scanner = port_lister::TTYPortScanner{};
27 for port in scanner.list_devices().unwrap() {
28 println!("Found port:");
29 println!("\tPort: {}", port.get_port());
30 println!("\tDescription: {}", port.get_desc());
31 println!("\tManufacturer: {}", port.get_manufacturer());
32 }
33 }
34
35 #[cfg(windows)]
36 let p = COMPort::new("COM7".into(), Some(
37 SerialPortSettings::default()
38 .baud(115200)
39 .read_timeout(Some(100))
40 .write_timeout(Some(100))
41 .set_flow_control(FlowControl::None)
42 ));
43 #[cfg(unix)]
44 let p = TTYPort::new("/dev/ttyUSB0".into(), Some(
45 SerialPortSettings::default()
46 .baud(115200)
47 .read_timeout(Some(100))
48 .write_timeout(Some(100))
49 .set_flow_control(FlowControl::None)
50 ));
51 match p {
52 Ok(mut port) => {
53 let clone_r = port.try_clone().unwrap();
54 let mut clone_w = port.try_clone().unwrap();
55 println!("Port open OK!");
56 let test_msg: &[u8] = "#07E11092\n".as_bytes();
57 let mut buf_reader = BufReader::new(clone_r);
58 let mut b = String::new();
59 loop {
60 if buf_reader.read_line(&mut b).is_ok() {
61 print!("IN : {}", b);
62 b.clear();
63 println!("OUT: {:02X?}", test_msg);
64 if let Err(e) = clone_w.write(test_msg) {
65 eprintln!("Write error {}", e)
66 }
67 } else {
68 std::thread::sleep(std::time::Duration::from_millis(50));
69 }
70 }
71 },
72 Err(e) => {
73 eprintln!("Cannot open com port {}", e)
74 }
75 }
76}
pub fn set_blocking(self, blocking: bool) -> Self
Trait Implementations§
Source§impl Clone for SerialPortSettings
impl Clone for SerialPortSettings
Source§fn clone(&self) -> SerialPortSettings
fn clone(&self) -> SerialPortSettings
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SerialPortSettings
impl Debug for SerialPortSettings
Source§impl Default for SerialPortSettings
impl Default for SerialPortSettings
Source§impl Ord for SerialPortSettings
impl Ord for SerialPortSettings
Source§fn cmp(&self, other: &SerialPortSettings) -> Ordering
fn cmp(&self, other: &SerialPortSettings) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for SerialPortSettings
impl PartialEq for SerialPortSettings
Source§impl PartialOrd for SerialPortSettings
impl PartialOrd for SerialPortSettings
impl Copy for SerialPortSettings
impl Eq for SerialPortSettings
impl StructuralPartialEq for SerialPortSettings
Auto Trait Implementations§
impl Freeze for SerialPortSettings
impl RefUnwindSafe for SerialPortSettings
impl Send for SerialPortSettings
impl Sync for SerialPortSettings
impl Unpin for SerialPortSettings
impl UnwindSafe for SerialPortSettings
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more