-
Notifications
You must be signed in to change notification settings - Fork 4
Update __init__.py to handle short report lengths. #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Added a check to readone that prevents a crash if the returned report is shorter than expected
can you try this version? diff --git a/src/radexreader/__init__.py b/src/radexreader/__init__.py
index 4238f6c238..6a42905cb2 100644
--- a/src/radexreader/__init__.py
+++ b/src/radexreader/__init__.py
@@ -278,30 +278,32 @@
self.hid_set_report((0x7b, 0xff, 0x20, 0, 0x06, 0, self.keyA, self.keyB, 0, 0, self.keyC, self.keyD, 0, 0x08, 0x0c, 0, 0xf3, 0xf7))
hexa = self.hid_get_report()
+ if hexa != b'' and len(hexa) >= 31:
+ # measure = 0.15 µSv/h = 15 / 0.15 µSv accumulated = 15 / 15 CPM = 15
+ measure = (hexa[20] + hexa[21] * 256 + hexa[22] * 256 * 256) / 100
+ measure_acc = (hexa[24] + hexa[25] * 256 + hexa[26] * 256 * 256) / 100
+ measure_cpm = hexa[28] + hexa[29] * 256 + hexa[30] * 256 * 256
+ # uncertainty of the result
+ percent = 15 + 6 / measure
+ measure_min = measure * (1 - percent / 100)
+ measure_max = measure * (1 + percent / 100)
+ if measure_min < 0:
+ measure_min = 0
+ if percent > 99.9:
+ percent = 99.9
+ # most recent measure
+ timestamp = int(time.time())
+ return { timestamp: {
+ 'pct': percent,
+ 'min': measure_min,
+ 'val': measure,
+ 'max': measure_max,
+ 'acc': measure_acc,
+ 'cpm': measure_cpm,
+ 'time': timestamp
+ } }
- # measure = 0.15 µSv/h = 15 / 0.15 µSv accumulated = 15 / 15 CPM = 15
- measure = (hexa[20] + hexa[21] * 256 + hexa[22] * 256 * 256) / 100
- measure_acc = (hexa[24] + hexa[25] * 256 + hexa[26] * 256 * 256) / 100
- measure_cpm = hexa[28] + hexa[29] * 256 + hexa[30] * 256 * 256
- # uncertainty of the result
- percent = 15 + 6 / measure
- measure_min = measure * (1 - percent / 100)
- measure_max = measure * (1 + percent / 100)
- if measure_min < 0:
- measure_min = 0
- if percent > 99.9:
- percent = 99.9
-
- timestamp = int(time.time())
- return { timestamp: {
- 'pct': percent,
- 'min': measure_min,
- 'val': measure,
- 'max': measure_max,
- 'acc': measure_acc,
- 'cpm': measure_cpm,
- 'time': timestamp
- } }
+ return {}
def erase(self):
if self.com == 'RD1212v2':
it's similar between RD1212 and One, and without print |
It appears that applying that patch caused everything that's returned to be empty. When I reverted to the old code it started returning data again. I was testing why that was, but I didn't figure it out. |
loool, I suppose this line: |
Oh so nice! There is probably something wrong with the addresses used to read data from the Radex ONE.
But the address is not "simple": I'm going to run it again for a few days to check that the minutes add up for my Radex RD1212. |
Did you find something? |
I added a check to readone that prevents a crash if the returned report is shorter than expected.
I encountered an issue with my code crashing due to some of the reports being shorter than expected, this stop-gap addition prevents the code from crashing out.