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>
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;
}
@ -17,20 +17,20 @@ public readonly struct ModemStatus
/// <summary>
/// Condition of the Clear To Send signal.
/// </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>
/// Condition of the Data Set Ready signal.
/// </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>
/// Condition of the Receive Line Status Detection signal.
/// </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>
/// Condition of the Ring Detection signal.
/// </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 Nefarius.Peripherals.SerialPort.Win32PInvoke;
namespace Nefarius.Peripherals.SerialPort
{
namespace Nefarius.Peripherals.SerialPort;
/// <summary>
/// Represents the current condition of the port queues.
/// </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 _inQueue;
private readonly uint _outQueue;
@ -26,32 +33,32 @@ namespace Nefarius.Peripherals.SerialPort
/// <summary>
/// Output is blocked by CTS handshaking.
/// </summary>
public bool CtsHold => (_status & COMSTAT.fCtsHold) != 0;
public bool CtsHold => (_status & fCtsHold) != 0;
/// <summary>
/// Output is blocked by DRS handshaking.
/// </summary>
public bool DsrHold => (_status & COMSTAT.fDsrHold) != 0;
public bool DsrHold => (_status & fDsrHold) != 0;
/// <summary>
/// Output is blocked by RLSD handshaking.
/// </summary>
public bool RlsdHold => (_status & COMSTAT.fRlsdHold) != 0;
public bool RlsdHold => (_status & fRlsdHold) != 0;
/// <summary>
/// Output is blocked because software handshaking is enabled and XOFF was received.
/// </summary>
public bool XoffHold => (_status & COMSTAT.fXoffHold) != 0;
public bool XoffHold => (_status & fXoffHold) != 0;
/// <summary>
/// Output was blocked because XOFF was sent and this station is not yet ready to receive.
/// </summary>
public bool XoffSent => (_status & COMSTAT.fXoffSent) != 0;
public bool XoffSent => (_status & fXoffSent) != 0;
/// <summary>
/// There is a character waiting for transmission in the immediate buffer.
/// </summary>
public bool ImmediateWaiting => (_status & COMSTAT.fTxim) != 0;
public bool ImmediateWaiting => (_status & fTxim) != 0;
/// <summary>
/// Number of bytes waiting in the input queue.
@ -140,4 +147,3 @@ namespace Nefarius.Peripherals.SerialPort
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;
}