C#
1using System; 2using System.Threading.Tasks; 3using System.Runtime.InteropServices.WindowsRuntime; 4using Windows.Devices.Enumeration; 5using Windows.Devices.Bluetooth.GenericAttributeProfile; 6 7namespace TestGATT 8{ 9 static class Program 10 { 11 static void Main(string[] args) 12 { 13 communicate().Wait(); 14 } 15 static void callback(GattCharacteristic sender, GattValueChangedEventArgs eventArgs) 16 { 17 Console.Write(System.Text.Encoding.ASCII.GetString(eventArgs.CharacteristicValue.ToArray())); 18 } 19 static async Task communicate() 20 { 21 var selector = GattDeviceService.GetDeviceSelectorFromUuid(ToolboxIdentifications.GattServiceUuids.Nordic_UART); 22 var collection = await DeviceInformation.FindAllAsync(selector); 23 foreach (DeviceInformation info in collection) 24 { 25 Console.WriteLine(string.Format("Name={0} IsEnabled={1}", info.Name, info.IsEnabled)); 26 27 var service = await GattDeviceService.FromIdAsync(info.Id); 28 29 var tx_characteristics = service.GetCharacteristics(ToolboxIdentifications.GattCharacteristicsUuid.TX)[0]; 30 var rx_characteristics = service.GetCharacteristics(ToolboxIdentifications.GattCharacteristicsUuid.RX)[0]; 31 rx_characteristics.ValueChanged += callback; 32 await rx_characteristics.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify); 33 while (true) 34 { 35 var input = Console.ReadLine(); 36 var result = await tx_characteristics.WriteValueAsync(System.Text.Encoding.ASCII.GetBytes(input + "\n").AsBuffer(), GattWriteOption.WriteWithoutResponse); 37 } 38 } 39 } 40 } 41} 42
上記のようなサンプルコードをフォームアプリに書き写したのですが、
「型'IBuffer'は、参照されていないアセンブリに定義されています。」、
「型'IAsyncAction'は、参照されていないアセンブリに定義されています。」
などのエラーの対処方法が分からず、苦慮しています。
参照設定に問題があるのでしょうか。
初歩的で申し訳ございませんが、ご教示いただけませんでしょうか。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。