From 3040660d64f946baa9a9bbecfce7d1699a73100f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Mon, 3 Oct 2022 17:38:55 +0200 Subject: [PATCH] Added extension method --- Nefarius.Peripherals.SerialPort/Util.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Nefarius.Peripherals.SerialPort/Util.cs diff --git a/Nefarius.Peripherals.SerialPort/Util.cs b/Nefarius.Peripherals.SerialPort/Util.cs new file mode 100644 index 0000000..c0f22b0 --- /dev/null +++ b/Nefarius.Peripherals.SerialPort/Util.cs @@ -0,0 +1,23 @@ +using Windows.Win32.Devices.Communication; + +namespace Nefarius.Peripherals.SerialPort; + +internal static class DCBExtensions +{ + public static void Init(this DCB dcb, bool parity, bool outCts, bool outDsr, int dtr, bool inDsr, bool txc, + bool xOut, + bool xIn, int rts) + { + dcb.DCBlength = 28; + dcb._bitfield = 0x8001; + if (parity) dcb._bitfield |= 0x0002; + if (outCts) dcb._bitfield |= 0x0004; + if (outDsr) dcb._bitfield |= 0x0008; + dcb._bitfield |= (uint)((dtr & 0x0003) << 4); + if (inDsr) dcb._bitfield |= 0x0040; + if (txc) dcb._bitfield |= 0x0080; + if (xOut) dcb._bitfield |= 0x0100; + if (xIn) dcb._bitfield |= 0x0200; + dcb._bitfield |= (uint)((rts & 0x0003) << 12); + } +} \ No newline at end of file