本文实例为大家分享了C#实现PC蓝牙通信代码,供大家参考,具体内容如下
添加引用InTheHand.Net.Personal.dll
首先创建一个蓝牙类
class LanYa {
public string blueName { get; set; } //l蓝牙名字
public BluetoothAddress blueAddress { get; set; } //蓝牙的唯一标识符
public ClassOfDevice blueClassOfDevice { get; set; } //蓝牙是何种类型
public bool IsBlueAuth { get; set; } //指定设备通过验证
public bool IsBlueRemembered { get; set; } //记住设备
public DateTime blueLastSeen { get; set; }
public DateTime blueLastUsed { get; set; }
}
然后就是搜索设备
List lanYaList = new List(); //搜索到的蓝牙的集合
BluetoothClient client = new BluetoothClient();
BluetoothRadio radio = BluetoothRadio.PrimaryRadio; //获取蓝牙适配器
radio.Mode = RadioMode.Connectable;
BluetoothDeviceInfo[] devices = client.DiscoverDevices();//搜索蓝牙 10秒钟
foreach (var item in devices) {
l