SiLA2.SerialPort.Features 10.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package SiLA2.SerialPort.Features --version 10.2.2
                    
NuGet\Install-Package SiLA2.SerialPort.Features -Version 10.2.2
                    
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="SiLA2.SerialPort.Features" Version="10.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SiLA2.SerialPort.Features" Version="10.2.2" />
                    
Directory.Packages.props
<PackageReference Include="SiLA2.SerialPort.Features" />
                    
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 SiLA2.SerialPort.Features --version 10.2.2
                    
#r "nuget: SiLA2.SerialPort.Features, 10.2.2"
                    
#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 SiLA2.SerialPort.Features@10.2.2
                    
#: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=SiLA2.SerialPort.Features&version=10.2.2
                    
Install as a Cake Addin
#tool nuget:?package=SiLA2.SerialPort.Features&version=10.2.2
                    
Install as a Cake Tool

SiLA2.SerialPort.Features

A SiLA2 Feature package that exposes serial port communication capabilities via gRPC. This module provides a complete SiLA2 Feature Definition (FDL) and gRPC service implementation for serial port discovery, connection management, and data transfer.

Features

  • SiLA2-Compliant Interface: Full FDL-defined feature with gRPC service implementation
  • Port Discovery: Enumerate available serial ports with USB device metadata (VID/PID/Serial)
  • Connection Management: Connect/disconnect to multiple ports simultaneously
  • Data Transfer: Send data, read lines, and execute command-response protocols (SCPI)
  • Observable Properties: Subscribe to real-time updates for available and connected ports
  • USB Device Identification: Connect by VID/PID for reliable device identification
  • Cross-Platform: Windows, Linux, and macOS support

Installation

dotnet add package SiLA2.SerialPort.Features

This package requires SiLA2.Core and SiLA2.SerialPort which will be installed automatically as dependencies.

Quick Start

Register Services

// Program.cs
builder.Services.AddSerialPortManager();
builder.Services.AddSingleton<SerialCommunicationService>();

var app = builder.Build();

// Initialize SiLA2 features
app.InitializeSiLA2Features(siLA2Server);

// Map gRPC service
app.MapGrpcService<SerialCommunicationService>();

Client Usage

// Create channel and client
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new SerialCommunication.SerialCommunicationClient(channel);

// Connect to a port
await client.ConnectAsync(new Connect_Parameters
{
    PortName = new String { Value = "COM3" },
    BaudRate = new Integer { Value = 9600 },
    DataBits = new Integer { Value = 8 },
    StopBits = new String { Value = "One" },
    Parity = new String { Value = "None" }
});

// Send a SCPI command and get response
var response = await client.SendCommandAsync(new SendCommand_Parameters
{
    PortName = new String { Value = "COM3" },
    Command = new String { Value = "*IDN?" },
    TimeoutMs = new Integer { Value = 5000 }
});

Console.WriteLine($"Device ID: {response.Response.Value}");

Feature Definition

The SerialCommunication feature (FDL v1.0) provides:

Properties

Property Observable Description
AvailablePorts Yes List of available serial ports with detailed metadata
ConnectedPorts Yes List of currently connected port names

Commands

Command Description
Connect Connect to a serial port with configuration options
Disconnect Disconnect from a serial port
SendData Send string data to a connected port
SendCommand Send command and wait for response (SCPI-style)
ReadLine Read a line of text from a port
GetPortInfo Get detailed information about a specific port
ConnectByUsbId Connect by USB VID/PID for reliable device identification
FindPortByUsbId Find ports matching VID/PID without connecting

Defined Execution Errors

Error Description
PortNotFound The specified serial port was not found
PortInUse The serial port is in use by another process
ConnectionFailed Failed to establish connection
NotConnected Operation attempted on disconnected port
TransmissionFailed Data transmission failed
TimeoutError Operation timed out

Data Types

SerialPortInfo - Structured information about a serial port:

  • PortName - System port name (e.g., "COM3", "/dev/ttyUSB0")
  • Description - Friendly name or description
  • IsAvailable - Whether the port can be opened
  • IsConnected - Whether this service has it connected
  • VendorId - USB VID (hexadecimal, e.g., "0403")
  • ProductId - USB PID (hexadecimal, e.g., "6001")
  • SerialNumber - USB device serial number
  • Manufacturer - Device manufacturer name

Observable Properties

Subscribe to real-time port updates:

// Subscribe to available ports
using var call = client.Subscribe_AvailablePorts(new Subscribe_AvailablePorts_Parameters());

await foreach (var response in call.ResponseStream.ReadAllAsync())
{
    foreach (var port in response.AvailablePorts)
    {
        Console.WriteLine($"{port.SerialPortInfo.PortName.Value}: " +
                          $"{port.SerialPortInfo.Description.Value}");
    }
}

USB Device Identification

Connect to devices by VID/PID for reliable identification regardless of port assignment:

// Find FTDI devices (VID=0403)
var ftdiPorts = await client.FindPortByUsbIdAsync(new FindPortByUsbId_Parameters
{
    VendorId = new String { Value = "0403" },
    ProductId = new String { Value = "6001" }
});

// Connect by USB ID
var result = await client.ConnectByUsbIdAsync(new ConnectByUsbId_Parameters
{
    VendorId = new String { Value = "0403" },
    ProductId = new String { Value = "6001" },
    SerialNumber = new String { Value = "" },  // Match any
    BaudRate = new Integer { Value = 115200 },
    DataBits = new Integer { Value = 8 },
    StopBits = new String { Value = "One" },
    Parity = new String { Value = "None" }
});

Console.WriteLine($"Connected to port: {result.PortName.Value}");

Server Implementation

To implement the service in your SiLA2 server:

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        // Add SiLA2 services
        builder.Services.AddSingleton<ISiLA2Server, SiLA2Server>();
        builder.Services.AddSerialPortManager();
        builder.Services.AddSingleton<SerialCommunicationService>();
        builder.Services.AddGrpc();

        var app = builder.Build();

        // Initialize SiLA2
        var silaServer = app.Services.GetRequiredService<ISiLA2Server>();
        app.InitializeSiLA2Features(silaServer);

        // Map gRPC services
        app.MapGrpcService<SerialCommunicationService>();

        silaServer.Start();
        app.Run();
    }
}

Feature Definition Location

The SiLA2 Feature Definition XML file is embedded in the assembly:

  • Features/SerialCommunication-v1_0.sila.xml

At runtime, copy this file to your output directory or include it as embedded resource.

  • SiLA2.SerialPort: Core serial port library (non-gRPC)
  • SiLA2.Core: Core SiLA2 server implementation
  • SiLA2.AspNetCore: ASP.NET Core integration

Platform Support

  • Windows: Full support with native COM port and WMI-based USB enumeration
  • Linux: Supported via .NET (ports at /dev/ttyUSB*, /dev/ttyACM*)
  • macOS: Supported via .NET (ports at /dev/tty.*)

License

MIT License - See LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  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
10.2.4 90 3/13/2026
10.2.3 76 3/7/2026
10.2.2 87 3/1/2026