Issues and Simpler Implementation Methods for Serial Communication in .Net Core Cross-Platform Applications

2019年12月15日 88点热度 2人点赞 2条评论
内容目录

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 GCC

sudo apt-get install gcc

Install 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:

 https://www.cnblogs.com/whuanle/p/10499597.html

痴者工良

高级程序员劝退师

文章评论