Oakrey.UHD 3.0.3

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

Oakrey.UHD

A .NET P/Invoke wrapper for the Ettus Research UHD (USRP Hardware Driver) native library. It provides TX streaming, frequency and gain tuning, stream metadata handling, and structured logging via IObservable<ILogEvent> for USRP software-defined radio devices.

Main features

  • TX streaming - UhdStream extends System.IO.Stream and implements IObservable<ILogEvent>. Write raw IQ sample data directly from any .NET stream source, including files.
  • Frequency and gain tuning - TuneRequest / TuneResult with configurable RF and DSP policies. Actual vs. requested values are compared and reported through the log observable.
  • Sample rate control - Per-channel TX sample rate get/set via UhdWrapper.
  • TX metadata - TxMetadataHandle supports time-spec, start-of-burst, and end-of-burst flags.
  • RX infrastructure - RxStreamerHandle, RxMetadataHandle, MetadataRxWrapper, and StreamCommand are available for receive-side integration.
  • Structured logging - ILogEvent with concrete types: InfoEventArgs, SetEventArgs, SetWarningEventArgs, ErrorEventArgs.
  • Safe native handles - All UHD handles (DeviceHandle, TxStreamerHandle, RxStreamerHandle, TxMetadataHandle, RxMetadataHandle, AsyncMetadataHandle) extend SafeHandleZeroOrMinusOneIsInvalid and are disposed automatically.
  • Error handling - Every native call is checked; failures throw UhdException with the UHD error code.

Architecture

graph TD
    A[Consumer code] -->|new UhdSettings| B[UhdStream]
    B -->|Init / Write| C[UhdWrapper]
    C -->|P/Invoke safe| D[UsrpSafeNativeMethods]
    C -->|P/Invoke unsafe| E[UsrpUnsafeNativeMethods]
    D --> F[uhd.dll]
    E --> F
    B -->|IObservable| G[ILogEvent stream]
    G --> H[InfoEventArgs]
    G --> I[SetEventArgs / SetWarningEventArgs]
    G --> J[ErrorEventArgs]
    B --> K[DeviceHandle]
    B --> L[TxStreamerHandle]
    B --> M[TxMetadataHandle]

Project structure

Path Purpose
UhdStream.cs Main public API - write-only Stream + IObservable<ILogEvent>
UhdSettings.cs Configuration struct passed to UhdStream
Wrapper/UhdWrapper.cs Static facade converting P/Invoke results to exceptions
Wrapper/UhdException.cs Exception type thrown on non-zero UHD error codes
Handles/ Safe handle wrappers for device, streamer, and metadata objects
NativeMethods/ Internal P/Invoke declarations against uhd.dll
DataTypes/ Interop structs: TuneRequest, TuneResult, StreamArgs, ErrorCode
Logging/ ILogEvent and concrete event argument types

Requirements

  • .NET 10 or higher
  • Windows x64
  • uhd.dll from the Ettus Research UHD driver placed alongside the application binary (bundled in the NuGet package)
  • A supported Ettus Research / National Instruments USRP device

Installation

dotnet add package Oakrey.UHD

Or via the Visual Studio NuGet Package Manager: search for Oakrey.UHD.

Configuration

UhdSettings is a value type. All properties have defaults suitable for a single-channel TX scenario.

Property Default Description
Frequency (required) TX center frequency in Hz
Channel 0 USRP channel index
CpuFormat sc16 Host-side sample format (sc16 or fc32)
DeviceArgs "" UHD device arguments string (e.g. "addr=192.168.10.2")
Gain 50 TX gain in dB
GainName "" Named gain stage; empty selects the default
Rate 2.6e6 Sample rate in samples per second
TimeOut 3 Send timeout in seconds
HastTimeSpecify false Enable time-spec on TX metadata
FullSecs 0 Integer seconds part of time-spec
FracSecs 0.1 Fractional seconds part of time-spec

Example usage

Stream raw IQ samples from a file to a USRP device at GPS L1 (1575.42 MHz):

using Oakrey.UHD;
using Oakrey.UHD.Logging;

UhdSettings settings = new(frequency: 1_575_420_000.0)
{
    DeviceArgs = "addr=192.168.10.2",
    Gain = 60,
    Rate = 2_600_000
};

await using UhdStream uhdStream = new(settings);

// Subscribe to log events before initialising
IDisposable subscription = uhdStream.Subscribe(Observer.Create<ILogEvent>(
    e => Console.WriteLine(e.Message)));

uhdStream.Init();

using FileStream iqFile = File.OpenRead("samples.bin");
await uhdStream.CopyFrom(iqFile, fileBlockSize: 4096, CancellationToken.None);

subscription.Dispose();

Development notes

  • uhd.dll must match the architecture of the host process (x64).
  • The native UHD API reference used for P/Invoke mapping: https://files.ettus.com/manual/usrp_8h.html
  • UhdStream is write-only (CanRead = false, CanSeek = false). The Read and Seek overrides throw InvalidOperationException.
  • Sample buffers are managed with ArrayPool<short> to reduce GC pressure during streaming.
  • UhdWrapper is a static class; handle lifetime is managed entirely by the SafeHandle subclasses.
  • AllowUnsafeBlocks is required for the fixed-pointer send path in UsrpUnsafeNativeMethods.

License

MIT - Copyright (c) Oakrey 2016-present. See LICENSE or the PackageLicenseExpression field in the .csproj.

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
3.0.3 156 5/22/2026
3.0.2 117 5/14/2026
3.0.1 164 2/2/2026
3.0.0 322 11/14/2025
2.0.0 266 6/18/2025
1.0.0 322 4/17/2025