【发布时间】:2016-03-17 16:25:58
【问题描述】:
我有一台徕卡 DISTO D3a BT。 它是一个测量设备,它通过蓝牙发送测量值。
我写了一些代码来获取蓝牙流,我收到了数据,但我总是收到“错误 240”消息。
这意味着(来自用户手册)我不确认数据传输是否成功。
我该怎么做?
这是我的代码:
int bytesRead = 0;
System.IO.Stream stream = client_.GetStream();
byte[] buffer = new byte[k_BUFFER_BYTES];
while(true)
{
Task.Delay(100);
if (client_.Available > 0) // Available contains the available bytes
{
int counter = 0;
string output = "";
while (counter < client_.Available)
{
bytesRead = stream.Read(buffer, 0, k_BUFFER_BYTES);
counter += bytesRead ;
output += System.Text.Encoding.ASCII.GetString(buffer, 0, bytesRead);
}
stream.Write(Encoding.ASCII.GetBytes("\r\n"), 0, 2);
stream.Flush();
Console.WriteLine(output + " - " + counter + " - " + client_.Available);
}
}
提前感谢您的帮助!
【问题讨论】: