File: peripherals.html

package info (click to toggle)
raritan-json-rpc-sdk 3.6.1%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 41,748 kB
  • sloc: cs: 162,629; perl: 85,818; python: 24,275; javascript: 5,937; makefile: 21
file content (83 lines) | stat: -rw-r--r-- 7,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Raritan PX2/PX3 JSON-RPC API: Peripheral Devices</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Raritan PX2/PX3 JSON-RPC API
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Peripheral Devices </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Peripheral devices (external sensors and actuators) are handled by the <b>PeripheralDeviceManager</b> interface. The device manager has a fixed number of slots that discovered sensors can be associated with. Assigning sensors to slots defines the order in which sensors are listed in other client interfaces like SNMP.</p>
<p>The peripheral device manager can either be accessed via its well-known URI <code>/model/peripheraldevicemanager</code>, or its reference can be retrieved by using the <b>getPeripheralDeviceManager</b> method of the <b>Pdu</b> or <b>Emd</b> interfaces.</p>
<h2>Using Peripheral Devices</h2>
<p>Peripheral devices must be assigned to one of the device manager's slots in order to be used. A device associated with a slot can have settings (like name or location) and a reading.</p>
<p>Settings for a sensor slot can be retrieved with the <b>getSettings</b> method and written with <b>setSettings</b>. <b>getDevice</b> returns information about the device associated with the slot (or <code>null</code> if the slot is unassigned), as well as a reference to the respective <b>NumericSensor</b> or <b>StateSensor</b> instance.</p>
<div class="fragment"><div class="line"><span class="comment"># Python example: Display information about all managed peripheral devices</span></div><div class="line"></div><div class="line"><span class="keyword">import</span> raritan.rpc.peripheral</div><div class="line"></div><div class="line">pdm = raritan.rpc.peripheral.DeviceManager(<span class="stringliteral">&quot;/model/peripheraldevicemanager&quot;</span>, agent)</div><div class="line"></div><div class="line">slots = pdm.getDeviceSlots()</div><div class="line"></div><div class="line"><span class="keywordflow">for</span> num, slot <span class="keywordflow">in</span> enumerate(slots):</div><div class="line">    settings = slot.getSettings()</div><div class="line">    device = slot.getDevice()</div><div class="line">    <span class="keywordflow">if</span> device == <span class="keywordtype">None</span>:</div><div class="line">        print(<span class="stringliteral">&quot;Slot %d: unassigned&quot;</span> % (num + 1))</div><div class="line">    <span class="keywordflow">else</span>:</div><div class="line">        print(<span class="stringliteral">&quot;Slot %d: %s (%s)&quot;</span> % (num + 1, settings.name, device.deviceID.serial))</div><div class="line">        <span class="keywordflow">if</span> device.device:</div><div class="line">            <span class="keywordflow">if</span> device.deviceID.type.readingtype == raritan.rpc.sensors.Sensor.NUMERIC:</div><div class="line">                reading = device.device.getReading()</div><div class="line">                print(<span class="stringliteral">&quot;  Reading: %f&quot;</span> % reading.value)</div><div class="line">            <span class="keywordflow">else</span>:</div><div class="line">                state = device.device.getState()</div><div class="line">                print(<span class="stringliteral">&quot;  State: %d&quot;</span> % state.value)</div></div><!-- fragment --><h2>Manually Assigning Sensors to Slots</h2>
<p>Sensors must be assigned to one of the deivce manager's slots in order to be used. By default, newly discovered sensors are automatically associated with the first available slot. The assignment can be manually overridden with the <b>assign</b> and <b>unassign</b> methods of the <b>PeripheralDeviceSlot</b> interface:</p>
<div class="fragment"><div class="line"><span class="comment"># Python example: Assign the first discovered sensor to the third slot</span></div><div class="line"></div><div class="line"><span class="keyword">import</span> raritan.rpc.peripheral</div><div class="line"></div><div class="line">pdm = raritan.rpc.peripheral.DeviceManager(<span class="stringliteral">&quot;/model/peripheraldevicemanager&quot;</span>, agent)</div><div class="line"></div><div class="line">discovered_devices = pdm.getDiscoveredDevices()</div><div class="line">slots = pdm.getDeviceSlots()</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> len(discovered_devices) &gt; 0:</div><div class="line">    slots[2].assign(discovered_devices[0].deviceID)</div></div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Aug 21 2020 10:20:37 for Raritan PX2/PX3 JSON-RPC API by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>