2012-03-03 10:50:54 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
using PInvokeSerialPort.Win32PInvoke;
|
|
|
|
|
|
|
|
|
|
namespace PInvokeSerialPort
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Represents the current condition of the port queues.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
public struct QueueStatus
|
|
|
|
|
{
|
2018-11-22 21:33:25 +01:00
|
|
|
|
private readonly uint _status;
|
|
|
|
|
private readonly uint _inQueue;
|
|
|
|
|
private readonly uint _outQueue;
|
|
|
|
|
private readonly uint _inQueueSize;
|
|
|
|
|
private readonly uint _outQueueSize;
|
2012-03-03 10:50:54 +01:00
|
|
|
|
|
|
|
|
|
internal QueueStatus(uint stat, uint inQ, uint outQ, uint inQs, uint outQs)
|
2018-11-22 21:33:25 +01:00
|
|
|
|
{
|
|
|
|
|
_status = stat;
|
|
|
|
|
_inQueue = inQ;
|
|
|
|
|
_outQueue = outQ;
|
|
|
|
|
_inQueueSize = inQs;
|
|
|
|
|
_outQueueSize = outQs;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Output is blocked by CTS handshaking.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public bool CtsHold => (_status & COMSTAT.fCtsHold) != 0;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Output is blocked by DRS handshaking.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public bool DsrHold => (_status & COMSTAT.fDsrHold) != 0;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Output is blocked by RLSD handshaking.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public bool RlsdHold => (_status & COMSTAT.fRlsdHold) != 0;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Output is blocked because software handshaking is enabled and XOFF was received.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public bool XoffHold => (_status & COMSTAT.fXoffHold) != 0;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Output was blocked because XOFF was sent and this station is not yet ready to receive.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public bool XoffSent => (_status & COMSTAT.fXoffSent) != 0;
|
2012-03-03 10:50:54 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// There is a character waiting for transmission in the immediate buffer.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public bool ImmediateWaiting => (_status & COMSTAT.fTxim) != 0;
|
2012-03-03 10:50:54 +01:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Number of bytes waiting in the input queue.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public long InQueue => _inQueue;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Number of bytes waiting for transmission.
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public long OutQueue => _outQueue;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Total size of input queue (0 means information unavailable)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public long InQueueSize => _inQueueSize;
|
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// <summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
/// Total size of output queue (0 means information unavailable)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
/// </summary>
|
2018-11-22 21:33:25 +01:00
|
|
|
|
public long OutQueueSize => _outQueueSize;
|
2012-03-03 10:50:54 +01:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
var m = new StringBuilder("The reception queue is ", 60);
|
2018-11-22 21:33:25 +01:00
|
|
|
|
if (_inQueueSize == 0)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append("of unknown size and ");
|
|
|
|
|
else
|
2018-11-22 21:33:25 +01:00
|
|
|
|
m.Append(_inQueueSize + " bytes long and ");
|
|
|
|
|
if (_inQueue == 0)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
{
|
|
|
|
|
m.Append("is empty.");
|
|
|
|
|
}
|
2018-11-22 21:33:25 +01:00
|
|
|
|
else if (_inQueue == 1)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
{
|
|
|
|
|
m.Append("contains 1 byte.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m.Append("contains ");
|
2018-11-22 21:33:25 +01:00
|
|
|
|
m.Append(_inQueue.ToString());
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append(" bytes.");
|
|
|
|
|
}
|
2018-11-22 21:33:25 +01:00
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append(" The transmission queue is ");
|
2018-11-22 21:33:25 +01:00
|
|
|
|
if (_outQueueSize == 0)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append("of unknown size and ");
|
|
|
|
|
else
|
2018-11-22 21:33:25 +01:00
|
|
|
|
m.Append(_outQueueSize + " bytes long and ");
|
|
|
|
|
if (_outQueue == 0)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
{
|
|
|
|
|
m.Append("is empty");
|
|
|
|
|
}
|
2018-11-22 21:33:25 +01:00
|
|
|
|
else if (_outQueue == 1)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
{
|
|
|
|
|
m.Append("contains 1 byte. It is ");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m.Append("contains ");
|
2018-11-22 21:33:25 +01:00
|
|
|
|
m.Append(_outQueue.ToString());
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append(" bytes. It is ");
|
|
|
|
|
}
|
2018-11-22 21:33:25 +01:00
|
|
|
|
|
|
|
|
|
if (_outQueue > 0)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
{
|
2018-11-22 21:33:25 +01:00
|
|
|
|
if (CtsHold || DsrHold || RlsdHold || XoffHold || XoffSent)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
{
|
|
|
|
|
m.Append("holding on");
|
2018-11-22 21:33:25 +01:00
|
|
|
|
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");
|
2012-03-03 10:50:54 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m.Append("pumping data");
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-22 21:33:25 +01:00
|
|
|
|
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append(". The immediate buffer is ");
|
2018-11-22 21:33:25 +01:00
|
|
|
|
if (ImmediateWaiting)
|
2012-03-03 10:50:54 +01:00
|
|
|
|
m.Append("full.");
|
|
|
|
|
else
|
|
|
|
|
m.Append("empty.");
|
|
|
|
|
return m.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|