Skip to content

API Probing and Opening

dilshan edited this page Nov 22, 2026 · 1 revision

Probing and Opening

Functions for finding a sensor and getting a handle to it.

olru_probe

int olru_probe(olru_device_info *list, size_t max);

Finds supported sensors on the USB bus.

The function only reads /sys/bus/usb/devices; it does not open or talk to any device, so it is safe to call as often as you like (for example from a "Refresh" button).

Parameter Description
list array that receives the sensors found
max number of entries available in list

Returns the number of sensors stored in list (0 if none), or a negative olru_status:

  • OLRU_ERR_ARG - list is NULL or max is 0
  • OLRU_ERR_IO - the sysfs USB directory could not be read

Mass-storage-type sensors (2009:7638, 2109:7638) are included unless the environment variable OLRU_DENY_MSC is set.

olru_device_info list[OLRU_MAX_DEVICES];
int n = olru_probe(list, OLRU_MAX_DEVICES);
for (int i = 0; i < n; i++)
    printf("%d: %s %04x:%04x\n", i, list[i].name, list[i].vid, list[i].pid);

olru_open

int olru_open(const olru_device_info *info, olru_device **out);

Opens a sensor found by olru_probe and checks that it answers.

Steps performed:

  1. Opens /dev/bus/usb/<bus>/<address>.
  2. Claims interface 0, detaching a kernel driver (such as usb-storage) if one is bound.
  3. For bulk-type models, resets the device and waits 200 ms (as the vendor SDK does).
  4. Runs the link handshake (olru_link_check).
Parameter Description
info entry from olru_probe
out receives the new handle on success

Returns OLRU_OK, or:

Code Typical cause
OLRU_ERR_ARG info or out is NULL
OLRU_ERR_ACCESS no permission on the USB device node - see Troubleshooting
OLRU_ERR_NO_DEVICE sensor was unplugged between probe and open
OLRU_ERR_IO / OLRU_ERR_TIMEOUT the sensor did not answer
OLRU_ERR_DEVICE sensor answered with an error code
OLRU_ERR_NOMEM out of memory

On failure nothing is left open and *out is not modified.

Duration: about 0.2 s (handshake settling time), plus the USB reset for bulk-type models.

olru_device *dev;
int rc = olru_open(&list[0], &dev);
if (rc != OLRU_OK)
    fprintf(stderr, "open failed: %s\n", olru_strerror(rc));

olru_close

void olru_close(olru_device *dev);

Releases the USB interface and frees the handle. Passing NULL is allowed and does nothing. Do not use dev afterwards.

The kernel driver that was detached by olru_open is not re-attached. Unplug and re-plug the sensor to restore it.

olru_link_check

int olru_link_check(olru_device *dev);

Runs the link handshake: waits 200 ms, then tries up to 3 times (100 ms apart) to get a success reply to the sensor's link command. olru_open already calls this; call it yourself only to test that a long-open sensor is still responsive.

Returns OLRU_OK when the sensor answers, otherwise the error of the last attempt (OLRU_ERR_IO, OLRU_ERR_TIMEOUT, OLRU_ERR_PROTOCOL, OLRU_ERR_DEVICE), or OLRU_ERR_ARG if dev is NULL.

Clone this wiki locally