Merge branch 'master' into nefarius/bugfix/refactoring

This commit is contained in:
Benjamin Höglinger-Stelzer 2024-07-13 14:12:03 +02:00
commit 6aaf2aacb3
6 changed files with 50 additions and 32 deletions

View File

@ -1,6 +1,6 @@
MIT License 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 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -15,7 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PInvokeSerialPort.Test", "PInvokeSerialPort.Test\PInvokeSerialPort.Test.csproj", "{928609B4-70AB-4D93-A43E-4BE75C279066}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PInvokeSerialPort.Test", "PInvokeSerialPort.Test\PInvokeSerialPort.Test.csproj", "{928609B4-70AB-4D93-A43E-4BE75C279066}"
EndProject 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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.ActiveCfg = Release|Any CPU
{928609B4-70AB-4D93-A43E-4BE75C279066}.Release|Any CPU.Build.0 = 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.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 {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.ActiveCfg = Debug|Any CPU
{76FAB402-7515-4A9B-8605-4FEC0736C78A}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|Any CPU.Build.0 = 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.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.ActiveCfg = Release|x86
{76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|x86.Build.0 = Release|x86 {76FAB402-7515-4A9B-8605-4FEC0736C78A}.Release|x86.Build.0 = Release|x86
EndGlobalSection EndGlobalSection

View File

@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Rlsd/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Savailable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xoff/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -1,29 +1,36 @@
using Nefarius.Peripherals.SerialPort.Win32PInvoke; using Windows.Win32.Devices.Communication;
namespace Nefarius.Peripherals.SerialPort namespace Nefarius.Peripherals.SerialPort;
/// <summary>
/// Represents the status of the modem control input signals.
/// </summary>
public readonly struct ModemStatus
{ {
/// <summary> private readonly MODEM_STATUS_FLAGS _status;
/// Represents the status of the modem control input signals.
/// </summary> internal ModemStatus(MODEM_STATUS_FLAGS val)
public struct ModemStatus
{ {
private readonly uint _status; _status = val;
internal ModemStatus(uint val) { _status = val; }
/// <summary>
/// Condition of the Clear To Send signal.
/// </summary>
public bool Cts { get { return ((_status & Win32Com.MS_CTS_ON) != 0); } }
/// <summary>
/// Condition of the Data Set Ready signal.
/// </summary>
public bool Dsr { get { return ((_status & Win32Com.MS_DSR_ON) != 0); } }
/// <summary>
/// Condition of the Receive Line Status Detection signal.
/// </summary>
public bool Rlsd { get { return ((_status & Win32Com.MS_RLSD_ON) != 0); } }
/// <summary>
/// Condition of the Ring Detection signal.
/// </summary>
public bool Ring { get { return ((_status & Win32Com.MS_RING_ON) != 0); } }
} }
/// <summary>
/// Condition of the Clear To Send signal.
/// </summary>
public bool Cts => (_status & MODEM_STATUS_FLAGS.MS_CTS_ON) != 0;
/// <summary>
/// Condition of the Data Set Ready signal.
/// </summary>
public bool Dsr => (_status & MODEM_STATUS_FLAGS.MS_DSR_ON) != 0;
/// <summary>
/// Condition of the Receive Line Status Detection signal.
/// </summary>
public bool Rlsd => (_status & MODEM_STATUS_FLAGS.MS_RLSD_ON) != 0;
/// <summary>
/// Condition of the Ring Detection signal.
/// </summary>
public bool Ring => (_status & MODEM_STATUS_FLAGS.MS_RING_ON) != 0;
} }

View File

@ -31,6 +31,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.63-beta"> <PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.63-beta">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>

16
README.md Executable file → Normal file
View File

@ -1,9 +1,17 @@
<img src="assets/NSS-128x128.png" align="right" /> # <img src="assets/NSS-128x128.png" align="left" />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) 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`