crozone.SerialPorts.LinuxSerialPort 2.0.3

dotnet add package crozone.SerialPorts.LinuxSerialPort --version 2.0.3                
NuGet\Install-Package crozone.SerialPorts.LinuxSerialPort -Version 2.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="crozone.SerialPorts.LinuxSerialPort" Version="2.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add crozone.SerialPorts.LinuxSerialPort --version 2.0.3                
#r "nuget: crozone.SerialPorts.LinuxSerialPort, 2.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 crozone.SerialPorts.LinuxSerialPort as a Cake Addin
#addin nuget:?package=crozone.SerialPorts.LinuxSerialPort&version=2.0.3

// Install crozone.SerialPorts.LinuxSerialPort as a Cake Tool
#tool nuget:?package=crozone.SerialPorts.LinuxSerialPort&version=2.0.3                

crozone.SerialPorts.LinuxSerialPort

NuGet license

A managed Linux Serial Port implementation targeting netstandard2.0. This implementation performs all serial port setup by calling the /bin/stty binary, rather than relying on any native interop directly. This means it should work on any system that has a POSIX compatible /bin/stty binary.

About

This SerialPort class is intended to offer similar functionality to the System.IO.Ports.SerialPort class provided by Microsoft. However, although much of the interface is the same or similar, it is not intended to be a direct drop in replacement.

Most basic functionality is covered, including the configuration of the BaudRate, DataBits, StopBits, Handshake, and Parity.

The class implements the shared ISerialPort interface from crozone.SerialPorts.Abstractions. This allows it to be compatible with the crozone.SerialPorts.WindowsSerialPort wrapper for System.IO.Ports.SerialPort, which makes cross-platform development easier.

Properties

The SerialPort.BaseStream property provides the underlying Stream used to read and write from the serial port. It is a direct filestream opened on the serial port file. The SerialPort.Read() and SerialPort.Write() methods are absent from the SerialPort class itself (as an aside, these are problematic in the Microsoft implementation anyway). The SerialPort.DataReceived event is also absent (and it is also unreliable in the Microsoft implementation, and difficult to implement correctly).

SerialPort.EnableRawMode must be set to true in order to disable Linux TTY behaviour, and since v1.1.0 is set to true by default. This will be the desired behaviour for most people and allow the reading/writing of raw bytes to the serial port without the interference of the kernel TTY layer.

SerialPort.MinimumBytesToRead and SerialPort.ReadTimeout allow the blocking behaviour of BaseStream.Read() to be modified.

SerialPort.MinimumBytesToRead corresponds to the stty min parameter. MinimumBytesToRead specifies the minimum number of bytes to be read before BaseStream.Read() will return. BaseStream.Read() will only return after MinimumBytesToRead bytes have been read, or the timeout has been reached. Setting MinimumBytesToRead to 0 will cause BaseStream.Read() to never block, and instantly return whatever bytes are available in the buffer, even if the buffer is empty.

SerialPort.ReadTimeout corresponds to the stty time parameter. ReadTimeout specifies the number of milliseconds a BaseStream.Read() will block for, before it times out. After it times out, it will return whatever data has been read, which may be zero bytes. Due to stty constraints, the time-span will be rounded to the nearest tenth of a second (100ms resolution). A ReadTimeout of 0 specifies an infinite timeout. When an infinite timeout is set, the BaseStream.Read() will only return after MinimumBytesToRead bytes have been read.

SerialPort.EnableDrain controls the use of the stty [-]drain setting. If drain is enabled (true), stty will attempt to flush the serial port write buffer before applying any configuration to the serial port. This is problematic if the serial port has data in the write buffer and flow control is enabled, since the buffer may never flush, causing stty to hang indefinitely.

If your code is hanging during LinuxSerialPort.Open(), this is likely the bug you are seeing.

To fix this, set SerialPort.EnableDrain = false. This is only possible if [-]drain is available in your version of stty. [-]drain is not a POSIX compatible command, and older/different versions of stty may not have it available, so be sure to check before setting this. All versions of stty use drain enabled behaviour by default, including the stty versions that to not have the option available.

Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on crozone.SerialPorts.LinuxSerialPort:

Package Downloads
TRONIC.GsmModemSmsLibrary

Library to handle connection to GSM Modem and sending sms using AT+ commands. Support for both Windows and Linux OS.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 2,449 9/2/2019
2.0.2 725 8/28/2019

Use updated abstractions version