Example #1
0
        internal virtual void OpenEndpoints()
        {
            var endpointIds = GetBluetoothEndpointIds();

            endpoints[UsbBluetoothEndpointType.Commands]   = usbDevice.OpenEndpointWriter((WriteEndpointID)endpointIds[UsbBluetoothEndpointType.Commands]);
            endpoints[UsbBluetoothEndpointType.Events]     = usbDevice.OpenEndpointReader((ReadEndpointID)endpointIds[UsbBluetoothEndpointType.Events]);
            endpoints[UsbBluetoothEndpointType.AclDataOut] = usbDevice.OpenEndpointWriter((WriteEndpointID)endpointIds[UsbBluetoothEndpointType.AclDataOut]);
            endpoints[UsbBluetoothEndpointType.AclDataIn]  = usbDevice.OpenEndpointReader((ReadEndpointID)endpointIds[UsbBluetoothEndpointType.AclDataIn]);
            var failedEndpointTypes = from x in endpoints where x.Value == null select x.Key;

            if (failedEndpointTypes.Count() > 0)
            {
                throw new WinBeaconException("Failed to open endpoint(s): {0}", string.Join(" ", failedEndpointTypes));
            }
            endpoints[UsbBluetoothEndpointType.Events].SubscribeForDataReceived(data => OnDataReceived(data, DataType.Command));
            endpoints[UsbBluetoothEndpointType.AclDataIn].SubscribeForDataReceived(data => OnDataReceived(data, DataType.Acl));
        }