Exemplo n.º 1
0
        private void ValidateClientMap(BlePeripheralMap map)
        {
            if (!ProtocolServices.ALL_SERVICES.All(service => map.Services.Any(mapService => mapService.ServiceUUID.Equals(service))))
            {
                throw new Exception("Not all expected services found on the device!");
            }

            if (ProtocolServices.ALL_CHARACTERISTICS.Any(charac => map.FindCharacteristicByUUID(charac) == null))
            {
                throw new Exception("Not all expected characteristics found on the device!");
            }
        }
        public BlePeripheralMap Execute()
        {
            this.PeripheralMap = new BlePeripheralMap();

            this.FindServices();

            foreach (BlePeripheralService service in this.PeripheralMap.Services)
            {
                this.FindAttributes(service);

                this.ConvertAttributesToCharacteristics(service);
            }

            return(this.PeripheralMap);
        }
Exemplo n.º 3
0
        public BlePeripheralMap Connect()
        {
            // Init BgLib, open port, and start receiving thread
            this.InitTools();

            BleDiscoverService    discoverBlock = new BleDiscoverService(Ble, Port, Config.ServiceUUID);
            ScanResponseEventArgs found         = discoverBlock.Execute();

            BleConnectToService connectBlock = new BleConnectToService(Ble, Port, found.sender, found.address_type);

            this.ConnectionHandle = connectBlock.Execute().connection;

            BleFindServicesAndCharacteristics infoBlock = new BleFindServicesAndCharacteristics(Ble, Port, this.ConnectionHandle);

            this.PeripheralMap = infoBlock.Execute();

            this.InitializeCharacteristicNotifications();

            this.Ble.Lib.BLEEventConnectionDisconnected += DisconnectedHandler;

            return(this.PeripheralMap);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="port">The port with the bluegiga ble adapter</param>
        /// <param name="notificationMode">Can't be changed after initialization!</param>
        /// <param name="config">Must be suplied when choosing EasyConfigurable notificatoin mode. Otherwise - ignored!</param>
        private void ConnectToDevice(string port, NotificationSubscriptionMode notificationMode, NotificationAutoConfigurableValues config = null)
        {
            // connect
            _ble = new BleConnector(new BleConnectorInitData(port, ProtocolServices.MYO_INFO_SERVICE, _config.Debug, _config.PortThreadSleep));
            _ble.Disconnected += DisconnectedHandler;
            BlePeripheralMap clientMap = _ble.Connect();

            // init functionallity object
            this.Controller = new MyoController(_ble);

            // validate
            this.ValidateClientMap(clientMap);

            FirmwareVersion fv = this.Controller.GetFirmwareVersion();

            if (fv.Major < ProtocolRevision.MAJOR_VERSION ||
                (fv.Major == ProtocolRevision.MAJOR_VERSION && fv.Minor < ProtocolRevision.MINOR_VERSION))
            {
                throw new Exception("Not supported protocol version. Please upgrade!");
            }

            // handle notification events
            this.InitializeNotificationSystem(notificationMode, config, _config.NotificationThreadSleep);
        }