Smart.Ports 1.0.0-beta.3

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 1.0.0-beta.3                
NuGet\Install-Package Smart.Ports -Version 1.0.0-beta.3                
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-beta.3" />                
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-beta.3                
#r "nuget: Smart.Ports, 1.0.0-beta.3"                
#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-beta.3&prerelease

// Install Smart.Ports as a Cake Tool
#tool nuget:?package=Smart.Ports&version=1.0.0-beta.3&prerelease                

Smart.Ports

NuGet
Smart.Ports 是一个支持 .NET 6/8/9 的实用串口通信库,基于SerialPort类进行封装,核心类是SmartSerialPort,提供异步操作。

使用示例

csharp
// 创建串口通信参数SerialPortSetting实例
SerialPortSetting setting = new SerialPortSetting("COM1", 9600, 8, Parity.None, StopBits.One);

// 创建串口通信SmartSerialPort实例,指定串口接收缓冲区数据接收模式
SmartSerialPort smartSerial = new SmartSerialPort(setting, ReceiveMode.Trigger);

// 按需订阅如下事件
smartSerial.OnOpen += (sp) => Console.WriteLine($"串口{sp.PortName}打开成功");
smartSerial.OnSend += (sp, data) => Console.WriteLine($"串口{sp.PortName}发送数据成功");
smartSerial.OnReceive += (sp, data) => Console.WriteLine($"串口{sp.PortName}接收数据成功");
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[] data = smartSerial.ReceiveAsync(3000);//接收数据,当ReceiveMode为Trigger时不建议调用该方法
smartSerial.ChangeSetting(2400, 8, Parity.None, StopBits.One);//更改串口参数
smartSerial.Close();//关闭串口

// 提供获取系统串口列表集合的静态方法
var ports = SmartSerialPort.GetPortNames();

注意:ReceiveMode枚举提供两种数据接收模式,Read表示由用户主动读取,Trigger表示通过SerialPort类的DataReceived事件触发。

Developed by zenglei

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.

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