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. 桌面环境配置

    • 关闭桌面环境
    systemctl set-default multi-user.target
    
    • 开启桌面环境
    systemctl set-default graphical.target
    
  5. Ubuntu16.04以上配置自启动服务

    • 创建服务配置文件
    vim /etc/systemd/system/test.service
    [Unit]
    Description=test service.
    
    [Service]
    Type=simple
    #ExecStartPre=-cd /root/Published
    ExecStart=/usr/bin/dotnet /root/Published/test.dll
    # 工作目录
    WorkingDirectory=/root/Published/
    ExecReload=/bin/kill -SIGHUP $MAINPID
    ExecStop=/bin/kill -SIGINT $MIANPID
    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载入修改

  6. 查看服务运行日志

    • 通过service配置的日志重定向查看
    • 通过journalctl -u test.servcie查看
    • 在未设置StandardOutput的情况下,可以通过sh启动并重定向ExecStart=/bin/sh 'exec /bin/dotnet /root/Published/test.dll >> /root/Published/test.log 2>&1'
posted @ 2020-11-13 12:07  非法关键字  阅读(384)  评论(0编辑  收藏  举报