This commit is contained in:
Benjamin Höglinger-Stelzer 2022-09-26 23:51:23 +02:00
parent 5b8daef830
commit 54ed60d9f8
4 changed files with 608 additions and 684 deletions

View File

@ -7,9 +7,9 @@ namespace Nefarius.Peripherals.SerialPort;
/// </summary> /// </summary>
public readonly struct ModemStatus public readonly struct ModemStatus
{ {
private readonly uint _status; private readonly MODEM_STATUS_FLAGS _status;
internal ModemStatus(uint val) internal ModemStatus(MODEM_STATUS_FLAGS val)
{ {
_status = val; _status = val;
} }
@ -17,20 +17,20 @@ public readonly struct ModemStatus
/// <summary> /// <summary>
/// Condition of the Clear To Send signal. /// Condition of the Clear To Send signal.
/// </summary> /// </summary>
public bool Cts => (_status & (uint)MODEM_STATUS_FLAGS.MS_CTS_ON) != 0; public bool Cts => (_status & MODEM_STATUS_FLAGS.MS_CTS_ON) != 0;
/// <summary> /// <summary>
/// Condition of the Data Set Ready signal. /// Condition of the Data Set Ready signal.
/// </summary> /// </summary>
public bool Dsr => (_status & (uint)MODEM_STATUS_FLAGS.MS_DSR_ON) != 0; public bool Dsr => (_status & MODEM_STATUS_FLAGS.MS_DSR_ON) != 0;
/// <summary> /// <summary>
/// Condition of the Receive Line Status Detection signal. /// Condition of the Receive Line Status Detection signal.
/// </summary> /// </summary>
public bool Rlsd => (_status & (uint)MODEM_STATUS_FLAGS.MS_RLSD_ON) != 0; public bool Rlsd => (_status & MODEM_STATUS_FLAGS.MS_RLSD_ON) != 0;
/// <summary> /// <summary>
/// Condition of the Ring Detection signal. /// Condition of the Ring Detection signal.
/// </summary> /// </summary>
public bool Ring => (_status & (uint)MODEM_STATUS_FLAGS.MS_RING_ON) != 0; public bool Ring => (_status & MODEM_STATUS_FLAGS.MS_RING_ON) != 0;
} }

View File

@ -1,13 +1,20 @@
using System.Text; using System.Text;
using Nefarius.Peripherals.SerialPort.Win32PInvoke;
namespace Nefarius.Peripherals.SerialPort namespace Nefarius.Peripherals.SerialPort;
{
/// <summary> /// <summary>
/// Represents the current condition of the port queues. /// Represents the current condition of the port queues.
/// </summary> /// </summary>
public struct QueueStatus public readonly struct QueueStatus
{ {
private const uint fCtsHold = 0x1;
private const uint fDsrHold = 0x2;
private const uint fRlsdHold = 0x4;
private const uint fXoffHold = 0x8;
private const uint fXoffSent = 0x10;
internal const uint fEof = 0x20;
private const uint fTxim = 0x40;
private readonly uint _status; private readonly uint _status;
private readonly uint _inQueue; private readonly uint _inQueue;
private readonly uint _outQueue; private readonly uint _outQueue;
@ -26,32 +33,32 @@ namespace Nefarius.Peripherals.SerialPort
/// <summary> /// <summary>
/// Output is blocked by CTS handshaking. /// Output is blocked by CTS handshaking.
/// </summary> /// </summary>
public bool CtsHold => (_status & COMSTAT.fCtsHold) != 0; public bool CtsHold => (_status & fCtsHold) != 0;
/// <summary> /// <summary>
/// Output is blocked by DRS handshaking. /// Output is blocked by DRS handshaking.
/// </summary> /// </summary>
public bool DsrHold => (_status & COMSTAT.fDsrHold) != 0; public bool DsrHold => (_status & fDsrHold) != 0;
/// <summary> /// <summary>
/// Output is blocked by RLSD handshaking. /// Output is blocked by RLSD handshaking.
/// </summary> /// </summary>
public bool RlsdHold => (_status & COMSTAT.fRlsdHold) != 0; public bool RlsdHold => (_status & fRlsdHold) != 0;
/// <summary> /// <summary>
/// Output is blocked because software handshaking is enabled and XOFF was received. /// Output is blocked because software handshaking is enabled and XOFF was received.
/// </summary> /// </summary>
public bool XoffHold => (_status & COMSTAT.fXoffHold) != 0; public bool XoffHold => (_status & fXoffHold) != 0;
/// <summary> /// <summary>
/// Output was blocked because XOFF was sent and this station is not yet ready to receive. /// Output was blocked because XOFF was sent and this station is not yet ready to receive.
/// </summary> /// </summary>
public bool XoffSent => (_status & COMSTAT.fXoffSent) != 0; public bool XoffSent => (_status & fXoffSent) != 0;
/// <summary> /// <summary>
/// There is a character waiting for transmission in the immediate buffer. /// There is a character waiting for transmission in the immediate buffer.
/// </summary> /// </summary>
public bool ImmediateWaiting => (_status & COMSTAT.fTxim) != 0; public bool ImmediateWaiting => (_status & fTxim) != 0;
/// <summary> /// <summary>
/// Number of bytes waiting in the input queue. /// Number of bytes waiting in the input queue.
@ -140,4 +147,3 @@ namespace Nefarius.Peripherals.SerialPort
return m.ToString(); return m.ToString();
} }
} }
}

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace Nefarius.Peripherals.SerialPort.Win32PInvoke;
[StructLayout(LayoutKind.Sequential)]
internal struct COMSTAT
{
internal const uint fCtsHold = 0x1;
internal const uint fDsrHold = 0x2;
internal const uint fRlsdHold = 0x4;
internal const uint fXoffHold = 0x8;
internal const uint fXoffSent = 0x10;
internal const uint fEof = 0x20;
internal const uint fTxim = 0x40;
internal UInt32 Flags;
internal UInt32 cbInQue;
internal UInt32 cbOutQue;
}