public override IObservable <DescriptorResult> Write(byte[] data) { return(Observable.Create <DescriptorResult>(ob => { var p = this.native.Characteristic.Service.Peripheral; var handler = new EventHandler <CBDescriptorEventArgs>((sender, args) => { if (args.Descriptor.UUID.Equals(this.native.UUID)) { if (args.Error != null) { ob.OnError(new ArgumentException(args.Error.ToString())); } else { this.Value = data; var result = new DescriptorResult(this, DescriptorEvent.Write, this.Value); ob.Respond(result); this.WriteSubject.OnNext(result); } } }); p.WroteDescriptorValue += handler; var nsdata = NSData.FromArray(data); p.WriteValue(nsdata, this.native); return () => p.WroteDescriptorValue -= handler; })); }
public override IObservable <DescriptorResult> Read() { //this.native.Permissions == GattDescriptorPermission.Read return(Observable.Create <DescriptorResult>(ob => { var handler = new EventHandler <GattDescriptorEventArgs>((sender, args) => { if (args.Descriptor.Equals(this.native)) { if (!args.IsSuccessful) { ob.OnError(new ArgumentException($"Failed to read descriptor value {this.Uuid} - {args.Status}")); } else { this.Value = this.native.GetValue(); var result = new DescriptorResult(this, DescriptorEvent.Write, this.Value); ob.Respond(result); this.ReadSubject.OnNext(result); } } }); this.context.Callbacks.DescriptorRead += handler; this.context.Gatt.ReadDescriptor(this.native); return () => this.context.Callbacks.DescriptorRead -= handler; })); }
public override IObservable <DescriptorResult> Read() { return(Observable.Create <DescriptorResult>(ob => { var p = this.native.Characteristic.Service.Peripheral; var handler = new EventHandler <CBDescriptorEventArgs>((sender, args) => { if (args.Descriptor.UUID.Equals(this.native.UUID)) { if (args.Error != null) { ob.OnError(new ArgumentException(args.Error.ToString())); } else { this.Value = ((NSData)args.Descriptor.Value).ToArray(); var result = new DescriptorResult(this, DescriptorEvent.Read, this.Value); ob.Respond(result); this.ReadSubject.OnNext(result); } } }); p.UpdatedValue += handler; p.ReadValue(this.native); return () => p.UpdatedValue -= handler; })); }
public override IObservable <DescriptorResult> Write(byte[] data) { return(Observable.Create <DescriptorResult>(ob => { var handler = new EventHandler <GattDescriptorEventArgs>((sender, args) => { if (args.Descriptor.Equals(this.native)) { if (!args.IsSuccessful) { ob.OnError(new ArgumentException($"Failed to write descriptor value - {this.Uuid} - {args.Status}")); } else { this.Value = data; var result = new DescriptorResult(this, DescriptorEvent.Write, data); ob.Respond(result); this.WriteSubject.OnNext(result); } } }); this.context.Callbacks.DescriptorWrite += handler; AndroidConfig.SyncPost(() => { this.native.SetValue(data); this.context.Gatt.WriteDescriptor(this.native); }); return () => this.context.Callbacks.DescriptorWrite -= handler; })); }