我已经为我的树莓派编写了.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)