Struct SerialPortSettings

Source
pub struct SerialPortSettings { /* private fields */ }
Expand description

Serial port settings

Implementations§

Source§

impl SerialPortSettings

Source

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}
Source

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}
Source

pub fn byte_size(self, byte_size: ByteSize) -> Self

Source

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}
Source

pub fn parity(self, parity: Parity) -> Self

Source

pub fn stop_bits(self, stop_bits: StopBits) -> Self

Source

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}
Source

pub fn set_blocking(self, blocking: bool) -> Self

Trait Implementations§

Source§

impl Clone for SerialPortSettings

Source§

fn clone(&self) -> SerialPortSettings

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SerialPortSettings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SerialPortSettings

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Ord for SerialPortSettings

Source§

fn cmp(&self, other: &SerialPortSettings) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SerialPortSettings

Source§

fn eq(&self, other: &SerialPortSettings) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SerialPortSettings

Source§

fn partial_cmp(&self, other: &SerialPortSettings) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for SerialPortSettings

Source§

impl Eq for SerialPortSettings

Source§

impl StructuralPartialEq for SerialPortSettings

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.