public BleMoCoBusCommService(Ble.IDevice device, Ble.IAdapter adapter) { Debug.WriteLine("Create BleMoCoBusCommService"); _device = device; _adapter = adapter; _adapter.DeviceConnected += AdapterOnDeviceConnected; _adapter.DeviceDisconnected += AdapterOnDeviceDisconnected; }
private void AdapterOnDeviceDisconnected(object sender, Ble.DeviceConnectionEventArgs e) { Debug.WriteLine("AdapterOnDeviceDisconnected 1"); if (e.Device.ID != _device.ID) return; Debug.WriteLine("AdapterOnDeviceDisconnected 2"); _device = e.Device; OnDisconnect(); }
private void AdapterOnDeviceConnected(object sender, Ble.DeviceConnectionEventArgs e) { Debug.WriteLine("AdapterOnDeviceConnected 1"); if (e.Device.ID != _device.ID) return; Debug.WriteLine("AdapterOnDeviceConnected 2"); _device = e.Device; _device.ServicesDiscovered += DeviceOnServicesDiscovered; _device.DiscoverServices(); }
private View GetDevicesAdapter(Ble.IDevice device) { var convertView = LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem1, null); var title = convertView.FindViewById<TextView>(Android.Resource.Id.Text1); title.Text = device.Name; return convertView; }
private void MoCoBusRxCharacteristicOnValueUpdated(object sender, Ble.CharacteristicReadEventArgs e) { Debug.WriteLine("MoCoBusRxCharacteristicOnValueUpdated: Entering"); try { if (e.Characteristic?.Value == null) { Debug.WriteLine("MoCoBusRxCharacteristicOnValueUpdated: Characteristic or Characteristic value is null"); return; } } catch (Exception ex) { Debug.WriteLine("MoCoBusRxCharacteristicOnValueUpdated: Exception: {0}", ex); return; } Debug.WriteLine("MoCoBusRxCharacteristicOnValueUpdated: Value received"); _rxBytesQueue.Enqueue(e.Characteristic.Value); _newRxBytesReceived.Set(); }