crozone.SerialPorts.LinuxSerialPort 2.0.3

.NET Standard 2.0
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


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.


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.


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 Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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

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 1,628 9/2/2019
2.0.2 547 8/28/2019

Use updated abstractions version