蓝牙监听器 - 如何从蓝牙设备收听消息

时间:2014-05-20 19:32:23

标签: c# bluetooth serial-port

我正在尝试创建一个收听蓝牙消息的服务器(带蓝牙的计算机)。我正在使用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();


    }

2 个答案:

答案 0 :(得分:0)

该消息表示它的内容......您的PC上有哪些蓝牙软件?

答案 1 :(得分:0)

在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();