CSoft.Communication.Bluetooth 11.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSoft.Communication.Bluetooth --version 11.0.2
                    
NuGet\Install-Package CSoft.Communication.Bluetooth -Version 11.0.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="CSoft.Communication.Bluetooth" Version="11.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSoft.Communication.Bluetooth" Version="11.0.2" />
                    
Directory.Packages.props
<PackageReference Include="CSoft.Communication.Bluetooth" />
                    
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 CSoft.Communication.Bluetooth --version 11.0.2
                    
#r "nuget: CSoft.Communication.Bluetooth, 11.0.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.
#:package CSoft.Communication.Bluetooth@11.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSoft.Communication.Bluetooth&version=11.0.2
                    
Install as a Cake Addin
#tool nuget:?package=CSoft.Communication.Bluetooth&version=11.0.2
                    
Install as a Cake Tool

CSoft.Communication.Bluetooth

经典蓝牙 RFCOMM/SPP 通讯包。BluetoothClassic 按设备地址连接远端串口服务,实现 IPhysicalPort。BluetoothClassic_Server 监听标准 SPP 服务,使用 Guid 区分连接,实现 IPhysicalPort_Server。BLE GATT 设备请使用 CSoft.Communication.BLE。 低功耗蓝牙包

安装与运行条件

dotnet add package CSoft.Communication.Bluetooth --version 11.0.2
目标或平台 使用条件
net8.0、net9.0、net10.0、net11.0 Windows 和 Linux 使用 32feet.NET 的经典蓝牙提供程序。适配器和对端设备都要支持经典蓝牙 RFCOMM/SPP。
netstandard2.0 提供兼容资产。能否发现或连接设备取决于宿主选中的蓝牙提供程序。
Linux 启用 BlueZ 和系统 D-Bus,并确认进程有权访问蓝牙适配器。

连接前打开蓝牙,并按设备要求完成配对。远端需提供标准串口服务 00001101-0000-1000-8000-00805f9b34fb。可以用 BluetoothClassic.DiscoverDevicesAsync() 获取设备的 Name 和 Address。设备名称相同时,优先使用扫描结果中的地址。

客户端

将设备地址作为程序的第一个参数。TopPort 把接收字节交给 TimeParser,适合简单文本调试。实际协议可换成匹配帧格式的解析器。

using Communication.Bluetooth;
using Parser.Parsers;
using System.Text;
using TopPortLib;

await using var client = new TopPort(new BluetoothClassic(args[0]), new TimeParser());
client.OnReceiveParsedData += data =>
{
    Console.WriteLine(Encoding.UTF8.GetString(data));
    return Task.CompletedTask;
};

await client.OpenAsync();
await client.SendAsync(Encoding.UTF8.GetBytes("ping"));
Console.ReadLine();

服务端

收到连接后用 clientId 向该连接回送数据。StartConsuming 每次处理当前读取到的一块字节,协议消息边界需要由应用解析。

using Communication.Bluetooth;
using Communication.Extensions;

await using var server = new BluetoothClassic_Server();
server.OnClientConnect += (clientId, reader) =>
{
    reader.StartConsuming(data => server.SendDataAsync(clientId, data));
    return Task.CompletedTask;
};

await server.StartAsync();
Console.ReadLine();

客户端可用 CloseAsync() 主动关闭,服务端可用 StopAsync() 主动停止监听并释放连接。两个示例退出作用域时会异步释放资源。

仓库提供 经典蓝牙客户端 和 服务端 WPF 示例。

接入 Pigeon

引用 CSoft.Communication.Bluetooth 11.0.2 后,NuGet 会一并还原 CSoft.TopPortLib、CSoft.CommTask 和 CSoft.Communication 11.0.2。使用本地包时,先按仓库说明配置本地包源。

客户端把 BluetoothClassic 交给 TopPort,再把该端口交给 PigeonPort。服务端把 BluetoothClassic_Server 和每客户端的分帧器工厂交给 TopPort_Server,再用 PigeonPort_Server 包装。分帧器和 Req/Rsp 由应用协议决定。

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net10.0 is compatible.  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.  net11.0 is compatible. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
11.0.3 47 11/13/2026
11.0.2 55 11/13/2026
11.0.1 48 11/12/2026
11.0.0 51 11/12/2026
10.6.2 195 5/28/2026
10.6.1 132 5/28/2026
10.6.0 132 5/27/2026
10.5.1 108 5/25/2026
10.5.0 135 5/25/2026
10.4.11 140 5/20/2026
10.4.10 133 5/19/2026
10.4.9 131 5/19/2026
10.4.8 132 5/18/2026
10.4.7 130 5/18/2026
10.4.6 125 5/15/2026
10.4.5 130 5/14/2026
10.4.3 133 5/14/2026
10.4.1 125 5/11/2026
10.4.0 131 5/11/2026
10.3.1 130 5/7/2026
Loading failed

依赖 CSoft.TopPortLib 11.0.2,安装经典蓝牙包即可使用新版 Pigeon。
继续提供 .NET 8、9、10、11 和 .NET Standard 2.0 资产。