When running rc.spectrum() in a loop, readout-errors occur after some time.
Here is a small piece of code reproducing the error:
import time, numpy as np
from radiacode import RadiaCode
#
rc = RadiaCode()
serial = rc.serial_number()
fw_version = rc.fw_version()
status_flags = eval(rc.status().split(':')[1])[0]
# this will crash after a (random) number of trials
while True:
counts = np.asarray(rc.spectrum().counts)
status_flags = eval(rc.status().split(':')[1])[0]
print(f'### Status flags: 0x{status_flags:x}')
# do something with counts
time.sleep(2)
results in the following output:
### Status flags: 0x2040002
...
### Status flags: 0x2040002
Traceback (most recent call last):
File "/home/quast/Projekte/RadiaCode102/radiacode/test.py", line 12, in <module>
status_flags = eval(rc.status().split(':')[1])[0]
^^^^^^^^^^^
File "/home/quast/Projekte/RadiaCode102/radiacode/radiacode/radiacode.py", line 78, in status
r = self.execute(b'\x05\x00')
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/quast/Projekte/RadiaCode102/radiacode/radiacode/radiacode.py", line 52, in execute
response = self._connection.execute(full_request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/quast/Projekte/RadiaCode102/radiacode/radiacode/transports/usb.py", line 28, in execute
response_length = struct.unpack_from('<I', data)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct.error: unpack_from requires a buffer of at least 4 bytes for unpacking 4 bytes at offset 0 (actual buffer size is 0)
The error occurs after a random number of trials; I tested on openSuse Leap 15.5, Ubuntu 22.04 and
on Rasperry Pi under OS11 with Python versions 3.10 and 3.11 and 3.9.
When running rc.spectrum() in a loop, readout-errors occur after some time.
Here is a small piece of code reproducing the error:
results in the following output:
The error occurs after a random number of trials; I tested on openSuse Leap 15.5, Ubuntu 22.04 and on Rasperry Pi under OS11 with Python versions 3.10 and 3.11 and 3.9.