Migrated mroe code

This commit is contained in:
Benjamin Höglinger-Stelzer 2022-10-03 19:17:59 +02:00
parent aabf3897fd
commit e48d103c63
3 changed files with 3 additions and 44 deletions

View File

@ -8,7 +8,6 @@ using Windows.Win32.Foundation;
using Windows.Win32.Storage.FileSystem;
using Microsoft.Win32.SafeHandles;
using Nefarius.Peripherals.SerialPort.Win32PInvoke;
using COMMPROP = Nefarius.Peripherals.SerialPort.Win32PInvoke.COMMPROP;
namespace Nefarius.Peripherals.SerialPort;
@ -300,14 +299,14 @@ public class SerialPort : IDisposable
protected unsafe QueueStatus GetQueueStatus()
{
COMSTAT cs;
COMMPROP cp;
var cp = new COMMPROP();
CLEAR_COMM_ERROR_FLAGS er;
CheckOnline();
if (!PInvoke.ClearCommError(_hPort, &er, &cs))
ThrowException("Unexpected failure");
if (!Win32Com.GetCommProperties(_hPort.DangerousGetHandle(), out cp))
if (!PInvoke.GetCommProperties(_hPort, ref cp))
ThrowException("Unexpected failure");
return new QueueStatus(cs._bitfield, cs.cbInQue, cs.cbOutQue, cp.dwCurrentRxQueue, cp.dwCurrentTxQueue);

View File

@ -1,28 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace Nefarius.Peripherals.SerialPort.Win32PInvoke
{
[StructLayout(LayoutKind.Sequential)]
internal struct COMMPROP
{
internal UInt16 wPacketLength;
internal UInt16 wPacketVersion;
internal UInt32 dwServiceMask;
internal UInt32 dwReserved1;
internal UInt32 dwMaxTxQueue;
internal UInt32 dwMaxRxQueue;
internal UInt32 dwMaxBaud;
internal UInt32 dwProvSubType;
internal UInt32 dwProvCapabilities;
internal UInt32 dwSettableParams;
internal UInt32 dwSettableBaud;
internal UInt16 wSettableData;
internal UInt16 wSettableStopParity;
internal UInt32 dwCurrentTxQueue;
internal UInt32 dwCurrentRxQueue;
internal UInt32 dwProvSpec1;
internal UInt32 dwProvSpec2;
internal Byte wcProvChar;
}
}

View File

@ -12,18 +12,7 @@ namespace Nefarius.Peripherals.SerialPort.Win32PInvoke
[DllImport("kernel32.dll")]
internal static extern Boolean GetHandleInformation(IntPtr hObject, out UInt32 lpdwFlags);
/// <summary>
/// Manipulating the communications settings.
/// </summary>
/// <summary>
/// Reading and writing.
/// </summary>
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern Boolean WriteFile(IntPtr fFile, Byte[] lpBuffer, UInt32 nNumberOfBytesToWrite,
out UInt32 lpNumberOfBytesWritten, IntPtr lpOverlapped);
[DllImport("kernel32.dll")]
internal static extern Boolean SetCommMask(IntPtr hFile, UInt32 dwEvtMask);
@ -100,7 +89,6 @@ namespace Nefarius.Peripherals.SerialPort.Win32PInvoke
internal const UInt32 CE_DNS = 0x0800;
internal const UInt32 CE_OOP = 0x1000;
internal const UInt32 CE_MODE = 0x8000;
[DllImport("kernel32.dll")]
internal static extern Boolean GetCommProperties(IntPtr hFile, out COMMPROP cp);
}
}