0

我试图通过互联网的一些(很多:P)帮助制作一个蓝牙应用程序。它只是向设备发送 byte[7] 命令(在 proj 中称为“tosend”)并通过侦听器接收 byte[7] 命令。

我正在从范围内搜索设备,获取所有数据(地址等)并且进展顺利(缓慢,但很好)。然后我双击列表以选择一个设备并启动客户端连接线程:

private void CCT()
    {
        BluetoothClient Client = new BluetoothClient();
        udConsole("CCT started.");
        Client.BeginConnect(info.DeviceAddress, mUUID, new AsyncCallback(Callback), Client);
        //"info" is just a BluetoothDeviceInfo (of selected device)
    }

    private void Callback(IAsyncResult res)
    {
        BluetoothClient Client = (BluetoothClient)res.AsyncState;
        Client.EndConnect(res);
        Stream str = Client.GetStream(); //<- error is here
        str.ReadTimeout = 1000;
        while (true)
        {
            while (!initializeSending) ;
            Client.GetStream().Write(tosend, 0, tosend.Length);
        }
    }

我无法发送任何内容,因为一旦我看到错误参数无效,其他错误地址无效(当我看到该地址正常时)。

两台设备一直配对!而且蓝牙很好用^^

发生了什么事:(?我花了很多时间寻找解决方案,但对我没有任何帮助。

4

0 回答 0