1. 程式人生 > 實用技巧 >dotnet core 與 ubuntu arm32開發體驗

dotnet core 與 ubuntu arm32開發體驗

dotnet core 與 ubuntu arm32開發體驗

  1. 選擇一款支援ubuntu的開發板相容wiringPI

  2. 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

    .NET Core 3.1 ARM32 SDK Dockerfile.

    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
    

    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
  3. 程式編寫

    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);
    
  4. 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載入修改

  5. 檢視服務執行日誌

    • 通過service配置的日誌重定向檢視
    • 通過journalctl -u test.servcie檢視