p5.serialport
Version:
Library for serial port and p5.js
966 lines (230 loc) • 11.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: SerialPort</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">Class: SerialPort</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>SerialPort<span class="signature">(serialport, serialoptions)</span><span class="type-signature"></span></h2>
<div class="class-description"><p>Represents a serialport object. Maintains an array of <a href="Client.html"><code>Client</code></a> objects subscribed to the serial port.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="SerialPort"><span class="type-signature"></span>new SerialPort<span class="signature">(serialport, serialoptions)</span><span class="type-signature"></span></h4>
<div class="description">
<p>creates a SerialPort object</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>serialport</code></td>
<td class="type">
<span class="param-type">serialport</span>
</td>
<td class="description last"><p>serialport object</p></td>
</tr>
<tr>
<td class="name"><code>serialoptions</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>JSON object of options for the serialport object</p></td>
</tr>
</tbody>
</table>
<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>LOGGING</code></td>
<td class="type">
<span class="param-type">Boolean</span>
</td>
<td class="description last"><p>sets whether to console.log detailed information</p></td>
</tr>
<tr>
<td class="name"><code>serialPortName</code></td>
<td class="type">
<span class="param-type">String</span>
</td>
<td class="description last"><p>name of the connected serialport</p></td>
</tr>
<tr>
<td class="name"><code>serialOptions</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>JSON array of options for the serialport</p></td>
</tr>
<tr>
<td class="name"><code>messageListeners</code></td>
<td class="type">
<span class="param-type">Array.<<a href="Client.html">Client</a>></span>
</td>
<td class="description last"><p>array of subscribed <a href="Client.html"><code>Client</code></a> objects</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classes_SerialPort.js.html">classes/SerialPort.js</a>, <a href="classes_SerialPort.js.html#line28">line 28</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="https://www.npmjs.com/package/serialport">https://www.npmjs.com/package/serialport</a></li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="addClient"><span class="type-signature"></span>addClient<span class="signature">(client)</span><span class="type-signature"></span></h4>
<div class="description">
<p>add a web client to messageListeners array</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>client</code></td>
<td class="type">
<span class="param-type"><a href="Client.html">Client</a></span>
</td>
<td class="description last"><p><a href="Client.html"><code>Client</code></a> object subscribing to the SerialPort</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classes_SerialPort.js.html">classes/SerialPort.js</a>, <a href="classes_SerialPort.js.html#line48">line 48</a>
</li></ul></dd>
</dl>
<h4 class="name" id="closeSerial"><span class="type-signature"></span>closeSerial<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>closes the serialport connection and sends message to the connected clients that the serialport is closed.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classes_SerialPort.js.html">classes/SerialPort.js</a>, <a href="classes_SerialPort.js.html#line134">line 134</a>
</li></ul></dd>
</dl>
<h4 class="name" id="onMessage"><span class="type-signature"></span>onMessage<span class="signature">(msg)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Forwards message emitted by SerialPort events to the susbscribed clients in the messageListeners array</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>msg</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>JSON object containing message method and data</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classes_SerialPort.js.html">classes/SerialPort.js</a>, <a href="classes_SerialPort.js.html#line68">line 68</a>
</li></ul></dd>
</dl>
<h4 class="name" id="openSerial"><span class="type-signature"></span>openSerial<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Opens SerialPort of serialPortName with serialOptions.
Sets serialport event listeners of method 'data', 'close' and 'error' and sends messages to the client via onMessage function</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classes_SerialPort.js.html">classes/SerialPort.js</a>, <a href="classes_SerialPort.js.html#line76">line 76</a>
</li></ul></dd>
</dl>
<h4 class="name" id="removeClient"><span class="type-signature"></span>removeClient<span class="signature">(client)</span><span class="type-signature"></span></h4>
<div class="description">
<p>remove client from messageListeners array to unsubscribe client</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>client</code></td>
<td class="type">
<span class="param-type"><a href="Client.html">Client</a></span>
</td>
<td class="description last"><p><a href="Client.html"><code>Client</code></a> object unsubscribing to the SerialPort</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="classes_SerialPort.js.html">classes/SerialPort.js</a>, <a href="classes_SerialPort.js.html#line59">line 59</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Client.html">Client</a></li><li><a href="SerialPort.html">SerialPort</a></li></ul><h3>Events</h3><ul><li><a href="Client.html#event:message">message</a></li></ul><h3>Global</h3><ul><li><a href="global.html#clients">clients</a></li><li><a href="global.html#LOGGING">LOGGING</a></li><li><a href="global.html#logit">logit</a></li><li><a href="global.html#serialPorts">serialPorts</a></li><li><a href="global.html#serialPortsList">serialPortsList</a></li><li><a href="global.html#start">start</a></li><li><a href="global.html#stop">stop</a></li><li><a href="global.html#wss">wss</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Sun Jul 17 2022 21:38:31 GMT-0400 (Chile Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>