如何修复总线 ID1 不存在 I2c 设备(GrovePi .net 核心)

How to fix No I2c device exists for bus ID1 (GrovePi .net core)

我正在制作一个 .net 核心 API 来控制我的 pi 的 LED 灯,但我遇到了以下错误:System.ArgumentException: 总线 ID 1 不存在 I2C 设备。

我试图找到一些关于如何找到 grovepi 的 busid 的信息,但没找到什么。也尝试了数字 1 到 5 也没有太远。

这是我的代码: [1] https://gyazo.com/aa01ab3068201360c3ece14f125b1c45

我的错误: [2] https://gyazo.com/6bf3215e4466b02643b6a9eb92d12e52

我希望打开灯并获得包含一些文本的页面,但我总是遇到同样的错误。

我可以重现这个问题。我跟踪了异常,它被抛出 here. I posted an issue(#590) in GitHub.

    public Windows10I2cDevice(I2cConnectionSettings settings)
    {
        _settings = settings;
        var winSettings = new WinI2c.I2cConnectionSettings(settings.DeviceAddress);

        string busFriendlyName = $"I2C{settings.BusId}";
        string deviceSelector = WinI2c.I2cDevice.GetDeviceSelector(busFriendlyName);

        DeviceInformationCollection deviceInformationCollection = DeviceInformation.FindAllAsync(deviceSelector).WaitForCompletion();
        if (deviceInformationCollection.Count == 0)
        {
            throw new ArgumentException($"No I2C device exists for bus ID {settings.BusId}.", $"{nameof(settings)}.{nameof(settings.BusId)}");
        }

        _winI2cDevice = WinI2c.I2cDevice.FromIdAsync(deviceInformationCollection[0].Id, winSettings).WaitForCompletion();
        if (_winI2cDevice == null)
        {
            throw new PlatformNotSupportedException($"I2C devices are not supported.");
        }
    }

众所周知,.net core 3.0 for IoT 是预览版。我可以知道你为什么不考虑使用传统方式来做到这一点吗?解决方法是,您可以在 UWP 应用程序中托管 Web 服务器,并且可以在 UWP 应用程序中添加 LED 控件。请参考IoTWeb.