UNPKG

splynx-mikronode-ng2

Version:
3,034 lines 56.2 kB
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Class: Connection</title>
    
    
    
    
    
    <meta property="og:title" content=""/>
    <meta property="og:type" content="website"/>
    <meta property="og:image" content=""/>
    
    <meta property="og:url" content=""/>
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <script src="scripts/jquery.min.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/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="styles/jaguar.css">
    
    
    <script>
    var config = {"monospaceLinks":true,"cleverLinks":true,"default":{"outputSourceFiles":true},"applicationName":"MikroNode","disqus":"","googleAnalytics":"","openGraph":{"title":"","type":"website","image":"","site_name":"","url":""},"meta":{"title":"","description":"","keyword":""},"linenums":false};
    </script>
    

    
</head>
<body>
<div id="wrap" class="clearfix">
    
<div class="navigation">
    <h3 class="applicationName"><a href="index.html">MikroNode</a></h3>

    <div class="search">
        <input id="search" type="text" class="form-control input-sm" placeholder="Search Documentations">
    </div>
    <ul class="list">
    
        <li class="item" data-name="mikronode-ng">
            <span class="title">
                <a href="mikronode-ng.html">mikronode-ng</a>
                
                <span class="static">static</span>
                
            </span>
            <ul class="members itemMembers">
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="mikronode-ng.getConnection"><a href="mikronode-ng.html#.getConnection">getConnection</a></li>
            
                <li data-name="mikronode-ng.parseItems"><a href="mikronode-ng.html#.parseItems">parseItems</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="mikronode-ng.Channel">
            <span class="title">
                <a href="mikronode-ng.Channel.html">mikronode-ng.Channel</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="mikronode-ng.Channel#clearEvents"><a href="mikronode-ng.Channel.html#clearEvents">clearEvents</a></li>
            
                <li data-name="mikronode-ng.Channel#closed"><a href="mikronode-ng.Channel.html#closed">closed</a></li>
            
                <li data-name="mikronode-ng.Channel#closeOnDone"><a href="mikronode-ng.Channel.html#closeOnDone">closeOnDone</a></li>
            
                <li data-name="mikronode-ng.Channel#closing"><a href="mikronode-ng.Channel.html#closing">closing</a></li>
            
                <li data-name="mikronode-ng.Channel#id"><a href="mikronode-ng.Channel.html#id">id</a></li>
            
                <li data-name="mikronode-ng.Channel#lastCommand"><a href="mikronode-ng.Channel.html#lastCommand">lastCommand</a></li>
            
                <li data-name="mikronode-ng.Channel#running"><a href="mikronode-ng.Channel.html#running">running</a></li>
            
                <li data-name="mikronode-ng.Channel#saveBuffer"><a href="mikronode-ng.Channel.html#saveBuffer">saveBuffer</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="mikronode-ng.Channel.writeCallback"><a href="mikronode-ng.Channel.html#.writeCallback">writeCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="mikronode-ng.Channel#close"><a href="mikronode-ng.Channel.html#close">close</a></li>
            
                <li data-name="mikronode-ng.Channel#finalize"><a href="mikronode-ng.Channel.html#finalize">finalize</a></li>
            
                <li data-name="mikronode-ng.Channel#write"><a href="mikronode-ng.Channel.html#write">write</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="mikronode-ng.Channel#event:close"><a href="mikronode-ng.Channel.html#event:event:close">event:close</a></li>
            
                <li data-name="mikronode-ng.Channel#event:done"><a href="mikronode-ng.Channel.html#event:event:done">event:done</a></li>
            
                <li data-name="mikronode-ng.Channel#event:error"><a href="mikronode-ng.Channel.html#event:event:error">event:error</a></li>
            
                <li data-name="mikronode-ng.Channel#event:timeout"><a href="mikronode-ng.Channel.html#event:event:timeout">event:timeout</a></li>
            
                <li data-name="mikronode-ng.Channel#event:trap"><a href="mikronode-ng.Channel.html#event:event:trap">event:trap</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="mikronode-ng.Connection">
            <span class="title">
                <a href="mikronode-ng.Connection.html">mikronode-ng.Connection</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="mikronode-ng.Connection#channels"><a href="mikronode-ng.Connection.html#channels">channels</a></li>
            
                <li data-name="mikronode-ng.Connection#closeOnDone"><a href="mikronode-ng.Connection.html#closeOnDone">closeOnDone</a></li>
            
                <li data-name="mikronode-ng.Connection#host"><a href="mikronode-ng.Connection.html#host">host</a></li>
            
                <li data-name="mikronode-ng.Connection#password"><a href="mikronode-ng.Connection.html#password">password</a></li>
            
                <li data-name="mikronode-ng.Connection#port"><a href="mikronode-ng.Connection.html#port">port</a></li>
            
                <li data-name="mikronode-ng.Connection#status"><a href="mikronode-ng.Connection.html#status">status</a></li>
            
                <li data-name="mikronode-ng.Connection#timeout"><a href="mikronode-ng.Connection.html#timeout">timeout</a></li>
            
                <li data-name="mikronode-ng.Connection#tls"><a href="mikronode-ng.Connection.html#tls">tls</a></li>
            
                <li data-name="mikronode-ng.Connection#user"><a href="mikronode-ng.Connection.html#user">user</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            <span class="subtitle">Typedefs</span>
            
                <li data-name="mikronode-ng.Connection.connectCallback"><a href="mikronode-ng.Connection.html#.connectCallback">connectCallback</a></li>
            
            </ul>
            <ul class="methods itemMembers">
            
            <span class="subtitle">Methods</span>
            
                <li data-name="mikronode-ng.Connection.parseItems"><a href="mikronode-ng.Connection.html#.parseItems">parseItems</a></li>
            
                <li data-name="mikronode-ng.Connection#closeChannel"><a href="mikronode-ng.Connection.html#closeChannel">closeChannel</a></li>
            
                <li data-name="mikronode-ng.Connection#connect"><a href="mikronode-ng.Connection.html#connect">connect</a></li>
            
                <li data-name="mikronode-ng.Connection#getChannel"><a href="mikronode-ng.Connection.html#getChannel">getChannel</a></li>
            
                <li data-name="mikronode-ng.Connection#getCommandPromise"><a href="mikronode-ng.Connection.html#getCommandPromise">getCommandPromise</a></li>
            
                <li data-name="mikronode-ng.Connection#getConnectPromise"><a href="mikronode-ng.Connection.html#getConnectPromise">getConnectPromise</a></li>
            
                <li data-name="mikronode-ng.Connection#openChannel"><a href="mikronode-ng.Connection.html#openChannel">openChannel</a></li>
            
            </ul>
            <ul class="events itemMembers">
            
            <span class="subtitle">Events</span>
            
                <li data-name="mikronode-ng.Connection#event:close"><a href="mikronode-ng.Connection.html#event:event:close">event:close</a></li>
            
                <li data-name="mikronode-ng.Connection#event:error"><a href="mikronode-ng.Connection.html#event:event:error">event:error</a></li>
            
                <li data-name="mikronode-ng.Connection#event:timeout"><a href="mikronode-ng.Connection.html#event:event:timeout">event:timeout</a></li>
            
                <li data-name="mikronode-ng.Connection#event:trap"><a href="mikronode-ng.Connection.html#event:event:trap">event:trap</a></li>
            
            </ul>
        </li>
    
        <li class="item" data-name="mikronode-ng.Trap">
            <span class="title">
                <a href="mikronode-ng.Trap.html">mikronode-ng.Trap</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="mikronode-ng.Trap#channel"><a href="mikronode-ng.Trap.html#channel">channel</a></li>
            
                <li data-name="mikronode-ng.Trap#channelId"><a href="mikronode-ng.Trap.html#channelId">channelId</a></li>
            
                <li data-name="mikronode-ng.Trap#errors"><a href="mikronode-ng.Trap.html#errors">errors</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
        <li class="item" data-name="mikronode-ng.TrapError">
            <span class="title">
                <a href="mikronode-ng.TrapError.html">mikronode-ng.TrapError</a>
                
            </span>
            <ul class="members itemMembers">
            
            <span class="subtitle">Members</span>
            
                <li data-name="mikronode-ng.TrapError#category"><a href="mikronode-ng.TrapError.html#category">category</a></li>
            
                <li data-name="mikronode-ng.TrapError#message"><a href="mikronode-ng.TrapError.html#message">message</a></li>
            
            </ul>
            <ul class="typedefs itemMembers">
            
            </ul>
            <ul class="methods itemMembers">
            
            </ul>
            <ul class="events itemMembers">
            
            </ul>
        </li>
    
    </ul>
</div>
    <div class="main">
        <h1 class="page-title" data-filename="mikronode-ng.Connection.html">Class: Connection</h1>
        



<section>
    
<header>
    <h2>
        <span class="ancestors"><a href="mikronode-ng.html">mikronode-ng</a>.</span>
    
    Connection
    </h2>
    
</header>  

<article>
    <div class="container-overview">
    
    
    
        
<dt>
    <div class="nameContainer">
        <h4 class="name" id="Connection">
            
            new mikronode-ng.Connection<span class="signature">(host, user, password, <span class="optional">options</span>)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line109">line 109</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p><strong>An instance of Connection is fully self-contained. You can have as many open<br>in parallel in the same node process as your environment can handle.</strong></p>
<p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>host</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The host name or ip address</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>user</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The user name</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>password</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>The users password</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                
                

<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>port</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    8728
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Sets the port if not the standard 8728 (8729<br>          for TLS).</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>closeOnDone</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If set, when the last channel closes,<br>          the connection will automatically close.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>timeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
                <td class="default">
                
                    0
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Sets the socket inactivity timeout. A timeout<br>          does not necessarily mean that an error has occurred, especially if you're<br>          only listening for events.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>closeOnTimeout</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If set, when a socket timeout<br>          happens the connection will automatically close.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>tls</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>
|

<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Set to true to use TLS for this<br>          connection. Set to an object to use TLS and pass the object to tls.connect<br>          as the tls options. If your device uses self-signed certificates, you'll<br>          either have to set 'rejectUnauthorized : false' or supply the proper CA<br>          certificate. See the options for<br>          <a href="https://nodejs.org/api/tls.html#tls_tls_connect_port_host_options_callback">tls.connect()</a><br>          for more info.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
    <h5>Fires:</h5>
    <ul>
        <li><a href="mikronode-ng.Connection.html#event:event:trap">mikronode-ng.Connection#event:trap</a></li>
    
        <li><a href="mikronode-ng.Connection.html#event:event:error">mikronode-ng.Connection#event:error</a></li>
    
        <li><a href="mikronode-ng.Connection.html#event:event:timeout">mikronode-ng.Connection#event:timeout</a></li>
    
        <li><a href="mikronode-ng.Connection.html#event:event:close">mikronode-ng.Connection#event:close</a></li>
    </ul>
    

    

    
    
    
    <h5>Throws:</h5>
    
            

    <div class="param-desc">
    
        <p><strong>WARNING: If you do not listen for 'error' or 'timeout' events and<br>           one occurrs during the initial connection (host unreachable, connection<br>           refused, etc.), an &quot;Unhandled 'error' event&quot; exception will be thrown.</strong></p>
    
    </div>


        
    
    
    
    
        <h5>Example</h5>
        

    
    <pre class="prettyprint">
var MikroNode = require('mikronode');

var connection = new MikroNode.Connection('192.168.88.1', 'admin', 'mypassword', {
    timeout : 4,
    closeOnDone : true,
    closeOnTimeout : true,
});

connection.on('error', function(err) {
    console.error('Error: ', err);
});

</pre>
    

    
</dd>

    
    </div>
    
    
    
    
    
    
    
    
    
    
    
    
        <h3 class="subsection-title">Members</h3>
        
        <dl>
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="channels"><span class="type-signature ">readonly</span>channels<span class="type-signature type object">object</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Active channels keyed by channel id</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="closeOnDone">closeOnDone<span class="type-signature type boolean">boolean</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>If set, when the last channel closes, the<br>        connection will automatically close.</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="host"><span class="type-signature ">readonly</span>host<span class="type-signature type string">string</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Hostname or ip address</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="password"><span class="type-signature ">readonly</span>password<span class="type-signature type string">string</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Password</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="port"><span class="type-signature ">readonly</span>port<span class="type-signature type number">number</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Port</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    <dt class="tag-default">Default Value:</dt>
    <dd class="tag-default"><ul class="dummy"><li>8728</li></ul></dd>
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="status"><span class="type-signature ">readonly</span>status<span class="type-signature type string">string</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Connection status</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="timeout"><span class="type-signature ">readonly</span>timeout<span class="type-signature type number">number</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Socket inactivity timeout</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="tls"><span class="type-signature ">readonly</span>tls<span class="type-signature type object">object</span> <span class="type-signature type boolean">boolean</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>Set to true to use TLS for this connection<br>        with default options. Set to an object to use TLS and pass the object to<br>        tls.connect as the tls options. If your device uses self-signed<br>        certificates, you'll either need to set 'rejectUnauthorized : false' or<br>        supply the proper CA certificate. See the options for<br>        <a href="https://nodejs.org/api/tls.html#tls_tls_connect_port_host_options_callback">tls.connect()</a><br>        for more info.</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="user"><span class="type-signature ">readonly</span>user<span class="type-signature type string">string</span> </h4>
    </div>
    
    
</dt>
<dd>
    
    <div class="description">
        <p>User ID</p>
    </div>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
</dd>

        </dl>
    
    
    
        <h3 class="subsection-title">Methods</h3>
        
        <dl>
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id=".parseItems">
            
            <span class="type-signature static">static</span>mikronode-ng.Connection.parseItems<span class="signature">(data)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Array.&lt;object>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line237">line 237</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Parse !re return records into an array of objects</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>data</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">Array.&lt;string></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The data[] returned from Channel.on('done')</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="closeChannel">
            
            closeChannel<span class="signature">(id)</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line664">line 664</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Closes the channel specified by id.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>id</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The id of the channel to close</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="connect">
            
            connect<span class="signature">(callback)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="mikronode-ng.Connection.html">mikronode-ng.Connection</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line466">line 466</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Opens the socket and performs authentication</p>
    </div>
    

    
    
    
    
    
        

<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="mikronode-ng.Connection.html#.connectCallback">mikronode-ng.Connection.connectCallback</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>Called when<br>          authentication succeeds and the connection is ready for channel activity</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    
    <h5>Fires:</h5>
    <ul>
        <li><a href="mikronode-ng.Connection.html#event:event:trap">mikronode-ng.Connection#event:trap</a></li>
    
        <li><a href="mikronode-ng.Connection.html#event:event:error">mikronode-ng.Connection#event:error</a></li>
    
        <li><a href="mikronode-ng.Connection.html#event:event:timeout">mikronode-ng.Connection#event:timeout</a></li>
    
        <li><a href="mikronode-ng.Connection.html#event:event:close">mikronode-ng.Connection#event:close</a></li>
    </ul>
    

    

    
    
    
    <h5>Throws:</h5>
    
            

    <div class="param-desc">
    
        <p><strong>WARNING: If you do not listen for 'error' or 'timeout' events and an<br>           error occurrs during the initial connection (host unreachable, connection<br>           refused, etc.), an &quot;Unhandled 'error' event&quot; exception will be thrown.</strong></p>
    
    </div>


        
    
    
    
    


    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="getChannel">
            
            getChannel<span class="signature">(id)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="mikronode-ng.Channel.html">mikronode-ng.Channel</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line648">line 648</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Returns the channel specified by id.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>id</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>
            
            
            
            <td class="description last">
                
                <p>The id of the channel desired</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="getCommandPromise">
            
            getCommandPromise<span class="signature">(data, <span class="optional">parameters</span>, <span class="optional">options</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line871">line 871</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>** Returnes a Promise of a completed command.</p>
<p><p><br>The promise will resolve when the command completes or reject if there's an error or<br>trap. If resolved, the result will be an array of instances of DestinationClass (or<br>Object, if no destination class was specified). If rejected, the result will be an<br>Error if there was a socket error or timeout, or a <a href="mikronode-ng.Trap.html"><code>mikronode-ng.Trap</code></a> if the<br>command failed on the device.</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</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.&lt;string></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                    
                        
                    
                
                <p>Can be a single string with the command and<br>          optional parameters separated by '\n' or an array of strings with the<br>          command in the first position and the parameters in the rest.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>parameters</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>
|

<span class="param-type">Array.&lt;string></span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If the first parameter is a command<br>          string, this object will be treated as the parameters for the command.<br>          <p><br>          It can be an array or strings...</p>
<pre>
['name=value','name=value'...]
</pre>

<p>or an Object...</p>
<pre>
{'name': 'value', 'name': 'value'...}
</pre></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>options</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">object</span>


            
            </td>
            
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>A set of options that determine what to do with the<br>          return data (if any). If neither dataClass nor itemClass are provided, the<br>          default behavior will be as though itemClass were set to Object. This will<br>          result in Promise.resolve() being called with an array of plain Objects,<br>          one for each parsed item.</p>
                

<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>closeOnDone</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    true
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If true, the channel will<br>          automatically close when the command completes.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>dontParse</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
                <td class="default">
                
                    false
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If true, Promise.resolve() will be<br>          called with the unaltered data array provided by the channel's 'done'<br>          event. with the unaltered data array provided by the channel's 'done'<br>          event.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>dataClass</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">class</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If provided, this class will be instantiated<br>          with the data array provided by the channel's 'done' event as the<br>          constructor's sole argument. Promise.resolve() will then be called with<br>          this object.</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>itemClass</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">class</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If provided, {mikronode-ng.parseItems} will be<br>          called on the returned data and this class will be instantiated once for<br>          each resulting item. The item object will be passed as the sole argument<br>          to the constructor. An array of itemClass objects will be passed to<br>          Promise.resolve().</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>itemKey</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>If provided, instead of an array of parsed<br>          objects being passed to Promise.resolve(), the parsed objects will be<br>          added to a wrapper object using the value of itemKey as the property name.</p></td>
        </tr>
	
	
	</tbody>
</table>
            </td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


<h5>Returns:</h5>
promise will have a channel property added which will be set<br>        to the channel used to fulfill the promise.
<br />

    
    
    
        <h5>Example</h5>
        

    
    <pre class="prettyprint">

function Interface(intf) {
    var _this = this;
    Object.keys(intf).forEach(function(key) {
        _this[key] = intf[key];
    });
}

var chan1Promise = conn.getCommandPromise('/interface/print', {
    itemClass : Interface,
    itemKey : 'name'
});

chan1Promise.then(function(values){
// It succeeded. You'll have a hash of Interfaces keyed by interface name.
});

chan1Promise.catch(function(result){
// It failed. result will tell you why.
});
</pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="getConnectPromise">
            
            getConnectPromise<span class="signature">()</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{Promise}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line755">line 755</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Returns a Promise for an open connection.</p>
<p><p><br>The promise will resolve when the connection is ready for use or reject if there's<br>an error or trap. If resolved, the result object will be the<br><a href="mikronode-ng.Connection.html"><code>mikronode-ng.Connection</code></a> with authentication completed and ready for<br>channels. If rejected, the result object will be an Error if there was a socket<br>error or timeout during connection or login or a <a href="mikronode-ng.Trap.html"><code>mikronode-ng.Trap</code></a> if there<br>was a problem with the login credentials.</p>
<p>
    </div>
    

    
    
    
    
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
        <h5>Example</h5>
        

    
    <pre class="prettyprint">
var MikroNode = require('mikronode');

var connection = new MikroNode.Connection(process.argv[2], process.argv[3], process.argv[4], {
    closeOnDone : true
});

var connPromise = connection.getConnectPromise().then(function resolve(conn) {
// You now have an open, authenticated connection
// To issue some commands see <a href="mikronode-ng.Connection.html#getCommandPromise"><code>getCommandPromise</code></a>
});
</pre>
    

    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="openChannel">
            
            openChannel<span class="signature">(<span class="optional">id</span>)</span><span class="glyphicon glyphicon-circle-arrow-right"></span><span class="type-signature returnType">{<a href="mikronode-ng.Channel.html">mikronode-ng.Channel</a>}</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line624">line 624</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Opens a new Channel</p>
    </div>
    

    
    
    
    
    
        

<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>id</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
                <td class="default">
                
                    next available
                
                </td>
            
            
            <td class="description last">
                
                    
                        <span class="optional">optional</span>
                    
                    
                        
                    
                
                <p>Automatically assigned ids are numbers but you<br>          can specify any string.</p></td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    


    
    
    
</dd>

        </dl>
    
    
    
        <h3 class="subsection-title">Type Definitions</h3>
        
        <dl>
                
<dt>
    <div class="nameContainer">
        <h4 class="name" id=".connectCallback">
            
            mikronode-ng.Connection.connectCallback<span class="signature">()</span>
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line447">line 447</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Called when the connection is established and authenticated</p>
    </div>
    

    
    
    
    
    
        

<table class="params">
    <thead>
	<tr>
		
		
		<th>Type</th>
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="mikronode-ng.Connection.html">mikronode-ng.Connection</a></span>


            
            </td>
            
            
            
            <td class="description last">
                
                </td>
        </tr>
	
	
	</tbody>
</table>
    
    
    
<dl class="details">
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

            </dl>
    
    
    
        <h3 class="subsection-title">Events</h3>
        
        <dl>
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="event:event:close">
            
            event:close
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line41">line 41</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Emitted when the connection is closed either by an explicit call to<br><code>mikronode-ng.Connection#close</code> or when the connection is closed automatically<br>via <a href="mikronode-ng.Connection.html#closeOnDone"><code>mikronode-ng.Connection#closeOnDone</code></a></p>
    </div>
    

    
    
    
    
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="mikronode-ng.Connection.html">mikronode-ng.Connection</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection originating the<br>          event</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="event:event:error">
            
            event:error
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line25">line 25</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Emitted when a non-recoverable error has occurred on the socket. No further commands<br>can be processed on any channel.</p>
    </div>
    

    
    
    
    
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>error</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">error</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The error object</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="mikronode-ng.Connection.html">mikronode-ng.Connection</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection originating the<br>          event</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="event:event:timeout">
            
            event:timeout
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line33">line 33</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Emitted when a socket has been idle too long.</p>
    </div>
    

    
    
    
    
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>message</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>'Socket Timeout'</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>socketStillOpen</code></td>
            
            
            <td class="type">
            
                
<span class="param-type">boolean</span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>If true, communications can continue</p></td>
        </tr>
	
	
	
        <tr>
            
                <td class="name"><code>connection</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="mikronode-ng.Connection.html">mikronode-ng.Connection</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The connection originating the<br>          event</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

        
            
<dt>
    <div class="nameContainer">
        <h4 class="name" id="event:event:trap">
            
            event:trap
        </h4>
    
        
        <div class="tag-source">
            <a href="connection.js.html">connection.js</a>, <a href="connection.js.html#line49">line 49</a>
        </div>
        
    </div>

    
</dt>
<dd>
    
    
    <div class="description">
        <p>Emitted when a login has failed. No further commands can be processed on any<br>channel.</p>
    </div>
    

    
    
    
    
    
    
    
<dl class="details">
    
        
        <h5 class="subsection-title">Properties:</h5>
        
        <dl>

<table class="props">
    <thead>
	<tr>
		
		<th>Name</th>
		
		
		<th>Type</th>
		
		
		
		
		
		<th class="last">Description</th>
	</tr>
	</thead>
	
	<tbody>
	
	
        <tr>
            
                <td class="name"><code>trap</code></td>
            
            
            <td class="type">
            
                
<span class="param-type"><a href="mikronode-ng.Trap.html">mikronode-ng.Trap</a></span>


            
            </td>
            
            
            
            
            
            <td class="description last"><p>The trap object</p></td>
        </tr>
	
	
	</tbody>
</table></dl>
        
    
        
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
</dl>

    
    

    

    
    
    
    
    
    
    
</dd>

        </dl>
    
</article>

</section>  





        

        <footer>
            Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Wed Jul 06 2016 06:45:18 GMT-0600 (MDT)
        </footer>
    </div>
</div>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/main.js"></script>
</body>
</html>