我有一个蓝牙设备发送&以串行端口模式接收数据。 从代码成功连接到设备后:
var btService = await RfcommDeviceService.FromIdAsync(deviceInformation.Id);
streamSocket = new StreamSocket();
await streamSocket.ConnectAsync(btService.ConnectionHostName, btService.ConnectionServiceName);
我将命令发送到输出流:
var bytes = Encoding.UTF8.GetBytes(command);
var writed = await streamSocket.OutputStream.WriteAsync(bytes.AsBuffer());
await streamSocket.OutputStream.FlushAsync();
这里没有例外。在此之后,我倾听回应:
IBuffer buffer = new Windows.Storage.Streams.Buffer(256);
var message = await streamSocket.InputStream.ReadAsync(buffer, 256, InputStreamOptions.None);
但方法ReadAsync()
无限执行。
我尝试通过DataReader / DataWriter类连接,但结果相同。
有什么问题?