Recently, I was studying serial communication in a cross-platform manner under .NET Core, and I came across an article discussing communication in Linux/IoT.
The main issues arise with the following two libraries:
SerialPortStream
flyfire.CustomSerialPort
Author's address: https://www.cnblogs.com/lonelyxmas/p/10363869.html
Instructions
Since the serialport library is no longer available in .NET Core 2.x, it is necessary to use third-party frameworks which can be found by searching directly in NuGet.
SerialPortStream
Open source address: https://github.com/jcurl/SerialPortStream
For convenience, someone has wrapped it, and you can search for it in NuGet.
flyfire.CustomSerialPort
This is an enhanced custom serial port class that implements protocol-independent complete data frame reception functionality and supports cross-platform use, based on the SerialPortStream library.
How to Use the Library
SerialPortStream works normally under Windows, but under the Linux system, you must compile the support library for the Linux platform. The library author states as follows:
Otherwise, when packing the project to Linux, the following issue will arise:
The method provided by the article's author is to compile it yourself under Linux, but many people fail here and cannot install gcc and cmake, as well as other software, after entering the commands.
Install and update GCCsudo apt
-get install gccInstall cmake
sudo apt
-get install cmake
The purpose of installing GCC and Cmake is to compile SerialPortStream and generate a .so file.
After installation, you also need to install Git to clone SerialPortStream and compile it.
Some friends encountered issues with installation while installing GCC and Cmake.
They can try this method: https://zhidao.baidu.com/question/150155324.html
A More Convenient Method
To avoid hassle and make it easier to use, after successfully compiling the supporting libraries on Linux, I packaged the necessary files.
You only need to place the files into your .NET Core project, no need to install GCC/Cmake and conduct subsequent compilations in Linux.
Download link: http://pan.whuanle.cn/index.php?dir=uploads/dotnet-core-串口&response
Download these three files:
- libnserial.so
- libnserial.so.1
- libnserial.so.1.1
Send these three libraries to your project and package them along with the project.
Simplifying complexity.
Regarding the usage of flyfire.CustomSerialPort and example implementations of serial communication, I have another article:
文章评论