Windows phone 8 在windows phone 8中,无法通过蓝牙从arduino接收多个数据

Windows phone 8 在windows phone 8中,无法通过蓝牙从arduino接收多个数据,windows-phone-8,bluetooth,arduino,Windows Phone 8,Bluetooth,Arduino,我有Arduino Uno R3和无线Proto Shield,我想与Windows Phone 8通信 我使用的是示例中的基础 这是一种异步接收方法: private async void ReceiveMessages(object sender, DoWorkEventArgs e) { try { while (true) { // Read first byte (

我有Arduino Uno R3和无线Proto Shield,我想与Windows Phone 8通信

我使用的是示例中的基础

这是一种异步接收方法:

private async void ReceiveMessages(object sender, DoWorkEventArgs e)
    {
        try
        {
            while (true)
            {

                // Read first byte (length of the subsequent message, 255 or less). 
                uint sizeFieldCount = await dataReader.LoadAsync(1);
                if (sizeFieldCount != 1)
                {
                    // The underlying socket was closed before we were able to read the whole data. 
                    return;
                }

                // Read the message. 
                uint messageLength = dataReader.ReadByte();
                uint actualMessageLength = await dataReader.LoadAsync(messageLength);
                if (messageLength != actualMessageLength)
                {
                    // The underlying socket was closed before we were able to read the whole data. 
                    return;
                }
                // Read the message and process it.
                string message = dataReader.ReadString(actualMessageLength);
                MessageReceived(message);
            }
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }

    }
我有一些从Arduino发回信息的方法,(SendCarId,SendRideId)

如果我尝试单独发送每个命令,它将(从Arduino)返回正确的数据

但当我一个接一个地发送请求时,它只响应第一个请求,而不响应第二个请求。(它永远不会第二次访问ReceiveMessages方法)


有人知道问题出在哪里吗?

我发现如果我在得到答案时终止连接, 然后我可以初始化新连接(可能不是最有效的解决方案,但它正在工作)

  public void Terminate()
    {
        connected = false;

        dataReadWorker.DoWork -= new DoWorkEventHandler(ReceiveMessages);

        if (socket != null)
        {
            socket.Dispose();
            socket = null;
        }
        if (dataReadWorker != null)
        {
            dataReadWorker.CancelAsync();

        }
    }


public void Initialize()
    {
        socket = new StreamSocket();
        dataReadWorker = new BackgroundWorker();
        dataReadWorker.WorkerSupportsCancellation = true;
        dataReadWorker.DoWork += new DoWorkEventHandler(ReceiveMessages);
    }