public void Stop()
 {
     if (Central != null)
     {
         Central.PeripheralsChanged -= Central_PeripheralsChanged;
         Central = null;
     }
     if (rPeripheral != null)
     {
         rPeripheral.StreamReceived -= Peripheral_StreamReceived;
         if (rPeripheral.Status != PeripheralStatus.Disconnected)
         {
             rPeripheral.Stop();
         }
         rPeripheral = null;
     }
     if (lPeripheral != null)
     {
         lPeripheral.StreamReceived -= Peripheral_StreamReceived;
         if (lPeripheral.Status != PeripheralStatus.Disconnected)
         {
             lPeripheral.Stop();
         }
         lPeripheral = null;
     }
 }
        private void Peripheral_StreamReceived(object sender, BoardStreamEventArgs e)
        {
            if (e.StreamType == BoardStreamType.SensorsState)
            {
                var args  = e as BoardFloatSequenceEventArgs;
                var value = FloatsToString(args.Value);

                IBoardPeripheral peripheral = sender as IBoardPeripheral;

                if (peripheral.Name == "CaptoGlove1502")
                {
                    rSensors = args.Value;
                }
                else if (peripheral.Name == "CaptoGlove1401")
                {
                    lSensors = args.Value;
                }

                Debug.Log(peripheral.Name + " received sensors state: " + value);
            }
        }
        private void Central_PeripheralsChanged(object sender, PeripheralsEventArgs e)
        {
            foreach (var peripheral in e.Inserted)
            {
                try
                {
                    Debug.Log("Trying to connect peripheral");
                    Debug.Log("- ID: " + peripheral.Id);
                    Debug.Log("- Name: " + peripheral.Name);
                    peripheral.Start();

                    if (peripheral.Name == "CaptoGlove1502")
                    {
                        rPeripheral = peripheral as IBoardPeripheral;
                        rPeripheral.StreamTimeslotsWrite(new StreamTimeslots()
                        {
                            SensorsState = 6
                        });
                        rPeripheral.StreamReceived += Peripheral_StreamReceived;

                        Debug.Log(peripheral.Name + " - Status: " + rPeripheral.Status.ToString());
                    }
                    else if (peripheral.Name == "CaptoGlove1401")
                    {
                        lPeripheral = peripheral as IBoardPeripheral;
                        lPeripheral.StreamTimeslotsWrite(new StreamTimeslots()
                        {
                            SensorsState = 6
                        });
                        lPeripheral.StreamReceived += Peripheral_StreamReceived;

                        Debug.Log(peripheral.Name + " - Status: " + lPeripheral.Status.ToString());
                    }
                }
                catch
                {
                    Debug.Log(peripheral.Name + " - Status: " + peripheral.Status.ToString());
                }
            }
        }