.net core程序 Win10中編譯 樹莓派中運行
引用大神博客
.NET Core IoT 入門指南1
在樹莓派上運行 .net core 2.1 程序 並實現開機啓動2
安裝 .net core runtime
sudo apt install curl libunwind8 gettext
curl -sSL -o dotnet.tar.gz https://download.microsoft.com/download/1/f/7/1f7755c5-934d-4638-b89f-1f4ffa5afe89/dotnet-runtime-2.1.2-linux-arm.tar.gz
sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet
sudo ln -s /opt/dotnet/dotnet /usr/local/bin
引入 System.Device.GPIO NuGet
Install-Package System.Device.Gpio -Version 0.1.0-prerelease.19171.3
編寫程序
using System;
using System.Device.Gpio;
using System.Threading;
namespace coreblink
{
class Program
{
static void Main(string[] args)
{
//
GpioController controller = new GpioController(PinNumberingScheme.Board);
// 設置引腳
controller.OpenPin(11, PinMode.Output);
// 設置延遲時間
int time = 1000;
while (true)
{
Thread.Sleep(time);
// 打開
controller.Write(11, PinValue.High);
Thread.Sleep(time);
// 關閉
controller.Write(11, PinValue.Low);
}
}
}
}
佈署
dotnet publish -c release -r linux-arm
傳送
在Release\netcoreapp2.1\linux-arm目錄下運行
scp -r ./publish [email protected]:/home/pi/
運行
cd ~
cd publish
chmod 777 coreblink
./coreblink