Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The usbhotplug object can be used to generate events when USB devices are added or removed. 

usbhotplug IDL

Code Block
languagejs
interface usbhotplugevent {
    attribute String action;    // "add", "remove"
    attribute String path;      // platform specific device path
};

callback UsbHotplugEventCallback = void (usbhotplugevent event);

interface UsbHotplug {
    void addEventListener(String type, UsbHotplugEventCallback callback);
    void removeEventListener(String type, UsbHotplugEventCallback callback);
};
Panel
borderColor#3D3D3D
bgColor#F4F4F4
titleColor#3D3D3D
borderWidth0
titleBGColor#3D3D3D
borderStylesolid

ON THIS PAGE

Table of Contents
indent20px



Event Creation

To create a usbhotplug event, load the @brightsign/usbhotplug module using the require() method:

Code Block
languagejs
let usbhotplugClass = require("@brightsign/usbhotplug");
let usbhotplug = new usbhotplugClass();

UsbHotPlug 

Use this interface to configure a usbhotplug event.

usbhotplugevent: This event is raised when the hotplug status changes. Use the addEventListener() method to listen for this event, or the removeEventListener() method to remove an event listener.

usbhotplugevent Properties 

  • [String] action string: Indicates whether a USB device has been added or removed.

  • [String] path string: The path is an arbitrary string which varies between models and should not be parsed.  It may be useful for diagnostics. The path will be the same for add and remove events for a particular USB device. Use @brightsign/deviceinfogetUsbBusTopology() to examine attached devices. These events are hints that the topology has changed.

Example

Code Block
languagejs
let usbhotplugClass = require("@brightsign/usbhotplug");
let usbhotplug = new usbhotplugClass();

function onusbhotplugevent(event) {
  if (event.action == 'add') {
     console.log('New device at' + event.path)
  } else if (event.action == 'remove')
  {
     console.log('Device removed from' + event.path)
  }
}

usbhotplug.addEventListener("usbhotplugevent", onusbhotplugevent);