Skip to content

Commit 3805627

Browse files
committed
Add Mark and Space variants to Parity enum
1 parent c320919 commit 3805627

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ project adheres to [Semantic Versioning](https://semver.org/).
99
### Added
1010
* Added conversions between `DataBits`, `StopBits` types and their numeric representations
1111
* Added `FromStr` implementation for `FlowControl`
12+
* Added `Mark` and `Space` variants to `Parity` enum
1213
### Changed
1314
### Fixed
1415
* Fixes a bug where `available_ports()` returned disabled devices on Windows.

src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ pub enum Parity {
204204

205205
/// Parity bit sets even number of 1 bits.
206206
Even,
207+
208+
/// Parity bit is set to 1.
209+
///
210+
/// Only supported on Windows and Linux.
211+
Mark,
212+
213+
/// Parity bit is set to 0.
214+
///
215+
/// Only supported on Windows and Linux.
216+
Space,
207217
}
208218

209219
impl fmt::Display for Parity {
@@ -212,6 +222,8 @@ impl fmt::Display for Parity {
212222
Parity::None => write!(f, "None"),
213223
Parity::Odd => write!(f, "Odd"),
214224
Parity::Even => write!(f, "Even"),
225+
Parity::Mark => write!(f, "Mark"),
226+
Parity::Space => write!(f, "Space"),
215227
}
216228
}
217229
}

src/posix/termios.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ pub(crate) fn set_parity(termios: &mut Termios, parity: Parity) {
163163
termios.c_iflag |= libc::INPCK;
164164
termios.c_iflag &= !libc::IGNPAR;
165165
}
166+
Parity::Mark => {
167+
termios.c_cflag |= libc::PARODD;
168+
termios.c_cflag |= libc::PARENB;
169+
termios.c_iflag |= libc::INPCK;
170+
termios.c_iflag &= !libc::IGNPAR;
171+
#[cfg(any(target_os = "linux", target_os = "android"))]
172+
{
173+
termios.c_iflag |= libc::CMSPAR;
174+
}
175+
}
176+
Parity::Space => {
177+
termios.c_cflag &= !libc::PARODD;
178+
termios.c_cflag |= libc::PARENB;
179+
termios.c_iflag |= libc::INPCK;
180+
termios.c_iflag &= !libc::IGNPAR;
181+
#[cfg(any(target_os = "linux", target_os = "android"))]
182+
{
183+
termios.c_iflag |= libc::CMSPAR;
184+
}
185+
}
166186
};
167187
}
168188

src/windows/com.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ impl SerialPort for COMPort {
314314
match dcb.Parity {
315315
ODDPARITY => Ok(Parity::Odd),
316316
EVENPARITY => Ok(Parity::Even),
317+
MARKPARITY => Ok(Parity::Mark),
318+
SPACEPARITY => Ok(Parity::Space),
317319
NOPARITY => Ok(Parity::None),
318320
_ => Err(Error::new(
319321
ErrorKind::Unknown,

src/windows/dcb.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ pub(crate) fn set_parity(dcb: &mut DCB, parity: Parity) {
8181
Parity::None => NOPARITY,
8282
Parity::Odd => ODDPARITY,
8383
Parity::Even => EVENPARITY,
84+
Parity::Mark => MARKPARITY,
85+
Parity::Space => SPACEPARITY,
8486
};
8587

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

0 commit comments

Comments
 (0)