我正在 Windows 8.1 和 Windows Phone 8.1 平台上实现一个通用应用程序,它应该通过蓝牙技术与体重秤或血压监测器等设备连接。不幸的是,我在发现过程中遇到了困难,因此我没有机会配对和连接到设备。
我找到了关于这个问题的线程,但不幸的是它与 Android 相关联。
从上面的帖子:
描述医疗设备:该设备正在使用服务发现协议 (SDP) 和串行端口配置文件 (SPP)。它启动查询程序以发现(最多 10 个)具有匹配 COD 过滤器和服务名称的周围接入点。然后它通过检查 PIN 顺序地与接入点建立连接(使用 Page Procedure)。匹配 PIN 后,将上传数据。上传数据后,设备等待确认。设备是主设备并启动通信。
我也从Microsoft Bluetooth Rfcomm Sample开始。
我的问题:
我对我的标准UUID编号 00001101-0000-1000-8000-00805F9B34FB 持怀疑态度。在这种情况下合适吗?
// The Id of the Service Name SDP attribute protected const UInt16 SdpServiceNameAttributeId = 0x100; // The SDP Type of the Service Name SDP attribute. // The first byte in the SDP Attribute encodes the SDP Attribute Type as follows : // - the Attribute Type size in the least significant 3 bits, // - the SDP Attribute Type value in the most significant 5 bits. protected const byte SdpServiceNameAttributeType = (4 << 3) | 5; public async Task Start() { try { if (rfcommProvider == null) rfcommProvider = await RfcommServiceProvider.CreateAsync( RfcommServiceId.FromUuid(BluetoothServiceUuid)); if (rfcommProvider != null) { if (socketListener != null) { socketListener.Dispose(); socketListener = null; } // Create a listener for this service and start listening socketListener = new StreamSocketListener(); socketListener.ConnectionReceived += OnConnectionReceived; await socketListener.BindServiceNameAsync(rfcommProvider.ServiceId.AsString(), SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication); // Set the SDP attributes and start Bluetooth advertising DataWriter sdpWriter = new DataWriter(); // Write the Service Name Attribute. sdpWriter.WriteByte(SdpServiceNameAttributeType); // The length of the UTF-8 encoded Service Name SDP Attribute. sdpWriter.WriteByte((byte)BluetoothServiceDisplayName.Length); // The UTF-8 encoded Service Name value. sdpWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; sdpWriter.WriteString(BluetoothServiceDisplayName); // Set the SDP Attribute on the RFCOMM Service Provider. if (rfcommProvider.SdpRawAttributes.ContainsKey(SdpServiceNameAttributeId)) rfcommProvider.SdpRawAttributes.Remove(SdpServiceNameAttributeId); rfcommProvider.SdpRawAttributes.Add(SdpServiceNameAttributeId, sdpWriter.DetachBuffer()); // Start Bluetooth advertising //SetState(BluetoothServerState.Started); rfcommProvider.StartAdvertising(socketListener); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine( "ERROR: " + e.Message); } }
我不确定是否有更好的方法来设置服务名称?也许我做错了?我认为这是一个主要问题。
那么COD 过滤器呢(在规范中有一个注释,它应该等于 [00000000] 以进行正确的通信?有没有使用 RfcommServiceProvider 设置它的方法?也许我还应该手动设置 PIN 码,或者仅在配对过程中需要它?
我注意到,在 microsoft 示例中 - 服务器仅支持 Windows 平台。是否也可以为 WP 实现服务器功能?- 将从医疗设备接收数据的设备应该是从设备。
我也读过 Gatt 协议,但它没有为我需要的所有设备提供配置文件。
在此先感谢您的帮助。