C# Raspberry Pi上的.Net Core 2.1 GPIO filesystemwatcher

C# Raspberry Pi上的.Net Core 2.1 GPIO filesystemwatcher,c#,raspberry-pi,.net-core,C#,Raspberry Pi,.net Core,我已经为我的raspberry pi编写了一个.Net Core 2.1应用程序,但是当GPIO通过按钮被驱动为高/低时,filesystemwatcher没有调用事件处理程序 static void Main(string[] args) { Console.WriteLine("Hello World!"); GPIO.PinMode(21, GPIO.Direction.Input, GPIO.Edge.Both); var fileSystemWatcher

我已经为我的raspberry pi编写了一个.Net Core 2.1应用程序,但是当GPIO通过按钮被驱动为高/低时,filesystemwatcher没有调用事件处理程序

static void Main(string[] args)
{
    Console.WriteLine("Hello World!");

    GPIO.PinMode(21, GPIO.Direction.Input, GPIO.Edge.Both);


    var fileSystemWatcher = new FileSystemWatcher();

    // Associate event handlers with the events
    fileSystemWatcher.Created += FileSystemWatcher_Created;
    fileSystemWatcher.Changed += FileSystemWatcher_Changed;
    fileSystemWatcher.Deleted += FileSystemWatcher_Deleted;
    fileSystemWatcher.Renamed += FileSystemWatcher_Renamed;

    // tell the watcher where to look
    fileSystemWatcher.Path = "/sys/devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio21";

    // You must add this line - this allows events to fire.
    fileSystemWatcher.EnableRaisingEvents = true;


    Console.ReadLine();

}

private static void FileSystemWatcher_Renamed(object sender, RenamedEventArgs e)
{
    Console.WriteLine($"A new file has been renamed from {e.OldName} to {e.Name}");
}

private static void FileSystemWatcher_Deleted(object sender, FileSystemEventArgs e)
{
    Console.WriteLine($"A new file has been deleted - {e.Name}");
}

private static void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
    Console.WriteLine($"A new file has been changed - {e.Name}");
}

private static void FileSystemWatcher_Created(object sender, FileSystemEventArgs e)
{
    Console.WriteLine($"A new file has been created - {e.Name}");
}
我知道filesystemwatcher此时无法在符号链接上运行,因此使用了完整的系统路径

基本上,当GPIO 21实际更改状态时,不会调用任何事件

我已通过以下方式确认该值正在更改:

cat /sys/devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio21/value
但是,当我编辑该目录中的文件时,例如当我从另一个bash终端发出命令时,会调用上述事件:

echo out > /sys/devices/platform/soc/3f200000.gpio/gpiochip0/gpio/gpio21/direction
我从跑步计划中获得:

A new file has been changed - direction

那么有人获得了GPIO输入来调用filesystemwatcher事件了吗?

首先是的,.NET Core filesystemwatcher似乎不支持检查Linux系统中的更改,我尝试了对“/dev/input”中的条目进行相同的检查,得到了相同的结果

第二,对于您的问题GPIO控件,使用.NET基金项目:

DOTNET/IOT是由微软员工和.NET基金会社区所维护的,应该成为.NET内核……/P>中GPIO、PWM、I2C控制器的默认API。 在Linux上开始使用libgpiod,dotnet/iot已经有了libgpiod驱动程序。不推荐使用/sys/class/gpio,到2020年,控制这些sysf的驱动程序将从Linux内核中删除: