private void GattObserverOnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
 {
     if (_onRead != null)
     {
         _onRead(characteristic.GetValue(), status);
     }
 }
        private void NotifyOnValueChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic)
        {
            var hexText = FindViewById<TextView>(Resource.Id.ReceivedNotificationHex);
            var stringText = FindViewById<TextView>(Resource.Id.ReceivedNotificationString);

            var receivedBytes = characteristic.GetValue();

            RunOnUiThread(() =>
            {
                hexText.SetText(BitConverter.ToString(receivedBytes), TextView.BufferType.Normal);
                stringText.SetText(Encoding.ASCII.GetString(receivedBytes), TextView.BufferType.Normal);
            });
        }
        public override void OnCharacteristicRead(bt.BluetoothGatt gatt, bt.BluetoothGattCharacteristic characteristic, [GeneratedEnum] bt.GattStatus status)
        {
            base.OnCharacteristicRead(gatt, characteristic, status);

            this.CharacteristicRead?.Invoke(this, new CharacteristicValueChangedEventArgs(gatt, characteristic, status));

            byte[] value = characteristic.GetValue();

            var myChar = this.ServicesById[characteristic.Service.Uuid].CharacteristicsById[characteristic.Uuid];

            // If the system architecture is little-endian (that is, little end first),
            // reverse the byte array.
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(value);
            }

            myChar.GetValueCompletionSource?.SetResult(value);
            myChar.GetValueCompletionSource = null;
        }
		public void BroadcastUpdate (String action, BluetoothGattCharacteristic characteristic) 
		{
			Intent intent = new Intent (action);

			// This is special handling for the Heart Rate Measurement profile.  Data parsing is
			// carried out as per profile specifications:
			// http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.heart_rate_measurement.xml
			if (UUID_HEART_RATE_MEASUREMENT == (characteristic.Uuid)) {
				GattProperty flag = characteristic.Properties;
				GattFormat format = (GattFormat) (-1);

				if (((int) flag & 0x01) != 0) {
					format = GattFormat.Uint16;
					Log.Debug (TAG, "Heart rate format UINT16.");
				} else {
					format = GattFormat.Uint8;
					Log.Debug (TAG, "Heart rate format UINT8.");
				}

				var heartRate = characteristic.GetIntValue (format, 1);
				Log.Debug (TAG, String.Format ("Received heart rate: {0}", heartRate));
				intent.PutExtra (EXTRA_DATA, heartRate);
			} else {
				// For all other profiles, writes the data formatted in HEX.
				byte[] data = characteristic.GetValue ();

				if (data != null && data.Length > 0) {
					StringBuilder stringBuilder = new StringBuilder (data.Length);
					foreach (byte byteChar in data)
						stringBuilder.Append (String.Format ("{0}02X ", byteChar));
					intent.PutExtra (EXTRA_DATA, Convert.ToBase64String (data) + "\n" + stringBuilder.ToString());
				}
			}

			SendBroadcast (intent);
		}
예제 #5
0
 Task <byte[]> PlatformGetValue()
 {
     return(Task.FromResult(_characteristic.GetValue()));
 }
예제 #6
0
 byte[] PlatformGetValue()
 {
     return(_characteristic.GetValue());
 }
예제 #7
0
		public override void OnCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
		{
			base.OnCharacteristicWrite(gatt, characteristic, status);

			string hex = BitConverter.ToString(characteristic.GetValue());

			Console.WriteLine("GattCallBack: OnCharacteristicWrite: " + hex.Replace("-", ""));
		}
예제 #8
0
        public override void OnCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
        {
            base.OnCharacteristicWrite(gatt, characteristic, status);

            Trace.Message("OnCharacteristicWrite: value {0} status {1}", characteristic.GetValue().ToHexString(), status);

            CharacteristicValueWritten?.Invoke(this, new CharacteristicWriteCallbackEventArgs(characteristic, GetExceptionFromGattStatus(status)));
        }
예제 #9
0
        public override void OnCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, GattStatus status)
        {
            base.OnCharacteristicRead(gatt, characteristic, status);

            Trace.Message("OnCharacteristicRead: value {0}; status {1}", characteristic.GetValue().ToHexString(), status);

            CharacteristicValueUpdated?.Invoke(this, new CharacteristicReadCallbackEventArgs(characteristic));
        }