Applied some refactoring

This commit is contained in:
Benjamin Höglinger-Stelzer 2018-11-22 21:33:25 +01:00
parent b11f56bfee
commit 55c3aefa2d
4 changed files with 85 additions and 73 deletions

1
.gitignore vendored
View File

@ -29,3 +29,4 @@ _ReSharper*/
[Tt]est[Rr]esult*
*.testsettings
PInvokeSerialPort.nupkg
/.vs/PInvokeSerialPort/v15/Server/sqlite3

View File

@ -4,127 +4,136 @@ using PInvokeSerialPort.Win32PInvoke;
namespace PInvokeSerialPort
{
/// <summary>
/// Represents the current condition of the port queues.
/// Represents the current condition of the port queues.
/// </summary>
public struct QueueStatus
{
private uint status;
private uint inQueue;
private uint outQueue;
private uint inQueueSize;
private uint outQueueSize;
private readonly uint _status;
private readonly uint _inQueue;
private readonly uint _outQueue;
private readonly uint _inQueueSize;
private readonly uint _outQueueSize;
internal QueueStatus(uint stat, uint inQ, uint outQ, uint inQs, uint outQs)
{ status = stat; inQueue = inQ; outQueue = outQ; inQueueSize = inQs; outQueueSize = outQs; }
/// <summary>
/// Output is blocked by CTS handshaking.
/// </summary>
public bool ctsHold { get { return ((status & COMSTAT.fCtsHold) != 0); } }
/// <summary>
/// Output is blocked by DRS handshaking.
/// </summary>
public bool dsrHold { get { return ((status & COMSTAT.fDsrHold) != 0); } }
/// <summary>
/// Output is blocked by RLSD handshaking.
/// </summary>
public bool rlsdHold { get { return ((status & COMSTAT.fRlsdHold) != 0); } }
/// <summary>
/// Output is blocked because software handshaking is enabled and XOFF was received.
/// </summary>
public bool xoffHold { get { return ((status & COMSTAT.fXoffHold) != 0); } }
/// <summary>
/// Output was blocked because XOFF was sent and this station is not yet ready to receive.
/// </summary>
public bool xoffSent { get { return ((status & COMSTAT.fXoffSent) != 0); } }
{
_status = stat;
_inQueue = inQ;
_outQueue = outQ;
_inQueueSize = inQs;
_outQueueSize = outQs;
}
/// <summary>
/// There is a character waiting for transmission in the immediate buffer.
/// Output is blocked by CTS handshaking.
/// </summary>
public bool immediateWaiting { get { return ((status & COMSTAT.fTxim) != 0); } }
public bool CtsHold => (_status & COMSTAT.fCtsHold) != 0;
/// <summary>
/// Number of bytes waiting in the input queue.
/// Output is blocked by DRS handshaking.
/// </summary>
public long InQueue { get { return inQueue; } }
public bool DsrHold => (_status & COMSTAT.fDsrHold) != 0;
/// <summary>
/// Number of bytes waiting for transmission.
/// Output is blocked by RLSD handshaking.
/// </summary>
public long OutQueue { get { return outQueue; } }
public bool RlsdHold => (_status & COMSTAT.fRlsdHold) != 0;
/// <summary>
/// Total size of input queue (0 means information unavailable)
/// Output is blocked because software handshaking is enabled and XOFF was received.
/// </summary>
public long InQueueSize { get { return inQueueSize; } }
public bool XoffHold => (_status & COMSTAT.fXoffHold) != 0;
/// <summary>
/// Total size of output queue (0 means information unavailable)
/// Output was blocked because XOFF was sent and this station is not yet ready to receive.
/// </summary>
public long OutQueueSize { get { return outQueueSize; } }
public bool XoffSent => (_status & COMSTAT.fXoffSent) != 0;
/// <summary>
/// There is a character waiting for transmission in the immediate buffer.
/// </summary>
public bool ImmediateWaiting => (_status & COMSTAT.fTxim) != 0;
/// <summary>
/// Number of bytes waiting in the input queue.
/// </summary>
public long InQueue => _inQueue;
/// <summary>
/// Number of bytes waiting for transmission.
/// </summary>
public long OutQueue => _outQueue;
/// <summary>
/// Total size of input queue (0 means information unavailable)
/// </summary>
public long InQueueSize => _inQueueSize;
/// <summary>
/// Total size of output queue (0 means information unavailable)
/// </summary>
public long OutQueueSize => _outQueueSize;
public override string ToString()
{
var m = new StringBuilder("The reception queue is ", 60);
if (inQueueSize == 0)
{
if (_inQueueSize == 0)
m.Append("of unknown size and ");
}
else
{
m.Append(inQueueSize.ToString() + " bytes long and ");
}
if (inQueue == 0)
m.Append(_inQueueSize + " bytes long and ");
if (_inQueue == 0)
{
m.Append("is empty.");
}
else if (inQueue == 1)
else if (_inQueue == 1)
{
m.Append("contains 1 byte.");
}
else
{
m.Append("contains ");
m.Append(inQueue.ToString());
m.Append(_inQueue.ToString());
m.Append(" bytes.");
}
m.Append(" The transmission queue is ");
if (outQueueSize == 0)
{
if (_outQueueSize == 0)
m.Append("of unknown size and ");
}
else
{
m.Append(outQueueSize.ToString() + " bytes long and ");
}
if (outQueue == 0)
m.Append(_outQueueSize + " bytes long and ");
if (_outQueue == 0)
{
m.Append("is empty");
}
else if (outQueue == 1)
else if (_outQueue == 1)
{
m.Append("contains 1 byte. It is ");
}
else
{
m.Append("contains ");
m.Append(outQueue.ToString());
m.Append(_outQueue.ToString());
m.Append(" bytes. It is ");
}
if (outQueue > 0)
if (_outQueue > 0)
{
if (ctsHold || dsrHold || rlsdHold || xoffHold || xoffSent)
if (CtsHold || DsrHold || RlsdHold || XoffHold || XoffSent)
{
m.Append("holding on");
if (ctsHold) m.Append(" CTS");
if (dsrHold) m.Append(" DSR");
if (rlsdHold) m.Append(" RLSD");
if (xoffHold) m.Append(" Rx XOff");
if (xoffSent) m.Append(" Tx XOff");
if (CtsHold) m.Append(" CTS");
if (DsrHold) m.Append(" DSR");
if (RlsdHold) m.Append(" RLSD");
if (XoffHold) m.Append(" Rx XOff");
if (XoffSent) m.Append(" Tx XOff");
}
else
{
m.Append("pumping data");
}
}
m.Append(". The immediate buffer is ");
if (immediateWaiting)
if (ImmediateWaiting)
m.Append("full.");
else
m.Append("empty.");

View File

@ -625,7 +625,7 @@ namespace PInvokeSerialPort
/// <summary>
/// Number of stop bits (default: one)
/// </summary>
public StopBits StopBits = StopBits.one;
public StopBits StopBits = StopBits.One;
/// <summary>
/// If true, transmission is halted unless CTS is asserted by the remote station (default: false)
/// </summary>

View File

@ -1,21 +1,23 @@
namespace PInvokeSerialPort
{
/// <summary>
/// Stop bit settings
/// Stop bit settings
/// </summary>
public enum StopBits
{
/// <summary>
/// Line is asserted for 1 bit duration at end of each character
/// Line is asserted for 1 bit duration at end of each character
/// </summary>
one = 0,
One = 0,
/// <summary>
/// Line is asserted for 1.5 bit duration at end of each character
/// Line is asserted for 1.5 bit duration at end of each character
/// </summary>
onePointFive = 1,
OnePointFive = 1,
/// <summary>
/// Line is asserted for 2 bit duration at end of each character
/// Line is asserted for 2 bit duration at end of each character
/// </summary>
two = 2
};
Two = 2
}
}