usb
- Version 3.0.1
- Published
- 57.6 kB
- 1 dependency
- MIT license
Install
npm i usbyarn add usbpnpm add usbOverview
Library to access USB devices
Index
Variables
Classes
class WebUSB
class WebUSB extends EventTarget implements USB {}WebUSB class
### Events
| Name | Event | Description | | ---- | ----- | ----------- | |
connect| USBConnectionEvent | Device connected | |disconnect| USBConnectionEvent | Device disconnected |
constructor
constructor(options?: USBOptions);property authorisedDevices
protected authorisedDevices: Set<USBDeviceFilter>;property eventListeners
protected eventListeners: Map<string, Set<EventListener>>;property knownDevices
protected knownDevices: Map<string, UsbDevice>;property listenerCount
protected listenerCount: number;property nativeEmitter
protected nativeEmitter: Emitter;method addEventListener
addEventListener: { ( type: 'connect' | 'disconnect', listener: (this: this, ev: USBConnectionEvent) => void ): void; (type: 'connect' | 'disconnect', listener: EventListener): void;};method findDeviceByIds
findDeviceByIds: (vid: number, pid: number) => Promise<UsbDevice | undefined>;Convenience method to get the first device with the specified VID and PID, or
undefinedif no such device is present.Parameter vid
Parameter pid
method findDeviceBySerial
findDeviceBySerial: (serialNumber: string) => Promise<UsbDevice | undefined>;Convenience method to get the device with the specified serial number, or
undefinedif no such device is present.Parameter serialNumber
method getDevices
getDevices: () => Promise<UsbDevice[]>;Gets all allowed Web USB devices which are connected
Returns
Promise containing an array of devices
method removeEventListener
removeEventListener: { ( type: 'connect' | 'disconnect', callback: (this: this, ev: USBConnectionEvent) => void ): void; (type: 'connect' | 'disconnect', callback: EventListener): void;};method requestDevice
requestDevice: (options?: USBDeviceRequestOptions) => Promise<UsbDevice>;Requests a single Web USB device
Parameter options
The options to use when scanning
Returns
Promise containing the selected device
Interfaces
interface USBOptions
interface USBOptions {}USB Options
property allowAllDevices
allowAllDevices?: boolean;Optional flag to automatically allow all devices
property allowedDevices
allowedDevices?: USBDeviceFilter[];Optional array of preconfigured allowed devices
property devicesFound
devicesFound?: (devices: UsbDevice[]) => Promise<UsbDevice | void>;Optional
device foundcallback function to allow the user to select a device
property deviceTimeout
deviceTimeout?: number;Optional timeout (in milliseconds) to use for the device control transfers
Package Files (1)
Dependencies (1)
Dev Dependencies (5)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/usb.
- Markdown[](https://www.jsdocs.io/package/usb)
- HTML<a href="https://www.jsdocs.io/package/usb"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2553 ms. - Missing or incorrect documentation? Open an issue for this package.
