蓝牙监听器-如何监听来自蓝牙设备的消息
本文关键字:消息 监听器 何监听 监听 | 更新日期: 2023-09-27 18:04:30
我正在尝试创建一个服务器(一台带有蓝牙的计算机)来收听蓝牙消息。我用的是32英尺的图书馆。但是我得到了一个异常,我找不到它是什么。例外情况是:没有找到支持的蓝牙协议栈。
下面是代码:using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using InTheHand;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Ports;
using InTheHand.Net.Sockets;
using System.IO;
namespace Bluetoot_Tutorial
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void bGo_Click(object sender, EventArgs e)
{
connectAsServer();
}
private void connectAsServer()
{
Thread bluetoothServerThread = new Thread(new ThreadStart(ServerConnectThread));
bluetoothServerThread.Start();
}
private void connectAsClient()
{
throw new NotImplementedException();
}
Guid uUUID = new Guid("00001101-0000-1000-8000-00805F9B34FB");
public void ServerConnectThread()
{
BluetoothListener blueListener = new BluetoothListener(uUUID);
blueListener.Start();
BluetoothClient conn = blueListener.AcceptBluetoothClient();
}
消息是什么意思…你的电脑上有什么蓝牙软件?
在BluetoothListener中添加本地地址,如下所示。
BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;
if (myRadio == null)
{
Console.WriteLine("No radio hardware or unsupported software stack");
return;
}
RadioMode mode = myRadio.Mode;
var lsnr = new BluetoothListener(myRadio.LocalAddress, serviceClass);
lsnr.Start();