rskibbe.IO.Ports 1.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package rskibbe.IO.Ports --version 1.0.5                
NuGet\Install-Package rskibbe.IO.Ports -Version 1.0.5                
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="rskibbe.IO.Ports" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add rskibbe.IO.Ports --version 1.0.5                
#r "nuget: rskibbe.IO.Ports, 1.0.5"                
#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 rskibbe.IO.Ports as a Cake Addin
#addin nuget:?package=rskibbe.IO.Ports&version=1.0.5

// Install rskibbe.IO.Ports as a Cake Tool
#tool nuget:?package=rskibbe.IO.Ports&version=1.0.5                

Description

A simple package to extend SerialPort communication by adding some async helper methods.

Getting started

After installation, just go ahead and import the corresponding namespace:

C#

using rskibbe.IO.Ports;

Visual Basic .NET

Imports rskibbe.IO.Ports

Examples

Simple, general SerialPort setup

// create serial port instance
var serialPort = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);

// setting (only) newline without carriage return as line / message terminator
serialPort.NewLine = "\n";

Simple async line-read

// reading the data till newline terminator - but not inclusive!
var data = await serialPort.ReadLineAsync();

// do something with the data..

Simple async line-write

// create some string-data to be sent
var myData = "A message to com device";

// sends the string data with ending NewLine terminator
await serialPort.WriteLineAsync(myData);

Do a simple request<->response thing

// create some command to be sent
var cmd = "MOVE:30:30";

// send the command and retrieve the response in one step
var response = await serialPort.RequestResponseAsync(cmd);

// process the response somehow..

Functions & Methods

This will enable using the following helper methods & functions.

Keep in mind to actually set a correct NewLine property on the SerialPort-instance itself. Otherwise the functions may not work as you would expect.

ReadLineAsync

Read all data bytewise as string, till a NewLine occurence is being found.

This function does not include the NewLine String itself.

ReadLineAsync(CancellationToken)

Same as above, but with the possibility to provide a CancellationToken.

WriteLineAsync(String)

Writes the target String into the stream, followed by the specified SerialPorts instance NewLine property value as message terminator.

This function will also Flush the Stream async

RequestResponseAsync(String)

Many SerialPort devices are built to work with a Request->Response-alike mechanism. Use this function to send some string data and to get the response right afterwards.

Is the same as using WriteLineAsync first and then getting the response by ReadLineAsync.

RequestResponseAsync(String, CancellationToken)

Same as above, but with the possibility to provide a CancellationToken.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 381 2/1/2023
1.0.5 419 6/15/2022
1.0.4 393 6/15/2022
1.0.3 401 6/13/2022
1.0.2 395 6/13/2022
1.0.1 404 6/10/2022
1.0.0 407 6/10/2022