ElegantSeries.SerialPort
1.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ElegantSeries.SerialPort --version 1.0.3
NuGet\Install-Package ElegantSeries.SerialPort -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ElegantSeries.SerialPort" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ElegantSeries.SerialPort --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ElegantSeries.SerialPort, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ElegantSeries.SerialPort as a Cake Addin #addin nuget:?package=ElegantSeries.SerialPort&version=1.0.3 // Install ElegantSeries.SerialPort as a Cake Tool #tool nuget:?package=ElegantSeries.SerialPort&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ElegantSeries.SerialPort
This is a .Net System.IO.Ports extension library, designed to help simplify packet reading.
Download
Package is available at NuGet:
Using the code
- Read fixed length data.
SerialPort serialPort = new SerialPort();
byte[] bytes = new byte[10];
// default timeout 5000ms
serialPort.Read(bytes);
// custom timeout 1000ms
serialPort.Read(bytes, 1000);
- Read fixed length data, specify the first few bytes.
SerialPort serialPort = new SerialPort();
byte[] bytes = new byte[10];
byte[] first = new byte[2];
first[0] = 0x0A;
first[1] = 0x0B;
serialPort.Read(bytes, first);
- Read fixed length data, specify the first few bytes and the last few bytes.
SerialPort serialPort = new SerialPort();
byte[] bytes = new byte[10];
byte[] first = new byte[2];
first[0] = 0x0A;
first[1] = 0x0B;
byte[] last = new byte[2];
last[0] = 0xA0;
last[1] = 0xB0;
serialPort.Read(bytes, first, last);
- Cancel reading data.
CancellationTokenSource cts = new CancellationTokenSource();
CancellationToken token = cts.Token;
SerialPort serialPort = new SerialPort();
byte[] bytes = new byte[10];
serialPort.Read(bytes, token:token);
// Execute on other thread
cts.Cancel();
Using the Utilities
- ReuseBuffer Class.
Multiplex the same packet. e.g., different methods use the same packet for data parsing.
ReuseBuffer reuseBuffer = new() { Number = 2 };
SerialPort serialPort = new SerialPort();
byte[] bytes = new byte[10];
serialPort.Read(bytes);
reuseBuffer.Data = bytes;
var bytes1 = reuseBuffer.Data;
var bytes2 = reuseBuffer.Data;
var bytes3 = reuseBuffer.Data;
// bytes1 == bytes2 == bytes, bytes3 == null.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- System.IO.Ports (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
.Net SerialPort Extensions