public async Task Connect() { // create service DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[0].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[1].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[2].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[3].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[4].Id)); // register characteristics A00 RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A01); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A02); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A0A_Movement); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A0B_SimpleCommands); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A0C_EmergencyStop); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A1E_InitCount1To20); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A1F); // register characteristics B00 RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B01); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B0E_DroneState); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B1B); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B1C); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B1F); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B0F_Battery); // register characteristics C00 RegisterCharacteristic(ParrotUuids.Service_C00, ParrotUuids.Characteristic_C1); // register characteristics D21 RegisterCharacteristic(ParrotUuids.Service_D21, ParrotUuids.Characteristic_D22); RegisterCharacteristic(ParrotUuids.Service_D21, ParrotUuids.Characteristic_D23); RegisterCharacteristic(ParrotUuids.Service_D21, ParrotUuids.Characteristic_D24); // register characteristics D51 RegisterCharacteristic(ParrotUuids.Service_D51, ParrotUuids.Characteristic_D52); RegisterCharacteristic(ParrotUuids.Service_D51, ParrotUuids.Characteristic_D53); RegisterCharacteristic(ParrotUuids.Service_D51, ParrotUuids.Characteristic_D54); await RegisterEventhandling(ParrotUuids.Service_B00); await RegisterEventhandling(ParrotUuids.Service_D21); await RegisterEventhandling(ParrotUuids.Service_D51); //await InitChannelA1E(); }
public async Task Connect() { // create service DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[0].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[1].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[2].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[3].Id)); DeviceServices.Add(await GattDeviceService.FromIdAsync(DeviceInformations[4].Id)); // register characteristics A00 RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A01); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A02); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A0A_Movement); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A0B_SimpleCommands); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A0C_EmergencyStop); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A1E_InitCount1To20); RegisterCharacteristic(ParrotUuids.Service_A00, ParrotUuids.Characteristic_A1F); // register characteristics B00 RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B01); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B0E_DroneState); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B1B); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B1C); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B1F); RegisterCharacteristic(ParrotUuids.Service_B00, ParrotUuids.Characteristic_B0F_Battery); // register characteristics C00 RegisterCharacteristic(ParrotUuids.Service_C00, ParrotUuids.Characteristic_C1); // register characteristics D21 RegisterCharacteristic(ParrotUuids.Service_D21, ParrotUuids.Characteristic_D22); RegisterCharacteristic(ParrotUuids.Service_D21, ParrotUuids.Characteristic_D23); RegisterCharacteristic(ParrotUuids.Service_D21, ParrotUuids.Characteristic_D24); // register characteristics D51 RegisterCharacteristic(ParrotUuids.Service_D51, ParrotUuids.Characteristic_D52); RegisterCharacteristic(ParrotUuids.Service_D51, ParrotUuids.Characteristic_D53); RegisterCharacteristic(ParrotUuids.Service_D51, ParrotUuids.Characteristic_D54); await RegisterEventhandling(ParrotUuids.Service_B00); await RegisterEventhandling(ParrotUuids.Service_D21); await RegisterEventhandling(ParrotUuids.Service_D51); // get list of characteristics by serviceGuid var characteristicList = Characteristics[ParrotUuids.Service_A00.ToString()]; // get characteristic var characteristic = characteristicList.FirstOrDefault(c => c.Uuid == ParrotUuids.Characteristic_A1E_InitCount1To20); for (int i = 0; i < 20; i++) { byte[] value = new byte[3]; value[0] = (byte)(0x1); value[1] = (byte)(i + 1); value[2] = (byte)(i + 1); // write value async await characteristic.WriteValueAsync(value.AsBuffer(), GattWriteOption.WriteWithoutResponse); Task.WaitAll(Task.Delay(50)); } }