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

Not compatible with RADEX ONE? #7

Closed Klikini closed 1 year ago

Klikini commented 2 years ago

I wanted to use this library to create a Home Assistant integration for RADEX devices, but it seems my RADEX ONE does not offer a serial port.

radexreader recognizes my device but cannot find a serial port to open, and prints:

ValueError: Error: RADEX ONE (serial) not found

OS: OpenSUSE Leap 15.3

Relevant lsusb line:

Bus 001 Device 006: ID abba:a011 Silicon Labs RADEX ONE

Relevant dmesg lines:

[10280.918511] usb 1-3: new full-speed USB device number 6 using xhci_hcd
[10281.070112] usb 1-3: New USB device found, idVendor=abba, idProduct=a011, bcdDevice= 1.00
[10281.070121] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[10281.070127] usb 1-3: Product: RADEX ONE
[10281.070131] usb 1-3: Manufacturer: Silicon Labs
[10281.070135] usb 1-3: SerialNumber: 0001

I attempted to create a library like this on my own before I found this one, and during that process I stumbled across https://gist.github.com/mwwhited/2491b47c3483f1ac319c227f0dd3a814, so maybe these devices just don't offer a serial port anymore?

Please let me know if there's any other information I could provide or testing I could do that would be helpful :)

luigifab commented 2 years ago

Not sure why, but you can try to print the devices variable here:

https://github.com/luigifab/python-radexreader/blob/fd77d6900155618d6ed189b0c7ddd0d48ff309a2/src/radexreader/__init__.py#L78-L84

Perhaps you didn't have the same version of RADEX ONE, perhaps the baud rate is not working... Perhaps also that like RADEX RD1212, v1 use usb+serial, v2 use usb only.

Klikini commented 2 years ago

I added print(list(devices)) at line 80 and it printed [].

My Radex One is orange, and I think it might be a newer version than the white ones pictured. Maybe they stopped offering a serial port over USB?

luigifab commented 2 years ago

I don't know, we can try the following. Replace:

# RADEX ONE v1
# search usb device (ABBA/A011)
self.usb = usb.core.find(idVendor=0xabba, idProduct=0xa011, backend=backend)
if self.usb is not None:
    self.com = 'ONEv1'
    # search usb serial device (https://stackoverflow.com/a/25112066/2980105)
    devices  = serial.tools.list_ports.grep('RADEX')
    for device in devices:
        self.serial = serial.Serial(port = device.device, baudrate = 9600, timeout = 0.5)
        return # device found
    if self.serial is None:
        raise ValueError('Error: RADEX ONE (serial) not found')

by:

# RADEX ONE v1
# search usb device (ABBA/A011)
self.usb = usb.core.find(idVendor=0xabba, idProduct=0xa011, backend=backend)
if self.usb is not None:
    self.com = 'RD1212v2'
    # usb reset
    self.usb.reset()
    if sys.platform != 'win32' and sys.platform != 'cygwin' and self.usb.is_kernel_driver_active(0):
        self.usb.detach_kernel_driver(0)
    self.usb.set_configuration()
    return # device found

Is this your device?

Klikini commented 2 years ago

Yes, that's my device.

Trying that code lets the constructor succeed, but now read(last=True) fails with:

Traceback (most recent call last):
  File "/home/andy/PycharmProjects/libradex/main.py", line 5, in <module>
    reading = reader.read(last=True)
  File "/home/andy/.local/share/virtualenvs/libradex-l8hJUGoj/lib/python3.9/site-packages/radexreader/__init__.py", line 183, in read
    self.hid_set_report((0x12, 0x12, 0x01, 0x02, key, 0, 0, 0, 0, 0, 0, 0, 0x3c, 0x84))
  File "/home/andy/.local/share/virtualenvs/libradex-l8hJUGoj/lib/python3.9/site-packages/radexreader/__init__.py", line 144, in hid_set_report
    self.usb.ctrl_transfer(
  File "/home/andy/.local/share/virtualenvs/libradex-l8hJUGoj/lib/python3.9/site-packages/usb/core.py", line 1082, in ctrl_transfer
    ret = self._ctx.backend.ctrl_transfer(
  File "/home/andy/.local/share/virtualenvs/libradex-l8hJUGoj/lib/python3.9/site-packages/usb/backend/libusb1.py", line 893, in ctrl_transfer
    ret = _check(self.lib.libusb_control_transfer(
  File "/home/andy/.local/share/virtualenvs/libradex-l8hJUGoj/lib/python3.9/site-packages/usb/backend/libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

Process finished with exit code 1

That enters libusb code at https://github.com/luigifab/python-radexreader/blob/master/src/radexreader/__init__.py#L145

luigifab commented 2 years ago

I get also a Pipe error with my RD1212v2 when the report data used by hid_set_report are wrong. I suggest to you to install Wireshark or something similar and official tool of QuartaRad, to capture packets.

I also see in gist that it uses different addresses. Perhaps you can try them here: https://github.com/luigifab/python-radexreader/blob/fd77d6900155618d6ed189b0c7ddd0d48ff309a2/src/radexreader/__init__.py#L184

For example something like 0x7b, 0xff, 0x20, 0... for 7BFF 2000 0600 1800 ____ 4600 0008 0C00 F3F7, I don't remember how it's work exactly.

What are the functionalities of your device? instant µSv/h? history of µSv/h? date/hour?