Skip to content

Commit

Permalink
Don't pretend a device address is a port path.
Browse files Browse the repository at this point in the history
Programs that desire this behavior can do it explicitly in JS:
`dev.portNumbers || [dev.deviceAddress]`. You might want to include
`dev.busNumber` in there too, or it won't even be guaranteed unique if
there are multiple USB buses.
  • Loading branch information
kevinmehall committed Feb 18, 2017
1 parent a9ca854 commit 01f59d6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Expand Up @@ -58,7 +58,7 @@ Integer USB device number
Integer USB device address

### .portNumbers
Array containing the USB device port numbers
Array containing the USB device port numbers, or `undefined` if not supported on this platform.

### .deviceDescriptor
Object with properties for the fields of the device descriptor:
Expand Down
13 changes: 1 addition & 12 deletions src/device.cc
Expand Up @@ -82,23 +82,12 @@ static NAN_METHOD(deviceConstructor) {

uint8_t port_numbers[MAX_PORTS];
int ret = libusb_get_port_numbers(self->device, &port_numbers[0], MAX_PORTS);
if (ret >= 0) {
if (ret > 0) {
Local<Array> array = Nan::New<Array>(ret);
for (int i = 0; i < ret; ++ i) {
array->Set(i, Nan::New(port_numbers[i]));
}
info.This()->ForceSet(V8SYM("portNumbers"), array, CONST_PROP);
} else {
// FreeBSD workarounds based on https://sourceforge.net/p/sigrok/mailman/attachment/54C11DD2.10002%40uffe.org/1/
#ifdef __FreeBSD__
struct libusb_device_handle* dh;
CHECK_USB(libusb_open(self->device, &dh));
Local<Array> array = Nan::New<Array>(1);
array->Set(0, Nan::New(libusb_get_device_address(self->device)));
info.This()->ForceSet(V8SYM("portNumbers"), array, CONST_PROP);
libusb_close(dh);
#endif
// If get_port_numbers fails on other platforms, just don't set the property
}
info.GetReturnValue().Set(info.This());
}
Expand Down

0 comments on commit 01f59d6

Please sign in to comment.