Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the serial ports of .net Core cross-platform application development?

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the ".net Core cross-platform application development serial port", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn ".net Core cross-platform application development serial port" bar!

Introduction

In order to verify whether the data acquisition and access service application of Internet of things developed by dotnet core technology can run on the cost-effective linux embedded platform, the release, deployment and running verification research of embedded linux environment is carried out for dotnet core application.

Hardware environment

After comparing and screening the hardware system, the NanoPC-T3 Plus produced by friendly arm is selected. The control board is a handheld embedded Linux system mini-PC, using 64-bit Samsung arm CPU, with perfect hardware interface and driver support, more than 1G of memory and more than 8G of eMMC flash memory, with a high ratio of performance to price.

NanoPC-T3 Plus is a friendly arm designed specifically for enterprise users. It uses Samsung's eight-core Cortex-A53 architecture S5P6818 processor and dynamically runs the main frequency 400M-1.4GHz. NanoPC-T3 Plus is equipped with 16GB eMMC, audio interface, video input / output interface, etc.; and integrates WiFi and Bluetooth, adds Gigabit Ethernet and power management functions, on-board ceramic antenna, with serial port debugging function. In order to meet the needs of industrial customers, NanoPC-T3 Plus has installed a standard heat sink to solve the chip heating problem.

NanoPC-T3 Plus has two video inputs, supports DVP camera and MIPI-CSI camera, and has four video outputs, namely HDMI 1.4A interface, LVDS interface, parallel RGB-LCD interface and MIPI-DSI interface. And support RTC, on-board backup battery interface, lead to four USB interfaces (three of which are standard An interface, the other is 2.54mm bus) and so on.

NanoPC-T3 Plus) runs Android5.1, Debian, UbuntuCore+Qt and other systems smoothly. The kernel driver source code is completely open source and the interfaces are rich.

Hardware resource characteristics

CPU: S5P6818, run the main frequency 1.4GHz

Power management: an ARM ®Cortex ®- M0 single chip microcomputer is used for power management, supporting dynamic voltage regulation, software shutdown, timing boot and other functions.

Memory: 2GB 32bit DDR3 RAM

Storage: 1 x microSD card slot

Network: Gbit Ethernet (RTL8211E)

Wireless:802.11 b/g/n

Bluetooth: 4.0 dual mode

Antenna: Wi-Fi and Bluetooth common, on-board ceramic antenna, also provides IPX interface

EMMC: 16GB

Video input: DVP Camera/MIPI-CSI (dual camera port)

Video output: HDMI/LVDS/ parallel RGB-LCD/MIPI-DSI (four video output interfaces)

Audio: 3.5mm headset holder / Via HDMI

Microphone: onboard microphone

USB Host: 4 x USB 2.0 Host, of which three are standard type An interfaces and the other is 2.54mm bus

Micro USB: 1 x USB 2.0 Client

LCD interface: 45pin, 0.5mm pitch FPC patch holder, supports full color TFT LCD (RGB:8-8-8)

HDMI: HDMI 1.4a, Type A port, 1080p HD display

DVP Camera interface: 24pin, 0.5mm spacing, FPC patch vertical seat

GPIO expansion interface: 30 Pin2.54mm bus, including 4 UART, 1 way I2C, 1 way SPI, 3 way PWM,9 GPIO

I2S/USB: 2.54mm spacing busbar

Debug serial port: 2.54mm spacing pin

Buttons: power button, reset button, start select button each

LED: 1 x power LED and 1 x system LED

CPU temperature detection: CPU internal integrated temperature sensor

RTC: supports RTC, with backup battery interface on the board

Heat sink screw hole: a heat sink that can be fixed with screws

Power supply: DC 5V/3A

PCB Size:100 x 64mm, eight layers, gold deposition process

Temperature operating range:-40 ℃ to 80 ℃

In order to avoid advertising, but more instructions on the equipment (it seems inevitable, if there is a problem in this regard, ask the administrator to help with harmony)

The wiki address of the device is given here: http://wiki.friendlyarm.com/wiki/index.php/NanoPC-T3_Plus/zh

Supported system platform

The system image file provided by the manufacturer supports the following versions of the system

Lubuntu-desktop-xenial-4.4-armhf (ubuntu16.04-based LUbuntu desktop version, 32-bit arm system)

Friendlycore-xenial-4.4-armhf (ubuntu16.04-based FriendlyCore system, 32-bit arm system)

Friendlycore-xenial-4.4-arm64 (ubuntu16.04-based FriendlyCore system, 64-bit arm system)

Android5.1 system

FriendlyCore is a Ubuntu core-based system without X-windows environment, which uses Qt-Embedded as a lightweight system with graphical interface. It is compatible with Ubuntu system software source, and is very suitable for enterprise users as the basic OS of products.

In addition to retaining the features of Ubuntu Core, the system also includes the following features:

Support capacitive and resistive touch screens

Support for WiFi connections

Support for Ethernet connections

Support for Bluetooth, pre-installed bluez and other related software packages

Audio playback is supported

Support for Qt 5.10.0 EGLES and OpenGL ES1.1/2.0

Linux versions supported by the system platform .NET Core

Https://docs.microsoft.com/zh-cn/dotnet/core/linux-prerequisites?tabs=netcore2x

.net Core 2.x treats Linux as an operating system. All supported Linux distributions correspond to a Linux build (based on the chip architecture).

The following Linux distributions / releases support NET Core 2.x:

Red Hat Enterprise Linux 7cr 6-64 bits (x86c64 or amd64)

CentOS 7-64 bit (x86x64 or amd64)

Oracle Linux 7-64 bit (x86x64 or amd64)

Fedora 28, 27-64 bit (x86x64 or amd64)

Debian 9 (64-bit, arm32), 8.7 or later-64-bit (x86 / 64 or amd64)

Ubuntu 18.04 (64-bit, arm32), 16.04,14.04-64-bit (x86room64 or amd64)

Linux Mint 18, 17-64 bit (x86x64 or amd64)

OpenSUSE 42.3 or later-64-bit (x86room64 or amd64)

SUSE Enterprise Linux (SLES) 12 Service Pack 2 or later-64-bit (x86x64 or amd64)

Alpine Linux 3.7or later-64-bit (x86room64 or amd64)

System platform selection

According to the support of .NET Core 2.x to Linux system, friendlycore-xenial-4.4-arm64 is selected as the system running platform.

Download the system image file provided by the manufacturer, and burn the NanoPC-T3/Plus. See the WIKI tutorial for details.

The main steps of burning writing:

1. Download the image file provided by the manufacturer and the burning tool win32diskimager (download link is provided in wiki)

Prepare a TF card and format it as a partition (FAT32)

Run the win32diskimager software, select the image file, select the partition corresponding to the TF card, and click write

4. Completion of burning and writing

5. Insert the TF card into the card holder and press the letter boot key to power up the control board (external monitor, keyboard and mouse are required)

6. Follow the on-screen prompts to install the system to the eMMC flash memory.

Connect embedded Linux system

The FriendlyCore system supports a variety of connection modes by default, which can be connected through external input and output devices (keyboard / mouse, monitor), or through serial terminals, or through the network, using ssh terminals.

The FriendlyCore system is configured with two user accounts by default

Ordinary users:

User name: pi

Password: pi

Root users:

User name: root

Password: fa

By default, the system will log in automatically as a pi user. You can cancel the automatic login by using the sudo npi-config command.

Physical connection

NanoPC has HDMI, TFT display interface and USB interface, which can be directly connected to the monitor, keyboard / mouse for operation.

Serial port connection

NanoPC supports debugging serial port as a terminal by default.

Connect through the serial port module from USB to TTL serial port. Default communication parameters: 115200 Npenny 8 pencil 1

The software can use any serial terminal tool, such as SecureCRT or Windows system with its own hyperterminal.

Network connection

You can connect to the network through the SSH tool and access it through the network terminal. (included with Win10 system)

The FriendlyCore system network configuration defaults to automatically obtaining IP addresses. To connect a device over a network, you need to determine the IP address of the device.

The initial IP address can be viewed by entering the ifconfig command in serial terminal mode, or determined by network scanning.

After determining the IP address of the device, you can use the ssh command to make a terminal connection

In this experiment, the IP address of our device is 172.16.93.74, and the network terminal is connected by the following command:

Ssh pi@172.16.93.74

After entering the password according to the prompt, you can log in successfully.

.net Core cross-platform verification

As the main program functions to be used in the later stage are network communication and serial communication, we mainly verify the network and serial communication under the target embedded linux system.

In this experiment, we first verify the serial communication.

Write a netcore2.x console program, the program realizes the functions of system information display, serial port resource enumeration, serial port selection, serial port opening / closing, serial port receiving display and serial port regular sending test data.

Validate program design

Use SerialPort class to realize serial port test (netcore project needs to install SerailPort library through Nuget)

Implement the following functions:

Display system platform information

Serial port resource enumeration

Serial port selection

Serial port open

Serial port closed

Serial port receiving / data display

Serial port sends test data regularly

The program is relatively simple. Post some functional codes here:

Display system platform information

Serial port resource enumeration

Serial port test

Compiler, test program passed under window.

Cross-platform release

Because the target platform is arm64 embedded linux system, the program is released in the following ways:

In the command line window, switch to the project folder and run the following command:

Dotnetpublish-rlinux-arm64-cRelease

With the above command, the distribution package of the generated target platform, the program files and related .netcore runtime dependencies are published to the project release\ netcoreapp2.2\ linux-arm64\ publish folder.

Remote deployment

Copy the release file to the target machine using the scp command

On the windows (win10) system, open a console window and enter the scp command in the following format:

Scp-r d:\ ubuntu\ publish\ pi@172.16.93.74:/home/pi/.

Enter the user password according to the prompt to complete the replication of the folder.

In the ssh terminal window, switch to the program folder

Cd / home/pi/publish

Set program execution permissions:

Chmod 777./ HelloArm # HelloArm is the filename of the test program

Enter. / HelloArm to run the program

The Linux environment runs the. Net Core program

Run the program in the ordinary user pi

The program displays the system environment information.

Because the SerialPort.GetPortNames method was called after the program started, the program failed to execute as expected, and the following message appears:

The prompt indicates that the SerialPort class library only supports the Windows system platform, not cross-platform.

So far, the net core program runs successfully in the linux system, but the serial port class library does not support cross-platform.

Third-party serial port class library

In order to solve the problem of serial port class support, it is found that there is an open source SerialPortStream class library on github that supports netcore and Linux system.

Https://github.com/jcurl/SerialPortStream

This class library supports windows system and Linux system, but when it runs under Linux system, it needs to compile the target platform support library and configure the relevant environment.

Compilation of Linux Serial Port Class Library

You first need to compile the support library libnserial.so for your platform. To do that, you'll need a compiler (e.g. GCC 4.8or later) and cmake.

On the target system (FriendlyCore), install the GCC compiler and cmake

First of all, make sure that the network is properly connected and can access the Internet (requires a good network environment).

Execute the following command:

Sudo apt-get update

Install and update GCC

Sudo apt-get install gcc

Install cmake

Sudo apt-get install cmake

Ensure that gcc and cmake are installed properly. You can use the command to view the installation

Gcc-version

Cmake-version

After cloning the repository, execute the following:

$git clone https://github.com/jcurl/serialportstream.git

$cd serialportstream/dll/serialunix

$. / build.sh

According to the above command, complete the source code cloning and compilation of the class library.

Note: the class library linux dependent library only needs to be compiled once on the same target platform, other same target platform, copy and configure the dependent library to the target system.

Environment variable configuration

Binaries are built and put in the bin folder from where you ran the build script. You can add a reference to LD_LIBRARY_PATH to the library:

$export LD_LIBRARY_PATH= `pwd` / bin/usr/local/lib:$LD_LIBRARY_PATH

Execute the above command to configure the class library target to the environment variable (the above command is a temporary environment variable configuration, only the current shell is valid)

How to configure global environment variables:

Vi / etc/profile

On the last line of the file, add the configuration of the environment variable LD_LIBRARY_PATH

After saving and exiting, execute source / etc/profile to refresh the environment variables

Note: for vi related operations, please do Baidu or Bing by yourself.

Linux serial port test

Replace the SerialPort class in the test verification program with the SerialPortStream class library (methods and properties are basically compatible), make appropriate adjustments, compile and run on the windows system, and pass.

Reissue the running version of the Linux system and deploy the linux system.

Log in using ordinary user pi

If the environment variable is not effectively configured, the serial port class can not be executed normally, and the program execution stops when the serial port method is called.

Press Ctrl+C to terminate the program.

Configure the environment variables required by the serial port class library, rerun the program, and the program runs normally.

As shown in the following figure, the program starts and lists the valid serial ports of the system, as shown in the following figure:

Due to the authority of the pi user account, the program only displays one serial port of / dev/ttySAC0, which is the output serial port of the system debugging terminal.

Switch to system superuser

Su root

Enter the password at the prompt: fa

Change to the program directory, execute the test program. / publish/HelloArm, and the following interface appears:

Under the super user, the program enumerates 5 serial ports.

Through the operation command, open the designated serial port, open to receive events and send data in a fixed period, connect the computer serial port (at present, most computers no longer provide serial port, this experiment connects through USB to serial port module), communicate with Linux mini PC host through PC serial port tool software, sending and receiving communication is normal.

The configuration program starts up and runs

Under root user, configure / etc/rc.local file, add the program to the system boot and run

Vi / etc/rc.local

Add a line before exit 0

/ home/pi/publish/HelloArm

Save exit and restart the system

Reboot

After restarting the system, the output information of the program can be seen in the debug serial terminal interface. At this point, the program configuration is completed and the boot automatically runs successfully.

Thank you for reading, the above is the content of ".net Core cross-platform application development serial port". After the study of this article, I believe you have a deeper understanding of the problem of .net Core cross-platform application development serial port. Specific use also needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report