Smart.Ports
3.0.0
dotnet add package Smart.Ports --version 3.0.0
NuGet\Install-Package Smart.Ports -Version 3.0.0
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="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Smart.Ports" Version="3.0.0" />
<PackageReference Include="Smart.Ports" />
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 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Smart.Ports, 3.0.0"
#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=3.0.0
#tool nuget:?package=Smart.Ports&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Smart.Ports
Smart.Ports 是一个支持 .NET 8/9 的事件驱动的实用通信库,提供SerialPort、TcpClient、Udp通信接口。
使用示例
csharp
// 按需配置通信参数
PortConfig config= new PortConfig(PortType.SerialPort, "COM1:9600,8,N,1"); // 串口的通信端口配置
PortConfig config= new PortConfig(PortType.TcpClient, "127.0.0.1:5055"); // TCP客户端的通信端口配置,使用':'分割服务端IP和Port
PortConfig config= new PortConfig(PortType.Udp, "5000;127.0.0.1:5055"); // UDP的通信端口配置,';'左边表示UDP组件监听的本地端口,右边表示远程地址和远程端口,远程地址和远程端口使用':'分割
// 创建IPort通信端口实例
IPort port = PortFactory.GetPort(config);
// 按需订阅如下事件
port.OnOpen += (sp) => 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();
// 发送数据
port.Send([1, 2, 3]);
// 关闭通信端口
result = port.Close();
注意:如果创建的IPort的PortType为Udp,则其OnSend和OnReceive的实际事件参数为UdpDataEventArgs,继承于DataEventArgs。
Developed by zenglei
Product | Versions 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.
-
net8.0
- HPSocket.Net (>= 6.0.3.1)
- Smart.Helper (>= 3.2.0)
- System.IO.Ports (>= 9.0.0)
-
net9.0
- HPSocket.Net (>= 6.0.3.1)
- Smart.Helper (>= 3.2.0)
- System.IO.Ports (>= 9.0.0)
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 |
---|---|---|
3.0.0 | 84 | 5/25/2025 |
2.0.0 | 79 | 4/5/2025 |
1.0.3 | 132 | 3/16/2025 |
1.0.2 | 109 | 2/26/2025 |
1.0.1 | 92 | 2/26/2025 |
1.0.0 | 101 | 2/25/2025 |
1.0.0-rc.2 | 65 | 2/25/2025 |
1.0.0-rc.1 | 66 | 2/24/2025 |
1.0.0-beta.4 | 39 | 2/24/2025 |
1.0.0-beta.3 | 66 | 2/23/2025 |
1.0.0-beta.2 | 59 | 2/23/2025 |
1.0.0-beta.1 | 62 | 2/23/2025 |