DotSerial 1.1.0

dotnet add package DotSerial --version 1.1.0
                    
NuGet\Install-Package DotSerial -Version 1.1.0
                    
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="DotSerial" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotSerial" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DotSerial" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotSerial --version 1.1.0
                    
#r "nuget: DotSerial, 1.1.0"
                    
#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.
#:package DotSerial@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotSerial&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DotSerial&version=1.1.0
                    
Install as a Cake Tool

๐Ÿ”Œ DotSerial

NuGet NuGet Downloads CI codecov License: MIT .NET

DotSerial is a modern, cross-platform .NET serial port library that works identically on Windows, Linux, macOS, Android, and iOS. It provides a clean interface for both classic byte-level I/O and stream-based communication, with built-in logging and full dependency injection support.

โœจ Features

  • ๐ŸŒ Cross-platform โ€” Windows, Linux, macOS, Android, iOS
  • ๐Ÿ”„ Classic & Stream I/O โ€” Write/Read and Stream-based access
  • โšก Async-first โ€” full async/await support with CancellationToken
  • ๐Ÿ“‹ Dependency Injection โ€” works with Microsoft.Extensions.DependencyInjection
  • ๐Ÿ“ Logging โ€” built-in Microsoft.Extensions.Logging integration
  • ๐Ÿงช Testable โ€” interface-based design; fully mockable
  • ๐ŸŽฏ SOLID โ€” clean abstractions, single-responsibility, open for extension

๐Ÿ“ฆ Installation

dotnet add package DotSerial

๐Ÿš€ Quick Start

Classic I/O

using DotSerial;
using DotSerial.Models;

var factory = new SerialPortFactory(LoggerFactory.Create(b => b.AddConsole()));

using var port = factory.Create(new SerialPortSettings
{
    PortName = "COM3",
    BaudRate = 115200,
    DataBits = 8,
});

port.Open();
port.WriteLine("Hello, Serial!");
string response = port.ReadLine();
port.Close();

Stream-based I/O

port.Open();
var stream = port.BaseStream;

using var writer = new StreamWriter(stream, leaveOpen: true);
using var reader = new StreamReader(stream, leaveOpen: true);

await writer.WriteLineAsync("AT");
string? reply = await reader.ReadLineAsync();

Dependency Injection

builder.Services.AddLogging();
builder.Services.AddDotSerial();

public class MyService(ISerialPortFactory factory)
{
    public void Send(string portName, string data)
    {
        using var port = factory.Create(new SerialPortSettings { PortName = portName });
        port.Open();
        port.WriteLine(data);
    }
}

๐Ÿ–ฅ๏ธ Supported Platforms

Platform Support Notes
Windows โœ… Full COM1โ€ฆCOMn via System.IO.Ports
Linux โœ… Full /dev/ttyUSB*, /dev/ttyS*
macOS โœ… Full /dev/cu.*
Android ๐Ÿšง Planned USB Host Mode, requires android.permission.USB_PERMISSION
iOS ๐Ÿšง Planned External Accessory (MFi accessories only)

๐Ÿ“ก Events

port.DataReceived  += (s, e) => Console.WriteLine($"Data: {e.EventType}");
port.ErrorReceived += (s, e) => Console.WriteLine($"Error: {e.ErrorType}");
port.PinChanged    += (s, e) => Console.WriteLine($"Pin: {e.EventType}");

๐Ÿ” Port Discovery

var factory = new SerialPortFactory(loggerFactory);
var ports = factory.GetPortNames();
foreach (var name in ports) Console.WriteLine(name);

๐Ÿงช Running Tests

# Unit tests
dotnet test tests/DotSerial.Tests.Unit

# Single test
dotnet test tests/DotSerial.Tests.Unit --filter "FullyQualifiedName~SerialPortSettingsTests"

# Integration tests (requires a real or virtual COM port)
dotnet test tests/DotSerial.Tests.Integration

๐Ÿค Contributing

Please read CONTRIBUTING.md before opening a pull request.

๐Ÿ“„ License

MIT ยฉ Piergiorgio Vagnozzi

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-android36.0 is compatible.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.1.0 104 5/1/2026