BlackSharp.IO.Ports 1.3.2

Prefix Reserved
dotnet add package BlackSharp.IO.Ports --version 1.3.2
                    
NuGet\Install-Package BlackSharp.IO.Ports -Version 1.3.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="BlackSharp.IO.Ports" Version="1.3.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlackSharp.IO.Ports" Version="1.3.2" />
                    
Directory.Packages.props
<PackageReference Include="BlackSharp.IO.Ports" />
                    
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 BlackSharp.IO.Ports --version 1.3.2
                    
#r "nuget: BlackSharp.IO.Ports, 1.3.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 BlackSharp.IO.Ports@1.3.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=BlackSharp.IO.Ports&version=1.3.2
                    
Install as a Cake Addin
#tool nuget:?package=BlackSharp.IO.Ports&version=1.3.2
                    
Install as a Cake Tool

<h1 align="center">BlackSharp.IO.Ports</h1>

<p align="center"> <img src="https://raw.githubusercontent.com/Blacktempel/BlackSharp/master/Assets/BlackSharpFull.png" width="128" height="128" alt="BlackSharp.IO.Ports logo"/> </p>

NuGet NuGet downloads .NET Framework .NET GitHub Sponsors PayPal License

BlackSharp.IO.Ports provides native serial-port and raw USB-device access. Its serial-port API uses the underlying operating system directly.

Features

  • USB serial device discovery
  • Configurable baud rate, data bits, parity and stop bits
  • No flow control, XON/XOFF, RTS/CTS or combined XON/XOFF and RTS/CTS
  • DTR/RTS control, buffer purge, read/write timeouts and close waits
  • Raw USB reads and writes through USBDeviceStream on supported platforms
  • Linux USB discovery with optional vendor and product ID filtering
  • Configurable libusb interfaces, bulk endpoints and kernel-driver detachment
  • libusb control transfers and endpoint halt recovery
  • Optional Windows read IOCTL mapping for driver-backed USB devices

Supported .NET versions

.NET version Support
.NET Framework 4.7.2 ✅
.NET Framework 4.8.1 ✅
.NET Standard 2.0 ✅
.NET 8 ✅
.NET 9 ✅
.NET 10 ✅
.NET 11 ✅

NuGet

dotnet add package BlackSharp.IO.Ports

Supported platforms

Operating system Support Serial Raw USB
Windows ✅ Win32 COM port handles with overlapped I/O Native driver-backed device handles
Linux ✅ POSIX I/O with termios libusb
Other ❌ Not implemented Not implemented

Linux raw USB access requires libusb-1.0.so.0 and operating-system permissions for the target device. On Windows, supply the native device path from a device-specific enumerator to USBDeviceInfo. USBDeviceStream.GetDevices() enumerates raw USB devices on Linux only.

Usage

Serial port

Replace COM12 with the target port. Linux accepts a full path such as /dev/ttyUSB0 or a short name such as ttyUSB0.

using BlackSharp.IO.Ports;

using var port = new SerialPort("COM12")
{
    BaudRate     = 115200,
    DataBits     = 8,
    Parity       = Parity.None,
    StopBits     = StopBits.One,
    Handshake    = Handshake.None,
    ReadTimeout  = 500,
    WriteTimeout = 500,
    CloseTimeout = TimeSpan.FromMilliseconds(500),
    DtrEnable    = false,
    RtsEnable    = false,
};

port.Open();
port.Write(new byte[] { 0x01, 0x02, 0x03 });

var buffer = new byte[256];
int read = port.Read(buffer, 0, buffer.Length);

Console.WriteLine($"Received {read} bytes.");

bool closed = port.TryClose(TimeSpan.FromMilliseconds(500));

if (!closed)
{
    Console.WriteLine("The port is still closing in the background.");
}

Raw USB on Linux

Replace the example IDs, interface, endpoints and request byte with the values for your device.

using BlackSharp.IO.Ports;

var devices = USBDeviceStream.GetDevices(
    (vendorID, productID) => vendorID == 0x1234 && productID == 0x5678);

var options = new USBDeviceStreamOptions
{
    InterfaceNumber = 0,
    ReadEndpoint    = 0x81,
    WriteEndpoint   = 0x01,
};

using var stream = USBDeviceStream.Open(devices.FirstOrDefault(), options);

if (stream != null && stream.Write(new byte[] { 0x01 }, 500, out int bytesWritten))
{
    var response = new byte[64];

    if (stream.Read(response, 500, out int bytesRead))
    {
        Console.WriteLine($"Sent {bytesWritten} bytes and received {bytesRead} bytes.");
    }
}

Serial port close timeouts

TryClose(timeout) returns false if the native close path does not finish within the specified timeout. Discard that SerialPort instance. The close request stays in the background, so the OS may still hold the port until the request finishes or the process exits.

The close worker rotates after a timeout. Requests still queued on the old worker move to the new worker. A permanently blocked native operation can leave the old background thread running until process exit.

Support and license

Report issues in the BlackSharp issue tracker. Licensed under the Mozilla Public License 2.0.

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 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.  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.  net11.0 is compatible. 
.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 is compatible.  net48 was computed.  net481 is compatible. 
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

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.3.2 91 11/30/2026
1.3.1 98 11/24/2026
1.3.0 106 11/21/2026
1.2.12 111 11/16/2026
1.2.11 117 11/10/2026
1.2.10 103 11/6/2026
1.2.9 94 11/4/2026
1.2.8 111 11/1/2026
1.2.7 107 10/30/2026
1.2.6 113 10/28/2026
1.2.5 113 10/23/2026
1.2.4 112 10/22/2026
1.2.3 133 10/11/2026
1.2.2 135 9/23/2026
1.2.1 160 9/14/2026
1.2.0 154 8/21/2026
1.1.4 160 7/23/2026
1.1.3 146 7/19/2026
1.1.2 154 6/14/2026
1.1.1 158 5/22/2026
Loading failed