private void ReadWrite_ValueUpdated(object sender, CharacteristicUpdatedEventArgs e) { var value = e.Characteristic.Value; _logger.Debug($"BLE receive: {ByteArrayToString(value)}"); BytesReceived?.Invoke(this, value); }
private void OnValueUpdated(object sender, CharacteristicUpdatedEventArgs e) { if (e.Characteristic.Id == _bleCharacteristic.Id) { NotifyValueUpdated(e.Characteristic.Value); } }
private void heartValue_updated(object sender, CharacteristicUpdatedEventArgs e) { var value = e.Characteristic.Value[0]; HeartService._heartValues.Add(value); HeartService._heartIncrement++; }
private void MeasurementCharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs e) { Device.BeginInvokeOnMainThread(() => { editor.Text += $"❤️: {e.Characteristic.Value[1]} \n"; }); }
private void CharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs args) { System.Diagnostics.Debug.WriteLine("Update notify !"); // Send message MessagingCenter.Send <BLEService, CharacteristicUpdatedEventArgs>(this, "characteristicUpdated", args); }
async void HandleReceiveValueUpdated(object sender, CharacteristicUpdatedEventArgs 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); } await reset.WriteAsync(new byte[] { 1 }); dataReceived.Set(); }
/// <summary> /// Here we catch the data sended from the Slave Modbus Device /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">E.</param> void ReadCharac_ValueUpdated(object sender, CharacteristicUpdatedEventArgs e) { if (readCharac.Value.Length > 0) { cts = new CancellationTokenSource(TIMEOUT); // Set timeout receivedMessageData.AddRange(readCharac.Value); if (receivedMessageData.Count >= 3) { if (receivedMessageData[1] > 16) { sizeOfMessage += 2; //because here we have an exception response } else if (frameToSend.FrameType == ModbusFrameType.RequestRead && updatedFinalSize == false) { sizeOfMessage += receivedMessageData[2] + 2; //2 because of the CRC bytes updatedFinalSize = true; } } if (receivedMessageData.Count == sizeOfMessage) { receivedBytes = true; updatedFinalSize = false; } } }
private void acceleroX_updated(object sender, CharacteristicUpdatedEventArgs e) { var value = e.Characteristic.Value[0]; AcceleroService._acceleroX.Add(value); AcceleroService._acceleroIncrement_X++; }
private void TxCharacteristic_ValueUpdated(object sender, CharacteristicUpdatedEventArgs e) { var bytes = e.Characteristic.Value; string result = System.Text.Encoding.UTF8.GetString(bytes); Plugin.BLE.Abstractions.Trace.Message(result); Console.WriteLine("rx data: " + result); }
private void CharacteristicValueUpdated(object sender, CharacteristicUpdatedEventArgs e) { if (_subscriptions.ContainsKey(e.Characteristic.Id)) { foreach (var handler in _subscriptions[e.Characteristic.Id]) { handler(e.Characteristic.Value); } } }
void OnCharacteristicUpdated(CharacteristicUpdatedEventArgs args) { if (args.Characteristic.Value[0] == 1) { _player.Play(); } else if (args.Characteristic.Value[0] == 0) { _player.Stop(); } }
public async void OnDataAvailable(object sender, CharacteristicUpdatedEventArgs e) { var pair = new GattPair(e.Characteristic); var measureField = TelemetryMap[pair.GattKey]; var value = e.Characteristic.GetValue(); //XamarinDevice.BeginInvokeOnMainThread(() => //{ // FormattedText.Spans.Add(new Span { Text = $"Sending {measureField}={value}\n", ForegroundColor = Color.Green }); //}); //TODO only if device connected await DeviceClient.SendTelemetry($"{{\"{measureField}\":{value}}}", null); }
private void CharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { getcharacteristicRXAsync(); // Messages.Insert(0, $"Updated value: {CharacteristicValue}"); //RaisePropertyChanged(() => CharacteristicValue); OnPropertyChanged(nameof(bleprofile.CharacteristicValue)); if (!String.IsNullOrEmpty(bleprofile.CharacteristicValue)) { batteryLevel = System.Text.Encoding.UTF8.GetString(bleprofile.CharacteristicT.Value, 0, bleprofile.CharacteristicT.Value.Length); } }
private async void BLE_Recv(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { try { byte[] data = characteristicUpdatedEventArgs.Characteristic.Value; CSLibrary.Debug.WriteBytes("BT data received", data); CharacteristicOnValueUpdated(data); } catch (Exception ex) { Debug.WriteLine("Program execption error, please check!!!"); } }
public void CharacteristicsChanged(object sender, CharacteristicUpdatedEventArgs e) { byte[] data = e.Characteristic.Value; //DisplayAlert("Notice", data[0].ToString(), "OK"); if (data != null) { data_packets.Enqueue(data); } if (WoundCalculationThread == null) { WoundCalculationThread = new Thread(ScaleReadyData); WoundCalculationThread.Start(); } }
/************************************************************************** * * Event handlers * **************************************************************************/ private void OnSteps(object sender, CharacteristicUpdatedEventArgs arguments) { byte[] stepsBytes; int stepsValue; EventHandler <MeasureEventArgs> steps; stepsBytes = arguments.Characteristic.Value; stepsValue = DecodeSteps(stepsBytes); steps = Steps; Log.Debug("BAND", $"##### STEPS UPDATED: {stepsValue}"); if (steps != null) { steps(this, new MeasureEventArgs(stepsValue)); } }
private void IntentFound(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { if (button.Value[0] == 1 || button.Value [0] == 2 || button.Value [0] == 3) { Intent = true; //COLLECT DATA System.Diagnostics.Debug.WriteLine("Something is happening"); //_vm.CaptureState = string.Concat(movementData.Value.Select(b => Convert.ToString(b, 2).PadLeft(8, '0'))); } else if (button.Value[0] == 0 && Intent) { //Intent = false; //this password won't get set if intent isn't set to true, meaning you need to click the button _vm.Password = "******"; _vm.CaptureState = "Done Capturing"; } }
/// <summary> /// Method executed when new data is received in the RX characteristic. /// </summary> /// <param name="sender">Characteristic Updated Event sender.</param> /// <param name="args">Characteristic Updated Event arguments.</param> /// <seealso cref="CharacteristicUpdatedEventArgs"/> private void DataReceived(object sender, CharacteristicUpdatedEventArgs args) { byte[] value = args.Characteristic.Value; // If the communication is encrypted, decrypt the received data. if (encrypt) { value = decryptor.TransformFinalBlock(value, 0, value.Length); } Debug.WriteLine("----- RX char " + HexUtils.ByteArrayToHexString(value)); Stream.Write(value, 0, value.Length); // Notify that data has been received. lock (this) { Monitor.Pulse(this); } }
private void OnHeartRate(object sender, CharacteristicUpdatedEventArgs arguments) { byte[] heartRateBytes; int heartRateValue; EventHandler <MeasureEventArgs> heartRate; heartRateBytes = arguments.Characteristic.Value; heartRateValue = DecodeHeartRate(heartRateBytes); heartRate = HeartRate; if (heartRateValue > 0) { Log.Debug("BAND", $"##### HEART RATE UPDATED: {heartRateValue}"); if (heartRate != null) { heartRate(this, new MeasureEventArgs(heartRateValue)); } } }
private void OnCharacteristicUpdated(object sender, CharacteristicUpdatedEventArgs args) { ICharacteristic characteristic = args.Characteristic; if (characteristic != null) { Guid uuid = characteristic.Id; if (uuid == UUID_GAIA_RESPONSE_ENDPOINT) { byte[] bytes = characteristic.Value; if (bytes != null) { string value = Utils.GetHexStringFromBytes(bytes); Debug.WriteLine(TAG + ":::RSP: " + value); value = DateTime.Now.ToString("HH:mm:ss") + " Received: " + value; RefreshToast(value); ReceiveGaiaPacket(bytes); } } } }
private void UpdateGyroData(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { if (Intent) { var moveData = movementData.Value; short gyroX = BitConverter.ToInt16(new byte[2] { moveData[0], moveData[1] }, 0); var xDeg = (gyroX * 1.0) / (65536 / 500); short gyroY = BitConverter.ToInt16(new byte[2] { moveData[2], moveData[3] }, 0);; var yDeg = (gyroY * 1.0) / (65536 / 500); short gyroZ = BitConverter.ToInt16(new byte[2] { moveData[4], moveData[5] }, 0);; var zDeg = (gyroZ * 1.0) / (65536 / 500); _vm.CaptureState = xDeg + " deg/s\n" + yDeg + " deg/s\n" + zDeg + " deg/s"; } }
private void Listener(object sender, CharacteristicUpdatedEventArgs args) { try { var bytes = args.Characteristic.Value; for (int i = 1; i < bytes.Length; i++) { RawData.Add(bytes[i]); } if (bytes[0] == 0xff) { var uncompressedRawData = DeCompressBuffer(RawData.ToArray()); var cardNumberAsBytes = uncompressedRawData.Skip(624).Take(112).ToArray(); var cardNumberAsString = System.Text.Encoding.Default.GetString(cardNumberAsBytes); if (cardNumberAsString.Length >= 9) { cardNumberAsString = cardNumberAsString.Substring(0, 9); } else { throw new Exception("Card number is not of sufficient length"); } if (!Int32.TryParse(cardNumberAsString, out int dummy)) { throw new Exception("Card number is not a number"); } RawData = new List <byte>(); SwipeResultHandler.Invoke(cardNumberAsString); } } catch { RawData = new List <byte>(); SwipeResultHandler.Invoke("000000000"); } }
private void ValueUpdated(object sender, CharacteristicUpdatedEventArgs args) { var bytes = args.Characteristic.Value; string str = System.Text.Encoding.UTF8.GetString(bytes); Console.WriteLine("BLE: " + str); var bits = str.Split(':').ToList(); foreach (var result in bits) { switch (result.Substring(0, 1)) { case "r": try { var rpm = double.Parse(result.Replace("r", "")); TachoGaugeAnnotationsLabel.Text = rpm + " RPM"; TachoGauge.Scales[0].Pointers[0].Value = (rpm / 100); } catch (Exception) { } break; case "v": try { var volts = double.Parse(result.Replace("v", "")); //double volts = (double)v / 1000; VoltageGaugeAnnotationsLabel.Text = volts + " V"; VoltageGuage.Scales[0].Pointers[0].Value = volts; } catch (Exception) { } break; } } }
private void BluetoothNotifyReceivedHandler(object sender, CharacteristicUpdatedEventArgs e) { InvokeDataReceived(new ButtplugDeviceDataEventArgs("rx", e.Characteristic.Value)); }
public void CharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { var bytes = characteristicUpdatedEventArgs.Characteristic.Value; Plugin.BLE.Abstractions.Trace.Message(bytes.ToString()); }
private void CharacteristicValueChanged(object sender, CharacteristicUpdatedEventArgs e) { ValueUpdated?.Invoke(this, e.Characteristic.Value); }
private void CharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { var data = characteristicUpdatedEventArgs.Characteristic.Value; Device.BeginInvokeOnMainThread(() => { if (MasterDeviceId == characteristicUpdatedEventArgs.Characteristic.Service.Device.Id) { //TODO: logging //if data is from master device if (count == MasterDeviceSamplingRate) { for (int i = 0; i < 5; i++) { ecg = (UInt16)((data[2 * i + 1]) | data[2 * i] << 8); //ViewRed = "ecg: " + ecg.ToString(); scg = (UInt16)((data[2 * i + 11]) | data[2 * i + 10] << 8); //Debug.WriteLine("asdfasdf" + ecg.ToString()); bool checkRedundancy = false; if (!checkRedundancy) { if (!(DataCollections[2].Count < PrimalAxisMax)) { DataCollections[2].RemoveAt(0); } if (!(DataCollections[3].Count < PrimalAxisMax)) { DataCollections[3].RemoveAt(0); } Debug.WriteLine("::::::::" + ecg.ToString()); DataCollections[2].Insert(DataCollections[2].Count, new BleDataModel(DataCollections[2].Count.ToString(), ecg)); DataCollections[3].Insert(DataCollections[3].Count, new BleDataModel(DataCollections[3].Count.ToString(), scg)); //count = 0; checkRedundancy = true; } //}); } } //TODO: Signal Processing count++; } if (SlaveDeviceId == characteristicUpdatedEventArgs.Characteristic.Service.Device.Id) { //TODO: logging if (data.Length == 5) { var num = (UInt16)data[3] + (UInt16)data[4] * 0.0625; var tempnum = (int)(num * 10); var temp = tempnum * .1; ViewTemp = "TEMP: " + temp.ToString(); } else { if (data.Length == 20) { for (int i = 0; i < 5; i++) { red = (UInt16)((data[2 * i + 1]) | data[2 * i] << 8); ir = (UInt16)((data[2 * i + 11]) | data[2 * i + 10] << 8); ViewRed = "IR: " + red.ToString(); ViewIr = "RED: " + ir.ToString(); if (!(DataCollections[0].Count < PrimalAxisMax)) { DataCollections[0].RemoveAt(0); } if (!(DataCollections[1].Count < PrimalAxisMax)) { DataCollections[1].RemoveAt(0); } DataCollections[1].Insert(DataCollections[1].Count, new BleDataModel(DataCollections[1].Count.ToString(), ir)); DataCollections[0].Insert(DataCollections[0].Count, new BleDataModel(DataCollections[0].Count.ToString(), red)); } } } //TODO: Signal Processing } }); }
protected virtual void OnCharacteristicValueUpdated(object o, CharacteristicUpdatedEventArgs args) { _responseFrame = args.Characteristic.Value; }
private void CharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { Messages.Insert(0, $"Updated value: {CharacteristicValue}"); RaisePropertyChanged(() => CharacteristicValue); }
private void CharacteristicOnValueUpdated(object sender, CharacteristicUpdatedEventArgs characteristicUpdatedEventArgs) { Messages.Insert(0, $"{DateTime.Now.TimeOfDay} - Updated: {CharacteristicValue}"); RaisePropertyChanged(() => CharacteristicValue); RaisePropertyChanged(() => CharacteristicValuePresumed); }