Smart.Ports
1.0.0-rc.2
This is a prerelease version of Smart.Ports.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Smart.Ports --version 1.0.0-rc.2
NuGet\Install-Package Smart.Ports -Version 1.0.0-rc.2
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="1.0.0-rc.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Smart.Ports --version 1.0.0-rc.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Smart.Ports, 1.0.0-rc.2"
#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.
// Install Smart.Ports as a Cake Addin #addin nuget:?package=Smart.Ports&version=1.0.0-rc.2&prerelease // Install Smart.Ports as a Cake Tool #tool nuget:?package=Smart.Ports&version=1.0.0-rc.2&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Smart.Ports
Smart.Ports 是一个支持 .NET 8/9 的实用串口通信库,基于SerialPort类进行封装,核心类是SmartSerialPort,提供异步操作。
使用示例
csharp
// 创建串口通信参数SerialPortSetting实例
SerialPortSetting setting = new SerialPortSetting("COM1", 9600, 8, Parity.None, StopBits.One);
// 创建串口通信SmartSerialPort实例,指定串口接收缓冲区数据接收模式
SmartSerialPort smartSerial = new SmartSerialPort(setting, SerialDataReceivedMode.EventHandler);
// 按需订阅如下事件
smartSerial.OnOpen += (sp) => Console.WriteLine($"串口{sp.PortName}打开成功");
smartSerial.OnSend += (sp, data) => Console.WriteLine($"串口{sp.PortName}发送数据成功");
smartSerial.OnReceive += (sp, data) => Console.WriteLine($"串口{sp.PortName}接收数据成功,数据长度{data.Length}");
smartSerial.OnClose += (sp) => Console.WriteLine($"串口{sp.PortName}关闭成功");
smartSerial.OnError += (sp, msg) => Console.WriteLine($"串口{sp.PortName}发生错误:{msg}");
// 串口操作
smartSerial.Open();//打开串口
smartSerial.SendAsync(new byte[] { 0x01, 0x03, 0x06, 0xC4, 0x0B });//发送数据
byte[] data1 = await smartSerial.ReceiveAsync(3000);//接收数据,当SerialDataReceivedMode为EventHandler时不能调用该方法
byte[] data2 = smartSerial.Receive();//接收数据,当SerialDataReceivedMode为EventHandler时不能调用该方法
smartSerial.ChangeSetting(2400, 8, Parity.None, StopBits.One);//更改串口参数
smartSerial.Close();//关闭串口
// 提供获取系统串口列表集合的静态方法
var ports = SmartSerialPort.GetPortNames();
注意:SerialDataReceivedMode枚举提供两种数据接收模式,ActiveRead表示由用户主动读取,EventHandler表示通过SerialPort类的DataReceived事件触发。
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- System.IO.Ports (>= 9.0.2)
-
net9.0
- System.IO.Ports (>= 9.0.2)
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 |
---|---|---|
1.0.2 | 97 | 2/26/2025 |
1.0.1 | 80 | 2/26/2025 |
1.0.0 | 90 | 2/25/2025 |
1.0.0-rc.2 | 53 | 2/25/2025 |
1.0.0-rc.1 | 55 | 2/24/2025 |
1.0.0-beta.4 | 30 | 2/24/2025 |
1.0.0-beta.3 | 57 | 2/23/2025 |
1.0.0-beta.2 | 49 | 2/23/2025 |
1.0.0-beta.1 | 54 | 2/23/2025 |