Listing calculators connected by USB#

In order to list calculators connected by USB, you must use cahute_detect_usb(), while providing it with a callback to either add the USB device to your list or display it.

An example program using this function is the following:

/* Compile using: gcc detect-usb.c `pkg-config cahute --cflags --libs`. */

#include <stdio.h>
#include <cahute.h>

int my_callback(void *cookie, cahute_usb_detection_entry const *entry) {
    char const *type_name;

    switch (entry->cahute_usb_detection_entry_type) {
    case CAHUTE_USB_DETECTION_ENTRY_TYPE_SEVEN:
        type_name = "fx-9860G or compatible";
        break;

    case CAHUTE_USB_DETECTION_ENTRY_TYPE_SCSI:
        type_name = "fx-CG or compatible";
        break;

    default:
        type_name = "(unknown)";
    }

    printf("New entry data:\n");
    printf(
        "- Address: %03d:%03d\n",
        entry->cahute_usb_detection_entry_bus,
        entry->cahute_usb_detection_entry_address
    );
    printf("- Type: %s\n", type_name);

    return 0;
}

int main(void) {
    int err;

    err = cahute_detect_usb(&my_callback, NULL);
    if (err)
        fprintf(stderr, "Cahute has returned error 0x%04X.\n", err);

    return 0;
}

An example output for this program is the following:

New entry data:
- Address: 003:042
- Type: fx-9860G or compatible
New entry data:
- Address: 003:043
- Type: fx-CG or compatible

Note

On Linux, you can compare this output to the output of lsusb, for example in the case above:

$ lsusb
...
Bus 003 Device 042: ID 07cf:6101 Casio Computer Co., Ltd fx-9750gII
Bus 003 Device 043: ID 07cf:6102 Casio Computer Co., Ltd fx-CP400
...