Migrated to CsWin32 #1
@ -5,7 +5,6 @@ FILE_ACCESS_RIGHTS
|
||||
GetCommModemStatus
|
||||
GetCommProperties
|
||||
GetHandleInformation
|
||||
GetHandleInformation
|
||||
GetOverlappedResult
|
||||
MODEM_STATUS_FLAGS
|
||||
ReadFile
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Text;
|
||||
using Nefarius.Peripherals.SerialPort.Win32PInvoke;
|
||||
|
||||
|
||||
namespace Nefarius.Peripherals.SerialPort
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -11,8 +11,6 @@ using Windows.Win32.Storage.FileSystem;
|
||||
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
using Nefarius.Peripherals.SerialPort.Win32PInvoke;
|
||||
|
||||
namespace Nefarius.Peripherals.SerialPort;
|
||||
|
||||
/// <summary>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user