Difference between revisions of "Device (Java)"

From Neurotech Software Development Kit
Jump to: navigation, search
(Created page with "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- NewPage --> <html lang="en"> <head> <!-- Generated by javadoc (1.8....")
 
(See also)
 
(30 intermediate revisions by the same user not shown)
Line 1: Line 1:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
ru.neuromd.neurosdk
<!-- NewPage -->
+
 
<html lang="en">
+
<span style="font-size: 150%;">'''Class Device'''</span>
<head>
+
 
<!-- Generated by javadoc (1.8.0_152-release) on Wed Apr 25 14:11:42 MSK 2018 -->
+
==Related Classes==
<title>Device</title>
+
 
<meta name="date" content="2018-04-25">
+
ru.neuromd.neurosdk.[[DeviceScanner (Java)|DeviceScanner]]
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
+
 
<script type="text/javascript" src="../../../script.js"></script>
+
==Classes hierarchy==
</head>
+
<ul>
<body>
 
<script type="text/javascript"><!--
 
    try {
 
        if (location.href.indexOf('is-external=true') == -1) {
 
            parent.document.title="Device";
 
        }
 
    }
 
    catch(err) {
 
    }
 
//-->
 
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10};
 
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
 
var altColor = "altColor";
 
var rowColor = "rowColor";
 
var tableTab = "tableTab";
 
var activeTableTab = "activeTableTab";
 
</script>
 
<noscript>
 
<div>JavaScript is disabled on your browser.</div>
 
</noscript>
 
<!-- ========= START OF TOP NAVBAR ======= -->
 
<div class="topNav"><a name="navbar.top">
 
<!--  -->
 
</a>
 
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
 
<a name="navbar.top.firstrow">
 
<!--  -->
 
</a>
 
<ul class="navList" title="Navigation">
 
<li><a href="../../../overview-summary.html">Overview</a></li>
 
<li><a href="package-summary.html">Package</a></li>
 
<li class="navBarCell1Rev">Class</li>
 
<li><a href="package-tree.html">Tree</a></li>
 
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
 
<li><a href="../../../index-files/index-1.html">Index</a></li>
 
<li><a href="../../../help-doc.html">Help</a></li>
 
</ul>
 
</div>
 
<div class="subNav">
 
<ul class="navList">
 
<li>Prev&nbsp;Class</li>
 
<li><a href="../../../ru/neurotech/neurosdk/DeviceScanner.html" title="class in ru.neurotech.neurosdk"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
 
</ul>
 
<ul class="navList">
 
<li><a href="../../../index.html?ru/neurotech/neurosdk/Device.html" target="_top">Frames</a></li>
 
<li><a href="Device.html" target="_top">No&nbsp;Frames</a></li>
 
</ul>
 
<ul class="navList" id="allclasses_navbar_top">
 
<li><a href="../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
 
</ul>
 
<div>
 
<script type="text/javascript"><!--
 
  allClassesLink = document.getElementById("allclasses_navbar_top");
 
  if(window==top) {
 
    allClassesLink.style.display = "block";
 
  }
 
  else {
 
    allClassesLink.style.display = "none";
 
  }
 
  //-->
 
</script>
 
</div>
 
<div>
 
<ul class="subNavList">
 
<li>Summary:&nbsp;</li>
 
<li>Nested&nbsp;|&nbsp;</li>
 
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
 
<li>Constr&nbsp;|&nbsp;</li>
 
<li><a href="#method.summary">Method</a></li>
 
</ul>
 
<ul class="subNavList">
 
<li>Detail:&nbsp;</li>
 
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
 
<li>Constr&nbsp;|&nbsp;</li>
 
<li><a href="#method.detail">Method</a></li>
 
</ul>
 
</div>
 
<a name="skip.navbar.top">
 
<!--  -->
 
</a></div>
 
<!-- ========= END OF TOP NAVBAR ========= -->
 
<!-- ======== START OF CLASS DATA ======== -->
 
<div class="header">
 
<div class="subTitle">ru.neurotech.neurosdk</div>
 
<h2 title="Class Device" class="title">Class Device</h2>
 
</div>
 
<div class="contentContainer">
 
<ul class="inheritance">
 
 
<li>java.lang.Object</li>
 
<li>java.lang.Object</li>
<li>
+
<ul>
<ul class="inheritance">
+
<li>ru.neuromd.neurosdk.'''Device'''</li>
<li>ru.neurotech.neurosdk.Device</li>
 
</ul>
 
</li>
 
</ul>
 
<div class="description">
 
<ul class="blockList">
 
<li class="blockList">
 
<hr>
 
<br>
 
<pre>public class <span class="typeNameLabel">Device</span>
 
extends java.lang.Object</pre>
 
</li>
 
</ul>
 
</div>
 
<div class="summary">
 
<ul class="blockList">
 
<li class="blockList">
 
<!-- =========== FIELD SUMMARY =========== -->
 
<ul class="blockList">
 
<li class="blockList"><a name="field.summary">
 
<!--  -->
 
</a>
 
<h3>Field Summary</h3>
 
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation">
 
<caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption>
 
<tr>
 
<th class="colFirst" scope="col">Modifier and Type</th>
 
<th class="colLast" scope="col">Field and Description</th>
 
</tr>
 
<tr class="altColor">
 
<td class="colFirst"><code><a href="../../../ru/neurotech/common/SubscribersNotifier.html" title="class in ru.neurotech.common">SubscribersNotifier</a>&lt;<a href="../../../ru/neurotech/neurosdk/parameters/ParameterName.html" title="enum in ru.neurotech.neurosdk.parameters">ParameterName</a>&gt;</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#parameterChanged">parameterChanged</a></span></code>
 
<div class="block">Subscribe this event to receive notifications about changes of device parameters</div>
 
</td>
 
</tr>
 
</table>
 
</li>
 
</ul>
 
<!-- ========== METHOD SUMMARY =========== -->
 
<ul class="blockList">
 
<li class="blockList"><a name="method.summary">
 
<!--  -->
 
</a>
 
<h3>Method Summary</h3>
 
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
 
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
 
<tr>
 
<th class="colFirst" scope="col">Modifier and Type</th>
 
<th class="colLast" scope="col">Method and Description</th>
 
</tr>
 
<tr id="i0" class="altColor">
 
<td class="colFirst"><code><a href="../../../ru/neurotech/neurosdk/channels/ChannelInfo.html" title="interface in ru.neurotech.neurosdk.channels">ChannelInfo</a>[]</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#channels--">channels</a></span>()</code>
 
<div class="block">Returns information about supported channels
 
Check this information before creation of channel.</div>
 
</td>
 
</tr>
 
<tr id="i1" class="rowColor">
 
<td class="colFirst"><code><a href="../../../ru/neurotech/neurosdk/parameters/Command.html" title="enum in ru.neurotech.neurosdk.parameters">Command</a>[]</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#commands--">commands</a></span>()</code>
 
<div class="block">Returns supported commands of device</div>
 
</td>
 
</tr>
 
<tr id="i2" class="altColor">
 
<td class="colFirst"><code>void</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#connect--">connect</a></span>()</code>
 
<div class="block">Tries to establish connection with device
 
Check DeviceState parameter or subscribe parameterChanged event for operation result</div>
 
</td>
 
</tr>
 
<tr id="i3" class="rowColor">
 
<td class="colFirst"><code>void</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#disconnect--">disconnect</a></span>()</code>
 
<div class="block">Disconnects from device
 
Check DeviceState parameter or subscribe parameterChanged event for operation result</div>
 
</td>
 
</tr>
 
<tr id="i4" class="altColor">
 
<td class="colFirst"><code>boolean</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#execute-ru.neurotech.neurosdk.parameters.Command-">execute</a></span>(<a href="../../../ru/neurotech/neurosdk/parameters/Command.html" title="enum in ru.neurotech.neurosdk.parameters">Command</a>&nbsp;cmd)</code>
 
<div class="block">Tries to execute command and returns value indicating operations success.</div>
 
</td>
 
</tr>
 
<tr id="i5" class="rowColor">
 
<td class="colFirst"><code>void</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#finalize--">finalize</a></span>()</code>&nbsp;</td>
 
</tr>
 
<tr id="i6" class="altColor">
 
<td class="colFirst"><code><a href="../../../ru/neurotech/neurosdk/parameters/Parameter.html" title="class in ru.neurotech.neurosdk.parameters">Parameter</a>[]</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#parameters--">parameters</a></span>()</code>
 
<div class="block">Returns all available parameters of device, their types and access rights</div>
 
</td>
 
</tr>
 
<tr id="i7" class="rowColor">
 
<td class="colFirst"><code>&lt;ParamType&gt;<br>ParamType</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#readParam-ru.neurotech.neurosdk.parameters.ParameterName-">readParam</a></span>(<a href="../../../ru/neurotech/neurosdk/parameters/ParameterName.html" title="enum in ru.neurotech.neurosdk.parameters">ParameterName</a>&nbsp;param)</code>
 
<div class="block">Return value of specified parameter of device.</div>
 
</td>
 
</tr>
 
<tr id="i8" class="altColor">
 
<td class="colFirst"><code>boolean</code></td>
 
<td class="colLast"><code><span class="memberNameLink"><a href="../../../ru/neurotech/neurosdk/Device.html#setParam-ru.neurotech.neurosdk.parameters.ParameterName-java.lang.Object-">setParam</a></span>(<a href="../../../ru/neurotech/neurosdk/parameters/ParameterName.html" title="enum in ru.neurotech.neurosdk.parameters">ParameterName</a>&nbsp;param,
 
        java.lang.Object&nbsp;value)</code>
 
<div class="block">Sets value for specified parameter and returns value indicating success of operation.</div>
 
</td>
 
</tr>
 
</table>
 
<ul class="blockList">
 
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
 
<!--  -->
 
</a>
 
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
 
<code>clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
 
</ul>
 
</li>
 
</ul>
 
</li>
 
</ul>
 
</div>
 
<div class="details">
 
<ul class="blockList">
 
<li class="blockList">
 
<!-- ============ FIELD DETAIL =========== -->
 
<ul class="blockList">
 
<li class="blockList"><a name="field.detail">
 
<!--  -->
 
</a>
 
<h3>Field Detail</h3>
 
<a name="parameterChanged">
 
<!--  -->
 
</a>
 
<ul class="blockListLast">
 
<li class="blockList">
 
<h4>parameterChanged</h4>
 
<pre>public final&nbsp;<a href="../../../ru/neurotech/common/SubscribersNotifier.html" title="class in ru.neurotech.common">SubscribersNotifier</a>&lt;<a href="../../../ru/neurotech/neurosdk/parameters/ParameterName.html" title="enum in ru.neurotech.neurosdk.parameters">ParameterName</a>&gt; parameterChanged</pre>
 
<div class="block">Subscribe this event to receive notifications about changes of device parameters</div>
 
</li>
 
</ul>
 
</li>
 
</ul>
 
<!-- ============ METHOD DETAIL ========== -->
 
<ul class="blockList">
 
<li class="blockList"><a name="method.detail">
 
<!--  -->
 
</a>
 
<h3>Method Detail</h3>
 
<a name="finalize--">
 
<!--  -->
 
</a>
 
<ul class="blockList">
 
<li class="blockList">
 
<h4>finalize</h4>
 
<pre>public&nbsp;void&nbsp;finalize()
 
              throws java.lang.Throwable</pre>
 
<dl>
 
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
 
<dd><code>finalize</code>&nbsp;in class&nbsp;<code>java.lang.Object</code></dd>
 
<dt><span class="throwsLabel">Throws:</span></dt>
 
<dd><code>java.lang.Throwable</code></dd>
 
</dl>
 
</li>
 
</ul>
 
<a name="connect--">
 
<!--  -->
 
</a>
 
<ul class="blockList">
 
<li class="blockList">
 
<h4>connect</h4>
 
<pre>public&nbsp;void&nbsp;connect()</pre>
 
<div class="block">Tries to establish connection with device
 
Check DeviceState parameter or subscribe parameterChanged event for operation result</div>
 
</li>
 
 
</ul>
 
</ul>
<a name="disconnect--">
 
<!--  -->
 
</a>
 
<ul class="blockList">
 
<li class="blockList">
 
<h4>disconnect</h4>
 
<pre>public&nbsp;void&nbsp;disconnect()</pre>
 
<div class="block">Disconnects from device
 
Check DeviceState parameter or subscribe parameterChanged event for operation result</div>
 
</li>
 
 
</ul>
 
</ul>
<a name="channels--">
+
 
<!--   -->
+
==Class definition==
</a>
+
<code><span style="color:#0066FF;">'''public class'''</span> Device</code>
<ul class="blockList">
+
 
<li class="blockList">
+
The Device class is an abstraction for NeuroMD BLE devices. This abstraction provides functions for changing of device state by executing commands and setting parameters. Each device have different sets of supported commands and parameters, Device class has functions designed to get information about these sets. Callibri and Braibit devices has different parameters sets and provides different ways to access them. Device class hides all differences behind its interface and provides universal way to read and write parameters, execute commands and receive biopotential signals.
<h4>channels</h4>
+
 
<pre>public&nbsp;<a href="../../../ru/neurotech/neurosdk/channels/ChannelInfo.html" title="interface in ru.neurotech.neurosdk.channels">ChannelInfo</a>[]&nbsp;channels()</pre>
+
==Fields Summary==
<div class="block">Returns information about supported channels
+
{| class="wikitable"
Check this information before creation of channel. If device does not support channel,
+
|- style="background-color: #dee3e9;"
channel object won't be initialized with it</div>
+
|'''Modifier and Type'''
 +
|'''Field and Description'''
 +
|- valign="top"
 +
|[[SubscribersNotifier Class|SubscribersNotifier]]&lt;'''[[ParameterName (Java)|ParameterName]]'''&gt;
 +
|[[#parameterChanged|'''parameterChanged''']]
 +
Subscribe this event to receive notifications about changes of device parameters
 +
|}
 +
 
 +
==Constructor Summary==
 +
You are not able to create Device directly. Use [[DeviceScanner (Java)|DeviceScanner]] to find and create devices
 +
 
 +
==Methods Summary==
 +
{| class="wikitable"
 +
|- style="background-color: #dee3e9;"
 +
|'''Modifier and Type'''
 +
|'''Method and Description'''
 +
|- valign="top"
 +
|style="color:#0066FF;" |'''void'''
 +
|[[#connect|connect]]()
 +
Establishes connection with device services
 +
|- valign="top"
 +
|style="color:#0066FF;" |'''void'''
 +
|[[#disconnect|disconnect]]()
 +
Disconnects from device
 +
|- valign="top"
 +
|[[ChannelInfo (java)|ChannelInfo]][]
 +
|[[#channels|channels]]()
 +
Returns information about supported channels.
 +
Check this information before creation of channel. If device does not support channel,
 +
channel object won't be initialized.
 +
|- valign="top"
 +
|[[Command (java)|Command]][]
 +
|[[#commands|commands]]()
 +
Returns supported commands of a device
 +
|- valign="top"
 +
|[[Parameter (Java)|Parameter]][]
 +
|[[#parameters|parameters]]()
 +
Returns all available parameters of device, their types and access rights
 +
|- valign="top"
 +
|style="color:#0066FF;" |'''boolean'''
 +
|[[#execute|execute]]()
 +
Tries to execute command and returns value indicating operation success.
 +
|- valign="top"
 +
|style="color:#0066FF;" |'''boolean'''
 +
|[[#setParam|setParam]]()
 +
Sets value for specified parameter and returns value indicating success of operation.
 +
|- valign="top"
 +
|style="color:#0066FF;" |<ParamType>
 +
ParamType
 +
|[[#readParam|readParam]]()
 +
Return value of specified parameter of device.
 +
|}
 +
 
 +
==Field Detail==
 +
<h3>parameterChanged</h3>
 +
<code><span style="color:#0066FF;">'''public final'''</span> [[SubscribersNotifier Class|SubscribersNotifier]]&lt;[[ParameterName (java)|ParameterName]]&gt; parameterChanged</code>
 +
 
 +
Subscribe this event to receive notifications about changes of device parameters
 +
 
 +
==Method Detail==
 +
<h3>connect</h3>
 +
<code><span style="color:#0066FF;">'''public void'''</span> connect()</code>
 +
 
 +
Tries to establish connection with device. Check DeviceState parameter or subscribe parameterChanged event for operation result.
 +
 
 +
<h3>disconnect</h3>
 +
<code><span style="color:#0066FF;">'''public void'''</span> disconnect()</code>
 +
 
 +
Disconnects from device. Check DeviceState parameter or subscribe parameterChanged event for operation result
 +
 
 +
<h3>channels</h3>
 +
<code><span style="color:#0066FF;">'''public'''</span> [[ChannelInfo (Java)|ChannelInfo]][] channels()</code>
 +
 
 +
Returns information about supported channels.
 +
 
 +
Check this information before creation of channel. If device does not support channel,
 +
channel object won't be initialized with it.
 
<dl>
 
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
 
<dd>Array of channel info objects</dd>
 
<dd>Array of channel info objects</dd>
 
</dl>
 
</dl>
</li>
+
 
</ul>
+
<h3>commands</h3>
<a name="commands--">
+
<code><span style="color:#0066FF;">'''public'''</span> [[Command (Java)|Command]][] commands()</code>
<!--  -->
+
 
</a>
+
Returns supported commands of device
<ul class="blockList">
 
<li class="blockList">
 
<h4>commands</h4>
 
<pre>public&nbsp;<a href="../../../ru/neurotech/neurosdk/parameters/Command.html" title="enum in ru.neurotech.neurosdk.parameters">Command</a>[]&nbsp;commands()</pre>
 
<div class="block">Returns supported commands of device</div>
 
 
<dl>
 
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
 
<dd>Array of supported commands</dd>
 
<dd>Array of supported commands</dd>
 
</dl>
 
</dl>
</li>
+
 
</ul>
+
<h3>parameters</h3>
<a name="parameters--">
+
<code><span style="color:#0066FF;">'''public'''</span> [[Parameter (Java)|Parameter]][] parameters()</code>
<!--  -->
+
 
</a>
+
Returns all available parameters of device, their types and access rights
<ul class="blockList">
 
<li class="blockList">
 
<h4>parameters</h4>
 
<pre>public&nbsp;<a href="../../../ru/neurotech/neurosdk/parameters/Parameter.html" title="class in ru.neurotech.neurosdk.parameters">Parameter</a>[]&nbsp;parameters()</pre>
 
<div class="block">Returns all available parameters of device, their types and access rights</div>
 
 
<dl>
 
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
 
<dd>Array of available parameters</dd>
 
<dd>Array of available parameters</dd>
 
</dl>
 
</dl>
</li>
+
 
</ul>
+
<h3>execute</h3>
<a name="execute-ru.neurotech.neurosdk.parameters.Command-">
+
<code><span style="color:#0066FF;">'''public boolean'''</span>&nbsp;execute([[Command (Java)|Command]] cmd)</code>
<!--  -->
+
 
</a>
+
Tries to execute command and returns value indicating operations success.  
<ul class="blockList">
+
 
<li class="blockList">
+
Will throw if device does not support specified command. To get supported commands call commands() method.
<h4>execute</h4>
 
<pre>public&nbsp;boolean&nbsp;execute(<a href="../../../ru/neurotech/neurosdk/parameters/Command.html" title="enum in ru.neurotech.neurosdk.parameters">Command</a>&nbsp;cmd)</pre>
 
<div class="block">Tries to execute command and returns value indicating operations success. Will throw if
 
device does not support specified command. To get supported commands call commands() method</div>
 
 
<dl>
 
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
+
<dt><span>Parameters:</span></dt>
<dd><code>cmd</code> - Command to execute</dd>
+
<dd>cmd - Command to execute</dd>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
 
<dd>Operation success indicator</dd>
 
<dd>Operation success indicator</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
+
<dt><span>Throws:</span></dt>
<dd><code>java.lang.UnsupportedOperationException</code></dd>
+
<dd>java.lang.UnsupportedOperationException</dd>
 
</dl>
 
</dl>
</li>
+
 
</ul>
+
<h3>readParam</h3>
<a name="readParam-ru.neurotech.neurosdk.parameters.ParameterName-">
+
<code><span style="color:#0066FF;">'''public'''</span><ParamType> ParamType readParam([[ParameterName (Java)|ParameterName]] param)</code>
<!--  -->
+
 
</a>
+
Return value of specified parameter of device.  
<ul class="blockList">
+
 
<li class="blockList">
+
Will throw if parameter does not present in device. To get supported parameters and type information for parameter call parameters()
<h4>readParam</h4>
+
method. It returns Parameter object which consists of parameter name, type and access mode.
<pre>public&nbsp;&lt;ParamType&gt;&nbsp;ParamType&nbsp;readParam(<a href="../../../ru/neurotech/neurosdk/parameters/ParameterName.html" title="enum in ru.neurotech.neurosdk.parameters">ParameterName</a>&nbsp;param)</pre>
+
 
<div class="block">Return value of specified parameter of device. Will throw if parameter does not present in
 
device. To get supported parameters and type information for parameter call parameters()
 
method. It returns Parameter object which consists of parameter name, type and access mode</div>
 
 
<dl>
 
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
+
<dt><span>Parameters:</span></dt>
<dd><code>param</code> - ParameterName to read</dd>
+
<dd>param - ParameterName to read</dd>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
 
<dd>Parameter value</dd>
 
<dd>Parameter value</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
+
<dt><span>Throws:</span></dt>
<dd><code>java.lang.UnsupportedOperationException</code></dd>
+
<dd>java.lang.UnsupportedOperationException</dd>
 
</dl>
 
</dl>
</li>
+
 
</ul>
+
<h3>setParam</h3>
<a name="setParam-ru.neurotech.neurosdk.parameters.ParameterName-java.lang.Object-">
+
<code><span style="color:#0066FF;">'''public boolean'''</span>&nbsp;setParam([[ParameterName (Java)|ParameterName]] param, Object value)</code>
<!--  -->
+
 
</a>
+
Sets value for specified parameter and returns value indicating success of operation.  
<ul class="blockListLast">
+
 
<li class="blockList">
+
Will throw if parameter does not present in device or has only Read access mode. To get supported
<h4>setParam</h4>
+
parameters and type information for parameter call parameters() method. It returns Parameter
<pre>public&nbsp;boolean&nbsp;setParam(<a href="../../../ru/neurotech/neurosdk/parameters/ParameterName.html" title="enum in ru.neurotech.neurosdk.parameters">ParameterName</a>&nbsp;param,
+
object which consists of parameter name, type and access mode
                        java.lang.Object&nbsp;value)</pre>
 
<div class="block">Sets value for specified parameter and returns value indicating success of operation. Will
 
throw if parameter does not present in device or has only Read access mode. To get supported
 
parameters and type information for parameter call parameters() method. It returns Parameter
 
object which consists of parameter name, type and access mode</div>
 
 
<dl>
 
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
+
<dt><span>Parameters:</span></dt>
<dd><code>param</code> - Name of parameter to set</dd>
+
<dd>param - Name of parameter to set</dd>
<dd><code>value</code> - Parameter value</dd>
+
<dd>value - Parameter value</dd>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
<dd>Operation success</dd>
+
<dd>Operation success indicator</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
+
<dt><span>Throws:</span></dt>
<dd><code>java.lang.UnsupportedOperationException</code></dd>
+
<dd>java.lang.UnsupportedOperationException</dd>
 
</dl>
 
</dl>
</li>
+
 
</ul>
+
==Example==
</li>
+
This example shows how to find devices and list their features
</ul>
+
 
</li>
+
<syntaxhighlight lang="java">
</ul>
+
import com.neuromd.common.INotificationCallback;
</div>
+
import com.neuromd.neurosdk.Device;
</div>
+
import com.neuromd.neurosdk.DeviceScanner;
<!-- ========= END OF CLASS DATA ========= -->
+
import com.neuromd.neurosdk.channels.ChannelInfo;
<!-- ======= START OF BOTTOM NAVBAR ====== -->
+
import com.neuromd.neurosdk.parameters.Command;
<div class="bottomNav"><a name="navbar.bottom">
+
import com.neuromd.neurosdk.parameters.Parameter;
<!--  -->
+
import com.neuromd.neurosdk.parameters.ParameterName;
</a>
+
import com.neuromd.neurosdk.parameters.types.DeviceState;
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
+
 
<a name="navbar.bottom.firstrow">
+
public class DeviceInfoActivity extends AppCompatActivity
<!--  -->
+
{
</a>
+
    private DeviceScanner mScanner;
<ul class="navList" title="Navigation">
+
    @Override
<li><a href="../../../overview-summary.html">Overview</a></li>
+
    protected void onCreate(Bundle savedInstanceState)
<li><a href="package-summary.html">Package</a></li>
+
    {
<li class="navBarCell1Rev">Class</li>
+
        super.onCreate(savedInstanceState);
<li><a href="package-tree.html">Tree</a></li>
+
        setContentView(R.layout.activity_device_info);
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
+
   
<li><a href="../../../index-files/index-1.html">Index</a></li>
+
        requestPermissions();
<li><a href="../../../help-doc.html">Help</a></li>
+
        enableBtAndGeolocation();
</ul>
+
        initScanner();
</div>
+
        initButtons();
<div class="subNav">
+
    }
<ul class="navList">
+
   
<li>Prev&nbsp;Class</li>
+
    private void initScanner()
<li><a href="../../../ru/neurotech/neurosdk/DeviceScanner.html" title="class in ru.neurotech.neurosdk"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
+
    {
</ul>
+
        mScanner = new DeviceScanner(getApplicationContext());
<ul class="navList">
+
        mScanner.scanStateChanged.subscribe(new INotificationCallback<Boolean>()
<li><a href="../../../index.html?ru/neurotech/neurosdk/Device.html" target="_top">Frames</a></li>
+
        {
<li><a href="Device.html" target="_top">No&nbsp;Frames</a></li>
+
            @Override
</ul>
+
            public void onNotify(Object o, final Boolean isScanning)
<ul class="navList" id="allclasses_navbar_bottom">
+
            {
<li><a href="../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
+
                runOnUiThread(new Runnable()
</ul>
+
                {
<div>
+
                    @Override
<script type="text/javascript"><!--
+
                    public void run()
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
+
                    {
  if(window==top) {
+
                        Button startButton = findViewById(R.id.startScanButton);
    allClassesLink.style.display = "block";
+
                        Button stopButton = findViewById(R.id.stopScanButton);
  }
+
                        startButton.setEnabled(!isScanning);
  else {
+
                        stopButton.setEnabled(isScanning);
    allClassesLink.style.display = "none";
+
                    }
  }
+
                });
  //-->
+
            }
</script>
+
        });
</div>
+
        mScanner.deviceFound.subscribe(new INotificationCallback<Device>()
<div>
+
        {
<ul class="subNavList">
+
            @Override
<li>Summary:&nbsp;</li>
+
            public void onNotify(Object o, Device device)
<li>Nested&nbsp;|&nbsp;</li>
+
            {
<li><a href="#field.summary">Field</a>&nbsp;|&nbsp;</li>
+
                onDeviceFound(device);
<li>Constr&nbsp;|&nbsp;</li>
+
            }
<li><a href="#method.summary">Method</a></li>
+
        });
</ul>
+
    }
<ul class="subNavList">
+
   
<li>Detail:&nbsp;</li>
+
    private void requestPermissions(){
<li><a href="#field.detail">Field</a>&nbsp;|&nbsp;</li>
+
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
<li>Constr&nbsp;|&nbsp;</li>
+
        {
<li><a href="#method.detail">Method</a></li>
+
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
</ul>
+
        }
</div>
+
    }
<a name="skip.navbar.bottom">
+
   
<!--  -->
+
    private void enableBtAndGeolocation(){
</a></div>
+
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
<!-- ======== END OF BOTTOM NAVBAR ======= -->
+
        startActivityForResult(enableBtIntent, 1);
</body>
+
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
</html>
+
            final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
 +
            if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
 +
                Intent enableGeoIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
 +
                startActivityForResult(enableGeoIntent, 1);
 +
            }
 +
        }
 +
    }
 +
   
 +
    private void initButtons()
 +
    {
 +
        Button startButton = findViewById(R.id.startScanButton);
 +
        startButton.setEnabled(true);
 +
        startButton.setOnClickListener(new View.OnClickListener()
 +
        {
 +
            @Override
 +
            public void onClick(View v)
 +
            {
 +
                mScanner.startScan(0); //zero is for infinity
 +
            }
 +
        });
 +
   
 +
        Button stopButton = findViewById(R.id.stopScanButton);
 +
        stopButton.setEnabled(false);
 +
        stopButton.setOnClickListener(new View.OnClickListener()
 +
        {
 +
            @Override
 +
            public void onClick(View v)
 +
            {
 +
                mScanner.stopScan();
 +
            }
 +
        });
 +
    }
 +
   
 +
    private void onDeviceFound(final Device device)
 +
    {
 +
        device.parameterChanged.subscribe(new INotificationCallback<ParameterName>()
 +
        {
 +
            @Override
 +
            public void onNotify(Object o, ParameterName parameterName)
 +
            {
 +
                if (parameterName == ParameterName.State){
 +
                    DeviceState state = device.readParam(ParameterName.State);
 +
                    if (state == DeviceState.Connected){
 +
                        runOnUiThread(new Runnable()
 +
                        {
 +
                            @Override
 +
                            public void run()
 +
                            {
 +
                                onDeviceConnected(device);
 +
                            }
 +
                        });
 +
                    }
 +
                }
 +
            }
 +
        });
 +
        device.connect();
 +
    }
 +
   
 +
    private void onDeviceConnected(Device device)
 +
    {
 +
        EditText deviceInfoText = findViewById(R.id.infoText);
 +
       
 +
        String deviceName = device.readParam(ParameterName.Name);
 +
        String deviceAddress = device.readParam(ParameterName.Address);
 +
        deviceInfoText.append(String.format("Found device: %s [%s]\n", deviceName, deviceAddress));
 +
   
 +
        deviceInfoText.append("Supported params:\n");
 +
        Parameter[] deviceParams = device.parameters();
 +
        for (Parameter param : deviceParams)
 +
        {
 +
            String paramName = param.getName().toString();
 +
            String accessMode = param.getAccess().toString();
 +
            deviceInfoText.append(String.format("-%s {%s}\n", paramName, accessMode));
 +
        }
 +
   
 +
        deviceInfoText.append("\nSupported commands:\n");
 +
        Command[] deviceCommands = device.commands();
 +
        for (Command cmd : deviceCommands)
 +
        {
 +
            deviceInfoText.append(String.format("-%s \n", cmd.toString()));
 +
        }
 +
   
 +
        deviceInfoText.append("\nSupported channels:\n");
 +
        ChannelInfo[] deviceChannels = device.channels();
 +
        for (ChannelInfo channel : deviceChannels)
 +
        {
 +
            String channelName = channel.getName();
 +
            deviceInfoText.append(String.format("-%s \n", channelName));
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 
 +
Possible output:
 +
 
 +
[[File:android_deviceinfo_example_1.png]]
 +
 
 +
==See also==
 +
[[NeuroMD SDK Manual]]
 +
 
 +
[[Device (C++)]]

Latest revision as of 03:42, 1 May 2018

ru.neuromd.neurosdk

Class Device

Related Classes

ru.neuromd.neurosdk.DeviceScanner

Classes hierarchy

  • java.lang.Object
    • ru.neuromd.neurosdk.Device

Class definition

public class Device

The Device class is an abstraction for NeuroMD BLE devices. This abstraction provides functions for changing of device state by executing commands and setting parameters. Each device have different sets of supported commands and parameters, Device class has functions designed to get information about these sets. Callibri and Braibit devices has different parameters sets and provides different ways to access them. Device class hides all differences behind its interface and provides universal way to read and write parameters, execute commands and receive biopotential signals.

Fields Summary

Modifier and Type Field and Description
SubscribersNotifier<ParameterName> parameterChanged

Subscribe this event to receive notifications about changes of device parameters

Constructor Summary

You are not able to create Device directly. Use DeviceScanner to find and create devices

Methods Summary

Modifier and Type Method and Description
void connect()

Establishes connection with device services

void disconnect()

Disconnects from device

ChannelInfo[] channels()

Returns information about supported channels. Check this information before creation of channel. If device does not support channel, channel object won't be initialized.

Command[] commands()

Returns supported commands of a device

Parameter[] parameters()

Returns all available parameters of device, their types and access rights

boolean execute()

Tries to execute command and returns value indicating operation success.

boolean setParam()

Sets value for specified parameter and returns value indicating success of operation.

<ParamType>

ParamType

readParam()

Return value of specified parameter of device.

Field Detail

parameterChanged

public final SubscribersNotifier<ParameterName> parameterChanged

Subscribe this event to receive notifications about changes of device parameters

Method Detail

connect

public void connect()

Tries to establish connection with device. Check DeviceState parameter or subscribe parameterChanged event for operation result.

disconnect

public void disconnect()

Disconnects from device. Check DeviceState parameter or subscribe parameterChanged event for operation result

channels

public ChannelInfo[] channels()

Returns information about supported channels.

Check this information before creation of channel. If device does not support channel, channel object won't be initialized with it.

Returns:
Array of channel info objects

commands

public Command[] commands()

Returns supported commands of device

Returns:
Array of supported commands

parameters

public Parameter[] parameters()

Returns all available parameters of device, their types and access rights

Returns:
Array of available parameters

execute

public boolean execute(Command cmd)

Tries to execute command and returns value indicating operations success.

Will throw if device does not support specified command. To get supported commands call commands() method.

Parameters:
cmd - Command to execute
Returns:
Operation success indicator
Throws:
java.lang.UnsupportedOperationException

readParam

public<ParamType> ParamType readParam(ParameterName param)

Return value of specified parameter of device.

Will throw if parameter does not present in device. To get supported parameters and type information for parameter call parameters() method. It returns Parameter object which consists of parameter name, type and access mode.

Parameters:
param - ParameterName to read
Returns:
Parameter value
Throws:
java.lang.UnsupportedOperationException

setParam

public boolean setParam(ParameterName param, Object value)

Sets value for specified parameter and returns value indicating success of operation.

Will throw if parameter does not present in device or has only Read access mode. To get supported parameters and type information for parameter call parameters() method. It returns Parameter object which consists of parameter name, type and access mode

Parameters:
param - Name of parameter to set
value - Parameter value
Returns:
Operation success indicator
Throws:
java.lang.UnsupportedOperationException

Example

This example shows how to find devices and list their features

import com.neuromd.common.INotificationCallback;
import com.neuromd.neurosdk.Device;
import com.neuromd.neurosdk.DeviceScanner;
import com.neuromd.neurosdk.channels.ChannelInfo;
import com.neuromd.neurosdk.parameters.Command;
import com.neuromd.neurosdk.parameters.Parameter;
import com.neuromd.neurosdk.parameters.ParameterName;
import com.neuromd.neurosdk.parameters.types.DeviceState;

public class DeviceInfoActivity extends AppCompatActivity
{
    private DeviceScanner mScanner;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_info);
    
        requestPermissions();
        enableBtAndGeolocation();
        initScanner();
        initButtons();
    }
    
    private void initScanner()
    {
        mScanner = new DeviceScanner(getApplicationContext());
        mScanner.scanStateChanged.subscribe(new INotificationCallback<Boolean>()
        {
            @Override
            public void onNotify(Object o, final Boolean isScanning)
            {
                runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        Button startButton = findViewById(R.id.startScanButton);
                        Button stopButton = findViewById(R.id.stopScanButton);
                        startButton.setEnabled(!isScanning);
                        stopButton.setEnabled(isScanning);
                    }
                });
            }
        });
        mScanner.deviceFound.subscribe(new INotificationCallback<Device>()
        {
            @Override
            public void onNotify(Object o, Device device)
            {
                onDeviceFound(device);
            }
        });
    }
    
    private void requestPermissions(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        }
    }
    
    private void enableBtAndGeolocation(){
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, 1);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
            if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
                Intent enableGeoIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivityForResult(enableGeoIntent, 1);
            }
        }
    }
    
    private void initButtons()
    {
        Button startButton = findViewById(R.id.startScanButton);
        startButton.setEnabled(true);
        startButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                mScanner.startScan(0); //zero is for infinity
            }
        });
    
        Button stopButton = findViewById(R.id.stopScanButton);
        stopButton.setEnabled(false);
        stopButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                mScanner.stopScan();
            }
        });
    }
    
    private void onDeviceFound(final Device device)
    {
        device.parameterChanged.subscribe(new INotificationCallback<ParameterName>()
        {
            @Override
            public void onNotify(Object o, ParameterName parameterName)
            {
                if (parameterName == ParameterName.State){
                    DeviceState state = device.readParam(ParameterName.State);
                    if (state == DeviceState.Connected){
                        runOnUiThread(new Runnable()
                        {
                            @Override
                            public void run()
                            {
                                onDeviceConnected(device);
                            }
                        });
                    }
                }
            }
        });
        device.connect();
    }
    
    private void onDeviceConnected(Device device)
    {
        EditText deviceInfoText = findViewById(R.id.infoText);
        
        String deviceName = device.readParam(ParameterName.Name);
        String deviceAddress = device.readParam(ParameterName.Address);
        deviceInfoText.append(String.format("Found device: %s [%s]\n", deviceName, deviceAddress));
    
        deviceInfoText.append("Supported params:\n");
        Parameter[] deviceParams = device.parameters();
        for (Parameter param : deviceParams)
        {
            String paramName = param.getName().toString();
            String accessMode = param.getAccess().toString();
            deviceInfoText.append(String.format("-%s {%s}\n", paramName, accessMode));
        }
    
        deviceInfoText.append("\nSupported commands:\n");
        Command[] deviceCommands = device.commands();
        for (Command cmd : deviceCommands)
        {
            deviceInfoText.append(String.format("-%s \n", cmd.toString()));
        }
    
        deviceInfoText.append("\nSupported channels:\n");
        ChannelInfo[] deviceChannels = device.channels();
        for (ChannelInfo channel : deviceChannels)
        {
            String channelName = channel.getName();
            deviceInfoText.append(String.format("-%s \n", channelName));
        }
    }
}

Possible output:

Android deviceinfo example 1.png

See also

NeuroMD SDK Manual

Device (C++)