Essy.FTDIWrapper 7.0.0

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

Essy.FTDIWrapper

A small, opinionated .NET wrapper around the FTDI D2XX (ftd2xx) native library.
It lets you enumerate FTDI devices, open them by serial number, configure the UART, read/write data, work with events, and access EEPROM/user area – all from managed C# code.

Namespace: Essy.FTDIWrapper


Features

  • Enumerate all connected FTDI devices (with description, serial number, IDs, flags).
  • Open a device by serial number and manage its lifetime via IDisposable.
  • Synchronous read/write of raw bytes with full‑length checks.
  • Query and purge RX/TX buffers.
  • Configure baud rate, data bits, parity, stop bits, and flow control.
  • Wait for incoming data or modem/pin changes via OS events (sync + async helpers).
  • Access user area EEPROM (read/write string or binary, query capacity).
  • Read and modify the device Product ID in the EEPROM while preserving user area.
  • Reset / cycle port / tweak latency and USB buffer sizes (where supported by the OS).
  • Strongly-typed enums for parity, stop bits, data length, flow control, and status pins.
  • Rich exception hierarchy for low-level and enumeration errors.

The native interop is centralized in a single internal FTDIFunctions class that P/Invokes into ftd2xx.


Installation

Once published to NuGet:

dotnet add package Essy.FTDIWrapper

Or via the NuGet Package Manager UI in Visual Studio: search for Essy.FTDIWrapper.


Requirements

  • .NET (classic Framework or modern .NET) with support for P/Invoke.
  • The FTDI D2XX driver installed on the system.
  • The ftd2xx native library (ftd2xx.dll / libftd2xx.so / libftd2xx.dylib) available on the library load path.

Some features (port cycling, driver version, reset pipe retry count) are only supported on Windows and are no-ops or short‑circuit on Unix-like platforms.


Getting started

1. Enumerate devices

using System;
using System.Collections.Generic;
using Essy.FTDIWrapper;

class Program
{
    static void Main()
    {
        List<FTDI_DeviceInfo> devices = FTDI_DeviceInfo.EnumerateDevices();

        if (devices.Count == 0)
        {
            Console.WriteLine("No FTDI devices found.");
            return;
        }

        foreach (var dev in devices)
        {
            Console.WriteLine(dev.ToString());
        }
    }
}

FTDI_DeviceInfo.EnumerateDevices() calls FT_CreateDeviceInfoList and FT_GetDeviceInfoDetail under the hood and converts the C strings to managed strings.


2. Open a device and configure the port

A device is opened by serial number via FT_OpenEx and wrapped in FTDI_Device, which is IDisposable.

using System;
using System.Text;
using Essy.FTDIWrapper;

class Program
{
    static void Main()
    {
        var devices = FTDI_DeviceInfo.EnumerateDevices();

        if (devices.Count == 0)
        {
            Console.WriteLine("No FTDI devices found.");
            return;
        }

        var info = devices[0];

        using var dev = new FTDI_Device(info);

        // Basic UART configuration
        dev.SetBaudrate(115200);
        dev.SetParameters(DataLength.EightBits, Parity.None, StopBits.OneStopBit);
        dev.SetFlowControl(FlowControl.None);

        // Clear buffers (optional)
        dev.ClearReceiveBuffer();
        dev.ClearSendBuffer();

        // Send some data
        var payload = Encoding.ASCII.GetBytes("Hello FTDI!");
        dev.WriteBytes(payload);

        // Read back anything available
        uint available = dev.NumberOfBytesInReceiveBuffer();
        if (available > 0)
        {
            byte[] response = dev.ReadBytes(available);
            Console.WriteLine("Read: " + BitConverter.ToString(response));
        }
    }
}

The WriteBytes and ReadBytes methods validate that the requested number of bytes were actually transmitted/received, and throw a FTDIDeviceNotAllBytesTransmittedException otherwise.


3. Waiting for incoming data

FTDI_Device can use event notifications to wait for RX data. On EnableWaitForDataEvent, it sets up an event with FT_SetEventNotification and waits on it via EventWaitHandle. fileciteturn0file0L168-L191turn0file3L60-L73

using System;
using System.Text;
using System.Threading.Tasks;
using Essy.FTDIWrapper;

class Program
{
    static async Task Main()
    {
        var devInfo = FTDI_DeviceInfo.EnumerateDevices()[0];

        using var dev = new FTDI_Device(devInfo);

        dev.SetBaudrate(115200);
        dev.EnableWaitForDataEvent();

        Console.WriteLine("Waiting for data...");

        // Asynchronously wait until the RXCHAR event is signalled
        await dev.WaitForDataAsync();

        uint available = dev.NumberOfBytesInReceiveBuffer();
        if (available > 0)
        {
            byte[] data = dev.ReadBytes(available);
            Console.WriteLine("Received: " + BitConverter.ToString(data));
        }
    }
}

There is also a synchronous WaitForData(int timeoutMs) plus equivalent methods for modem/pin‑change events (EnableWaitForPinChangeEvent, WaitForPinChange, WaitForPinChangeAsync).


4. Working with the user EEPROM area

The library exposes helpers to read/write the user area (UA) EEPROM as either text or raw bytes:

using System;
using Essy.FTDIWrapper;

class Program
{
    static void Main()
    {
        var info = FTDI_DeviceInfo.EnumerateDevices()[0];

        using var dev = new FTDI_Device(info);

        // Get capacity
        uint capacity = dev.GetSizeOfUAEEProm();
        Console.WriteLine($"User EEPROM size: {capacity} bytes");

        // Store a label
        dev.WriteToUAEEProm("My FTDI Device");

        // Read it back as string
        string label = dev.ReadFromUAEEProm();
        Console.WriteLine($"Label: {label}");

        // Or as raw bytes
        byte[] raw = dev.ReadBinaryFromUAEEProm(16);
        Console.WriteLine("Raw: " + BitConverter.ToString(raw));
    }
}

The implementation ensures that the requested size fits within the available user area and throws an FTDIDeviceLowLevelException if not.


5. Error handling

Most failures wrap the FT_STATUS code returned from ftd2xx in a typed exception:

  • FTDIException – base type, exposes the Status property.
  • FTDIEnumerationException – for enumeration problems.
  • FTDIDeviceException and its children:
    • FTDIDeviceLowLevelException
    • FTDIDeviceNotAllBytesTransmittedException

Example:

try
{
    using var dev = new FTDI_Device(info);
    dev.SetBaudrate(9600);
    dev.WriteBytes(new byte[] { 0x01, 0x02, 0x03 });
}
catch (FTDIException ex)
{
    Console.Error.WriteLine($"FTDI error: {ex.Message}");
    Console.Error.WriteLine($"Status: {ex.Status}");
}

Advanced operations

Some additional APIs you can call on FTDI_Device:

  • Reset() / TryReset() – reset the device.
  • ResetPort(), TryResetPort() – reset the USB port (Windows only).
  • CyclePort(), TryCyclePort() – cycle the USB port (Windows only).
  • SetResetPipeRetryCount(uint) – configure retry behaviour when resetting pipes.
  • SetBufferFlushTimer(byte) – configure latency timer.
  • SetBufferSizes(uint tx, uint rx) – change USB transfer sizes.
  • GetStatusPins() – read modem pins (CTS, DSR, RI, DCD).
  • SetRTS(bool) – assert/deassert RTS.
  • GetDriverVersion() – retrieve FTDI driver version (Windows only).
  • GetDeviceProductID() / SetDeviceProductID(ushort) – read or reprogram the Product ID in EEPROM, preserving the user area data.

Design notes

  • The wrapper is intentionally thin: all P/Invoke declarations live in FTDIFunctions, while public, user‑friendly APIs live in FTDI_Device and FTDI_DeviceInfo.
  • The library does not hide the FT_STATUS codes; instead it surfaces them via exceptions so advanced users can still reason about exact driver failures.
  • Device opening is based on serial numbers for deterministic device selection; if you need a different strategy you can select a device from the enumeration list by description or ID.

License

This library is licensed under the MIT License See the source files for the full license text.

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. 
.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 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
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 (2)

Showing the top 2 NuGet packages that depend on Essy.FTDIWrapper:

Package Downloads
Essy.LIS.Connection.FTDIConnection

This package implements a direct FTDI Chip RS-232 connection.

Essy.EssyBus.FTDI

An FTDI implementation of the EssyBus

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
7.0.0 0 11/13/2025
6.2.0 5,410 8/12/2020
6.1.0 2,574 4/18/2018
6.0.0 1,422 7/25/2017
5.0.2 1,658 2/28/2017
5.0.1 1,527 2/22/2017
4.3.1 1,701 5/3/2016
4.3.0 1,587 5/3/2016
1.0.0 2,470 7/18/2012

updated packages