---
name: "NJB_Discover"
section: "3"
platform: "linux"
package: "libnjb1-doc"
version: "1.1-2"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/NJB_Discover"
---

# NJB\_Discover(3)

Locate NJB devices on available USB busses

## NAME

NJB\_Discover - Locate NJB devices on available USB busses

## LIBRARY

libnjb

## SYNOPSIS

\#include \<libnjb.h\>

extern int njb\_error;

int NJB\_Discover (njb\_t  **\*njbs**, int **limit**, int **\*n**)

## DESCRIPTION

This function searches all configured USB busses for attached NJB devices.

The number of NJB devices found is placed into **n**, and the njb\_t array  **\*njbs** is populated with  **n** elements, describing the NJB's in the order in which they are found. It is the user's responsibility to ensure that the  **\*njbs** array is of sufficient size.  A good practice is to declare an array with NJB\_MAX\_DEVICES elements: while this is slightly wasteful in terms of memory, it will always guarantee that sufficient storage is available.

The  **limit** parameter can be used to restrict the search to  **limit** busses (starting with /dev/usb0, and counting up). If set to 0, then no limit is enforced, and all busses will be queried.

## RETURN VALUES

NJB\_Discover returns 0 if no errors occurred.  If any errors were encountered during the search, then -1 is returned. **njb\_error** will not be set to a meaningful value, but the  **njb\_error**(3) functions can still be used to obtain error messages corresponding to the problems found.

It is extremely important to note that an error does not automatically imply a failure.  You should always check the value stored in **n** to determine how many NJB devices were discovered, if any, regardless of the return value of NJB\_Discover.  Because multiple USB controllers can be present on a system, it is entirely possible, for example, that /dev/usb1 could not be opened while an NJB device on /dev/usb0 was located successfully.  In this case, NJB\_Discover would still return -1, but  **n** would be set to 1, and the **njbs** array would have a valid NJB device in described in **njbs\[0\]**.

Conversely, NJB\_Discover can return 0 even if no NJB devices are found.  In this case, there were no errors opening the available USB busses, but no NJB devices were attached and/or ready for communication.

## SEE ALSO

njb\_error(3)

## BUGS

The author is aware that the term "USB busses" is redundant (like "ATM machine").  It would be more correct to say "USBs", but that doesn't flow as well.
