From 5e30d626519093dc20e6c80ef9133c3d65800157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Sat, 13 Jul 2024 15:19:01 +0200 Subject: [PATCH] More type migrations --- .../NativeMethods.txt | 4 +++- .../SerialPort.Properties.cs | 17 ++++++++++------- .../Win32PInvoke/Win32Com.cs | 17 ----------------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/Nefarius.Peripherals.SerialPort/NativeMethods.txt b/Nefarius.Peripherals.SerialPort/NativeMethods.txt index 3194ae2..9de20e0 100644 --- a/Nefarius.Peripherals.SerialPort/NativeMethods.txt +++ b/Nefarius.Peripherals.SerialPort/NativeMethods.txt @@ -17,4 +17,6 @@ TransmitCommChar WIN32_ERROR WaitCommEvent WriteFile -CreateFile \ No newline at end of file +CreateFile +ESCAPE_COMM_FUNCTION +EscapeCommFunction \ No newline at end of file diff --git a/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs b/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs index e24b6e4..d44f695 100644 --- a/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs +++ b/Nefarius.Peripherals.SerialPort/SerialPort.Properties.cs @@ -1,4 +1,7 @@ -using Nefarius.Peripherals.SerialPort.Win32PInvoke; +using Windows.Win32; +using Windows.Win32.Devices.Communication; + +using Nefarius.Peripherals.SerialPort.Win32PInvoke; namespace Nefarius.Peripherals.SerialPort; @@ -141,14 +144,14 @@ public partial class SerialPort CheckOnline(); if (value) { - if (Win32Com.EscapeCommFunction(_hPort.DangerousGetHandle(), Win32Com.SETRTS)) + if (PInvoke.EscapeCommFunction(_hPort, ESCAPE_COMM_FUNCTION.SETRTS)) _stateRts = 1; else ThrowException("Unexpected Failure"); } else { - if (Win32Com.EscapeCommFunction(_hPort.DangerousGetHandle(), Win32Com.CLRRTS)) + if (PInvoke.EscapeCommFunction(_hPort, ESCAPE_COMM_FUNCTION.CLRRTS)) _stateRts = 1; else ThrowException("Unexpected Failure"); @@ -173,14 +176,14 @@ public partial class SerialPort CheckOnline(); if (value) { - if (Win32Com.EscapeCommFunction(_hPort.DangerousGetHandle(), Win32Com.SETDTR)) + if (PInvoke.EscapeCommFunction(_hPort, ESCAPE_COMM_FUNCTION.SETDTR)) _stateDtr = 1; else ThrowException("Unexpected Failure"); } else { - if (Win32Com.EscapeCommFunction(_hPort.DangerousGetHandle(), Win32Com.CLRDTR)) + if (PInvoke.EscapeCommFunction(_hPort, ESCAPE_COMM_FUNCTION.CLRDTR)) _stateDtr = 0; else ThrowException("Unexpected Failure"); @@ -200,14 +203,14 @@ public partial class SerialPort CheckOnline(); if (value) { - if (Win32Com.EscapeCommFunction(_hPort.DangerousGetHandle(), Win32Com.SETBREAK)) + if (PInvoke.EscapeCommFunction(_hPort, ESCAPE_COMM_FUNCTION.SETBREAK)) _stateBrk = 0; else ThrowException("Unexpected Failure"); } else { - if (Win32Com.EscapeCommFunction(_hPort.DangerousGetHandle(), Win32Com.CLRBREAK)) + if (PInvoke.EscapeCommFunction(_hPort, ESCAPE_COMM_FUNCTION.CLRBREAK)) _stateBrk = 0; else ThrowException("Unexpected Failure"); diff --git a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs index 010308c..a535791 100644 --- a/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs +++ b/Nefarius.Peripherals.SerialPort/Win32PInvoke/Win32Com.cs @@ -5,17 +5,6 @@ namespace Nefarius.Peripherals.SerialPort.Win32PInvoke; internal class Win32Com { - // Constants for dwFunc: - internal const UInt32 SETXOFF = 1; - internal const UInt32 SETXON = 2; - internal const UInt32 SETRTS = 3; - internal const UInt32 CLRRTS = 4; - internal const UInt32 SETDTR = 5; - internal const UInt32 CLRDTR = 6; - internal const UInt32 RESETDEV = 7; - internal const UInt32 SETBREAK = 8; - internal const UInt32 CLRBREAK = 9; - //Constants for lpErrors: internal const UInt32 CE_RXOVER = 0x0001; internal const UInt32 CE_OVERRUN = 0x0002; @@ -42,12 +31,6 @@ internal class Win32Com [DllImport("kernel32.dll")] internal static extern Boolean TransmitCommChar(IntPtr hFile, Byte cChar); - /// - /// Control port functions. - /// - [DllImport("kernel32.dll")] - internal static extern Boolean EscapeCommFunction(IntPtr hFile, UInt32 dwFunc); - [DllImport("kernel32.dll")] internal static extern Boolean GetCommModemStatus(IntPtr hFile, out UInt32 lpModemStat); } \ No newline at end of file