Bluetooth connection between Universal app and medical device - UUID and CODFilter

左心房为你撑大大i 提交于 2019-12-11 08:09:16

问题


I'm implementing an Universal app on both Windows 8.1 and Windows Phone 8.1 platforms, which should connect with devices like scale or blood pressure monitor by bluetooth technology. Unfortunatelly, I have difficulty in the discovering process and according to that I've no chance to pair and connect to the device.

I've found the thread about this issue, but unfortunatelly it's associated with Android.

From the post above:

Describing the medical device: The device is using Service Discovery Protocol (SDP) and Serial Port Profile (SPP). It starts an inquiry procedure to discover (up to 10) surrounding access points with matched COD Filter and Service Name. Then it sequentially establishes a connection (using Page Procedure) with the access point by checking the PIN. Once the PIN is matched, the data is uploaded. Upon uploading data the device waits for an acknowledge. The decice is the master and initiates the communication.

I've also started from the Microsoft Bluetooth Rfcomm Sample.

My questions:

  1. I'm dobious about my standard UUID number 00001101-0000-1000-8000-00805F9B34FB. Is it appropriate in this circumstances?

    // 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);
        }
    }
    
  2. I'm not sure if there is a better method to set Service Name? Maybe I do this wrong? I think it's a main problem.

  3. What about COD Filter (in the specification there is a note that it should equals [00000000] for proper communication? Is there any method to set it using RfcommServiceProvider? Maybe I should also manually set PIN number or if it's required only in the pairing process?

  4. I've noticed, in the microsoft samples - Server is only supported for the Windows platform. It is possible to implement server functionality also for the WP? - device which will receive data from the medical device should be a slave.

I've also read about Gatt protocol but it doesn't provide profiles for all devices which I need.

Thanks in advance for your help.


回答1:


The key to solving my problem was to declare serial port connection in the app manifest file instead of declaring connection by specified UUID number:

<Capabilities>
    <DeviceCapability Name="proximity" />
    <m2:DeviceCapability Name="bluetooth.rfcomm">
      <m2:Device Id="any">
        <m2:Function Type="name:serialPort" />
      </m2:Device>
    </m2:DeviceCapability>
  </Capabilities>

And use RfcommServiceId.SerialPort as argument of RfcommServiceProvider.




回答2:


I'm in a very similar boat; I'm trying to connect to a medical device using WinJS/HTML for an RT device, and I found this article to be very good:

http://blogs.windows.com/windows/b/buildingapps/archive/2014/05/07/talking-to-robots-or-other-devices-using-bluetooth-from-a-windows-runtime-app.aspx

It looks like you're using c#, but you can get the idea from the javascript in the article. Create a selector that looks for serial-type devices, then query for a list of all of those devices. Here's some of the javascript from the article to illustrate the idea

var selector = Windows.Devices.Bluetooth.Rfcomm.RfcommDeviceService.getDeviceSelector( Windows.Devices.Bluetooth.Rfcomm.RfcommServiceId.serialPort);

var devices = Windows.Devices.Enumeration.DeviceInformation.findAllAsync(selector, null);

var device = devices[0];

return Windows.Devices.Bluetooth.Rfcomm.RfcommDeviceService.fromIdAsync(device.id);

I'm still working on parsing the bytes that I get from the device, but using the above code, WinRT asks for a connection to the device, and my device begins to stream data, which has been the biggest hurdle. Good luck!



来源:https://stackoverflow.com/questions/24674084/bluetooth-connection-between-universal-app-and-medical-device-uuid-and-codfilt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!