我正在尝试等待一个可观察量,我得到一个
System.ArgumentNullException
值不能为空。
参数名称:源
堆栈跟踪:
System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Reactive.Linq.Observable.GetAwaiter[TSource] (System.IObservable`1[T] source) [0x00003] in <370f6a6bb34048878534065376a195cb>:0
at Lynkd.Models.Peripherals.RPHPeripheral+<readMacAddress>d__13.MoveNext () [0x00012] in /Users/ericbowman/Documents/Development/Mobile/LYNKD/Lynkd/Models/Peripherals/RPHPeripheral.cs:24
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
at Lynkd.Models.Peripherals.RPHGunbox+<InitializeAsync>d__1.MoveNext () [0x00020] in /Users/ericbowman/Documents/Development/Mobile/LYNKD/Lynkd/Models/Peripherals/RPHGunbox.cs:12
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at UIKit.UIKitSynchronizationContext+<>c__DisplayClass1_0.<Post>b__0 () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIKitSynchronizationContext.cs:24
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/Foundation/NSAction.cs:125
at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at Lynkd.iOS.Application.Main (System.String[] args) [0x00001] in /Users/ericbowman/Documents/Development/Mobile/LYNKD/Lynkd.iOS/Main.cs:17
这是我的消息来源:
protected async Task readMacAddress()
{
await (Device.ReadCharacteristic(BleService.DeviceInformation, BleCharacteristic.MacAddress).Subscribe(
onNext: Result =>
{
MacAddress = BitConverter.ToString(Result.Data).Replace("-", string.Empty);
},
onError: Error =>
{
throw new BleException("Cannot Retrive MAC Address, Error Reading MAC Address");
},
onCompleted: () =>
{
return;
}) as IObservable<CharacteristicGattResult>);
}
有什么想法吗?
我不知道API,但我冒昧地说值的类型不是CharacteristicGattResult
.
可能是蓝牙Gatt特征吗?
事实证明,我过度考虑了RX的使用。您可以简单地等待原始函数调用,如下所示:
protected async Task readMacAddress()
{
var macResult = await Device.ReadCharacteristic(BleService.DeviceInformation, BleCharacteristic.MacAddress);
MacAddress = BitConverter.ToString(macResult.Data).Replace("-", string.Empty);
}
非常感谢艾伦·里奇(Allan Ritchie(引导我朝着正确的方向前进。(我正在使用的方便的Xamarin BLE库的作者(https://github.com/aritchie/bluetoothle