Skip to content

Commit

Permalink
Merge pull request #37 from wentasah/fixes2
Browse files Browse the repository at this point in the history
Improve error reporting with device permission denied errors.
  • Loading branch information
darrylb123 authored Jan 30, 2020
2 parents 7e4163e + 133eaa9 commit f504ba5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion libusbrelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ int enumerate_relay_boards(const char *product, int verbose, int debug)
char *vendor;
int result = 0;
struct hid_device_info *devs, *cur_dev;
int num_opened = 0, num_error = 0;

//If we were given a product code, use it
if (product != NULL)
Expand Down Expand Up @@ -92,12 +93,14 @@ int enumerate_relay_boards(const char *product, int verbose, int debug)
handle = hid_open_path(cur_dev->path);
if (handle)
{
num_opened++;
result = get_board_features(&relay_boards[i], handle);
hid_close(handle);
}
else
{
perror("unable to open device - Use root, sudo or set the device permissions via udev\n");
num_error++;
perror(cur_dev->path);
result = -1;
}

Expand Down Expand Up @@ -133,6 +136,8 @@ int enumerate_relay_boards(const char *product, int verbose, int debug)
}
}
hid_free_enumeration(devs);
if (num_opened == 0 && num_error > 0)
fprintf(stderr, "Unable to open any device - Use root, sudo or set the device permissions via udev\n");
return result;
}

Expand Down

0 comments on commit f504ba5

Please sign in to comment.