BluetoohLE - Best way to manually read Characteristic value on a given interval? #1142
-
I need to read some Characteristic values each given interval. I do use Device.StartTimer but I am having problems writing in a Characteristic of this device, which takes too long. I wanted to disable the readouts while I'm trying to write, but this way doesn't seem to be threadsafe and I can't set a variable to prevent readouts while writing. What would be the correct way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Android prevents a read/write at the same time (it has to). iOS does not, but does its own internal synchronization. Observable
.Interval(TimeSpan.FromSeconds(30))
.Where(_ => !this.IsWriting)
.Select(_ => yourChar.Read())
.Switch()
.Subscribe(
x => {}, // do whatever with the read value
ex => {} // deal with error
); I'm not sure why you can't set a var when writing, but you need to for your requirement |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks for the help! But I'm facing the same problem with Observable.Interval that I was when using Timers.
For some reason, it still keeps reading the values even with IsBusy=true, and to Write a single bit takes several seconds (And I can see the UI still updating with new values while still awaiting for the writing. I'm thinking it's a ThreadSafe problem. Do you have any idea why this is occurring and the correct way to resolve this? |
Beta Was this translation helpful? Give feedback.
Android prevents a read/write at the same time (it has to). iOS does not, but does its own internal synchronization.
I'm not sure why you can't set a var when writing, but you need to for your requirement