コード例 #1
0
ファイル: SyncHandler.cs プロジェクト: cnapenas/SyncHandler
        void Adapter_DeviceConnected(object sender, DeviceConnectionEventArgs e)
        {
            Debug.WriteLine("Device Connected");

            this.Device = e.Device;

            //if (this.Device.Name.Replace("PE", "").Replace("FT", "").StartsWith("932"))
            //{
            //	Debug.WriteLine("Instantiating PE932 Handler");
            //	this.syncDeviceHandler = SyncDeviceHandler932.GetInstance();
            //}
            /*else */
            if (this.Device.Name.Replace("PE", "").Replace("FT", "").StartsWith("961"))
            {
                Debug.WriteLine("Instantiating PE/FT961 Handler");
                this.SyncDeviceHandler = SyncDeviceHandler961.GetInstance();
            }
            else if (this.Device.Name.StartsWith("H25FE2"))
            {
                this.SyncDeviceHandler = SyncDeviceHandlerStriiv.GetInstance();
            }

            this.SyncDeviceHandler.IncrementProgressBar += UpdateProgressBar;
            this.SyncDeviceHandler.SyncDone             += DoneSyncing;

            this.SyncDeviceHandler.SetAdapter(this.Adapter);
            this.SyncDeviceHandler.SetDevice(this.Device);
            this.SyncDeviceHandler.SetWebService(this.WebService);

            e.Device.ServicesDiscovered += Services_Discovered;
            //this.Adapter.CommandResponse += SyncDeviceHandler.ReceiveResponse;
            e.Device.DiscoverServices();
        }
コード例 #2
0
            public UsbHostControllerApiWrapper(NativeApi api)
            {
                this.Api = api;

                this.impl = api.Implementation;

                this.Acquire();

                this.onConnectDispatcher              = NativeEventDispatcher.GetDispatcher("GHIElectronics.TinyCLR.NativeEventNames.UsbHost.OnConnectionChanged");
                this.onConnectDispatcher.OnInterrupt += (apiName, d0, d1, d2, d3, ts) => {
                    if (this.Api.Name == apiName)
                    {
                        var id = (uint)d0;

                        var connection     = (DeviceConnectionStatus)d3;
                        var interfaceIndex = (byte)d1;
                        var deviceType     = (DeviceType)d2;

                        GetDeviceInformation(id, out var vendor, out var product, out var port);

                        var deviceConnectedEventArgs = new DeviceConnectionEventArgs(id, interfaceIndex, deviceType, vendor, product, port, connection);


                        this.onConnectionChangedCallbacks?.Invoke(null, deviceConnectedEventArgs);
                    }
                };
            }
コード例 #3
0
ファイル: SyncHandler.cs プロジェクト: yelkrebb/XamTest-
 void Adapter_DeviceConnected(object sender, DeviceConnectionEventArgs e)
 {
     Debug.WriteLine("Device Connected");
     this.Device = e.Device;
     e.Device.ServicesDiscovered += Services_Discovered;
     e.Device.DiscoverServices();
 }
コード例 #4
0
        public void ConnectToDevice(IDevice device)
        {
            connectedDevices.Add(device);
            var args = new DeviceConnectionEventArgs();

            args.Device = device;
            DeviceConnected?.Invoke(this, args);
        }
コード例 #5
0
        public void DisconnectDevice(IDevice device)
        {
            connectedDevices.Remove(device);
            var args = new DeviceConnectionEventArgs();

            args.Device = device;
            DeviceDisconnected?.Invoke(this, args);
        }
コード例 #6
0
        private void FailedToConnectPeripheral(object sender, CBPeripheralErrorEventArgs e)
        {
            var device = new Device(e.Peripheral);
            var args   = new DeviceConnectionEventArgs(device)
            {
                ErrorMessage = e.Error.Description
            };

            DeviceFailedToConnect(this, args);
        }
コード例 #7
0
        async void _adapter_DeviceConnected(object sender, DeviceConnectionEventArgs e)
        {
            var service = await e.Device.GetServiceAsync(Guid.Parse("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"));

            _characteristic = await service.GetCharacteristicAsync(Guid.Parse("d8de624e-140f-4a22-8594-e2216b84a5f2"));

            _characteristic.StartUpdates();
            _characteristic.ValueUpdated += _characteristic_ValueUpdated;
            _device = e.Device;
        }
コード例 #8
0
        private void BluetoothGatt_DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
        {
            var connDevice = ConnectedDevices.FirstOrDefault(x => x.Id == e.Device.Id);

            if (connDevice != null)
            {
                ConnectedDevices.Remove(connDevice);
            }

            DeviceDisconnected(this, e);
        }
コード例 #9
0
        void Adapter_DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
        {
            Device.BeginInvokeOnMainThread(() => {
                this.lblConnectedDevice.IsVisible = false;
                this.lblCodeCaption.IsVisible     = false;
                this.txtCode.IsVisible            = false;
                this.btnValidate.IsVisible        = false;
                this.btnGenerateCode.IsVisible    = false;
                this.btnValidate.IsEnabled        = false;
                this.btnDisconnect.IsVisible      = false;
                this.lblConnectedDevice.Text      = "";
                this.txtCode.Text = "";
            });

            //this.StartScanning();
            this.StartScanning(0x180F.UuidFromPartial());
        }
コード例 #10
0
        /// <summary>
        /// Connect to a device.
        /// </summary>
        /// <param name="device">The device.</param>
        public async void ConnectToDevice(IDevice device)
        {
            var peripheral = device.NativeDevice as CBPeripheral;

            _central.ConnectPeripheral(peripheral);

            await Task.Delay(ConnectionTimeout);

            if (ConnectedDevices.All(x => x.Id != device.Id))
            {
                _central.CancelPeripheralConnection(peripheral);
                var args = new DeviceConnectionEventArgs(device)
                {
                    ErrorMessage = "The device connection timed out."
                };

                DeviceFailedToConnect(this, args);
            }
        }
コード例 #11
0
        void Adapter_DeviceConnected(object sender, DeviceConnectionEventArgs e)
        {
            Debug.WriteLine("Device connected");
            //adapter.StopScanningForDevices();
            StopScanning();
            Device.BeginInvokeOnMainThread(() => {
                this.lblConnectedDevice.IsVisible = true;
                this.btnGenerateCode.IsVisible    = true;
                this.btnDisconnect.IsVisible      = true;
                this.lblConnectedDevice.Text      = "Device Connected: " + e.Device.Name;
            });

            Debug.WriteLine("Connected Devices Count: " + adapter.ConnectedDevices.Count);

            device = e.Device;
            device.ServicesDiscovered += Device_ServicesDiscovered;

            device.DiscoverServices();
        }
コード例 #12
0
ファイル: SyncHandler.cs プロジェクト: cnapenas/SyncHandler
        void Adapter_DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
        {
            Debug.WriteLine("SyncHandler: Device Disconnected");

            this.DeviceDisconnected(this, new EventArgs()
            {
            });

            this.ProcessingDevice        = false;
            this.Device                  = null;
            e.Device.ServicesDiscovered -= Services_Discovered;

            if (this.SyncDeviceHandler != null)
            {
                this.SyncDeviceHandler.CleanUp();
            }

            this.DeviceDisconnected(this, new EventArgs {
            });

            this.Adapter.StartScanningForDevices();
        }
コード例 #13
0
        void AdapterDeviceConnected(object sender, DeviceConnectionEventArgs e)
        {
            device = e.Device; // do we need to overwrite this?

            // when services are discovered
            device.ServicesDiscovered += (object se, EventArgs ea) =>
            {
                Debug.WriteLine("device.ServicesDiscovered");
                //services = (List<IService>)device.Services;
                if (services.Count == 0)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        foreach (var service in device.Services)
                        {
                            services.Add(service);
                        }
                    });
                }
            };

            // start looking for services
            device.DiscoverServices();
        }
コード例 #14
0
ファイル: SyncHandler.cs プロジェクト: yelkrebb/XamTest-
 void Adapter_DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
 {
 }
コード例 #15
0
 private void AdapterOnDeviceConnected(object sender, DeviceConnectionEventArgs deviceConnectionEventArgs)
 {
     _device = deviceConnectionEventArgs.Device;
     ProcessConnection();
 }
コード例 #16
0
 void DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
 {
     // todo: stale
 }
コード例 #17
0
        /*void Device_ServicesDiscovered (object sender, EventArgs e)
         * {
         *      Debug.WriteLine("device.ServicesDiscovered");
         *      //this.services = (List<IService>)device.Services;
         *
         *      if (this.services.Count == 0)
         *      {
         *              Debug.WriteLine ("Service Count: " + device.Services.Count);
         *              foreach (var service in device.Services)
         *              {
         *                      service.CharacteristicsDiscovered += (object s, EventArgs ce) => {
         *
         *                              Debug.WriteLine("service.CharacteristicsDiscovered");
         *                              if (this.characteristics.Count == 0)
         *                              {
         *                                      Debug.WriteLine("Characteristics count: "+service.Characteristics.Count);
         *                                      foreach (var characteristic in service.Characteristics)
         *                                      {
         *                                              if(characteristic !=null)
         *                                              {
         *                                                      if(characteristic.Uuid.ToUpper().Contains("2A24") ||
         *                                                              characteristic.Uuid.ToUpper().Contains("2A25") ||
         *                                                              characteristic.Uuid.ToUpper().Contains("2A26") ||
         *                                                              characteristic.Uuid.ToUpper().Contains("2A19") )
         *                                                      {
         *                                                              if(characteristic.CanRead)
         *                                                              {
         *                                                                      characteristic.ValueUpdated += (cs, chre) => {
         *                                                                              Debug.WriteLine("characteristic.ValueUpdated");
         *                                                                      };
         *                                                                      characteristic.ReadAsync();
         *                                                              }
         *                                                      }
         *                                                      else if(characteristic.Uuid.ToUpper().Contains("FF07"))
         *                                                      {
         *                                                              Debug.WriteLine("FF07");
         *                                                              if(characteristic.CanUpdate)
         *                                                              {
         *                                                                      this.ff07Char = characteristic;
         *
         *                                                                      characteristic.StartUpdates();
         *                                                              }
         *                                                      }
         *                                                      else if(characteristic.Uuid.ToUpper().Contains("FF08"))
         *                                                      {
         *                                                              Debug.WriteLine("FF08");
         *                                                              if(characteristic.CanUpdate)
         *                                                              {
         *                                                                      this.ff08Char = characteristic;
         *
         *                                                                      characteristic.StartUpdates();
         *                                                              }
         *                                                      }
         *                                              }
         *                                      }
         *                              }
         *                      };
         *
         *                      service.DiscoverCharacteristics ();
         *              }
         *      }
         * }*/


        void Adapter_DeviceFailedToConnect(object sender, DeviceConnectionEventArgs e)
        {
            StartScanning();
        }
コード例 #18
0
ファイル: SyncHandler.cs プロジェクト: cnapenas/SyncHandler
 void Adapter_DeviceFailedToConnect(object sender, DeviceConnectionEventArgs e)
 {
 }
コード例 #19
0
 void DeviceConnected(object sender, DeviceConnectionEventArgs e)
 {
     Navigation.PushAsync(new DevicePage(e.Device));
 }
コード例 #20
0
 private void BluetoothGatt_DeviceConnected(object sender, DeviceConnectionEventArgs e)
 {
     ConnectedDevices.Add(e.Device);
     DeviceConnected(this, e);
 }
コード例 #21
0
 private static void UsbHostController_OnConnectionChangedEvent(UsbHostController sender, DeviceConnectionEventArgs e)
 {
     if (e.DeviceStatus == DeviceConnectionStatus.Connected)
     {
         usbConnected = true;
     }
     else
     {
         usbConnected = false;
     }
 }
コード例 #22
0
 private void BluetoothGatt_DeviceDisconnected(object sender, DeviceConnectionEventArgs e)
 {
     DeviceDisconnected(this, e);
 }