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
<PackageReference Include="BlackSharp.IO.Ports" Version="1.3.2" />
<PackageVersion Include="BlackSharp.IO.Ports" Version="1.3.2" />
<PackageReference Include="BlackSharp.IO.Ports" />
paket add BlackSharp.IO.Ports --version 1.3.2
#r "nuget: BlackSharp.IO.Ports, 1.3.2"
#:package BlackSharp.IO.Ports@1.3.2
#addin nuget:?package=BlackSharp.IO.Ports&version=1.3.2
#tool nuget:?package=BlackSharp.IO.Ports&version=1.3.2
<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>
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
USBDeviceStreamon 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 | Versions 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. |
-
.NETFramework 4.7.2
- BlackSharp.Core (>= 1.3.2)
-
.NETFramework 4.8.1
- BlackSharp.Core (>= 1.3.2)
-
.NETStandard 2.0
- BlackSharp.Core (>= 1.3.2)
- Microsoft.Win32.Registry (>= 5.0.0)
-
net10.0
- BlackSharp.Core (>= 1.3.2)
-
net11.0
- BlackSharp.Core (>= 1.3.2)
-
net8.0
- BlackSharp.Core (>= 1.3.2)
-
net9.0
- BlackSharp.Core (>= 1.3.2)
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 |