RxSerialPort 1.2.31
dotnet add package RxSerialPort --version 1.2.31
NuGet\Install-Package RxSerialPort -Version 1.2.31
<PackageReference Include="RxSerialPort" Version="1.2.31" />
paket add RxSerialPort --version 1.2.31
#r "nuget: RxSerialPort, 1.2.31"
// Install RxSerialPort as a Cake Addin #addin nuget:?package=RxSerialPort&version=1.2.31 // Install RxSerialPort as a Cake Tool #tool nuget:?package=RxSerialPort&version=1.2.31
RxSerialPort
An extension to the classic System.IO.Ports.SerialPort
class, to be able to use reactive extensions.
It enables developers to create observable streams from received data of a serial port or to write data from an observable stream to a serial port in an reactive and functional way of programming.
Create observable stream from SerialPort
Internally managed SerialPort
Use one of the static connect methods from RxSerialPort
. There is a connect method for all SerialPort
constructors. If there is a need to do additional stuff, a port factory kann be provided.
var eventObservable = RxSerialPort.Connect("COM1");
Do NOT use the serialport from the read function anywhere else! This serialport will be created and opened by the static function upon subscribing to the stream und will also be disposed if the stream is not longer needed.
Externally managed SerialPort
If there is already a serial port available, just use on of the extension methods to connect to the port.
SerialPort serialPort = ...;
var eventObservable = serialPort.Connect()
In this case the serialPort needs to be opened, closed and disposed by the using code! If the port is not opend, no data events will be fired.
Read data from SerialPort
After connecting to the serial port a AndRead
extension can be used. For every read method of SerialPort
there is a extension function. Plus a specific read funtion can be provided (eg for testing).
var eventsWithData = eventObservable.AndReadLine();
var eventsWithData = eventObservable.AndReadExisting();
var eventsWithData = eventObservable.AndReadTo(string valueToReadTo);
var eventsWithData = eventObservable.AndReadByte();
var eventsWithData = eventObservable.AndReadChar();
var eventsWithData = eventObservable.AndRead<TResult>(serialPort => { /* Do the reading */ });
Write observable stream data to SerialPort
There are different extension methods to write data form an observable stream to a serialport. The SerialPort
can be managed internally or externally. A completed and error Action can be provided optionally. Plus a specific write funtion can be provided (eg for testing).
Internally managed SerialPort
IObservable<bytes[]> bytesToWrite = ...
IDisposable subscription = bytesToWrite.WriteTo("COM1");
IObservable<char[]> charsToWrite = ...
IDisposable subscription = charsToWrite.WriteTo("COM1");
IObservable<string> stringsToWrite = ...
IDisposable subscription = stringsToWrite.WriteTo("COM1");
IDisposable subscription = stringsToWrite.WriteLineTo("COM1");
IDisposable subscription = stringsToWrite.WriteLineTo("COM1", (serialPort, data) => { /* Do the writing */});
Externally managed SerialPort
SerialPort serialPort = ...
IObservable<bytes[]> bytesToWrite = ...
IDisposable subscription = bytesToWrite.WriteTo(serialPort);
IObservable<char[]> charsToWrite = ...
IDisposable subscription = charsToWrite.WriteTo(serialPort);
IObservable<string> stringsToWrite = ...
IDisposable subscription = stringsToWrite.WriteTo(serialPort);
IDisposable subscription = stringsToWrite.WriteLineTo(serialPort);
IDisposable subscription = stringsToWrite.WriteLineTo(serialPort, (serialPort, data) => { /* Do the writing */});
Testing
The test project consists mainly of tests to test the correct creation of the observbales and observers. To test with real serial ports the tag TEST_WITH_REAL_PORTS
needs to be set to true.
Virtual COM Ports are very easy to setup with NetBurner VirtualComPort. One port needs to send its data to the other port.
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 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.IO.Ports (>= 9.0.0)
- System.Reactive (>= 6.0.1)
-
net8.0
- System.IO.Ports (>= 9.0.0)
- System.Reactive (>= 6.0.1)
-
net9.0
- System.IO.Ports (>= 9.0.0)
- System.Reactive (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.