Added extension method

This commit is contained in:
Benjamin Höglinger-Stelzer 2022-10-03 17:38:55 +02:00
parent 59a094b949
commit 3040660d64

View File

@ -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);
}
}