luigifab / python-radexreader

Reader for the RADEX RD1212 and the RADEX ONE Geiger counters.
GNU General Public License v2.0
11 stars 3 forks source link

IndexError: index out of range (Radex One) #13

Closed Andrejkab closed 1 year ago

Andrejkab commented 1 year ago

Hello,

No ideas to solve - "IndexError: index out of range" for Radex One ?

  File "/usr/local/lib/python3.9/dist-packages/radexreader/__init__.py", line 186, in read
    if hexa[0] != 0:
IndexError: index out of range

From where this error coming? Unfortunatly I'am not Python programmer.

Many Thanks

luigifab commented 1 year ago

Can you try this version for init.py?

Andrejkab commented 1 year ago

Thanks for Your effort!

With new init.py I got with "readlast" immediately "no data stored" output. With "readall" is also out "no data stored", but after approx 90 sec. waiting time..

Thanks!

luigifab commented 1 year ago

What is the version of your device?

Andrejkab commented 1 year ago

RadexOne Dosimeter 02996-0017-12-21; V:1.8 (White casing)

Andrejkab commented 1 year ago

If this helps, I have (from Internet) some primitive python2 construction that works with Radex One and reports dose rate ant CPM. But this does not works with python3 due to differences with string conversion.

import serial
import struct

ser = serial.Serial(
    port='/dev/ttyUSB0',

    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS
)

ser.isOpen()
packet = bytearray(b'\x7b\xff\x20\x00\x06\x00\x0a\x00\x00\x00\x54\x00\x00\x08\x0c\x00\xf3\xf7')
ser.write(packet)

raw_rate = ""
raw_cpm =  ""

for x in range(0, 34):
        c = ser.read()
#       print '{0:x}'.format(ord(c), 10), " ",

        if x in range(20, 22):
                raw_rate = raw_rate + c
        if x in range(28, 30):
                raw_cpm = raw_cpm + c

print ""
[doserate] = struct.unpack('<h', raw_rate)
print "Dose rate uSv/h: " + str(doserate / 100.0)
[cpm] = struct.unpack('<h', raw_cpm)
print "Counts per minute: " + str(cpm)
pi@raspberrypi:~ $ python test.py
Dose rate uSv/h: 0.22
Counts per minute: 27

Thanks and Merry Christmas

luigifab commented 1 year ago

It seems that this it line 255 (it updated the gist). Can you try to comment it to use line 254 instead and try if it works?

Andrejkab commented 1 year ago

Happy New Year!

Looks I found what prevent Radex to communicate. And original 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)) works well also.

Perhaps trying to find device type between different models is add some mess to USB comm. I just deleted USB search routines related to RADEX RD1212 v1 and RADEX RD1212 v2 (from 47 to 74). And now its ok. It works!

Several questions:

  1. Whats is difference between options "readall" and "readlast" ?

  2. How I can simplify routine below to get only x.xx µSv/h reading (I no need info, warn messages, also without date, percents, accumulated, min max, cpm).

 if sys.argv[1] == 'readlast':
                print(msg)
                reader = radexreader.RadexReader()
                reader.print_info()
                measures = reader.read(True)
                for timestamp, measure in measures.items():
                        print('%s  %s µSv/h  ±%s%% (%s ≤ %s ≤ %s)' % (
                                str(datetime.utcfromtimestamp(timestamp)),
                                str('{:.2f}'.format(measure['val'])).rjust(6, ' '),
                                str(int(measure['pct'])),
                                str('{:.2f}'.format(measure['min'])),
                                str('{:.2f}'.format(measure['val'])),
                                str('{:.2f}'.format(measure['max']))
                        ))
                        if reader.com == 'ONEv1':
                                print('                     %s µSv accumulated / %s CPM  [±%s%%]' % (
                                        str('{:.2f}'.format(measure['acc'])).rjust(6, ' '),
                                        str('{:.0f}'.format(measure['cpm'])).rjust(6, ' '),
                                        str(int(measure['pct']))
                                ))
                if not measures:
                        print('no data stored')
                exit(0)

Many Thanks!

luigifab commented 1 year ago

Wow! Good! Happy year 2023!

For Radex One, readall and readlast are same, because there are no memory in the device. To get only µSv/h, you can use:

                for timestamp, measure in measures.items():
                        print('%s µSv/h' % (
                                str('{:.2f}'.format(measure['val'])),
                        ))

or simply:

                for timestamp, measure in measures.items():
                        print(measure['val'])

I will think about lines 47-74.

luigifab commented 1 year ago

Perhaps self.usb.reset()? I updated the gist, not sure, I can't test, can you try it?

Andrejkab commented 1 year ago

Ok. Thanks for info! With updated init.py I got

pi@raspberrypi:/usr/local/lib/python3.9/dist-packages/radexreader $ sudo python radexreader.py readall
Information   python3-radexreader 1.2.2 with python 3.9.2 + pyusb 1.0.2 + pyserial 3.5b0
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/radexreader/radexreader.py", line 123, in <module>
    reader = radexreader.RadexReader()
  File "/usr/local/lib/python3.9/dist-packages/radexreader/__init__.py", line 61, in __init__
    self.usb.reset()
AttributeError: 'NoneType' object has no attribute 'reset'
luigifab commented 1 year ago

Perhaps trying to find device type between different models is add some mess to USB comm. I just deleted USB search routines related to RADEX RD1212 v1 and RADEX RD1212 v2 (from 47 to 74). And now its ok. It works!

I searched some ideas... I have also tried to search all v1 before v2, but for me there is no problem, I can search any inexistant device without error.

The solution for me it's to put the detection of your device first.

luigifab commented 1 year ago

Fixed in v1.2.2.