dotnet core 與 ubuntu arm32開發體驗
阿新 • • 發佈:2020-11-13
dotnet core 與 ubuntu arm32開發體驗
-
選擇一款支援ubuntu的開發板相容wiringPI
-
Installing .Net core On Linux ARM32/64
Installing .NET Core on Linux ARM64
The following intructions can be used to install .NET Core on Linux ARM64.
Pro tip: Check out .NET Core Docker files to determine the exact instructions for installing .NET Core builds, for example
Installing .NET Core Globally
The following instructions install the latest .NET Core globally. It isn't required to do that, but it provides the best experience.
curl -SL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Sdk/master/dotnet-sdk-latest-linux-arm64.tar.gz sudo mkdir -p /usr/share/dotnet sudo tar -zxf dotnet.tar.gz -C /usr/share/dotnet sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet
- For ARM32, switch "arm64" to "arm" in the link above.
- For .NET Core 3.1, you can get the download link @ https://dotnet.microsoft.com/download/dotnet-core/3.1 (look for ARM binaries).
Dependencies
.NET Core has the following dependencies, on Ubuntu (other distros will vary):
- libc6
- libgcc1
- libgssapi-krb5-2
- libicu60
- liblttng-ust0
- libssl1.0.0
- libstdc++6
- zlib1g
-
程式編寫
internal const string WiringOP = "libwiringPi.so"; [DllImport(WiringOP, EntryPoint = "wiringPiSetup", SetLastError = true)] public static extern int WiringPiSetup(); [DllImport(WiringOP, EntryPoint = "pinModeAlt", SetLastError = true)] public static extern void PinModeAlt([MarshalAs(UnmanagedType.I4)] Pin pin, [MarshalAs(UnmanagedType.I4)]IOMode mode); [DllImport(WiringOP, EntryPoint = "pinMode", SetLastError = true)] public static extern void PinMode([MarshalAs(UnmanagedType.I4)] Pin pin, [MarshalAs(UnmanagedType.I4)]IOMode mode); [DllImport(WiringOP, EntryPoint = "pullUpDnControl", SetLastError = true)] public static extern void PullUpDnControl([MarshalAs(UnmanagedType.I4)] Pin pin, [MarshalAs(UnmanagedType.I4)]Pud pud); [DllImport(WiringOP, EntryPoint = "digitalRead", SetLastError = true)] [return: MarshalAs(UnmanagedType.I4)] public static extern Level DigitalRead([MarshalAs(UnmanagedType.I4)] Pin pin); [DllImport(WiringOP, EntryPoint = "digitalWrite", SetLastError = true)] public static extern void DigitalWrite([MarshalAs(UnmanagedType.I4)] Pin pin, [MarshalAs(UnmanagedType.I4)] Level level);
-
Ubuntu16.04以上配置自啟動服務
- 建立服務配置檔案
vim /etc/systemd/system/test.service [Unit] Description=test service. [Service] Type=simple ExecStart=/usr/bin/dotnet /root/Published/test.dll StandardOutput=file:/root/Published/log.log StandardError=file:/root/Published/err.log [Install] WantedBy=multi-user.target
- 對服務配置檔案賦予許可權
chmod 644 /etc/systemd/system/test.service
- 配置開機啟動
systemctl enable test.service
- 關閉開機啟動
systemctl disable test.service
service修改後,使用systemctl daemon-reload載入修改
-
檢視服務執行日誌
- 通過service配置的日誌重定向檢視
- 通過
journalctl -u test.servcie
檢視