使用幸狐LuckFox Pico Plus 板子搭载Alpine Linux,运行dotnet net6程序 闪烁一颗LED灯

程序截图

 实拍

 性能消耗非常小的,就是对ROM有要求,SDK+程序占了40M

 

步骤1:按照链接教程刷入系统

步骤2:修改以太信息

步骤3:使用ssh登录系统

步骤4:搭建dotnet环境,使用手动的方式

先下载运行时包

下载 .NET 6.0 Runtime (v6.0.28) - Linux Arm32 Alpine Binaries (microsoft.com)

 在 Linux 上不使用包管理器的情况下安装 .NET - .NET | Microsoft Learn

安装后输入dotnet --info验证

步骤5: 部署程序

 代码:

要求安装nuget(System.Device.Gpio)

 Console.WriteLine("Hello, World!");
 using (GpioController controller = new GpioController())
 {
     int pin = 55; // GPIO Pin number
     controller.OpenPin(pin, PinMode.Output);

     while (true)
     {
         controller.Write(pin, PinValue.High); // Turn on the LED
         Thread.Sleep(1000); // Wait for 1 second
         controller.Write(pin, PinValue.Low); // Turn off the LED
         Thread.Sleep(1000); // Wait for 1 second
     }
 }

  遇到的问题

Process terminated. Couldn't find a valid ICU package installed on the system. Please install libicu using your package manager and try again. Alternatively you can set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support. Please see https://aka.ms/dotnet-missing-libicu for more information.

处理方法

这个错误表明系统找不到安装在系统上的有效 ICU(International Components for Unicode)包。为了解决这个问题,您可以按照以下步骤之一操作:

安装 libicu:您可以通过包管理器安装 libicu 库。在 Alpine Linux 上,您可以使用 apk 包管理器安装 libicu。运行以下命令来安装 libicu:
apk add icu
设置 System.Globalization.Invariant 为 true:另一种解决方法是设置配置标志 System.Globalization.Invariant 为 true,这样可以在不支持全球化的情况下运行。您可以通过设置环境变量或在应用程序中进行配置来实现。示例:
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true

发布后复制到系统中即可正常运行

步骤6:接入LED灯

GPOI图:

55 号GPIO 3.3V所以需要挂上一个电阻,50-200欧姆即可

 成功点亮

拿C#写IOT简直是降维打击

posted @ 2024-03-29 16:47  AnAng  阅读(34)  评论(0编辑  收藏  举报