The project has been migrated to the .NET SDK project format. This is to allow better integration with .NET Core projects, and to allow better unit testing.
From Verson 3.0 and onwards, the SerialPortStream library is being split into
multiple libraries that some code originally came from other projects and is
also useful in other contexts. This allows for simpler maintenance.
The following other projects are needed in parallel
| Path | GIT Repository |
|---|---|
| serialportstream | RJCP.DLL.SerialPortStream.git |
| bufferio | RJCP.DLL.BufferIO.git |
| trace | RJCP.DLL.Trace.git |
| devicemgr | RJCP.DLL.DeviceMgr.git |
| environment | RJCP.DLL.Environment.git |
The project depends on the RJCP.MSBuildTasks NuGet package, which extends
MSBuild to provide Authenticode signing and get information about the GIT
repository when building. You'll need to have signtool.exe (Windows only) and
git.exe in your path.
To build the software, ensure to be in the working directory where the
SerialPortStream.sln file is kept.
-
To build DEBUG mode. This does not generate a NuGet package, to prevent mistakes in deployment.
PS1> dotnet build -
To build RELEASE mode. Release mode is unsigned, useful for beta testing or your own testing.
PS1> dotnet build -c Release
Building the library is normally done on the top level project that references this and other projects via GIT submodules. See the instructions there for building the entire framework suite (not just this library).
To build the package for upload (see building for the sign key) to NuGet:
PS1> dotnet build -c release .\code\SerialPortStream.csproj
PS1> dotnet pack -c release --include-source .\code\SerialPortStream.csprojI generally upload the symbols version that also includes the sources.
To packages are built:
- SerialPortStream
- SerialPortStream.Virtual
The tests written are a combination of unit tests and integration tests. The
tests can be run with the driver Com0Com. The ports used for the source and
destination are defined in test\SerialPortStreamTest\App.config. The default
is:
<appSettings>
<add key="Win32SourcePort" value="CNCA0"/>
<add key="Win32DestPort" value="CNCB0"/>
<add key="LinuxSourcePort" value="/dev/ttyUSB0"/>
<add key="LinuxDestPort" value="/dev/ttyUSB1"/>
</appSettings>Change the Win32SourcePort and Win32DestPort to be the actual hardware (e.g.
COM1, COM2).
Unit tests are supported for the configurations Debug and Release. Unit
tests marked as [Explicit]` will not run. But you can run these from within the
Visual Studio IDE.
-
To test DEBUG mode
PS1> dotnet test -
To test RELEASE mode
PS1> dotnet test -c Release --logger "trx"
To skip the manual tests in the Visual Studio IDE, filter with
-Trait:ManualTest.
When using the Com0Com driver, the following tests will fail (but pass with real hardware):
EvenParityLoopbackOddParityLoopbackParityChangeLoopback
The reason for this is that the driver doesn't take parity into account. It sends 8-bit, but receives 7-bit parity. When using real cables with null-modem adapters, the test cases should pass, as the hardware interprets the parity bits correctly.
Building on Linux should be done with the Microsoft dotnet commands.
Development should be done with VSCode. References to the MONO IDE have been
removed.
The instructions here were written and tested for Ubuntu 20.04. See Microsoft documentation for other Operating Systems.
To build on Linux, install the .NET SDK. For example, on Ubuntu the instructions are given at Install the .NET SDK or the .NET Runtime on Ubuntu
You should install the latest version of libnserial. The package for Ubuntu is
given on the release pages. For other Operating Systems, build and install from
sources (see the folder dll\serialunix for more information).
# apt install libnserial_1.1.4-0ubuntu1~focal1_amd64.deb- 1.1.4
- libnserial-1.1.4 trusty 32/64-bit
- libnserial-1.1.4 xenial 32/64-bit
- libnserial-1.1.4 yakkety 32/64-bit
- libnserial-1.1.4 zesty 32/64-bit
- libnserial-1.1.4 artful 32/64-bit
- libnserial-1.1.4 bionic 32/64-bit
- libnserial-1.1.4 cosmic 32/64-bit
- libnserial-1.1.4 disco 64-bit
- libnserial-1.1.4 eoan 64-bit
- libnserial-1.1.4 focal 64-bit
- libnserial-1.1.4 groovy 64-bit
- libnserial-1.1.4 hirsute 64-bit
- libnserial-1.1.4 impish 64-bit
- 1.1.2
The instructions to build are the same as Windows, e.g. from the directory where
the SerialPortStream.sln file is kept:
$ dotnet build
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
SerialPortStream -> /home/jcurl/source/rjcp.dll.serialportstream/code/bin/Debug/net40/RJCP.SerialPortStream.dll
SerialPortStream -> /home/jcurl/source/rjcp.dll.serialportstream/code/bin/Debug/net45/RJCP.SerialPortStream.dll
SerialPortStreamTest -> /home/jcurl/source/rjcp.dll.serialportstream/test/SerialPortStreamTest/bin/Debug/net45/RJCP.SerialPortStreamTest.dll
DatastructuresTest -> /home/jcurl/source/rjcp.dll.serialportstream/test/DatastructuresTest/bin/Debug/net40/RJCP.DatastructuresTest.dll
SerialPortStreamTest -> /home/jcurl/source/rjcp.dll.serialportstream/test/SerialPortStreamTest/bin/Debug/net40/RJCP.SerialPortStreamTest.dll
DatastructuresTest -> /home/jcurl/source/rjcp.dll.serialportstream/test/DatastructuresTest/bin/Debug/net45/RJCP.DatastructuresTest.dllYou will need to have two USB devices attached, that map to:
/dev/ttyUSB0; and/dev/ttyUSB1
that are connected via a null-modem physical connector. Many of the test cases are integration tests and rely on two serial ports to work properly.
The devices used are defined in the SerialPortStreamTest\App.config file, the
same as for Windows, but the variables LinuxSourcePort and LinuxDestPort.
Ensure that the user running the tests have permissions to access the serial ports. e.g. on Ubuntu this is not the case by default:
$ ls -l /dev/ttyU*
crw-rw---- 1 root dialout 188, 0 Apr 24 18:32 /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 1 Apr 24 18:32 /dev/ttyUSB1
$ sudo usermod -aG dialout <user>Replace <user> with the user name.
After assigning permissions, you may need to log out and log back in.
Executing the tests is the same as on Windows.
$ dotnet testThere are three failing tests on Linux. This functionality is missing on Linux, but provided on Windows. Linux doesn't provide this functionality natively.
WaitForRxCharEventOnEofCharWaitForCtsChangedEventWaitForDsrChangedEvent
This project uses the newest Microsoft SDK Project format, which is simpler and easier to write. It has been modified from the original to require explicit inclusion of files (this is for safety reasons to ensure that unexpected files do not get included).
The library targets .NET 4.0, .NET 4.5, .NET Core 6.0, 8.0.
When adding files, you'll need to look and modify the .csproj files directly,
Visual Studio 2022 will likely not be able to put the files in the correct
<ItemGroup/>.