Skip to content

Commit

Permalink
Add Mark and Space variants to Parity enum
Browse files Browse the repository at this point in the history
  • Loading branch information
YgorSouza committed May 15, 2024
1 parent c320919 commit b20e1c4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](https://semver.org/).
### Added
* Added conversions between `DataBits`, `StopBits` types and their numeric representations
* Added `FromStr` implementation for `FlowControl`
* Added `Mark` and `Space` variants to `Parity` enum
### Changed
### Fixed
* Fixes a bug where `available_ports()` returned disabled devices on Windows.
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ pub enum Parity {

/// Parity bit sets even number of 1 bits.
Even,

/// Parity bit is set to 1.
Mark,

/// Parity bit is set to 0.
Space,
}

impl fmt::Display for Parity {
Expand All @@ -212,6 +218,8 @@ impl fmt::Display for Parity {
Parity::None => write!(f, "None"),
Parity::Odd => write!(f, "Odd"),
Parity::Even => write!(f, "Even"),
Parity::Mark => write!(f, "Mark"),
Parity::Space => write!(f, "Space"),
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/posix/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ pub(crate) fn set_parity(termios: &mut Termios, parity: Parity) {
termios.c_iflag |= libc::INPCK;
termios.c_iflag &= !libc::IGNPAR;
}
Parity::Mark => {
termios.c_cflag |= libc::PARODD;
termios.c_cflag |= libc::PARENB;
termios.c_iflag |= libc::INPCK;
termios.c_iflag &= !libc::IGNPAR;
termios.c_iflag |= libc::CMSPAR;
}
Parity::Space => {
termios.c_cflag &= !libc::PARODD;
termios.c_cflag |= libc::PARENB;
termios.c_iflag |= libc::INPCK;
termios.c_iflag &= !libc::IGNPAR;
}
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/windows/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ impl SerialPort for COMPort {
match dcb.Parity {
ODDPARITY => Ok(Parity::Odd),
EVENPARITY => Ok(Parity::Even),
MARKPARITY => Ok(Parity::Mark),
SPACEPARITY => Ok(Parity::Space),
NOPARITY => Ok(Parity::None),
_ => Err(Error::new(
ErrorKind::Unknown,
Expand Down
2 changes: 2 additions & 0 deletions src/windows/dcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub(crate) fn set_parity(dcb: &mut DCB, parity: Parity) {
Parity::None => NOPARITY,
Parity::Odd => ODDPARITY,
Parity::Even => EVENPARITY,
Parity::Mark => MARKPARITY,
Parity::Space => SPACEPARITY,
};

dcb.set_fParity(if parity == Parity::None { FALSE } else { TRUE } as DWORD);
Expand Down

0 comments on commit b20e1c4

Please sign in to comment.