Smart.Ports 4.0.0-beta.8

This is a prerelease version of Smart.Ports.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Smart.Ports --version 4.0.0-beta.8
                    
NuGet\Install-Package Smart.Ports -Version 4.0.0-beta.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Smart.Ports" Version="4.0.0-beta.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Smart.Ports" Version="4.0.0-beta.8" />
                    
Directory.Packages.props
<PackageReference Include="Smart.Ports" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Smart.Ports --version 4.0.0-beta.8
                    
#r "nuget: Smart.Ports, 4.0.0-beta.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Smart.Ports&version=4.0.0-beta.8&prerelease
                    
Install Smart.Ports as a Cake Addin
#tool nuget:?package=Smart.Ports&version=4.0.0-beta.8&prerelease
                    
Install Smart.Ports as a Cake Tool

Smart.Ports

NuGet Smart.Ports 是一个支持 .NET 8/9 的事件驱动的实用通信库,提供SerialPort、TcpClient、TcpServer和Udp通信接口。

使用示例


csharp
// 按需配置通信参数
PortConfig config= new PortConfig(PortType.SerialPort, "COM1;9600,8,N,1;None"); // 串口名称、串口参数和流控配置
PortConfig config= new PortConfig(PortType.TcpClient, "127.0.0.1:5055"); // TcpClient的通信端口配置,使用':'分割服务端IP和Port
PortConfig config= new PortConfig(PortType.TcpServer, "0.0.0.0:5055"); // TcpServer的通信端口配置,使用':'分割监听IP和Port
PortConfig config= new PortConfig(PortType.Udp, "0.0.0.0:5055"); // UDP的通信端口配置,指定UDP的本机监听IP和Port

// 创建IPort通信端口实例
IPort port = PortFactory.GetPort(config);

// 按需订阅如下事件
port.OnOpen += (sp, args) => Console.WriteLine($"通信端口打开成功");
port.OnSend += (port, args) => Console.WriteLine($"发送数据成功,数据长度{args.Data.Length}");
port.OnReceive += (port, args) => Console.WriteLine($"接收数据成功,数据长度{args.Data.Length}");
port.OnClose += (port) => Console.WriteLine($"通信端口关闭");
port.OnError += (port,err) => Console.WriteLine($"错误信息:{err}");

// 打开通信端口
bool result = port.Open();

// TcpClient和SerialPort的发送数据
port.Send([1, 2, 3]);

// UDP发送数据
((IUdpPort)port).Send(byte[] data, PortEndPoint endPoint);

// TcpServer客户端连接事件
((IServerPort)port).OnConnect;
// TcpServer客户端断开事件
((IServerPort)port).OnDisConnect;
// TcpServer发送数据
((IServerPort)port).Send(byte[] data, nint clientId);
// TcpServer获取所有连接
List<nint> clients = ((IServerPort)port).GetAllClientIds();
// TcpServer断开指定客户端
((IServerPort)port).Disconnect(1);

// 关闭通信端口
result = port.Close();

// 注意:
// Udp和TcpServer通信端口不支持IPort.Send(byte[] data)方法;

Developed by zenglei

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.0.0 124 6/14/2025
4.0.0-beta.12 248 6/12/2025
4.0.0-beta.11 243 6/12/2025
4.0.0-beta.10 248 6/11/2025
4.0.0-beta.9 251 6/11/2025
4.0.0-beta.8 260 6/10/2025
4.0.0-beta.7 256 6/10/2025
4.0.0-beta.6 204 6/9/2025
4.0.0-beta.5 165 6/8/2025
4.0.0-beta.4 161 6/8/2025
4.0.0-beta.3 78 6/8/2025
4.0.0-beta.2 81 6/7/2025
4.0.0-beta.1 90 6/7/2025
3.1.0 142 6/1/2025
3.0.0 145 5/25/2025
2.0.0 82 4/5/2025
1.0.3 135 3/16/2025
1.0.2 113 2/26/2025
1.0.1 95 2/26/2025
1.0.0 104 2/25/2025
1.0.0-rc.2 69 2/25/2025
1.0.0-rc.1 68 2/24/2025
1.0.0-beta.4 42 2/24/2025
1.0.0-beta.3 69 2/23/2025
1.0.0-beta.2 61 2/23/2025
1.0.0-beta.1 64 2/23/2025