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* [Tt]est[Rr]esult*
*.testsettings *.testsettings
PInvokeSerialPort.nupkg PInvokeSerialPort.nupkg
/.vs/PInvokeSerialPort/v15/Server/sqlite3

View File

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

View File

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

View File

@ -1,21 +1,23 @@
namespace PInvokeSerialPort namespace PInvokeSerialPort
{ {
/// <summary> /// <summary>
/// Stop bit settings /// Stop bit settings
/// </summary> /// </summary>
public enum StopBits public enum StopBits
{ {
/// <summary> /// <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> /// </summary>
one = 0, One = 0,
/// <summary> /// <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> /// </summary>
onePointFive = 1, OnePointFive = 1,
/// <summary> /// <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> /// </summary>
two = 2 Two = 2
}; }
} }