Esempio n. 1
0
		public override void OnCharacteristicRead (BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
		{
			base.OnCharacteristicRead (gatt, characteristic, status);

			Console.WriteLine ("OnCharacteristicRead: " + characteristic.GetStringValue (0));
			var f = new CharacteristicReadEventArgs () { 
				Characteristic = new Characteristic (characteristic, gatt, this)};
			Debug.WriteLine ("OnCharacteristicRead" + f);

			this.CharacteristicValueUpdated (this, f);
		}
Esempio n. 2
0
		void HandleReceiveValueUpdated (object sender, CharacteristicReadEventArgs e)
		{
			var bytes = e.Characteristic.Value;
			if (bytes == null || bytes.Length == 0)
				return;

//			Debug.WriteLine ("Receive.Value: " + string.Join (" ", bytes.Select (x => x.ToString ("X2"))));

			lock (readBuffer) {
				if (readBuffer.Count + bytes.Length > ReadBufferSize) {
					readBuffer.RemoveRange (0, ReadBufferSize / 2);
				}
				readBuffer.AddRange (bytes);
			}

			reset.Write (new byte[] { 1 });

			dataReceived.Set ();
		}
Esempio n. 3
0
        void HandleReceiveValueUpdated(object sender, CharacteristicReadEventArgs e)
        {
            var bytes = e.Characteristic.Value;

            if (bytes == null || bytes.Length == 0)
            {
                return;
            }

//			Debug.WriteLine ("Receive.Value: " + string.Join (" ", bytes.Select (x => x.ToString ("X2"))));

            lock (readBuffer) {
                if (readBuffer.Count + bytes.Length > ReadBufferSize)
                {
                    readBuffer.RemoveRange(0, ReadBufferSize / 2);
                }
                readBuffer.AddRange(bytes);
            }

            reset.Write(new byte[] { 1 });

            dataReceived.Set();
        }