Skip to content

Commit

Permalink
sets binary, parity, and DTR handling for COM ports
Browse files Browse the repository at this point in the history
  • Loading branch information
dcuddeback committed Jul 2, 2017
1 parent cd79200 commit 9e00adf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions serial-windows/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ impl SerialDevice for COMPort {

match unsafe { GetCommState(self.handle, &mut dcb) } {
0 => Err(error::last_os_error()),
_ => Ok(COMSettings { inner: dcb }),
_ => {
dcb.fBits |= fBinary;
dcb.fBits &= fDtrControl;

Ok(COMSettings { inner: dcb })
}

}
}
Expand Down Expand Up @@ -306,22 +311,29 @@ impl SerialPortSettings for COMSettings {
core::Bits6 => 6,
core::Bits7 => 7,
core::Bits8 => 8,
}
};
}

fn set_parity(&mut self, parity: core::Parity) {
self.inner.Parity = match parity {
core::ParityNone => NOPARITY,
core::ParityOdd => ODDPARITY,
core::ParityEven => EVENPARITY,
};

if parity == core::ParityNone {
self.inner.fBits &= !fParity;
}
else {
self.inner.fBits |= fParity;
}
}

fn set_stop_bits(&mut self, stop_bits: core::StopBits) {
self.inner.StopBits = match stop_bits {
core::Stop1 => ONESTOPBIT,
core::Stop2 => TWOSTOPBITS,
}
};
}

fn set_flow_control(&mut self, flow_control: core::FlowControl) {
Expand Down

0 comments on commit 9e00adf

Please sign in to comment.