无法从蓝牙设备的指定索引中检索数据

时间:2011-12-09 02:50:51

标签: c# visual-studio-2008 bluetooth

以下应用程序通过与COM端口建立连接从Nonin 3150蓝牙设备读取数据。设备is here的文档。试图仅提取脉率和SPO数据。

以下进程缓冲区方法创建一个Bytes数组。指针如何从正确的索引(脉冲率/ SPO数据)中检索数据?

代码:

try
{
    serialPort.PortName = comboBox1.Text;
    serialPort.BaudRate = 9600;
    serialPort.Parity = Parity.None;
    serialPort.DataBits = 8;
    serialPort.StopBits = StopBits.One;
    serialPort.Encoding = System.Text.Encoding.ASCII ;

    serialPort.Open();
    label1.Text = comboBox1.Text + " is opened";
    // textBox1.Text = 
    serialPort.DataReceived += new SerialDataReceivedEventHandler(datareceived);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message.ToString());
}

void datareceived(object sender, SerialDataReceivedEventArgs e)
{
    myDelegate d = new myDelegate(update);
    textBox1.Invoke(d, new object[] { });
}

{
        while (serialPort.BytesToRead > 0)
        bBuffer.Add((byte)serialPort.ReadByte());

        ProcessBuffer(bBuffer);
    }

    private void ProcessBuffer(List<byte> bBuffer)
    {
        // Look in the byte array for useful information then remove the useful data from the buffer

        // Create a byte array buffer to hold the incoming data
        byte[] buffer = bBuffer.ToArray();


        // Show the user the incoming data 
        for (int i = 0; i < buffer.Length; i++)
        {
          textBox1.Text = bBuffer[i].ToString();
        }        

        textBox1.ScrollToCaret();        
    }

0 个答案:

没有答案