Adafruit FT232H and C# : No GPIO controllers exist on this system

73 Views Asked by At

Can Adafruit FT232H board be used with Microsoft's System.Device.Gpio / Iot.Device.Bindings libraries? I've followed the instructions on https://learn.adafruit.com/circuitpython-on-any-computer-with-ft232h/windows to setup the driver with zadig and I can see libusbK listed in Device Manager. However, running this code throws an exception:

int pin = 18;
using var controller = new GpioController();
controller.OpenPin(pin, PinMode.Output);
bool ledOn = true;
while (true)
{
    controller.Write(pin, ((ledOn) ? PinValue.High : PinValue.Low));
    Thread.Sleep(1000);
    ledOn = !ledOn;
}

Exception:

Unhandled exception. System.NotSupportedException: No GPIO controllers exist on this system.
   at System.Device.Gpio.Drivers.Windows10Driver..ctor()
   at System.Device.Gpio.GpioController.GetBestDriverForBoardOnWindows()
   at System.Device.Gpio.GpioController.GetBestDriverForBoard()
   at System.Device.Gpio.GpioController..ctor(PinNumberingScheme numberingScheme)
   at System.Device.Gpio.GpioController..ctor()
   at Program.<Main>$(String[] args) in C:\Users\....\source\repos\VS2022Staging\ConsoleApp1\Program.cs:line 10

C:\Users\....\source\repos\VS2022Staging\ConsoleApp1\bin\Debug\net6.0-windows10.0.17763.0\ConsoleApp1.exe (process 20168) exited with code -532462766.
1

There are 1 best solutions below

0
PMF On

Sure

However, you additionally need the Iot.Device.Bindings assembly, which contains drivers for a lot of different hardware. System.Device.Gpio only contains the basic low-level drivers for linux as well as the interface specifications.

Here's some sample code (from https://github.com/dotnet/iot/tree/main/src/devices/Ft232H)

var devices = FtCommon.GetDevices();
Console.WriteLine($"{devices.Count} available device(s)");
foreach (var device in devices)
{
    Console.WriteLine($"  {device.Description}");
    Console.WriteLine($"    Flags: {device.Flags}");
    Console.WriteLine($"    Id: {device.Id}");
    Console.WriteLine($"    LocId: {device.LocId}");
    Console.WriteLine($"    Serial number: {device.SerialNumber}");
    Console.WriteLine($"    Type: {device.Type}");
}

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

var ft232h = new Ft232HDevice(devices[0]);
var gpio = ft232h.CreateGpioDriver();
GpioController controller = new(PinNumberingScheme.Board, gpio);

.... // use the controller for whatever you want...

The implementation is a wrapper around the mentioned FTDI custom api, but it has already been written for you.