Adafruit FT232H 和 C#:此系统上不存在 GPIO 控制器

问题描述 投票:0回答:1

Adafruit FT232H 板可以与 Microsoft 的 System.Device.Gpio / Iot.Device.Bindings 库一起使用吗? 我已按照 https://learn.adafruit.com/ Circuitpython-on-any-computer-with-ft232h/windows 上的说明使用 zadig 设置驱动程序,我可以在设备管理器中看到 libusbK 列出。但是,运行此代码会引发异常:

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;
}

例外:

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.
c# iot adafruit
1个回答
0
投票

当然

但是,您还需要

Iot.Device.Bindings
程序集,其中包含许多不同硬件的驱动程序。
System.Device.Gpio
仅包含Linux的基本底层驱动以及接口规范。

这是一些示例代码(来自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...

该实现是上述 FTDI 自定义 API 的包装器,但它已经为您编写了。

© www.soinside.com 2019 - 2024. All rights reserved.