小编Law*_*Lee的帖子

Raspberry Pi上的.Net Core 2.1 GPIO filesystemwatcher

我已经为我的树莓派编写了.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} …
Run Code Online (Sandbox Code Playgroud)

c# raspberry-pi .net-core

5
推荐指数
1
解决办法
344
查看次数

标签 统计

.net-core ×1

c# ×1

raspberry-pi ×1