node-serialport-bindings-cpp/docs/SerialPort.html

2990 lines
No EOL
48 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>SerialPort - Documentation</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.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BaseBinding.html">BaseBinding</a><ul class='methods'><li data-type='method'><a href="BaseBinding.html#.list">list</a></li><li data-type='method'><a href="BaseBinding.html#close">close</a></li><li data-type='method'><a href="BaseBinding.html#drain">drain</a></li><li data-type='method'><a href="BaseBinding.html#flush">flush</a></li><li data-type='method'><a href="BaseBinding.html#get">get</a></li><li data-type='method'><a href="BaseBinding.html#getBaudRate">getBaudRate</a></li><li data-type='method'><a href="BaseBinding.html#open">open</a></li><li data-type='method'><a href="BaseBinding.html#read">read</a></li><li data-type='method'><a href="BaseBinding.html#set">set</a></li><li data-type='method'><a href="BaseBinding.html#update">update</a></li><li data-type='method'><a href="BaseBinding.html#write">write</a></li></ul></li><li><a href="ByteLengthParser.html">ByteLengthParser</a></li><li><a href="CCTalkParser.html">CCTalkParser</a></li><li><a href="DelimiterParser.html">DelimiterParser</a></li><li><a href="Poller.html">Poller</a><ul class='methods'><li data-type='method'><a href="Poller.html#once">once</a></li><li data-type='method'><a href="Poller.html#poll">poll</a></li><li data-type='method'><a href="Poller.html#stop">stop</a></li></ul></li><li><a href="ReadLineParser.html">ReadLineParser</a></li><li><a href="ReadyParser.html">ReadyParser</a></li><li><a href="RegexParser.html">RegexParser</a></li><li><a href="SerialPort.html">SerialPort</a><ul class='members'><li data-type='member'><a href="SerialPort.html#.Binding">Binding</a></li><li data-type='member'><a href="SerialPort.html#.parsers">parsers</a></li></ul><ul class='methods'><li data-type='method'><a href="SerialPort.html#.list">list</a></li><li data-type='method'><a href="SerialPort.html#close">close</a></li><li data-type='method'><a href="SerialPort.html#drain">drain</a></li><li data-type='method'><a href="SerialPort.html#flush">flush</a></li><li data-type='method'><a href="SerialPort.html#get">get</a></li><li data-type='method'><a href="SerialPort.html#open">open</a></li><li data-type='method'><a href="SerialPort.html#pause">pause</a></li><li data-type='method'><a href="SerialPort.html#read">read</a></li><li data-type='method'><a href="SerialPort.html#resume">resume</a></li><li data-type='method'><a href="SerialPort.html#set">set</a></li><li data-type='method'><a href="SerialPort.html#update">update</a></li><li data-type='method'><a href="SerialPort.html#write">write</a></li></ul></li></ul><h3>Events</h3><ul><li><a href="global.html#event:close">close</a></li><li><a href="global.html#event:data">data</a></li><li><a href="global.html#event:error">error</a></li><li><a href="global.html#event:open">open</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<div id="main">
<h1 class="page-title">SerialPort</h1>
<section>
<header>
<h2>
SerialPort
</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="SerialPort"><span class="type-signature"></span>new SerialPort<span class="signature">(path, options<span class="signature-attributes">opt</span>, openCallback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line77">line 77</a>
</li></ul></dd>
</dl>
<h5 class="subsection-title">Properties:</h5>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>baudRate</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>The port's baudRate. Use <code>.update</code> to change it. Read-only.</p></td>
</tr>
<tr>
<td class="name"><code>binding</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>The binding object backing the port. Read-only.</p></td>
</tr>
<tr>
<td class="name"><code>isOpen</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="description last"><p><code>true</code> if the port is open, <code>false</code> otherwise. Read-only. (<code>since 5.0.0</code>)</p></td>
</tr>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>The system path or name of the serial port. Read-only.</p></td>
</tr>
</tbody>
</table>
<div class="description">
<p>Create a new serial port object for the <code>path</code>. In the case of invalid arguments or invalid options, when constructing a new SerialPort it will throw an error. The port will open automatically by default, which is the equivalent of calling <code>port.open(openCallback)</code> in the next tick. You can disable this by setting the option <code>autoOpen</code> to <code>false</code>.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>The system path of the serial port you want to open. For example, <code>/dev/tty.XXX</code> on Mac/Linux, or <code>COM1</code> on Windows.</p></td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type"><a href="global.html#openOptions">openOptions</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Port configuration options</p></td>
</tr>
<tr>
<td class="name"><code>openCallback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called after a connection is opened. If this is not provided and an error occurs, it will be emitted on the port's <code>error</code> event. The callback will NOT be called if <code>autoOpen</code> is set to <code>false</code> in the <code>openOptions</code> as the open will not be performed.</p></td>
</tr>
</tbody>
</table>
<h5>Fires:</h5>
<ul>
<li><a href="global.html#event:open">event:open</a></li>
<li><a href="global.html#event:data">event:data</a></li>
<li><a href="global.html#event:close">event:close</a></li>
<li><a href="global.html#event:error">event:error</a></li>
</ul>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>When given invalid arguments, a <code>TypeError</code> will be thrown.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">TypeError</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".Binding"><span class="type-signature">(static) </span>Binding<span class="type-signature"> :<a href="BaseBinding.html">BaseBinding</a></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line9">line 9</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="BaseBinding.html">BaseBinding</a></span>
</li>
</ul>
<h4 class="name" id=".parsers"><span class="type-signature">(static) </span>parsers<span class="type-signature"> :<a href="global.html#Parsers">Parsers</a></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line14">line 14</a>
</li></ul></dd>
</dl>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="global.html#Parsers">Parsers</a></span>
</li>
</ul>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".list"><span class="type-signature">(static) </span>list<span class="signature">(callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line620">line 620</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Retrieves a list of available serial ports with metadata. Only the <code>comName</code> is guaranteed. If unavailable the other fields will be undefined. The <code>comName</code> is either the path or an identifier (eg <code>COM1</code>) used to open the SerialPort.</p>
<p>We make an effort to identify the hardware attached and have consistent results between systems. Linux and OS X are mostly consistent. Windows relies on 3rd party device drivers for the information and is unable to guarantee the information. On windows If you have a USB connected device can we provide a serial number otherwise it will be <code>undefined</code>. The <code>pnpId</code> and <code>locationId</code> are not the same or present on all systems. The examples below were run with the same Arduino Uno.</p>
</div>
<h5>Example</h5>
<pre class="prettyprint"><code>```js
// OSX example port
{
comName: '/dev/tty.usbmodem1421',
manufacturer: 'Arduino (www.arduino.cc)',
serialNumber: '752303138333518011C1',
pnpId: undefined,
locationId: '14500000',
productId: '0043',
vendorId: '2341'
}
// Linux example port
{
comName: '/dev/ttyACM0',
manufacturer: 'Arduino (www.arduino.cc)',
serialNumber: '752303138333518011C1',
pnpId: 'usb-Arduino__www.arduino.cc__0043_752303138333518011C1-if00',
locationId: undefined,
productId: '0043',
vendorId: '2341'
}
// Windows example port
{
comName: 'COM3',
manufacturer: 'Arduino LLC (www.arduino.cc)',
serialNumber: '752303138333518011C1',
pnpId: 'USB\\VID_2341&amp;PID_0043\\752303138333518011C1',
locationId: 'Port_#0003.Hub_#0001',
productId: '0043',
vendorId: '2341'
}
```
```js
var SerialPort = require('serialport');
// callback approach
SerialPort.list(function (err, ports) {
ports.forEach(function(port) {
console.log(port.comName);
console.log(port.pnpId);
console.log(port.manufacturer);
});
});
// promise approach
SerialPort.list()
.then(ports) {...});
.catch(err) {...});
```</code></pre>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#listCallback">listCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called with a list of available serial ports.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>Resolves with the list of available serial ports.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise</span>
</dd>
</dl>
<h4 class="name" id="close"><span class="type-signature"></span>close<span class="signature">(callback, disconnectError)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line408">line 408</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Closes an open connection.</p>
<p>If there are in progress writes when the port is closed the writes will error.</p>
</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>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="description last"><p>Called once a connection is closed.</p></td>
</tr>
<tr>
<td class="name"><code>disconnectError</code></td>
<td class="type">
<span class="param-type">Error</span>
</td>
<td class="description last"><p>used internally to propagate a disconnect error</p></td>
</tr>
</tbody>
</table>
<h5>Fires:</h5>
<ul>
<li><a href="global.html#event:close">event:close</a></li>
</ul>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="drain"><span class="type-signature"></span>drain<span class="signature">(callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line520">line 520</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Waits until all output data is transmitted to the serial port. After any pending write has completed it calls <a href="http://linux.die.net/man/3/tcdrain"><code>tcdrain()</code></a> or <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364439(v=vs.85">FlushFileBuffers()</a>.aspx) to ensure it has been written to the device.</p>
</div>
<h5>Example</h5>
<pre class="prettyprint"><code>Write the `data` and wait until it has finished transmitting to the target serial port before calling the callback. This will queue until the port is open and writes are finished.
```js
function writeAndDrain (data, callback) {
port.write(data);
port.drain(callback);
}
```</code></pre>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called once the drain operation returns.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="flush"><span class="type-signature"></span>flush<span class="signature">(callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line490">line 490</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Flush discards data received but not read, and written but not transmitted by the operating system. For more technical details, see <a href="http://linux.die.net/man/3/tcflush"><code>tcflush(fd, TCIOFLUSH)</code></a> for Mac/Linux and <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa364439"><code>FlushFileBuffers</code></a> for Windows.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called once the flush operation finishes.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="get"><span class="type-signature"></span>get<span class="signature">(callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line469">line 469</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Returns the control flags (CTS, DSR, DCD) on the open port.<br>Uses <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363258(v=vs.85"><code>GetCommModemStatus</code></a>.aspx) for Windows and <a href="http://linux.die.net/man/4/tty_ioctl"><code>ioctl</code></a> for mac and linux.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#modemBitsCallback">modemBitsCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called once the modem bits are retrieved.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="open"><span class="type-signature"></span>open<span class="signature">(openCallback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line220">line 220</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Opens a connection to the given serial port.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>openCallback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called after a connection is opened. If this is not provided and an error occurs, it will be emitted on the port's <code>error</code> event.</p></td>
</tr>
</tbody>
</table>
<h5>Fires:</h5>
<ul>
<li><a href="global.html#event:open">event:open</a></li>
</ul>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="pause"><span class="type-signature"></span>pause<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line537">line 537</a>
</li></ul></dd>
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>5.0.0</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>resume</li>
</ul>
</dd>
</dl>
<div class="description">
<p>The <code>pause()</code> method causes a stream in flowing mode to stop emitting 'data' events, switching out of flowing mode. Any data that becomes available remains in the internal buffer.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p><code>this</code></p>
</div>
<h4 class="name" id="read"><span class="type-signature"></span>read<span class="signature">(size<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {string|Buffer|null}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line328">line 328</a>
</li></ul></dd>
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>5.0.0</li></ul></dd>
</dl>
<div class="description">
<p>Request a number of bytes from the SerialPort. The <code>read()</code> method pulls some data out of the internal buffer and returns it. If no data is available to be read, null is returned. By default, the data is returned as a <code>Buffer</code> object unless an encoding has been specified using the <code>.setEncoding()</code> method.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>size</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Specify how many bytes of data to return, if available</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>The data from internal buffers</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">string</span>
|
<span class="param-type">Buffer</span>
|
<span class="param-type">null</span>
</dd>
</dl>
<h4 class="name" id="resume"><span class="type-signature"></span>resume<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line545">line 545</a>
</li></ul></dd>
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>5.0.0</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>pause</li>
</ul>
</dd>
</dl>
<div class="description">
<p>The <code>resume()</code> method causes an explicitly paused, <code>Readable</code> stream to resume emitting 'data' events, switching the stream into flowing mode.</p>
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p><code>this</code></p>
</div>
<h4 class="name" id="set"><span class="type-signature"></span>set<span class="signature">(options<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line442">line 442</a>
</li></ul></dd>
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>5.0.0</li></ul></dd>
</dl>
<div class="description">
<p>Set control flags on an open port. Uses <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa363257(v=vs.85"><code>SetCommMask</code></a>.aspx) for Windows and <a href="http://linux.die.net/man/4/tty_ioctl"><code>ioctl</code></a> for OS X and Linux.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>All options are operating system default when the port is opened. Every flag is set on each call to the provided or default values. If options isn't provided default options is used.</p>
<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>brk</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>false</code>
</td>
<td class="description last"><p>sets the brk flag</p></td>
</tr>
<tr>
<td class="name"><code>cts</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>false</code>
</td>
<td class="description last"><p>sets the cts flag</p></td>
</tr>
<tr>
<td class="name"><code>dsr</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>false</code>
</td>
<td class="description last"><p>sets the dsr flag</p></td>
</tr>
<tr>
<td class="name"><code>dtr</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>true</code>
</td>
<td class="description last"><p>sets the dtr flag</p></td>
</tr>
<tr>
<td class="name"><code>rts</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>true</code>
</td>
<td class="description last"><p>sets the rts flag</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called once the port's flags have been set.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(options<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {undefined}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line250">line 250</a>
</li></ul></dd>
</dl>
<div class="description">
<p>Changes the baud rate for an open port. Throws if you provide a bad argument. Emits an error or calls the callback if the baud rate isn't supported.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Only supports <code>baudRate</code>.</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>baudRate</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200. Custom rates are supported best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type"><a href="global.html#errorCallback">errorCallback</a></span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called once the port's baud rate changes. If <code>.update</code> is called without a callback, and there is an error, an error event is emitted.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">undefined</span>
</dd>
</dl>
<h4 class="name" id="write"><span class="type-signature"></span>write<span class="signature">(data, encoding<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="serialport.js.html">serialport.js</a>, <a href="serialport.js.html#line273">line 273</a>
</li></ul></dd>
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>5.0.0</li></ul></dd>
</dl>
<div class="description">
<p>Writes data to the given serial port. Buffers written data if the port is not open.</p>
<p>The write operation is non-blocking. When it returns, data might still not have been written to the serial port. See <code>drain()</code>.</p>
<p>Some devices, like the Arduino, reset when you open a connection to them. In such cases, immediately writing to the device will cause lost data as they wont be ready to receive the data. This is often worked around by having the Arduino send a &quot;ready&quot; byte that your Node program waits for before writing. You can also often get away with waiting around 400ms.</p>
<p>If a port is disconnected during a write, the write will error in addition to the <code>close</code> event.</p>
<p>From the <a href="https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback">stream docs</a> write errors don't always provide the error in the callback, sometimes they use the error event.</p>
<blockquote>
<p>If an error occurs, the callback may or may not be called with the error as its first argument. To reliably detect write errors, add a listener for the 'error' event.</p>
</blockquote>
<p>In addition to the usual <code>stream.write</code> arguments (<code>String</code> and <code>Buffer</code>), <code>write()</code> can accept arrays of bytes (positive numbers under 256) which is passed to <code>Buffer.from([])</code> for conversion. This extra functionality is pretty sweet.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">array</span>
|
<span class="param-type">buffer</span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>Accepts a <a href="http://nodejs.org/api/buffer.html"><code>Buffer</code> </a> object, or a type that is accepted by the <code>Buffer</code> constructor (e.g. an array of bytes or a string).</p></td>
</tr>
<tr>
<td class="name"><code>encoding</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>The encoding, if chunk is a string. Defaults to <code>'utf8'</code>. Also accepts <code>'ascii'</code>, <code>'base64'</code>, <code>'binary'</code>, and <code>'hex'</code> See <a href="https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings">Buffers and Character Encodings</a> for all available options.</p></td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last"><p>Called once the write operation finishes. Data may not yet be flushed to the underlying port. No arguments.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p><code>false</code> if the stream wishes for the calling code to wait for the <code>'drain'</code> event to be emitted before continuing to write additional data; otherwise <code>true</code>.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Feb 27 2018 22:46:41 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
</body>
</html>