qz-tray
Version:
Connects a web client to the QZ Tray software. Enables printing and device communication from javascript.
2,697 lines (802 loc) • 33.2 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: usb</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Namespace: usb</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="qz.html">qz</a>.</span>usb</h2>
</header>
<article>
<div class="container-overview">
<div class="description">Calls related to interaction with USB devices.</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1984">line 1984</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".claimDevice"><span class="type-signature">(static) </span>claimDevice<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Claim a USB device's interface to enable sending/reading data across an endpoint.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
<tr>
<td class="name"><code>interface</code></td>
<td class="type">
</td>
<td class="description last">Hex string of interface on the USB device to claim.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2063">line 2063</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".closeStream"><span class="type-signature">(static) </span>closeStream<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Stops the stream of read data from a claimed USB device.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
<tr>
<td class="name"><code>endpoint</code></td>
<td class="type">
</td>
<td class="description last">Hex string of endpoint on the claimed interface for the USB device.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2200">line 2200</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".isClaimed"><span class="type-signature">(static) </span>isClaimed<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(boolean|Error)>}</span></h4>
<div class="description">
Check the current claim state of a USB device.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>2.0.2</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2087">line 2087</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(boolean|Error)></span>
</dd>
</dl>
<h4 class="name" id=".listDevices"><span class="type-signature">(static) </span>listDevices<span class="signature">(includeHubs)</span><span class="type-signature"> → {Promise.<(Array.<Object>|Error)>}</span></h4>
<div class="description">
List of available USB devices. Includes (hexadecimal) vendor ID, (hexadecimal) product ID, and hub status.
If supported, also returns manufacturer and product descriptions.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>includeHubs</code></td>
<td class="type">
</td>
<td class="description last">Whether to include USB hubs.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1998">line 1998</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Array of JSON objects containing information on connected USB devices.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(Array.<Object>|Error)></span>
</dd>
</dl>
<h4 class="name" id=".listEndpoints"><span class="type-signature">(static) </span>listEndpoints<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(Array.<string>|Error)>}</span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
<tr>
<td class="name"><code>iface</code></td>
<td class="type">
</td>
<td class="description last">Hex string of interface on the USB device to search.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2025">line 2025</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
List of available (hexadecimal) endpoints on a USB device's interface.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(Array.<string>|Error)></span>
</dd>
</dl>
<h4 class="name" id=".listInterfaces"><span class="type-signature">(static) </span>listInterfaces<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(Array.<string>|Error)>}</span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2010">line 2010</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
List of available (hexadecimal) interfaces on a USB device.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(Array.<string>|Error)></span>
</dd>
</dl>
<h4 class="name" id=".openStream"><span class="type-signature">(static) </span>openStream<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Provides a continuous stream of read data from a claimed USB device.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="default">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="default">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
<tr>
<td class="name"><code>endpoint</code></td>
<td class="type">
</td>
<td class="default">
</td>
<td class="description last">Hex string of endpoint on the claimed interface for the USB device.</td>
</tr>
<tr>
<td class="name"><code>responseSize</code></td>
<td class="type">
</td>
<td class="default">
</td>
<td class="description last">Size of the byte array to receive a response in.</td>
</tr>
<tr>
<td class="name"><code>interval</code></td>
<td class="type">
</td>
<td class="default">
100
</td>
<td class="description last">Frequency to send read data back, in milliseconds.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2174">line 2174</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="qz.usb.html#.setUsbCallbacks">qz.usb.setUsbCallbacks</a></li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".readData"><span class="type-signature">(static) </span>readData<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(Array.<string>|Error)>}</span></h4>
<div class="description">
Read data from a claimed USB device.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
<tr>
<td class="name"><code>endpoint</code></td>
<td class="type">
</td>
<td class="description last">Hex string of endpoint on the claimed interface for the USB device.</td>
</tr>
<tr>
<td class="name"><code>responseSize</code></td>
<td class="type">
</td>
<td class="description last">Size of the byte array to receive a response in.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2145">line 2145</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
List of (hexadecimal) bytes received from the USB device.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(Array.<string>|Error)></span>
</dd>
</dl>
<h4 class="name" id=".releaseDevice"><span class="type-signature">(static) </span>releaseDevice<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Release a claimed USB device to free resources after sending/reading data.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2223">line 2223</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".sendData"><span class="type-signature">(static) </span>sendData<span class="signature">(deviceInfo)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Send data to a claimed USB device.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>deviceInfo</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last">Config details of the HID device.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>vendorId</code></td>
<td class="type">
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">Hex string of USB device's vendor ID.</td>
</tr>
<tr>
<td class="name"><code>productId</code></td>
<td class="type">
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">Hex string of USB device's product ID.</td>
</tr>
<tr>
<td class="name"><code>endpoint</code></td>
<td class="type">
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">Hex string of endpoint on the claimed interface for the USB device.</td>
</tr>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">Bytes to send over specified endpoint.</td>
</tr>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'PLAIN'
</td>
<td class="description last">Valid values <code>[FILE | PLAIN | HEX | BASE64]</code></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2106">line 2106</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".setUsbCallbacks"><span class="type-signature">(static) </span>setUsbCallbacks<span class="signature">(calls)</span><span class="type-signature"></span></h4>
<div class="description">
List of functions called for any response from open usb devices.
Event data will contain <code>{string} vendorId</code> and <code>{string} productId</code> for all types.
For RECEIVE types, <code>{Array} output</code> (in hexadecimal format).
For ERROR types, <code>{string} exception</code>.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>calls</code></td>
<td class="type">
<span class="param-type">function</span>
|
<span class="param-type">Array.<function()></span>
</td>
<td class="description last">Single or array of <code>Function({Object} eventData)</code> calls.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2048">line 2048</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="qz.html">qz</a></li><li><a href="qz.api.html">api</a></li><li><a href="qz.configs.html">configs</a></li><li><a href="qz.file.html">file</a></li><li><a href="qz.hid.html">hid</a></li><li><a href="qz.networking.html">networking</a></li><li><a href="qz.printers.html">printers</a></li><li><a href="qz.security.html">security</a></li><li><a href="qz.serial.html">serial</a></li><li><a href="qz.socket.html">socket</a></li><li><a href="qz.usb.html">usb</a></li><li><a href="qz.websocket.html">websocket</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Apr 02 2026 13:01:02 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>