저는 Bluetooth LE 프로그래밍의 초보자입니다. 이미 Android 용 프로그램을 작성했으며 이제는 C#/Windows IoT로 이식하려고합니다.GATT 특성을 얻을 수 없습니다. C# BluetoothLEDevice를 IBluetoothLEDevice3으로 전송할 수 없습니다.
BLE 알림 패키지에서 보낸 건강 온도계 데이터를 읽으려고합니다.
private TypedEventHandler<BluetoothLEAdvertisementWatcher, BluetoothLEAdvertisementReceivedEventArgs> OnAdvertisementReceived = async (w, eventArgs) =>
{
BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(eventArgs.BluetoothAddress);
try
{
var SERVICEUUID = eventArgs.Advertisement.ServiceUuids.FirstOrDefault();
var CHARACUUID = new Guid("00001809-0000-1000-8000-00805f9b34fb");
//FIXME: Getting invalid cast exception at this point
var gatt = await device.GetGattServicesForUuidAsync(SERVICEUUID);
Debug.WriteLine($"{device.Name} Services: {gatt.Services.Count}, {gatt.Status}, {gatt.ProtocolError}");
var characs = await gatt.Services.Single(s => s.Uuid == SERVICEUUID).GetCharacteristicsAsync();
var charac = characs.Characteristics.Single(c => c.Uuid == CHARACUUID);
//TODO: Parse temperature value to float
var val = await charac.ReadValueAsync();
}
catch (Exception e)
{
Debug.WriteLine("Error getting characteristics: " + e);
}
};
내가 얻을 예외는 다음과 같습니다 : 나는 장치의 GATT 서비스에 액세스하려고 할 때마다, 내 코드에서 예외가 발생
System.InvalidCastException: Unable to cast object of type 'Windows.Devices.Bluetooth.BluetoothLEDevice' to type 'Windows.Devices.Bluetooth.IBluetoothLEDevice3'
at System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget)
at Windows.Devices.Bluetooth.BluetoothLEDevice.GetGattServicesForUuidAsync(Guid serviceUuid)
BluetoothLEDevice 분명히 IBluetoothLEDevice3 인터페이스를 구현, 그래서하지 않습니다 그것이 어떻게 형통 될 수 없는지 이해하십시오. 왜 이런 일이 일어나는지에 대한 도움은 매우 감사하겠습니다. 그 장치가 중요하다면 내 장치는 Raspberry PI3입니다. 미리 감사드립니다!
업데이트 : 코드를 디버깅 할 때이
, 내가 BluetoothLEDevice의 DeviceAccessInformation 속성은 예외가 발생하고이 정상 수준으로 전파됩니다 것을 볼 수 :
DeviceAccessInformation = 'device.DeviceAccessInformation'던졌다 예외 유형 'System.InvalidCastException'
갱신 2
내가 직접이 방법을 GATT 서비스에 액세스하려고 할 때, 나는 다른 예외를 얻을 :
BluetoothLEDevice device = await BluetoothLEDevice.FromBluetoothAddressAsync(eventArgs.BluetoothAddress);
var gattService = await GattDeviceService.FromIdAsync(device.DeviceId);
이 경우에 예외가
System.IO.FileNotFoundException입니다 : 시스템을 파일을 찾을 수 없습니다. System.Runtime.CompilerServices.TaskAwaiter`1에서 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification에서 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (작업 작업) (작업 작업)에서 : (0x80070002가 HRESULT에서 예외). GetResult() at StempHub.StartupTask. <> c. < < -ctor> b__5_0> d.MoveNext()
Windows iot 핵심 버전은 무엇입니까? –
It 's 10.0.14393.1066 –