diff --git a/Nefarius.Peripherals.SerialPort/SerialPort.cs b/Nefarius.Peripherals.SerialPort/SerialPort.cs index dd22fb5..36f23d3 100644 --- a/Nefarius.Peripherals.SerialPort/SerialPort.cs +++ b/Nefarius.Peripherals.SerialPort/SerialPort.cs @@ -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); diff --git a/Nefarius.Peripherals.SerialPort/Win32PInvoke/COMMPROP.cs b/Nefarius.Peripherals.SerialPort/Win32PInvoke/COMMPROP.cs deleted file mode 100644 index bbd37be..0000000 --- a/Nefarius.Peripherals.SerialPort/Win32PInvoke/COMMPROP.cs +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs index 3a89c67..4c5f52f 100644 --- a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs +++ b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs @@ -12,18 +12,7 @@ namespace Nefarius.Peripherals.SerialPort.Win32PInvoke [DllImport("kernel32.dll")] internal static extern Boolean GetHandleInformation(IntPtr hObject, out UInt32 lpdwFlags); - - /// - /// Manipulating the communications settings. - /// - /// - /// Reading and writing. - /// - [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); + } } \ No newline at end of file