diff --git a/.gitignore b/.gitignore index 228e753..21072ad 100755 --- a/.gitignore +++ b/.gitignore @@ -28,4 +28,5 @@ obj/ _ReSharper*/ [Tt]est[Rr]esult* *.testsettings -PInvokeSerialPort.nupkg \ No newline at end of file +PInvokeSerialPort.nupkg +/.vs/PInvokeSerialPort/v15/Server/sqlite3 diff --git a/PInvokeSerialPort/QueueStatus.cs b/PInvokeSerialPort/QueueStatus.cs index c9c8aa3..33979c6 100755 --- a/PInvokeSerialPort/QueueStatus.cs +++ b/PInvokeSerialPort/QueueStatus.cs @@ -4,127 +4,136 @@ using PInvokeSerialPort.Win32PInvoke; namespace PInvokeSerialPort { /// - /// Represents the current condition of the port queues. + /// Represents the current condition of the port queues. /// 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; } - /// - /// Output is blocked by CTS handshaking. - /// - public bool ctsHold { get { return ((status & COMSTAT.fCtsHold) != 0); } } - /// - /// Output is blocked by DRS handshaking. - /// - public bool dsrHold { get { return ((status & COMSTAT.fDsrHold) != 0); } } - /// - /// Output is blocked by RLSD handshaking. - /// - public bool rlsdHold { get { return ((status & COMSTAT.fRlsdHold) != 0); } } - /// - /// Output is blocked because software handshaking is enabled and XOFF was received. - /// - public bool xoffHold { get { return ((status & COMSTAT.fXoffHold) != 0); } } - /// - /// Output was blocked because XOFF was sent and this station is not yet ready to receive. - /// - public bool xoffSent { get { return ((status & COMSTAT.fXoffSent) != 0); } } + { + _status = stat; + _inQueue = inQ; + _outQueue = outQ; + _inQueueSize = inQs; + _outQueueSize = outQs; + } /// - /// There is a character waiting for transmission in the immediate buffer. + /// Output is blocked by CTS handshaking. /// - public bool immediateWaiting { get { return ((status & COMSTAT.fTxim) != 0); } } + public bool CtsHold => (_status & COMSTAT.fCtsHold) != 0; /// - /// Number of bytes waiting in the input queue. + /// Output is blocked by DRS handshaking. /// - public long InQueue { get { return inQueue; } } + public bool DsrHold => (_status & COMSTAT.fDsrHold) != 0; + /// - /// Number of bytes waiting for transmission. + /// Output is blocked by RLSD handshaking. /// - public long OutQueue { get { return outQueue; } } + public bool RlsdHold => (_status & COMSTAT.fRlsdHold) != 0; + /// - /// Total size of input queue (0 means information unavailable) + /// Output is blocked because software handshaking is enabled and XOFF was received. /// - public long InQueueSize { get { return inQueueSize; } } + public bool XoffHold => (_status & COMSTAT.fXoffHold) != 0; + /// - /// 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. /// - public long OutQueueSize { get { return outQueueSize; } } + public bool XoffSent => (_status & COMSTAT.fXoffSent) != 0; + + /// + /// There is a character waiting for transmission in the immediate buffer. + /// + public bool ImmediateWaiting => (_status & COMSTAT.fTxim) != 0; + + /// + /// Number of bytes waiting in the input queue. + /// + public long InQueue => _inQueue; + + /// + /// Number of bytes waiting for transmission. + /// + public long OutQueue => _outQueue; + + /// + /// Total size of input queue (0 means information unavailable) + /// + public long InQueueSize => _inQueueSize; + + /// + /// Total size of output queue (0 means information unavailable) + /// + 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."); diff --git a/PInvokeSerialPort/SerialPort.cs b/PInvokeSerialPort/SerialPort.cs index f0b86c8..fcfc0d0 100755 --- a/PInvokeSerialPort/SerialPort.cs +++ b/PInvokeSerialPort/SerialPort.cs @@ -625,7 +625,7 @@ namespace PInvokeSerialPort /// /// Number of stop bits (default: one) /// - public StopBits StopBits = StopBits.one; + public StopBits StopBits = StopBits.One; /// /// If true, transmission is halted unless CTS is asserted by the remote station (default: false) /// diff --git a/PInvokeSerialPort/StopBits.cs b/PInvokeSerialPort/StopBits.cs index c727f72..cb72f33 100755 --- a/PInvokeSerialPort/StopBits.cs +++ b/PInvokeSerialPort/StopBits.cs @@ -1,21 +1,23 @@ namespace PInvokeSerialPort { /// - /// Stop bit settings + /// Stop bit settings /// public enum StopBits { /// - /// Line is asserted for 1 bit duration at end of each character + /// Line is asserted for 1 bit duration at end of each character /// - one = 0, + One = 0, + /// - /// 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 /// - onePointFive = 1, + OnePointFive = 1, + /// - /// Line is asserted for 2 bit duration at end of each character + /// Line is asserted for 2 bit duration at end of each character /// - two = 2 - }; + Two = 2 + } } \ No newline at end of file