diff --git a/Nefarius.Peripherals.SerialPort/NativeMethods.txt b/Nefarius.Peripherals.SerialPort/NativeMethods.txt index 88e99b5..48e53bd 100644 --- a/Nefarius.Peripherals.SerialPort/NativeMethods.txt +++ b/Nefarius.Peripherals.SerialPort/NativeMethods.txt @@ -5,7 +5,6 @@ FILE_ACCESS_RIGHTS GetCommModemStatus GetCommProperties GetHandleInformation -GetHandleInformation GetOverlappedResult MODEM_STATUS_FLAGS ReadFile diff --git a/Nefarius.Peripherals.SerialPort/QueueStatus.cs b/Nefarius.Peripherals.SerialPort/QueueStatus.cs index 63469fd..661b5dc 100644 --- a/Nefarius.Peripherals.SerialPort/QueueStatus.cs +++ b/Nefarius.Peripherals.SerialPort/QueueStatus.cs @@ -1,5 +1,5 @@ using System.Text; -using Nefarius.Peripherals.SerialPort.Win32PInvoke; + namespace Nefarius.Peripherals.SerialPort { diff --git a/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs b/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs index d44f695..55214cf 100644 --- a/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs +++ b/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs @@ -1,8 +1,6 @@ using Windows.Win32; using Windows.Win32.Devices.Communication; -using Nefarius.Peripherals.SerialPort.Win32PInvoke; - namespace Nefarius.Peripherals.SerialPort; public partial class SerialPort diff --git a/Nefarius.Peripherals.SerialPort/SerialPort.cs b/Nefarius.Peripherals.SerialPort/SerialPort.cs index a98a6da..75114e8 100644 --- a/Nefarius.Peripherals.SerialPort/SerialPort.cs +++ b/Nefarius.Peripherals.SerialPort/SerialPort.cs @@ -11,8 +11,6 @@ using Windows.Win32.Storage.FileSystem; using Microsoft.Win32.SafeHandles; -using Nefarius.Peripherals.SerialPort.Win32PInvoke; - namespace Nefarius.Peripherals.SerialPort; /// @@ -344,7 +342,7 @@ public partial class SerialPort : IDisposable public void SendImmediate(byte tosend) { CheckOnline(); - if (!Win32Com.TransmitCommChar(_hPort.DangerousGetHandle(), tosend)) + if (!PInvoke.TransmitCommChar(_hPort, new CHAR((sbyte)tosend))) { ThrowException("Transmission failure"); } @@ -357,12 +355,12 @@ public partial class SerialPort : IDisposable protected ModemStatus GetModemStatus() { CheckOnline(); - if (!Win32Com.GetCommModemStatus(_hPort.DangerousGetHandle(), out uint f)) + if (!PInvoke.GetCommModemStatus(_hPort, out MODEM_STATUS_FLAGS f)) { ThrowException("Unexpected failure"); } - return new ModemStatus((MODEM_STATUS_FLAGS)f); + return new ModemStatus(f); } /// @@ -591,12 +589,12 @@ public partial class SerialPort : IDisposable if (i != 0) { - if (!Win32Com.GetCommModemStatus(_hPort.DangerousGetHandle(), out uint f)) + if (!PInvoke.GetCommModemStatus(_hPort, out MODEM_STATUS_FLAGS f)) { throw new CommPortException("IO Error [005]"); } - OnStatusChange(new ModemStatus(i), new ModemStatus((MODEM_STATUS_FLAGS)f)); + OnStatusChange(new ModemStatus(i), new ModemStatus(f)); } } } @@ -620,7 +618,7 @@ public partial class SerialPort : IDisposable if (_online) { - if (Win32Com.GetHandleInformation(_hPort.DangerousGetHandle(), out uint _)) + if (PInvoke.GetHandleInformation(_hPort, out uint _)) { return true; } diff --git a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs deleted file mode 100644 index 5603c89..0000000 --- a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Nefarius.Peripherals.SerialPort.Win32PInvoke; - -[Obsolete("use CsWin32 instead.")] -internal class Win32Com -{ - [DllImport("kernel32.dll")] - internal static extern Boolean GetHandleInformation(IntPtr hObject, out UInt32 lpdwFlags); - - [DllImport("kernel32.dll")] - internal static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar); - - [DllImport("kernel32.dll")] - internal static extern Boolean GetCommModemStatus(IntPtr hFile, out UInt32 lpModemStat); -} \ No newline at end of file