diff --git a/LICENSE b/LICENSE index 5353eb2..21ca638 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Benjamin Höglinger-Stelzer +Copyright (c) 2012-2017 Ebrahim Byagowi, 2018 Benjamin Höglinger-Stelzer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Nefarius.Peripherals.SerialPort.sln b/Nefarius.Peripherals.SerialPort.sln index 0275349..3908637 100644 --- a/Nefarius.Peripherals.SerialPort.sln +++ b/Nefarius.Peripherals.SerialPort.sln @@ -15,7 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PInvokeSerialPort.Test", "PInvokeSerialPort.Test\PInvokeSerialPort.Test.csproj", "{928609B4-70AB-4D93-A43E-4BE75C279066}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PInvokeSerialPort.Sample", "PInvokeSerialPort.Sample\PInvokeSerialPort.Sample.csproj", "{76FAB402-7515-4A9B-8605-4FEC0736C78A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PInvokeSerialPort.Sample", "PInvokeSerialPort.Sample\PInvokeSerialPort.Sample.csproj", "{76FAB402-7515-4A9B-8605-4FEC0736C78A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -47,7 +47,6 @@ Global {928609B4-70AB-4D93-A43E-4BE75C279066}.Release|Any CPU.ActiveCfg = Release|Any CPU {928609B4-70AB-4D93-A43E-4BE75C279066}.Release|Any CPU.Build.0 = Release|Any CPU {928609B4-70AB-4D93-A43E-4BE75C279066}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {928609B4-70AB-4D93-A43E-4BE75C279066}.Release|Mixed Platforms.Build.0 = Release|Any CPU {928609B4-70AB-4D93-A43E-4BE75C279066}.Release|x86.ActiveCfg = Release|Any CPU {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -58,7 +57,6 @@ Global {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|Any CPU.ActiveCfg = Release|Any CPU {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|Any CPU.Build.0 = Release|Any CPU {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|Mixed Platforms.ActiveCfg = Release|x86 - {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|Mixed Platforms.Build.0 = Release|x86 {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|x86.ActiveCfg = Release|x86 {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|x86.Build.0 = Release|x86 EndGlobalSection diff --git a/Nefarius.Peripherals.SerialPort.sln.DotSettings b/Nefarius.Peripherals.SerialPort.sln.DotSettings new file mode 100644 index 0000000..e3e5fbe --- /dev/null +++ b/Nefarius.Peripherals.SerialPort.sln.DotSettings @@ -0,0 +1,4 @@ + + True + True + True \ No newline at end of file diff --git a/Nefarius.Peripherals.SerialPort/ModemStatus.cs b/Nefarius.Peripherals.SerialPort/ModemStatus.cs index dc993c9..64529c4 100644 --- a/Nefarius.Peripherals.SerialPort/ModemStatus.cs +++ b/Nefarius.Peripherals.SerialPort/ModemStatus.cs @@ -1,29 +1,36 @@ -using Nefarius.Peripherals.SerialPort.Win32PInvoke; +using Windows.Win32.Devices.Communication; -namespace Nefarius.Peripherals.SerialPort +namespace Nefarius.Peripherals.SerialPort; + +/// +/// Represents the status of the modem control input signals. +/// +public readonly struct ModemStatus { - /// - /// Represents the status of the modem control input signals. - /// - public struct ModemStatus + private readonly MODEM_STATUS_FLAGS _status; + + internal ModemStatus(MODEM_STATUS_FLAGS val) { - private readonly uint _status; - internal ModemStatus(uint val) { _status = val; } - /// - /// Condition of the Clear To Send signal. - /// - public bool Cts { get { return ((_status & Win32Com.MS_CTS_ON) != 0); } } - /// - /// Condition of the Data Set Ready signal. - /// - public bool Dsr { get { return ((_status & Win32Com.MS_DSR_ON) != 0); } } - /// - /// Condition of the Receive Line Status Detection signal. - /// - public bool Rlsd { get { return ((_status & Win32Com.MS_RLSD_ON) != 0); } } - /// - /// Condition of the Ring Detection signal. - /// - public bool Ring { get { return ((_status & Win32Com.MS_RING_ON) != 0); } } + _status = val; } + + /// + /// Condition of the Clear To Send signal. + /// + public bool Cts => (_status & MODEM_STATUS_FLAGS.MS_CTS_ON) != 0; + + /// + /// Condition of the Data Set Ready signal. + /// + public bool Dsr => (_status & MODEM_STATUS_FLAGS.MS_DSR_ON) != 0; + + /// + /// Condition of the Receive Line Status Detection signal. + /// + public bool Rlsd => (_status & MODEM_STATUS_FLAGS.MS_RLSD_ON) != 0; + + /// + /// Condition of the Ring Detection signal. + /// + public bool Ring => (_status & MODEM_STATUS_FLAGS.MS_RING_ON) != 0; } \ No newline at end of file diff --git a/Nefarius.Peripherals.SerialPort/Nefarius.Peripherals.SerialPort.csproj b/Nefarius.Peripherals.SerialPort/Nefarius.Peripherals.SerialPort.csproj index c462703..370ebf2 100644 --- a/Nefarius.Peripherals.SerialPort/Nefarius.Peripherals.SerialPort.csproj +++ b/Nefarius.Peripherals.SerialPort/Nefarius.Peripherals.SerialPort.csproj @@ -31,6 +31,7 @@ + all diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 39ab910..9558139 --- a/README.md +++ b/README.md @@ -1,9 +1,17 @@ - +# Nefarius.Peripherals.SerialPort -# Nefarius.Peripherals.SerialPort +Like `System.IO.Ports.SerialPort` but actually works 😏 -Originally copied from http://msdn.microsoft.com/en-us/magazine/cc301786.aspx that I guess licensed under Ms-PL so this project is also under Ms-PL. (Update: well, after the years now I think this was not a true claim, but well I don't think MS will sue anyone because a sample intended for public use) +## About + +Originally copied from [John Hind - "Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications"](http://msdn.microsoft.com/en-us/magazine/cc301786.aspx) that I guess licensed under Ms-PL so this project is also under Ms-PL. (Update: well, after the years now I think this was not a true claim, but well I don't think MS will sue anyone because a sample intended for public use) It is useful in the cases System.IO.Ports.SerialPort is not working well (for connecting to \\\\.\\... devices) -Download it from https://nuget.org/packages/PInvokeSerialPort :) +## Motivation behind this fork + +`System.IO.Ports.SerialPort` is terrible and [this is exactly what I've experienced in a project](https://www.sparxeng.com/blog/software/must-use-net-system-io-ports-serialport) so this library came to the rescue. + +## Download + +Consume the NuGet via `Install-Package Nefarius.Peripherals.SerialPort`