Browse Source

Updated sphinx docs.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
96a0105815
43 changed files with 4456 additions and 1343 deletions
  1. +1
    -0
      MANIFEST.in
  2. BIN
      docs/_build/doctrees/environment.pickle
  3. BIN
      docs/_build/doctrees/index.doctree
  4. BIN
      docs/_build/doctrees/modules.doctree
  5. BIN
      docs/_build/doctrees/pyad2.doctree
  6. BIN
      docs/_build/doctrees/pyad2.event.doctree
  7. BIN
      docs/_build/doctrees/pyad2usb.doctree
  8. BIN
      docs/_build/doctrees/pyad2usb.event.doctree
  9. +1
    -1
      docs/_build/html/.buildinfo
  10. +10
    -10
      docs/_build/html/_modules/index.html
  11. +669
    -0
      docs/_build/html/_modules/pyad2/ad2.html
  12. +482
    -126
      docs/_build/html/_modules/pyad2/devices.html
  13. +10
    -10
      docs/_build/html/_modules/pyad2/event/event.html
  14. +109
    -43
      docs/_build/html/_modules/pyad2/messages.html
  15. +25
    -14
      docs/_build/html/_modules/pyad2/util.html
  16. +38
    -21
      docs/_build/html/_modules/pyad2/zonetracking.html
  17. +0
    -588
      docs/_build/html/_modules/pyad2usb/ad2usb.html
  18. +2
    -2
      docs/_build/html/_sources/index.txt
  19. +2
    -2
      docs/_build/html/_sources/modules.txt
  20. +2
    -2
      docs/_build/html/_sources/pyad2.event.txt
  21. +9
    -9
      docs/_build/html/_sources/pyad2.txt
  22. +2
    -2
      docs/_build/html/_sources/pyad2usb.event.txt
  23. +7
    -7
      docs/_build/html/_sources/pyad2usb.txt
  24. +187
    -129
      docs/_build/html/genindex.html
  25. +23
    -23
      docs/_build/html/index.html
  26. +17
    -17
      docs/_build/html/modules.html
  27. BIN
      docs/_build/html/objects.inv
  28. +13
    -13
      docs/_build/html/py-modindex.html
  29. +146
    -0
      docs/_build/html/pyad2.event.html
  30. +1297
    -0
      docs/_build/html/pyad2.html
  31. +18
    -31
      docs/_build/html/pyad2usb.event.html
  32. +407
    -276
      docs/_build/html/pyad2usb.html
  33. +4
    -4
      docs/_build/html/search.html
  34. +1
    -1
      docs/_build/html/searchindex.js
  35. +37
    -0
      docs/_build/text/index.txt
  36. +25
    -0
      docs/_build/text/modules.txt
  37. +39
    -0
      docs/_build/text/pyad2.event.txt
  38. +784
    -0
      docs/_build/text/pyad2.txt
  39. +8
    -8
      docs/conf.py
  40. +2
    -2
      docs/index.rst
  41. +2
    -2
      docs/modules.rst
  42. +19
    -0
      docs/pyad2.event.rst
  43. +58
    -0
      docs/pyad2.rst

+ 1
- 0
MANIFEST.in View File

@@ -1 +1,2 @@
include README.rst
include docs/_build/html/*

BIN
docs/_build/doctrees/environment.pickle View File


BIN
docs/_build/doctrees/index.doctree View File


BIN
docs/_build/doctrees/modules.doctree View File


BIN
docs/_build/doctrees/pyad2.doctree View File


BIN
docs/_build/doctrees/pyad2.event.doctree View File


BIN
docs/_build/doctrees/pyad2usb.doctree View File


BIN
docs/_build/doctrees/pyad2usb.event.doctree View File


+ 1
- 1
docs/_build/html/.buildinfo View File

@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 0c889eb1b3df3f34fd7989e7aaada34f
config: bfabfef1f3b1f181eaa7d666d13e81ec
tags: a205e9ed8462ae86fdd2f73488852ba9

+ 10
- 10
docs/_build/html/_modules/index.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Overview: module code &mdash; pyad2usb documentation</title>
<title>Overview: module code &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../index.html" />
<link rel="top" title="pyad2 documentation" href="../index.html" />
</head>
<body>
<div class="related">
@@ -35,7 +35,7 @@
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -45,12 +45,12 @@
<div class="body">
<h1>All modules for which code is available</h1>
<ul><li><a href="pyad2usb/ad2usb.html">pyad2usb.ad2usb</a></li>
<li><a href="pyad2usb/devices.html">pyad2usb.devices</a></li>
<li><a href="pyad2usb/event/event.html">pyad2usb.event.event</a></li>
<li><a href="pyad2usb/messages.html">pyad2usb.messages</a></li>
<li><a href="pyad2usb/util.html">pyad2usb.util</a></li>
<li><a href="pyad2usb/zonetracking.html">pyad2usb.zonetracking</a></li>
<ul><li><a href="pyad2/ad2.html">pyad2.ad2</a></li>
<li><a href="pyad2/devices.html">pyad2.devices</a></li>
<li><a href="pyad2/event/event.html">pyad2.event.event</a></li>
<li><a href="pyad2/messages.html">pyad2.messages</a></li>
<li><a href="pyad2/util.html">pyad2.util</a></li>
<li><a href="pyad2/zonetracking.html">pyad2.zonetracking</a></li>
</ul>

</div>
@@ -84,7 +84,7 @@
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


+ 669
- 0
docs/_build/html/_modules/pyad2/ad2.html View File

@@ -0,0 +1,669 @@
<!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/html; charset=utf-8" />
<title>pyad2.ad2 &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="pyad2 documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>

<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2.ad2</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Provides the full AD2USB class and factory.</span>

<span class="sd">.. moduleauthor:: Scott Petersen &lt;scott@nutech.com&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">threading</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">devices</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">util</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">messages</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">zonetracking</span>

<div class="viewcode-block" id="Overseer"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer">[docs]</a><span class="k">class</span> <span class="nc">Overseer</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Factory for creation of AD2USB devices as well as provides attach/detach events.&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># Factory events</span>
<span class="n">on_attached</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when an AD2USB device has been detected.&#39;</span><span class="p">)</span>
<span class="n">on_detached</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when an AD2USB device has been removed.&#39;</span><span class="p">)</span>

<span class="n">__devices</span> <span class="o">=</span> <span class="p">[]</span>

<span class="nd">@classmethod</span>
<div class="viewcode-block" id="Overseer.find_all"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.find_all">[docs]</a> <span class="k">def</span> <span class="nf">find_all</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns all AD2USB devices located on the system.</span>

<span class="sd"> :returns: list of devices found</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cls</span><span class="o">.</span><span class="n">__devices</span> <span class="o">=</span> <span class="n">devices</span><span class="o">.</span><span class="n">USBDevice</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span>
</div>
<span class="nd">@classmethod</span>
<div class="viewcode-block" id="Overseer.devices"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.devices">[docs]</a> <span class="k">def</span> <span class="nf">devices</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns a cached list of AD2USB devices located on the system.</span>

<span class="sd"> :returns: cached list of devices found.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span>
</div>
<span class="nd">@classmethod</span>
<div class="viewcode-block" id="Overseer.create"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.create">[docs]</a> <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Factory method that returns the requested AD2USB device, or the first device.</span>

<span class="sd"> :param device: Tuple describing the USB device to open, as returned by find_all().</span>
<span class="sd"> :type device: tuple</span>

<span class="sd"> :returns: AD2USB object utilizing the specified device.</span>
<span class="sd"> :raises: util.NoDeviceError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cls</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">__devices</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;No AD2USB devices present.&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">device</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">device</span> <span class="o">=</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

<span class="n">vendor</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">sernum</span><span class="p">,</span> <span class="n">ifcount</span><span class="p">,</span> <span class="n">description</span> <span class="o">=</span> <span class="n">device</span>
<span class="n">device</span> <span class="o">=</span> <span class="n">devices</span><span class="o">.</span><span class="n">USBDevice</span><span class="p">((</span><span class="n">sernum</span><span class="p">,</span> <span class="n">ifcount</span> <span class="o">-</span> <span class="mi">1</span><span class="p">))</span>

<span class="k">return</span> <span class="n">AD2</span><span class="p">(</span><span class="n">device</span><span class="p">)</span>
</div>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attached_event</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">detached_event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param attached_event: Event to trigger when a device is attached.</span>
<span class="sd"> :type attached_event: function</span>
<span class="sd"> :param detached_event: Event to trigger when a device is detached.</span>
<span class="sd"> :type detached_event: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span> <span class="o">=</span> <span class="n">Overseer</span><span class="o">.</span><span class="n">DetectThread</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="k">if</span> <span class="n">attached_event</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_attached</span> <span class="o">+=</span> <span class="n">attached_event</span>

<span class="k">if</span> <span class="n">detached_event</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_detached</span> <span class="o">+=</span> <span class="n">detached_event</span>

<span class="n">Overseer</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>

<div class="viewcode-block" id="Overseer.close"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Clean up and shut down.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Overseer.start"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.start">[docs]</a> <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Starts the detection thread, if not already running.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span><span class="o">.</span><span class="n">is_alive</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Overseer.stop"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stops the detection thread.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Overseer.get_device"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.get_device">[docs]</a> <span class="k">def</span> <span class="nf">get_device</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Factory method that returns the requested AD2USB device, or the first device.</span>

<span class="sd"> :param device: Tuple describing the USB device to open, as returned by find_all().</span>
<span class="sd"> :type device: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Overseer</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">device</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Overseer.DetectThread"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.DetectThread">[docs]</a> <span class="k">class</span> <span class="nc">DetectThread</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Thread that handles detection of added/removed devices.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">overseer</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param overseer: Overseer object to use with the thread.</span>
<span class="sd"> :type overseer: Overseer</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_overseer</span> <span class="o">=</span> <span class="n">overseer</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>

<div class="viewcode-block" id="Overseer.DetectThread.stop"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.DetectThread.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stops the thread.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
</div>
<div class="viewcode-block" id="Overseer.DetectThread.run"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.Overseer.DetectThread.run">[docs]</a> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The actual detection process.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">True</span>

<span class="n">last_devices</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>

<span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">_running</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">Overseer</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="n">current_devices</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">Overseer</span><span class="o">.</span><span class="n">devices</span><span class="p">())</span>
<span class="n">new_devices</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">current_devices</span> <span class="k">if</span> <span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">last_devices</span><span class="p">]</span>
<span class="n">removed_devices</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">last_devices</span> <span class="k">if</span> <span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">current_devices</span><span class="p">]</span>
<span class="n">last_devices</span> <span class="o">=</span> <span class="n">current_devices</span>

<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">new_devices</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_overseer</span><span class="o">.</span><span class="n">on_attached</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">removed_devices</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_overseer</span><span class="o">.</span><span class="n">on_detached</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

<span class="k">except</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">pass</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.25</span><span class="p">)</span>

</div></div></div>
<div class="viewcode-block" id="AD2"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2">[docs]</a><span class="k">class</span> <span class="nc">AD2</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> High-level wrapper around AD2USB/AD2SERIAL devices.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># High-level Events</span>
<span class="n">on_arm</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the panel is armed.&#39;</span><span class="p">)</span>
<span class="n">on_disarm</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the panel is disarmed.&#39;</span><span class="p">)</span>
<span class="n">on_power_changed</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when panel power switches between AC and DC.&#39;</span><span class="p">)</span>
<span class="n">on_alarm</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the alarm is triggered.&#39;</span><span class="p">)</span>
<span class="n">on_fire</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a fire is detected.&#39;</span><span class="p">)</span>
<span class="n">on_bypass</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a zone is bypassed.&#39;</span><span class="p">)</span>
<span class="n">on_boot</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device finishes bootings.&#39;</span><span class="p">)</span>
<span class="n">on_config_received</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device receives its configuration.&#39;</span><span class="p">)</span>
<span class="n">on_zone_fault</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device detects a zone fault.&#39;</span><span class="p">)</span>
<span class="n">on_zone_restore</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device detects that a fault is restored.&#39;</span><span class="p">)</span>
<span class="n">on_low_battery</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device detects a low battery.&#39;</span><span class="p">)</span>
<span class="n">on_panic</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device detects a panic.&#39;</span><span class="p">)</span>
<span class="n">on_relay_changed</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a relay is opened or closed on an expander board.&#39;</span><span class="p">)</span>

<span class="c"># Mid-level Events</span>
<span class="n">on_message</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a message has been received from the device.&#39;</span><span class="p">)</span>
<span class="n">on_lrr_message</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when an LRR message is received.&#39;</span><span class="p">)</span>
<span class="n">on_rfx_message</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when an RFX message is received.&#39;</span><span class="p">)</span>

<span class="c"># Low-level Events</span>
<span class="n">on_open</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device has been opened.&#39;</span><span class="p">)</span>
<span class="n">on_close</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device has been closed.&#39;</span><span class="p">)</span>
<span class="n">on_read</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a line has been read from the device.&#39;</span><span class="p">)</span>
<span class="n">on_write</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when data has been written to the device.&#39;</span><span class="p">)</span>

<span class="c"># Constants</span>
<span class="n">F1</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Represents panel function key #1&quot;&quot;&quot;</span>
<span class="n">F2</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Represents panel function key #2&quot;&quot;&quot;</span>
<span class="n">F3</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Represents panel function key #3&quot;&quot;&quot;</span>
<span class="n">F4</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Represents panel function key #4&quot;&quot;&quot;</span>

<span class="n">BATTERY_TIMEOUT</span> <span class="o">=</span> <span class="mi">30</span>
<span class="sd">&quot;&quot;&quot;Timeout before the battery status reverts.&quot;&quot;&quot;</span>
<span class="n">FIRE_TIMEOUT</span> <span class="o">=</span> <span class="mi">30</span>
<span class="sd">&quot;&quot;&quot;Timeout before the fire status reverts.&quot;&quot;&quot;</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">device</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param device: The low-level device used for this AD2USB interface.</span>
<span class="sd"> :type device: devices.Device</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">device</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_zonetracker</span> <span class="o">=</span> <span class="n">zonetracking</span><span class="o">.</span><span class="n">Zonetracker</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_armed_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span> <span class="o">=</span> <span class="p">(</span><span class="bp">False</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span> <span class="o">=</span> <span class="p">(</span><span class="bp">False</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_panic_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_relay_status</span> <span class="o">=</span> <span class="p">{}</span>

<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="mi">18</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configbits</span> <span class="o">=</span> <span class="mh">0xFF00</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span> <span class="o">=</span> <span class="mh">0x00000000</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_lrr</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">deduplicate</span> <span class="o">=</span> <span class="bp">False</span>

<span class="nd">@property</span>
<div class="viewcode-block" id="AD2.id"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.id">[docs]</a> <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The ID of the AD2USB device.</span>

<span class="sd"> :returns: The identification string for the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">id</span>
</div>
<div class="viewcode-block" id="AD2.open"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Opens the device.</span>

<span class="sd"> :param baudrate: The baudrate used for the device.</span>
<span class="sd"> :type baudrate: int</span>
<span class="sd"> :param interface: The interface used for the device.</span>
<span class="sd"> :type interface: varies depends on device type.. FIXME</span>
<span class="sd"> :param index: Interface index.. can probably remove. FIXME</span>
<span class="sd"> :type index: int</span>
<span class="sd"> :param no_reader_thread: Specifies whether or not the automatic reader thread should be started or not</span>
<span class="sd"> :type no_reader_thread: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_wire_events</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">baudrate</span><span class="o">=</span><span class="n">baudrate</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="n">no_reader_thread</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AD2.close"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Closes the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="AD2.send"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.send">[docs]</a> <span class="k">def</span> <span class="nf">send</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AD2.get_config"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.get_config">[docs]</a> <span class="k">def</span> <span class="nf">get_config</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the configuration from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;C</span><span class="se">\r</span><span class="s">&quot;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AD2.save_config"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.save_config">[docs]</a> <span class="k">def</span> <span class="nf">save_config</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets configuration entries on the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">config_string</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>

<span class="c"># HACK: Both of these methods are ugly.. but I can&#39;t think of an elegant way of doing it.</span>

<span class="c">#config_string += &#39;ADDRESS={0}&amp;&#39;.format(self.address)</span>
<span class="c">#config_string += &#39;CONFIGBITS={0:x}&amp;&#39;.format(self.configbits)</span>
<span class="c">#config_string += &#39;MASK={0:x}&amp;&#39;.format(self.address_mask)</span>
<span class="c">#config_string += &#39;EXP={0}&amp;&#39;.format(&#39;&#39;.join([&#39;Y&#39; if z else &#39;N&#39; for z in self.emulate_zone]))</span>
<span class="c">#config_string += &#39;REL={0}&amp;&#39;.format(&#39;&#39;.join([&#39;Y&#39; if r else &#39;N&#39; for r in self.emulate_relay]))</span>
<span class="c">#config_string += &#39;LRR={0}&amp;&#39;.format(&#39;Y&#39; if self.emulate_lrr else &#39;N&#39;)</span>
<span class="c">#config_string += &#39;DEDUPLICATE={0}&#39;.format(&#39;Y&#39; if self.deduplicate else &#39;N&#39;)</span>

<span class="n">config_entries</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;ADDRESS&#39;</span><span class="p">,</span> <span class="s">&#39;{0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">address</span><span class="p">)))</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;CONFIGBITS&#39;</span><span class="p">,</span> <span class="s">&#39;{0:x}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">configbits</span><span class="p">)))</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;MASK&#39;</span><span class="p">,</span> <span class="s">&#39;{0:x}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span><span class="p">)))</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;EXP&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;Y&#39;</span> <span class="k">if</span> <span class="n">z</span> <span class="k">else</span> <span class="s">&#39;N&#39;</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span><span class="p">])))</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;REL&#39;</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;Y&#39;</span> <span class="k">if</span> <span class="n">r</span> <span class="k">else</span> <span class="s">&#39;N&#39;</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span><span class="p">])))</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;LRR&#39;</span><span class="p">,</span> <span class="s">&#39;Y&#39;</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">emulate_lrr</span> <span class="k">else</span> <span class="s">&#39;N&#39;</span><span class="p">))</span>
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">&#39;DEDUPLICATE&#39;</span><span class="p">,</span> <span class="s">&#39;Y&#39;</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">deduplicate</span> <span class="k">else</span> <span class="s">&#39;N&#39;</span><span class="p">))</span>

<span class="n">config_string</span> <span class="o">=</span> <span class="s">&#39;&amp;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&#39;=&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">config_entries</span><span class="p">])</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;C{0}</span><span class="se">\r</span><span class="s">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">config_string</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="AD2.reboot"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.reboot">[docs]</a> <span class="k">def</span> <span class="nf">reboot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reboots the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AD2.fault_zone"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.fault_zone">[docs]</a> <span class="k">def</span> <span class="nf">fault_zone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="p">,</span> <span class="n">simulate_wire_problem</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Faults a zone if we are emulating a zone expander.</span>

<span class="sd"> :param zone: The zone to fault.</span>
<span class="sd"> :type zone: int</span>
<span class="sd"> :param simulate_wire_problem: Whether or not to simulate a wire fault.</span>
<span class="sd"> :type simulate_wire_problem: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># Allow ourselves to also be passed an address/channel combination</span>
<span class="c"># for zone expanders.</span>
<span class="c">#</span>
<span class="c"># Format (expander index, channel)</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">):</span>
<span class="n">zone</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zonetracker</span><span class="o">.</span><span class="n">_expander_to_zone</span><span class="p">(</span><span class="o">*</span><span class="n">zone</span><span class="p">)</span>

<span class="n">status</span> <span class="o">=</span> <span class="mi">2</span> <span class="k">if</span> <span class="n">simulate_wire_problem</span> <span class="k">else</span> <span class="mi">1</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;L{0:02}{1}</span><span class="se">\r</span><span class="s">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="AD2.clear_zone"><a class="viewcode-back" href="../../pyad2.html#pyad2.ad2.AD2.clear_zone">[docs]</a> <span class="k">def</span> <span class="nf">clear_zone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Clears a zone if we are emulating a zone expander.</span>

<span class="sd"> :param zone: The zone to clear.</span>
<span class="sd"> :type zone: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;L{0:02}0</span><span class="se">\r</span><span class="s">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">zone</span><span class="p">))</span>
</div>
<span class="k">def</span> <span class="nf">_wire_events</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Wires up the internal device events.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_open</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_open</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_close</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_close</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_read</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_read</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_write</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_write</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_zonetracker</span><span class="o">.</span><span class="n">on_fault</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_zone_fault</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_zonetracker</span><span class="o">.</span><span class="n">on_restore</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_zone_restore</span>

<span class="k">def</span> <span class="nf">_handle_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parses messages from the panel.</span>

<span class="sd"> :param data: Panel data to parse.</span>
<span class="sd"> :type data: str</span>

<span class="sd"> :returns: An object representing the message.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">None</span>

<span class="n">msg</span> <span class="o">=</span> <span class="bp">None</span>

<span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span>
<span class="k">if</span> <span class="n">header</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;!&#39;</span> <span class="ow">or</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!KPE&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">messages</span><span class="o">.</span><span class="n">Message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span> <span class="o">&amp;</span> <span class="n">msg</span><span class="o">.</span><span class="n">mask</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update_internal_states</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!EXP&#39;</span> <span class="ow">or</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!REL&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_update_internal_states</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!RFX&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handle_rfx</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!LRR&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handle_lrr</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;!Ready&#39;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_boot</span><span class="p">()</span>

<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;!CONFIG&#39;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_handle_config</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">return</span> <span class="n">msg</span>

<span class="k">def</span> <span class="nf">_handle_rfx</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">messages</span><span class="o">.</span><span class="n">RFMessage</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_rfx_message</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">return</span> <span class="n">msg</span>

<span class="k">def</span> <span class="nf">_handle_lrr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Handle Long Range Radio messages.</span>

<span class="sd"> :param data: LRR message to parse.</span>
<span class="sd"> :type data: str</span>

<span class="sd"> :returns: An object representing the LRR message.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">messages</span><span class="o">.</span><span class="n">LRRMessage</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">event_type</span> <span class="o">==</span> <span class="s">&#39;ALARM_PANIC&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_panic_status</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_panic</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>

<span class="k">elif</span> <span class="n">msg</span><span class="o">.</span><span class="n">event_type</span> <span class="o">==</span> <span class="s">&#39;CANCEL&#39;</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_panic_status</span> <span class="o">==</span> <span class="bp">True</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_panic_status</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_panic</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_lrr_message</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">return</span> <span class="n">msg</span>

<span class="k">def</span> <span class="nf">_handle_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Handles received configuration data.</span>

<span class="sd"> :param data: Configuration string to parse.</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_</span><span class="p">,</span> <span class="n">config_string</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;&gt;&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">setting</span> <span class="ow">in</span> <span class="n">config_string</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;&amp;&#39;</span><span class="p">):</span>
<span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">setting</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;ADDRESS&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">v</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;CONFIGBITS&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">configbits</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;MASK&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;EXP&#39;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span><span class="p">[</span><span class="n">z</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="n">z</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;Y&#39;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;REL&#39;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span><span class="p">[</span><span class="n">r</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">v</span><span class="p">[</span><span class="n">r</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;Y&#39;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;LRR&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_lrr</span> <span class="o">=</span> <span class="p">(</span><span class="n">v</span> <span class="o">==</span> <span class="s">&#39;Y&#39;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">k</span> <span class="o">==</span> <span class="s">&#39;DEDUPLICATE&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">deduplicate</span> <span class="o">=</span> <span class="p">(</span><span class="n">v</span> <span class="o">==</span> <span class="s">&#39;Y&#39;</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_config_received</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">_update_internal_states</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Updates internal device states.</span>

<span class="sd"> :param message: Message to update internal states with.</span>
<span class="sd"> :type message: Message, ExpanderMessage, LRRMessage, or RFMessage</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">messages</span><span class="o">.</span><span class="n">Message</span><span class="p">):</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">ac_power</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_power_changed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span><span class="p">)</span>

<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">alarm_sounding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_alarm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span><span class="p">)</span>

<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">zone_bypassed</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_bypass</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span><span class="p">)</span>

<span class="k">if</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">|</span> <span class="n">message</span><span class="o">.</span><span class="n">armed_home</span><span class="p">)</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_armed_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_armed_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">|</span> <span class="n">message</span><span class="o">.</span><span class="n">armed_home</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_armed_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_armed_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_arm</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_disarm</span><span class="p">()</span>

<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">==</span> <span class="bp">True</span> <span class="ow">or</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">AD2</span><span class="o">.</span><span class="n">BATTERY_TIMEOUT</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span> <span class="o">=</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">battery_low</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_low_battery</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span><span class="p">)</span>

<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">==</span> <span class="bp">True</span> <span class="ow">or</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">AD2</span><span class="o">.</span><span class="n">FIRE_TIMEOUT</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span> <span class="o">=</span> <span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">fire_alarm</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_fire</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span><span class="p">)</span>

<span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="p">):</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_relay_status</span><span class="p">[(</span><span class="n">message</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">)]</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">value</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_relay_changed</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone_tracker</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_update_zone_tracker</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Trigger an update of the zonetracker.</span>

<span class="sd"> :param message: The message to update the zonetracker with.</span>
<span class="sd"> :type message: Message, ExpanderMessage, LRRMessage, or RFMessage</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># Retrieve a list of faults.</span>
<span class="c"># NOTE: This only happens on first boot or after exiting programming mode.</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">messages</span><span class="o">.</span><span class="n">Message</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">message</span><span class="o">.</span><span class="n">ready</span> <span class="ow">and</span> <span class="s">&quot;Hit * for faults&quot;</span> <span class="ow">in</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;*&#39;</span><span class="p">)</span>
<span class="k">return</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_zonetracker</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for opening the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for closing the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for reading from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_read</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="n">msg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handle_message</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="k">if</span> <span class="n">msg</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_message</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for writing to the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_zone_fault</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for zone faults.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_zone_fault</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_zone_restore</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for zone restoration.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_zone_restore</span><span class="p">(</span><span class="n">args</span><span class="p">)</span></div>
</pre></div>

</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" >Module code</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Author.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
</div>
</body>
</html>

docs/_build/html/_modules/pyad2usb/devices.html → docs/_build/html/_modules/pyad2/devices.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyad2usb.devices &mdash; pyad2usb documentation</title>
<title>pyad2.devices &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../../index.html" />
<link rel="top" title="pyad2 documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
@@ -36,7 +36,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>
@@ -46,24 +46,25 @@
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2usb.devices</h1><div class="highlight"><pre>
<h1>Source code for pyad2.devices</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Contains different types of devices belonging to the AD2USB family.</span>

<span class="sd">.. moduleauthor:: Scott Petersen &lt;scott@nutech.com&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">usb.core</span>
<span class="kn">import</span> <span class="nn">usb.util</span>
<span class="kn">import</span> <span class="nn">usb.core</span><span class="o">,</span> <span class="nn">usb.util</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">threading</span>
<span class="kn">import</span> <span class="nn">serial</span>
<span class="kn">import</span> <span class="nn">serial.tools.list_ports</span>
<span class="kn">import</span> <span class="nn">serial</span><span class="o">,</span> <span class="nn">serial.tools.list_ports</span>
<span class="kn">import</span> <span class="nn">socket</span>
<span class="kn">from</span> <span class="nn">OpenSSL</span> <span class="kn">import</span> <span class="n">SSL</span><span class="p">,</span> <span class="n">crypto</span>
<span class="kn">from</span> <span class="nn">pyftdi.pyftdi.ftdi</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">pyftdi.pyftdi.usbtools</span> <span class="kn">import</span> <span class="o">*</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">util</span>
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span>

<div class="viewcode-block" id="Device"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device">[docs]</a><span class="k">class</span> <span class="nc">Device</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="Device"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device">[docs]</a><span class="k">class</span> <span class="nc">Device</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Generic parent device to all AD2USB products.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -75,58 +76,88 @@
<span class="n">on_write</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when data has been written to the device&#39;</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span> <span class="o">=</span> <span class="n">Device</span><span class="o">.</span><span class="n">ReadThread</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="c"># NOTE: not sure this is going to work..</span>

<span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">pass</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span> <span class="o">=</span> <span class="n">Device</span><span class="o">.</span><span class="n">ReadThread</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieve the device ID.</span>

<span class="sd"> :returns: The identification string for the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_id</span>

<span class="nd">@id.setter</span>
<div class="viewcode-block" id="Device.id"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device.id">[docs]</a> <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<div class="viewcode-block" id="Device.id"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.id">[docs]</a> <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the device ID.</span>

<span class="sd"> :param value: The device identification.</span>
<span class="sd"> :type value: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="n">value</span>
</div>
<div class="viewcode-block" id="Device.is_reader_alive"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device.is_reader_alive">[docs]</a> <span class="k">def</span> <span class="nf">is_reader_alive</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="Device.is_reader_alive"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.is_reader_alive">[docs]</a> <span class="k">def</span> <span class="nf">is_reader_alive</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Indicates whether or not the reader thread is alive.</span>

<span class="sd"> :returns: Whether or not the reader thread is alive.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">is_alive</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Device.stop_reader"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device.stop_reader">[docs]</a> <span class="k">def</span> <span class="nf">stop_reader</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="Device.stop_reader"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.stop_reader">[docs]</a> <span class="k">def</span> <span class="nf">stop_reader</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stops the reader thread.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Device.ReadThread"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device.ReadThread">[docs]</a> <span class="k">class</span> <span class="nc">ReadThread</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">):</span>
<div class="viewcode-block" id="Device.close"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Closes the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

<span class="k">except</span><span class="p">:</span>
<span class="k">pass</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Device.ReadThread"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.ReadThread">[docs]</a> <span class="k">class</span> <span class="nc">ReadThread</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reader thread which processes messages from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">READ_TIMEOUT</span> <span class="o">=</span> <span class="mi">10</span>
<span class="sd">&quot;&quot;&quot;Timeout for the reader thread.&quot;&quot;&quot;</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">device</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param device: The device used by the reader thread.</span>
<span class="sd"> :type device: devices.Device</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">device</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>

<div class="viewcode-block" id="Device.ReadThread.stop"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device.ReadThread.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="Device.ReadThread.stop"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.ReadThread.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stops the running thread.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
</div>
<div class="viewcode-block" id="Device.ReadThread.run"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.Device.ReadThread.run">[docs]</a> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="Device.ReadThread.run"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.Device.ReadThread.run">[docs]</a> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The actual read process.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -135,126 +166,225 @@
<span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">_running</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read_line</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">READ_TIMEOUT</span><span class="p">)</span>

<span class="k">except</span> <span class="n">util</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">pass</span>

<span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>

<span class="c">#raise err</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span>
</div></div></div>
<div class="viewcode-block" id="USBDevice"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice">[docs]</a><span class="k">class</span> <span class="nc">USBDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
<div class="viewcode-block" id="USBDevice"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice">[docs]</a><span class="k">class</span> <span class="nc">USBDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> AD2USB device exposed with PyFTDI&#39;s interface.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># Constants</span>
<span class="n">FTDI_VENDOR_ID</span> <span class="o">=</span> <span class="mh">0x0403</span>
<span class="sd">&quot;&quot;&quot;Vendor ID used to recognize AD2USB devices.&quot;&quot;&quot;</span>
<span class="n">FTDI_PRODUCT_ID</span> <span class="o">=</span> <span class="mh">0x6001</span>
<span class="sd">&quot;&quot;&quot;Product ID used to recognize AD2USB devices.&quot;&quot;&quot;</span>
<span class="n">BAUDRATE</span> <span class="o">=</span> <span class="mi">115200</span>
<span class="sd">&quot;&quot;&quot;Default baudrate for AD2USB devices.&quot;&quot;&quot;</span>

<span class="nd">@staticmethod</span>
<div class="viewcode-block" id="USBDevice.find_all"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice.find_all">[docs]</a> <span class="k">def</span> <span class="nf">find_all</span><span class="p">():</span>
<div class="viewcode-block" id="USBDevice.find_all"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.find_all">[docs]</a> <span class="k">def</span> <span class="nf">find_all</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns all FTDI devices matching our vendor and product IDs.</span>

<span class="sd"> :returns: list of devices</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">devices</span> <span class="o">=</span> <span class="p">[]</span>

<span class="k">try</span><span class="p">:</span>
<span class="n">devices</span> <span class="o">=</span> <span class="n">Ftdi</span><span class="o">.</span><span class="n">find_all</span><span class="p">([(</span><span class="n">USBDevice</span><span class="o">.</span><span class="n">FTDI_VENDOR_ID</span><span class="p">,</span> <span class="n">USBDevice</span><span class="o">.</span><span class="n">FTDI_PRODUCT_ID</span><span class="p">)],</span> <span class="n">nocache</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>

<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error enumerating AD2USB devices: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error enumerating AD2USB devices: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">return</span> <span class="n">devices</span>
</div>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">vid</span><span class="o">=</span><span class="n">FTDI_VENDOR_ID</span><span class="p">,</span> <span class="n">pid</span><span class="o">=</span><span class="n">FTDI_PRODUCT_ID</span><span class="p">,</span> <span class="n">serial</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">interface</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the interface used to connect to the device.</span>

<span class="sd"> :returns: the interface used to connect to the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_endpoint</span><span class="p">)</span>

<span class="nd">@interface.setter</span>
<div class="viewcode-block" id="USBDevice.interface"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.interface">[docs]</a> <span class="k">def</span> <span class="nf">interface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the interface used to connect to the device.</span>

<span class="sd"> :param value: Tuple containing the serial number and endpoint number to use.</span>
<span class="sd"> :type value: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_endpoint</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">serial_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the serial number of the device.</span>

<span class="sd"> :returns: The serial number of the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span>

<span class="nd">@serial_number.setter</span>
<div class="viewcode-block" id="USBDevice.serial_number"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.serial_number">[docs]</a> <span class="k">def</span> <span class="nf">serial_number</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the serial number of the device.</span>

<span class="sd"> :param value: The serial number of the device.</span>
<span class="sd"> :type value: string</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">description</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the description of the device.</span>

<span class="sd"> :returns: The description of the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_description</span>

<span class="nd">@description.setter</span>
<div class="viewcode-block" id="USBDevice.description"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.description">[docs]</a> <span class="k">def</span> <span class="nf">description</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the description of the device.</span>

<span class="sd"> :param value: The description of the device.</span>
<span class="sd"> :type value: string</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_description</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="p">(</span><span class="bp">None</span><span class="p">,</span> <span class="mi">0</span><span class="p">)):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param interface: Tuple containing the device number and endpoint number to use.</span>
<span class="sd"> :type interface: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">Device</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">Ftdi</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_vendor_id</span> <span class="o">=</span> <span class="n">vid</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_product_id</span> <span class="o">=</span> <span class="n">pid</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span> <span class="o">=</span> <span class="n">serial</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_description</span> <span class="o">=</span> <span class="n">description</span>

<div class="viewcode-block" id="USBDevice.open"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="n">BAUDRATE</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span> <span class="o">=</span> <span class="n">interface</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_endpoint</span> <span class="o">=</span> <span class="n">interface</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_vendor_id</span> <span class="o">=</span> <span class="n">USBDevice</span><span class="o">.</span><span class="n">FTDI_VENDOR_ID</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_product_id</span> <span class="o">=</span> <span class="n">USBDevice</span><span class="o">.</span><span class="n">FTDI_PRODUCT_ID</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device_number</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_description</span> <span class="o">=</span> <span class="bp">None</span>

<div class="viewcode-block" id="USBDevice.open"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="n">BAUDRATE</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Opens the device.</span>

<span class="sd"> :param baudrate: The baudrate to use.</span>
<span class="sd"> :type baudrate: int</span>
<span class="sd"> :param no_reader_thread: Whether or not to automatically start the reader thread.</span>
<span class="sd"> :type no_reader_thread: bool</span>

<span class="sd"> :raises: util.NoDeviceError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c"># Set up defaults</span>
<span class="k">if</span> <span class="n">baudrate</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">baudrate</span> <span class="o">=</span> <span class="n">USBDevice</span><span class="o">.</span><span class="n">BAUDRATE</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">interface</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="mi">0</span>

<span class="k">if</span> <span class="n">interface</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>

<span class="k">if</span> <span class="n">index</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">index</span> <span class="o">=</span> <span class="mi">0</span>

<span class="c"># Open the device and start up the thread.</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_vendor_id</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_product_id</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span><span class="p">,</span>
<span class="n">index</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_endpoint</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device_number</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_description</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">set_baudrate</span><span class="p">(</span><span class="n">baudrate</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="s">&#39;USB {0}:{1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">usb_dev</span><span class="o">.</span><span class="n">bus</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">usb_dev</span><span class="o">.</span><span class="n">address</span><span class="p">)</span>

<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;Error opening device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;Error opening AD2USB device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">no_reader_thread</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_description</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="USBDevice.close"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="USBDevice.close"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Closes the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
<span class="c"># HACK: Probably should fork pyftdi and make this call in .close().</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">usb_dev</span><span class="o">.</span><span class="n">attach_kernel_driver</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_device_number</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">Device</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="c"># HACK: Probably should fork pyftdi and make this call in .close().</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">usb_dev</span><span class="o">.</span><span class="n">attach_kernel_driver</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_interface</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="n">FtdiError</span><span class="p">,</span> <span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">):</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">pass</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="USBDevice.write"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<div class="viewcode-block" id="USBDevice.write"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Writes data to the device.</span>

<span class="sd"> :param data: Data to write</span>
<span class="sd"> :type data: str</span>

<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write_data</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">except</span> <span class="n">FtdiError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error writing to AD2USB device.&#39;</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error writing to device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="USBDevice.read"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="USBDevice.read"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reads a single character from the device.</span>

<span class="sd"> :returns: The character read from the device.</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read_data</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">try</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read_data</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">return</span> <span class="n">ret</span>
</div>
<div class="viewcode-block" id="USBDevice.read_line"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.USBDevice.read_line">[docs]</a> <span class="k">def</span> <span class="nf">read_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
<div class="viewcode-block" id="USBDevice.read_line"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.USBDevice.read_line">[docs]</a> <span class="k">def</span> <span class="nf">read_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">purge_buffer</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reads a line from the device.</span>

<span class="sd"> :param timeout: Read timeout</span>
<span class="sd"> :type timeout: float</span>
<span class="sd"> :param purge_buffer: Indicates whether to purge the buffer prior to reading.</span>
<span class="sd"> :type purge_buffer: bool</span>

<span class="sd"> :returns: The line that was read.</span>
<span class="sd"> :raises: util.CommError, util.TimeoutError</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">if</span> <span class="n">purge_buffer</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>

<span class="k">def</span> <span class="nf">timeout_event</span><span class="p">():</span>
<span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span> <span class="o">=</span> <span class="bp">False</span>

@@ -287,12 +417,12 @@
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.001</span><span class="p">)</span>

<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
<span class="k">if</span> <span class="n">timer</span><span class="p">:</span>
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from AD2USB device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">got_line</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span>
@@ -309,18 +439,25 @@
<span class="k">return</span> <span class="n">ret</span>

</div></div>
<div class="viewcode-block" id="SerialDevice"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice">[docs]</a><span class="k">class</span> <span class="nc">SerialDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice">[docs]</a><span class="k">class</span> <span class="nc">SerialDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> AD2USB or AD2SERIAL device exposed with the pyserial interface.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># Constants</span>
<span class="n">BAUDRATE</span> <span class="o">=</span> <span class="mi">19200</span>
<span class="sd">&quot;&quot;&quot;Default baudrate for Serial devices.&quot;&quot;&quot;</span>

<span class="nd">@staticmethod</span>
<div class="viewcode-block" id="SerialDevice.find_all"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice.find_all">[docs]</a> <span class="k">def</span> <span class="nf">find_all</span><span class="p">(</span><span class="n">pattern</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice.find_all"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.find_all">[docs]</a> <span class="k">def</span> <span class="nf">find_all</span><span class="p">(</span><span class="n">pattern</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns all serial ports present.</span>

<span class="sd"> :param pattern: Pattern to search for when retrieving serial ports.</span>
<span class="sd"> :type pattern: str</span>

<span class="sd"> :returns: list of devices</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">devices</span> <span class="o">=</span> <span class="p">[]</span>

@@ -329,36 +466,63 @@
<span class="n">devices</span> <span class="o">=</span> <span class="n">serial</span><span class="o">.</span><span class="n">tools</span><span class="o">.</span><span class="n">list_ports</span><span class="o">.</span><span class="n">grep</span><span class="p">(</span><span class="n">pattern</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">devices</span> <span class="o">=</span> <span class="n">serial</span><span class="o">.</span><span class="n">tools</span><span class="o">.</span><span class="n">list_ports</span><span class="o">.</span><span class="n">comports</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error enumerating AD2SERIAL devices: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>

<span class="k">except</span> <span class="n">SerialException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error enumerating serial devices: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">return</span> <span class="n">devices</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">interface</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the interface used to connect to the device.</span>

<span class="sd"> :returns: the interface used to connect to the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span>

<span class="nd">@interface.setter</span>
<div class="viewcode-block" id="SerialDevice.interface"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.interface">[docs]</a> <span class="k">def</span> <span class="nf">interface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the interface used to connect to the device.</span>

<span class="sd"> :param value: The name of the serial device.</span>
<span class="sd"> :type value: string</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_port</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param interface: The device to open.</span>
<span class="sd"> :type interface: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">Device</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_port</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">serial</span><span class="o">.</span><span class="n">Serial</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">writeTimeout</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span> <span class="c"># Timeout = non-blocking to match pyftdi.</span>

<div class="viewcode-block" id="SerialDevice.open"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="n">BAUDRATE</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice.open"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="n">BAUDRATE</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Opens the device.</span>

<span class="sd"> :param baudrate: The baudrate to use with the device.</span>
<span class="sd"> :type baudrate: int</span>
<span class="sd"> :param no_reader_thread: Whether or not to automatically start the reader thread.</span>
<span class="sd"> :type no_reader_thread: bool</span>

<span class="sd"> :raises: util.NoDeviceError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c"># Set up the defaults</span>
<span class="k">if</span> <span class="n">baudrate</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">baudrate</span> <span class="o">=</span> <span class="n">SerialDevice</span><span class="o">.</span><span class="n">BAUDRATE</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">interface</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;No AD2SERIAL device interface specified.&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">interface</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;No device interface specified.&#39;</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">port</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">port</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span>

<span class="c"># Open the device and start up the reader thread.</span>
<span class="k">try</span><span class="p">:</span>
@@ -371,52 +535,74 @@
<span class="c"># all issues with it.</span>

<span class="k">except</span> <span class="p">(</span><span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;Error opening device on port {0}.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;Error opening AD2SERIAL device on port {0}.&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">interface</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">((</span><span class="s">&#39;N/A&#39;</span><span class="p">,</span> <span class="s">&quot;AD2SERIAL&quot;</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">()</span>

<span class="k">if</span> <span class="ow">not</span> <span class="n">no_reader_thread</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="SerialDevice.close"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice.close"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Closes the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
<span class="n">Device</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">pass</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="SerialDevice.write"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice.write"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Writes data to the device.</span>

<span class="sd"> :param data: The data to write.</span>
<span class="sd"> :type data: str</span>

<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialTimeoutException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">pass</span>

<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error writing to serial device.&#39;</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error writing to device.&#39;</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>

<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="SerialDevice.read"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice.read"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reads a single character from the device.</span>

<span class="sd"> :returns: The character read from the device.</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">try</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">return</span> <span class="n">ret</span>
</div>
<div class="viewcode-block" id="SerialDevice.read_line"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SerialDevice.read_line">[docs]</a> <span class="k">def</span> <span class="nf">read_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
<div class="viewcode-block" id="SerialDevice.read_line"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SerialDevice.read_line">[docs]</a> <span class="k">def</span> <span class="nf">read_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">purge_buffer</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reads a line from the device.</span>

<span class="sd"> :param timeout: The read timeout.</span>
<span class="sd"> :type timeout: float</span>
<span class="sd"> :param purge_buffer: Indicates whether to purge the buffer prior to reading.</span>
<span class="sd"> :type purge_buffer: bool</span>

<span class="sd"> :returns: The line read.</span>
<span class="sd"> :raises: util.CommError, util.TimeoutError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">timeout_event</span><span class="p">():</span>
<span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span> <span class="o">=</span> <span class="bp">False</span>
@@ -450,12 +636,12 @@
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.001</span><span class="p">)</span>

<span class="k">except</span> <span class="p">(</span><span class="ne">OSError</span><span class="p">,</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
<span class="k">if</span> <span class="n">timer</span><span class="p">:</span>
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from AD2SERIAL device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">got_line</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span>
@@ -471,90 +657,229 @@

<span class="k">return</span> <span class="n">ret</span>
</div></div>
<div class="viewcode-block" id="SocketDevice"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SocketDevice">[docs]</a><span class="k">class</span> <span class="nc">SocketDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
<div class="viewcode-block" id="SocketDevice"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice">[docs]</a><span class="k">class</span> <span class="nc">SocketDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Device that supports communication with an AD2USB that is exposed via ser2sock or another</span>
<span class="sd"> Serial to IP interface.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">interface</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the interface used to connect to the device.</span>

<span class="sd"> :returns: the interface used to connect to the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">)</span>

<span class="nd">@interface.setter</span>
<div class="viewcode-block" id="SocketDevice.interface"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.interface">[docs]</a> <span class="k">def</span> <span class="nf">interface</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the interface used to connect to the device.</span>

<span class="sd"> :param value: Tuple containing the device number and endpoint number to use.</span>
<span class="sd"> :type value: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_host</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_port</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">ssl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves whether or not the device is using SSL.</span>

<span class="sd"> :returns: Whether or not the device is using SSL.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_use_ssl</span>

<span class="nd">@ssl.setter</span>
<div class="viewcode-block" id="SocketDevice.ssl"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.ssl">[docs]</a> <span class="k">def</span> <span class="nf">ssl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets whether or not SSL communication is in use.</span>

<span class="sd"> :param value: Whether or not SSL communication is in use.</span>
<span class="sd"> :type value: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_use_ssl</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">ssl_certificate</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the SSL client certificate path used for authentication.</span>

<span class="sd"> :returns: The certificate path</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ssl_certificate</span>

<span class="nd">@ssl_certificate.setter</span>
<div class="viewcode-block" id="SocketDevice.ssl_certificate"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.ssl_certificate">[docs]</a> <span class="k">def</span> <span class="nf">ssl_certificate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the SSL client certificate to use for authentication.</span>

<span class="sd"> :param value: The path to the SSL certificate.</span>
<span class="sd"> :type value: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_ssl_certificate</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">ssl_key</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the SSL client certificate key used for authentication.</span>

<span class="sd"> :returns: The key path</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ssl_key</span>

<span class="nd">@ssl_key.setter</span>
<div class="viewcode-block" id="SocketDevice.ssl_key"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.ssl_key">[docs]</a> <span class="k">def</span> <span class="nf">ssl_key</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the SSL client certificate key to use for authentication.</span>

<span class="sd"> :param value: The path to the SSL key.</span>
<span class="sd"> :type value: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_ssl_key</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">ssl_ca</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the SSL Certificate Authority certificate used for authentication.</span>

<span class="sd"> :returns: The CA path</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ssl_ca</span>

<span class="nd">@ssl_ca.setter</span>
<div class="viewcode-block" id="SocketDevice.ssl_ca"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.ssl_ca">[docs]</a> <span class="k">def</span> <span class="nf">ssl_ca</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the SSL Certificate Authority certificate used for authentication.</span>

<span class="sd"> :param value: The path to the SSL CA certificate.</span>
<span class="sd"> :type value: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_ssl_ca</span> <span class="o">=</span> <span class="n">value</span>
</div>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="p">(</span><span class="s">&quot;localhost&quot;</span><span class="p">,</span> <span class="mi">10000</span><span class="p">)):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param interface: Tuple containing the hostname and port of our target.</span>
<span class="sd"> :type interface: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">Device</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_use_ssl</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_ssl_certificate</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_ssl_key</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_ssl_ca</span> <span class="o">=</span> <span class="bp">None</span>

<div class="viewcode-block" id="SocketDevice.open"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SocketDevice.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<div class="viewcode-block" id="SocketDevice.open"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Opens the device.</span>

<span class="sd"> :param baudrate: The baudrate to use</span>
<span class="sd"> :type baudrate: int</span>
<span class="sd"> :param no_reader_thread: Whether or not to automatically open the reader thread.</span>
<span class="sd"> :type no_reader_thread: bool</span>

<span class="sd"> :raises: util.NoDeviceError, util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">interface</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_interface</span> <span class="o">=</span> <span class="n">interface</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span> <span class="o">=</span> <span class="n">interface</span>

<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_INET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_STREAM</span><span class="p">)</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_use_ssl</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_init_ssl</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">))</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="s">&#39;{0}:{1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">)</span>

<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;Error opening device at {0}:{1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;Error opening AD2SOCKET device at {0}:{1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">True</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">((</span><span class="s">&#39;N/A&#39;</span><span class="p">,</span> <span class="s">&quot;AD2SOCKET&quot;</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">()</span>

<span class="k">if</span> <span class="ow">not</span> <span class="n">no_reader_thread</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="SocketDevice.close"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SocketDevice.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="SocketDevice.close"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Closes the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>

<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">shutdown</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">SHUT_RDWR</span><span class="p">)</span> <span class="c"># Make sure that it closes immediately.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">except</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ssl</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">shutdown</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">SHUT_RDWR</span><span class="p">)</span> <span class="c"># Make sure that it closes immediately.</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">()</span>
<span class="n">Device</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
<span class="k">pass</span>
</div>
<div class="viewcode-block" id="SocketDevice.write"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SocketDevice.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<div class="viewcode-block" id="SocketDevice.write"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Writes data to the device.</span>

<span class="sd"> :param data: The data to write.</span>
<span class="sd"> :type data: str</span>

<span class="sd"> :returns: The number of bytes sent.</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">data_sent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">data_sent</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">try</span><span class="p">:</span>
<span class="n">data_sent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">if</span> <span class="n">data_sent</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error writing to device.&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">data_sent</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error while sending data.&#39;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">except</span> <span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">Error</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error writing to device.&#39;</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>

<span class="k">return</span> <span class="n">data_sent</span>
</div>
<div class="viewcode-block" id="SocketDevice.read"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SocketDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<div class="viewcode-block" id="SocketDevice.read"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reads a single character from the device.</span>

<span class="sd"> :returns: The character read from the device.</span>
<span class="sd"> :raises: util.CommError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">try</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error while reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error while reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">return</span> <span class="n">data</span>
</div>
<div class="viewcode-block" id="SocketDevice.read_line"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.devices.SocketDevice.read_line">[docs]</a> <span class="k">def</span> <span class="nf">read_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
<div class="viewcode-block" id="SocketDevice.read_line"><a class="viewcode-back" href="../../pyad2.html#pyad2.devices.SocketDevice.read_line">[docs]</a> <span class="k">def</span> <span class="nf">read_line</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">purge_buffer</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reads a line from the device.</span>

<span class="sd"> :param timeout: The read timeout.</span>
<span class="sd"> :type timeout: float</span>
<span class="sd"> :param purge_buffer: Indicates whether to purge the buffer prior to reading.</span>
<span class="sd"> :type purge_buffer: bool</span>

<span class="sd"> :returns: The line read from the device.</span>
<span class="sd"> :raises: util.CommError, util.TimeoutError</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">if</span> <span class="n">purge_buffer</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>

<span class="k">def</span> <span class="nf">timeout_event</span><span class="p">():</span>
<span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span> <span class="o">=</span> <span class="bp">False</span>

@@ -587,12 +912,12 @@
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.001</span><span class="p">)</span>

<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
<span class="k">if</span> <span class="n">timer</span><span class="p">:</span>
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span>

<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error reading from Socket device: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">got_line</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span>
@@ -606,7 +931,38 @@
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="s">&#39;Timeout while waiting for line terminator.&#39;</span><span class="p">)</span>

<span class="k">return</span> <span class="n">ret</span></div></div>
<span class="k">return</span> <span class="n">ret</span>
</div>
<span class="k">def</span> <span class="nf">_init_ssl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Context</span><span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">TLSv1_METHOD</span><span class="p">)</span>

<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_key</span><span class="p">,</span> <span class="n">crypto</span><span class="o">.</span><span class="n">PKey</span><span class="p">):</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">use_privatekey</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_key</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">use_privatekey_file</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_key</span><span class="p">)</span>

<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_certificate</span><span class="p">,</span> <span class="n">crypto</span><span class="o">.</span><span class="n">X509</span><span class="p">):</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">use_certificate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_certificate</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">use_certificate_file</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_certificate</span><span class="p">)</span>

<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_ca</span><span class="p">,</span> <span class="n">crypto</span><span class="o">.</span><span class="n">X509</span><span class="p">):</span>
<span class="n">store</span> <span class="o">=</span> <span class="n">ctx</span><span class="o">.</span><span class="n">get_cert_store</span><span class="p">()</span>
<span class="n">store</span><span class="o">.</span><span class="n">add_cert</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_ca</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">load_verify_locations</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">ssl_ca</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>

<span class="n">ctx</span><span class="o">.</span><span class="n">set_verify</span><span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">VERIFY_PEER</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_verify_ssl_callback</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">)</span>

<span class="k">except</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">(</span><span class="s">&#39;Error setting up SSL connection.&#39;</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_verify_ssl_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">connection</span><span class="p">,</span> <span class="n">x509</span><span class="p">,</span> <span class="n">errnum</span><span class="p">,</span> <span class="n">errdepth</span><span class="p">,</span> <span class="n">ok</span><span class="p">):</span>
<span class="c">#print ok</span>
<span class="k">return</span> <span class="n">ok</span></div>
</pre></div>

</div>
@@ -640,7 +996,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" >Module code</a> &raquo;</li>
</ul>
</div>

docs/_build/html/_modules/pyad2usb/event/event.html → docs/_build/html/_modules/pyad2/event/event.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyad2usb.event.event &mdash; pyad2usb documentation</title>
<title>pyad2.event.event &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../_static/underscore.js"></script>
<script type="text/javascript" src="../../../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../../../index.html" />
<link rel="top" title="pyad2 documentation" href="../../../index.html" />
<link rel="up" title="Module code" href="../../index.html" />
</head>
<body>
@@ -36,7 +36,7 @@
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>
@@ -46,10 +46,10 @@
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2usb.event.event</h1><div class="highlight"><pre>
<h1>Source code for pyad2.event.event</h1><div class="highlight"><pre>
<span class="c"># event.py (improved)</span>

<div class="viewcode-block" id="Event"><a class="viewcode-back" href="../../../pyad2usb.event.html#pyad2usb.event.event.Event">[docs]</a><span class="k">class</span> <span class="nc">Event</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="Event"><a class="viewcode-back" href="../../../pyad2.event.html#pyad2.event.event.Event">[docs]</a><span class="k">class</span> <span class="nc">Event</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">doc</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">=</span> <span class="n">doc</span>
@@ -63,7 +63,7 @@
<span class="k">pass</span>

</div>
<div class="viewcode-block" id="EventHandler"><a class="viewcode-back" href="../../../pyad2usb.event.html#pyad2usb.event.event.EventHandler">[docs]</a><span class="k">class</span> <span class="nc">EventHandler</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="EventHandler"><a class="viewcode-back" href="../../../pyad2.event.html#pyad2.event.event.EventHandler">[docs]</a><span class="k">class</span> <span class="nc">EventHandler</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>

@@ -80,7 +80,7 @@
<span class="n">eventhandler</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">obj</span><span class="o">.</span><span class="n">__eventhandler__</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">return</span> <span class="n">eventhandler</span><span class="o">.</span><span class="n">setdefault</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">event</span><span class="p">,</span> <span class="p">[])</span>

<div class="viewcode-block" id="EventHandler.add"><a class="viewcode-back" href="../../../pyad2usb.event.html#pyad2usb.event.event.EventHandler.add">[docs]</a> <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
<div class="viewcode-block" id="EventHandler.add"><a class="viewcode-back" href="../../../pyad2.event.html#pyad2.event.event.EventHandler.add">[docs]</a> <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>

<span class="sd">&quot;&quot;&quot;Add new event handler function.</span>

@@ -91,7 +91,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_getfunctionlist</span><span class="p">()</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span>
</div>
<div class="viewcode-block" id="EventHandler.remove"><a class="viewcode-back" href="../../../pyad2usb.event.html#pyad2usb.event.event.EventHandler.remove">[docs]</a> <span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
<div class="viewcode-block" id="EventHandler.remove"><a class="viewcode-back" href="../../../pyad2.event.html#pyad2.event.event.EventHandler.remove">[docs]</a> <span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>

<span class="sd">&quot;&quot;&quot;Remove existing event handler function.</span>

@@ -101,7 +101,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_getfunctionlist</span><span class="p">()</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span>
</div>
<div class="viewcode-block" id="EventHandler.fire"><a class="viewcode-back" href="../../../pyad2usb.event.html#pyad2usb.event.event.EventHandler.fire">[docs]</a> <span class="k">def</span> <span class="nf">fire</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">earg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<div class="viewcode-block" id="EventHandler.fire"><a class="viewcode-back" href="../../../pyad2.event.html#pyad2.event.event.EventHandler.fire">[docs]</a> <span class="k">def</span> <span class="nf">fire</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">earg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>

<span class="sd">&quot;&quot;&quot;Fire event and call all handler functions</span>

@@ -151,7 +151,7 @@
<li class="right" >
<a href="../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../../index.html" >Module code</a> &raquo;</li>
</ul>
</div>

docs/_build/html/_modules/pyad2usb/messages.html → docs/_build/html/_modules/pyad2/messages.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyad2usb.messages &mdash; pyad2usb documentation</title>
<title>pyad2.messages &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../../index.html" />
<link rel="top" title="pyad2 documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
@@ -36,7 +36,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>
@@ -46,14 +46,24 @@
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2usb.messages</h1><div class="highlight"><pre>
<h1>Source code for pyad2.messages</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Message representations received from the panel through the AD2USB.</span>

<span class="sd">.. moduleauthor:: Scott Petersen &lt;scott@nutech.com&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">util</span>

<div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="BaseMessage"><a class="viewcode-back" href="../../pyad2.html#pyad2.messages.BaseMessage">[docs]</a><span class="k">class</span> <span class="nc">BaseMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Base class for messages.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../pyad2.html#pyad2.messages.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="n">BaseMessage</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a message from the alarm panel.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -61,6 +71,9 @@
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param data: Message data to parse.</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="bp">False</span>
@@ -94,6 +107,11 @@
<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parse the message from the device.</span>

<span class="sd"> :param data: The message data.</span>
<span class="sd"> :type data: str</span>

<span class="sd"> :raises: util.InvalidMessageError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_regex</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

@@ -103,23 +121,25 @@
<span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">,</span> <span class="n">alpha</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">3</span><span class="o">+</span><span class="mi">8</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">7</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">9</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">11</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">11</span><span class="p">:</span><span class="mi">12</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">13</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">entry_delay_off</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">13</span><span class="p">:</span><span class="mi">14</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">14</span><span class="p">:</span><span class="mi">15</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">15</span><span class="p">:</span><span class="mi">16</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">16</span><span class="p">:</span><span class="mi">17</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="n">is_bit_set</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">bit</span><span class="p">:</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="n">bit</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>

<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">12</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">entry_delay_off</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">13</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">14</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span>
<span class="c"># bits 17-20 unused.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="n">alpha</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s">&#39;&quot;&#39;</span><span class="p">)</span>

@@ -132,7 +152,7 @@
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;msg &gt; {0:0&lt;9} [{1}{2}{3}] -- ({4}) {5}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">),</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ExpanderMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.ExpanderMessage">[docs]</a><span class="k">class</span> <span class="nc">ExpanderMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="ExpanderMessage"><a class="viewcode-back" href="../../pyad2.html#pyad2.messages.ExpanderMessage">[docs]</a><span class="k">class</span> <span class="nc">ExpanderMessage</span><span class="p">(</span><span class="n">BaseMessage</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a message from a zone or relay expansion module.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -143,6 +163,9 @@
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param data: The message data to parse.</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="bp">None</span>
@@ -168,21 +191,28 @@
<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parse the raw message from the device.</span>

<span class="sd"> :param data: The message data</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">header</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="n">address</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">header</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="n">address</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">address</span>
<span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="n">channel</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">channel</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">&#39;Received invalid message: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>

<span class="k">if</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!EXP&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span>
<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!REL&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span>
</div>
<div class="viewcode-block" id="RFMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.RFMessage">[docs]</a><span class="k">class</span> <span class="nc">RFMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="RFMessage"><a class="viewcode-back" href="../../pyad2.html#pyad2.messages.RFMessage">[docs]</a><span class="k">class</span> <span class="nc">RFMessage</span><span class="p">(</span><span class="n">BaseMessage</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a message from an RF receiver.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -190,10 +220,16 @@
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param data: The message data to parse</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">battery</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">supervision</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loop</span> <span class="o">=</span> <span class="p">{}</span>

<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
@@ -202,18 +238,38 @@
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String conversion operator.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;rf &gt; {0}: {1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
<span class="k">return</span> <span class="s">&#39;rf &gt; {0}: {1:x}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parses the raw message from the device.</span>

<span class="sd"> :param data: The message data.</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>

<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>

<span class="n">is_bit_set</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">b</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">&amp;</span> <span class="p">(</span><span class="mi">1</span> <span class="o">&lt;&lt;</span> <span class="n">b</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span>

<span class="c"># Bit 1 = unknown</span>
<span class="bp">self</span><span class="o">.</span><span class="n">battery</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">supervision</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="c"># Bit 8 = unknown</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loop</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loop</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">6</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loop</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">7</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loop</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">8</span><span class="p">)</span>

<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">&#39;Received invalid message: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>

<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LRRMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.LRRMessage">[docs]</a><span class="k">class</span> <span class="nc">LRRMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="LRRMessage"><a class="viewcode-back" href="../../pyad2.html#pyad2.messages.LRRMessage">[docs]</a><span class="k">class</span> <span class="nc">LRRMessage</span><span class="p">(</span><span class="n">BaseMessage</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represent a message from a Long Range Radio.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -221,11 +277,14 @@
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>

<span class="sd"> :param data: The message data to parse.</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_partition</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">event_data</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">partition</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">event_type</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
@@ -234,16 +293,23 @@
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String conversion operator.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;lrr &gt; {0} @ {1} -- {2}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">()</span>
<span class="k">return</span> <span class="s">&#39;lrr &gt; {0} @ {1} -- {2}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">event_data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partition</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">event_type</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parses the raw message from the device.</span>

<span class="sd"> :param data: The message data.</span>
<span class="sd"> :type data: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>

<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">event_data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">partition</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">event_type</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>

<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_partition</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span></div>
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">&#39;Received invalid message: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span></div>
</pre></div>

</div>
@@ -277,7 +343,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" >Module code</a> &raquo;</li>
</ul>
</div>

docs/_build/html/_modules/pyad2usb/util.html → docs/_build/html/_modules/pyad2/util.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyad2usb.util &mdash; pyad2usb documentation</title>
<title>pyad2.util &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../../index.html" />
<link rel="top" title="pyad2 documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
@@ -36,7 +36,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>
@@ -46,41 +46,43 @@
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2usb.util</h1><div class="highlight"><pre>
<h1>Source code for pyad2.util</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Provides utility classes for the AD2USB devices.</span>

<span class="sd">.. moduleauthor:: Scott Petersen &lt;scott@nutech.com&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">ad2usb</span>
<span class="kn">import</span> <span class="nn">ad2</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">traceback</span>
<span class="kn">import</span> <span class="nn">threading</span>

<div class="viewcode-block" id="NoDeviceError"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.util.NoDeviceError">[docs]</a><span class="k">class</span> <span class="nc">NoDeviceError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<div class="viewcode-block" id="NoDeviceError"><a class="viewcode-back" href="../../pyad2.html#pyad2.util.NoDeviceError">[docs]</a><span class="k">class</span> <span class="nc">NoDeviceError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> No devices found.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span>
</div>
<div class="viewcode-block" id="CommError"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.util.CommError">[docs]</a><span class="k">class</span> <span class="nc">CommError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<div class="viewcode-block" id="CommError"><a class="viewcode-back" href="../../pyad2.html#pyad2.util.CommError">[docs]</a><span class="k">class</span> <span class="nc">CommError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> There was an error communicating with the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span>
</div>
<div class="viewcode-block" id="TimeoutError"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.util.TimeoutError">[docs]</a><span class="k">class</span> <span class="nc">TimeoutError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<div class="viewcode-block" id="TimeoutError"><a class="viewcode-back" href="../../pyad2.html#pyad2.util.TimeoutError">[docs]</a><span class="k">class</span> <span class="nc">TimeoutError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> There was a timeout while trying to communicate with the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span>
</div>
<div class="viewcode-block" id="InvalidMessageError"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.util.InvalidMessageError">[docs]</a><span class="k">class</span> <span class="nc">InvalidMessageError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<div class="viewcode-block" id="InvalidMessageError"><a class="viewcode-back" href="../../pyad2.html#pyad2.util.InvalidMessageError">[docs]</a><span class="k">class</span> <span class="nc">InvalidMessageError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The format of the panel message was invalid.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span>
</div>
<div class="viewcode-block" id="Firmware"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.util.Firmware">[docs]</a><span class="k">class</span> <span class="nc">Firmware</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="Firmware"><a class="viewcode-back" href="../../pyad2.html#pyad2.util.Firmware">[docs]</a><span class="k">class</span> <span class="nc">Firmware</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents firmware for the AD2USB/AD2SERIAL devices.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -94,9 +96,16 @@
<span class="n">STAGE_DONE</span> <span class="o">=</span> <span class="mi">5</span>

<span class="nd">@staticmethod</span>
<div class="viewcode-block" id="Firmware.upload"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.util.Firmware.upload">[docs]</a> <span class="k">def</span> <span class="nf">upload</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">progress_callback</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<div class="viewcode-block" id="Firmware.upload"><a class="viewcode-back" href="../../pyad2.html#pyad2.util.Firmware.upload">[docs]</a> <span class="k">def</span> <span class="nf">upload</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">progress_callback</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Uploads firmware to an AD2USB/AD2SERIAL device.</span>

<span class="sd"> :param filename: The firmware filename</span>
<span class="sd"> :type filename: str</span>
<span class="sd"> :param progress_callback: Callback function used to report progress.</span>
<span class="sd"> :type progress_callback: function</span>

<span class="sd"> :raises: util.NoDeviceError, util.TimeoutError</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="nf">do_upload</span><span class="p">():</span>
@@ -114,7 +123,7 @@
<span class="k">if</span> <span class="n">progress_callback</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">progress_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_UPLOADING</span><span class="p">)</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.05</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">read_until</span><span class="p">(</span><span class="n">pattern</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
@@ -171,10 +180,12 @@
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_WAITING</span><span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>

<span class="c"># Reboot the device and wait for the boot loader.</span>
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_BOOT</span><span class="p">)</span>
<span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;=&quot;</span><span class="p">)</span>
<span class="n">read_until</span><span class="p">(</span><span class="s">&#39;!boot&#39;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">15.0</span><span class="p">)</span>
<span class="n">read_until</span><span class="p">(</span><span class="s">&#39;......&#39;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">15.0</span><span class="p">)</span>

<span class="c"># Get ourselves into the boot loader and wait for indication</span>
<span class="c"># that it&#39;s ready for the firmware upload.</span>
@@ -218,7 +229,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" >Module code</a> &raquo;</li>
</ul>
</div>

docs/_build/html/_modules/pyad2usb/zonetracking.html → docs/_build/html/_modules/pyad2/zonetracking.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyad2usb.zonetracking &mdash; pyad2usb documentation</title>
<title>pyad2.zonetracking &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../../index.html" />
<link rel="top" title="pyad2 documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
@@ -36,7 +36,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>
@@ -46,16 +46,19 @@
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2usb.zonetracking</h1><div class="highlight"><pre>
<h1>Source code for pyad2.zonetracking</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Provides zone tracking functionality for the AD2USB device family.</span>

<span class="sd">.. moduleauthor:: Scott Petersen &lt;scott@nutech.com&gt;</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">messages</span>

<div class="viewcode-block" id="Zone"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.zonetracking.Zone">[docs]</a><span class="k">class</span> <span class="nc">Zone</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="Zone"><a class="viewcode-back" href="../../pyad2.html#pyad2.zonetracking.Zone">[docs]</a><span class="k">class</span> <span class="nc">Zone</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Representation of a panel zone.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -97,7 +100,7 @@
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;Zone({0}, {1}, ts {2})&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zone</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">STATUS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">timestamp</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Zonetracker"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.zonetracking.Zonetracker">[docs]</a><span class="k">class</span> <span class="nc">Zonetracker</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<div class="viewcode-block" id="Zonetracker"><a class="viewcode-back" href="../../pyad2.html#pyad2.zonetracking.Zonetracker">[docs]</a><span class="k">class</span> <span class="nc">Zonetracker</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Handles tracking of zone and their statuses.</span>
<span class="sd"> &quot;&quot;&quot;</span>
@@ -116,7 +119,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span> <span class="o">=</span> <span class="mi">0</span>

<div class="viewcode-block" id="Zonetracker.update"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.zonetracking.Zonetracker.update">[docs]</a> <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<div class="viewcode-block" id="Zonetracker.update"><a class="viewcode-back" href="../../pyad2.html#pyad2.zonetracking.Zonetracker.update">[docs]</a> <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Update zone statuses based on the current message.</span>

@@ -127,23 +130,24 @@

<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="p">):</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span><span class="p">:</span>
<span class="n">zone</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_expander_to_zone</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">address</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">))</span>
<span class="n">zone</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_expander_to_zone</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">)</span>

<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span>
<span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">value</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">FAULT</span>
<span class="k">elif</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">value</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CHECK</span>

<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span>

<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_add_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span>

<span class="k">else</span><span class="p">:</span>
<span class="c"># Panel is ready, restore all zones.</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">ready</span><span class="p">:</span>
<span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">):</span>
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span> <span class="o">=</span> <span class="mi">0</span>
@@ -158,10 +162,23 @@
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="n">zone</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>

<span class="c"># NOTE: Odd case for ECP failures. Apparently they report as zone 191 (0xBF) regardless</span>
<span class="c"># of whether or not the 3-digit mode is enabled... so we have to pull it out of the</span>
<span class="c"># alpha message.</span>
<span class="k">if</span> <span class="n">zone</span> <span class="o">==</span> <span class="mi">191</span><span class="p">:</span>
<span class="n">zone_regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">&#39;^CHECK (\d+).*$&#39;</span><span class="p">)</span>

<span class="n">m</span> <span class="o">=</span> <span class="n">zone_regex</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">return</span>

<span class="n">zone</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

<span class="c"># Add new zones and clear expired ones.</span>
<span class="k">if</span> <span class="n">zone</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_clear_zones</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span>

<span class="k">else</span><span class="p">:</span>
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">FAULT</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">check_zone</span><span class="p">:</span>
@@ -184,16 +201,16 @@
<span class="sd"> :type zone: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cleared_zones</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">found_last</span> <span class="o">=</span> <span class="n">found_new</span> <span class="o">=</span> <span class="n">at_end</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">found_last_faulted</span> <span class="o">=</span> <span class="n">found_current</span> <span class="o">=</span> <span class="n">at_end</span> <span class="o">=</span> <span class="bp">False</span>

<span class="c"># First pass: Find our start spot.</span>
<span class="n">it</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_last</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_last_faulted</span><span class="p">:</span>
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span><span class="p">:</span>
<span class="n">found_last</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">found_last_faulted</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">break</span>

<span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span>
@@ -202,11 +219,11 @@
<span class="c"># Continue until we find our end point and add zones in</span>
<span class="c"># between to our clear list.</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">at_end</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">found_new</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">at_end</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">found_current</span><span class="p">:</span>
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="n">zone</span><span class="p">:</span>
<span class="n">found_new</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">found_current</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">cleared_zones</span> <span class="o">+=</span> <span class="p">[</span><span class="n">z</span><span class="p">]</span>
@@ -216,15 +233,15 @@

<span class="c"># Second pass: roll through the list again if we didn&#39;t find</span>
<span class="c"># our end point and remove everything until we do.</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">found_new</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">found_current</span><span class="p">:</span>
<span class="n">it</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">)</span>

<span class="k">try</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_new</span><span class="p">:</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_current</span><span class="p">:</span>
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span>

<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="n">zone</span><span class="p">:</span>
<span class="n">found_new</span> <span class="o">=</span> <span class="bp">True</span>
<span class="n">found_current</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">cleared_zones</span> <span class="o">+=</span> <span class="p">[</span><span class="n">z</span><span class="p">]</span>
@@ -233,7 +250,7 @@
<span class="k">pass</span>

<span class="c"># Actually remove the zones and trigger the restores.</span>
<span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">cleared_zones</span><span class="p">):</span>
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">cleared_zones</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_clear_expired_zones</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@@ -356,7 +373,7 @@
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../../index.html">pyad2 documentation</a> &raquo;</li>
<li><a href="../index.html" >Module code</a> &raquo;</li>
</ul>
</div>

+ 0
- 588
docs/_build/html/_modules/pyad2usb/ad2usb.html View File

@@ -1,588 +0,0 @@
<!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/html; charset=utf-8" />
<title>pyad2usb.ad2usb &mdash; pyad2usb documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../_static/jquery.js"></script>
<script type="text/javascript" src="../../_static/underscore.js"></script>
<script type="text/javascript" src="../../_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="../../index.html" />
<link rel="up" title="Module code" href="../index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>

<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<h1>Source code for pyad2usb.ad2usb</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Provides the full AD2USB class and factory.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">threading</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">devices</span>
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">util</span>

<div class="viewcode-block" id="Overseer"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer">[docs]</a><span class="k">class</span> <span class="nc">Overseer</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Factory for creation of AD2USB devices as well as provide4s attach/detach events.&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># Factory events</span>
<span class="n">on_attached</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when an AD2USB device has been detected.&#39;</span><span class="p">)</span>
<span class="n">on_detached</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when an AD2USB device has been removed.&#39;</span><span class="p">)</span>

<span class="n">__devices</span> <span class="o">=</span> <span class="p">[]</span>

<span class="nd">@classmethod</span>
<div class="viewcode-block" id="Overseer.find_all"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.find_all">[docs]</a> <span class="k">def</span> <span class="nf">find_all</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns all AD2USB devices located on the system.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cls</span><span class="o">.</span><span class="n">__devices</span> <span class="o">=</span> <span class="n">devices</span><span class="o">.</span><span class="n">USBDevice</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span>
</div>
<span class="nd">@classmethod</span>
<div class="viewcode-block" id="Overseer.devices"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.devices">[docs]</a> <span class="k">def</span> <span class="nf">devices</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns a cached list of AD2USB devices located on the system.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span>
</div>
<span class="nd">@classmethod</span>
<div class="viewcode-block" id="Overseer.create"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.create">[docs]</a> <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Factory method that returns the requested AD2USB device, or the first device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cls</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cls</span><span class="o">.</span><span class="n">__devices</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">NoDeviceError</span><span class="p">(</span><span class="s">&#39;No AD2USB devices present.&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">device</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">device</span> <span class="o">=</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

<span class="n">vendor</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">sernum</span><span class="p">,</span> <span class="n">ifcount</span><span class="p">,</span> <span class="n">description</span> <span class="o">=</span> <span class="n">device</span>
<span class="n">device</span> <span class="o">=</span> <span class="n">devices</span><span class="o">.</span><span class="n">USBDevice</span><span class="p">(</span><span class="n">serial</span><span class="o">=</span><span class="n">sernum</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="n">description</span><span class="p">)</span>

<span class="k">return</span> <span class="n">AD2USB</span><span class="p">(</span><span class="n">device</span><span class="p">)</span>
</div>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attached_event</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">detached_event</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span> <span class="o">=</span> <span class="n">Overseer</span><span class="o">.</span><span class="n">DetectThread</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="k">if</span> <span class="n">attached_event</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_attached</span> <span class="o">+=</span> <span class="n">attached_event</span>

<span class="k">if</span> <span class="n">detached_event</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_detached</span> <span class="o">+=</span> <span class="n">detached_event</span>

<span class="n">Overseer</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="bp">self</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>

<div class="viewcode-block" id="Overseer.close"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Clean up and shut down.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Overseer.start"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.start">[docs]</a> <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Starts the detection thread, if not already running.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span><span class="o">.</span><span class="n">is_alive</span><span class="p">():</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Overseer.stop"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stops the detection thread.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_detect_thread</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="Overseer.get_device"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.get_device">[docs]</a> <span class="k">def</span> <span class="nf">get_device</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">device</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Factory method that returns the requested AD2USB device, or the first device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">Overseer</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">device</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="Overseer.DetectThread"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.DetectThread">[docs]</a> <span class="k">class</span> <span class="nc">DetectThread</span><span class="p">(</span><span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Thread that handles detection of added/removed devices.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">overseer</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_overseer</span> <span class="o">=</span> <span class="n">overseer</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>

<div class="viewcode-block" id="Overseer.DetectThread.stop"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.DetectThread.stop">[docs]</a> <span class="k">def</span> <span class="nf">stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Stops the thread.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span>
</div>
<div class="viewcode-block" id="Overseer.DetectThread.run"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Overseer.DetectThread.run">[docs]</a> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The actual detection process.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">True</span>

<span class="n">last_devices</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>

<span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">_running</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">Overseer</span><span class="o">.</span><span class="n">find_all</span><span class="p">()</span>

<span class="n">current_devices</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">Overseer</span><span class="o">.</span><span class="n">devices</span><span class="p">())</span>
<span class="n">new_devices</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">current_devices</span> <span class="k">if</span> <span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">last_devices</span><span class="p">]</span>
<span class="n">removed_devices</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">last_devices</span> <span class="k">if</span> <span class="n">d</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">current_devices</span><span class="p">]</span>
<span class="n">last_devices</span> <span class="o">=</span> <span class="n">current_devices</span>

<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">new_devices</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_overseer</span><span class="o">.</span><span class="n">on_attached</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">removed_devices</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_overseer</span><span class="o">.</span><span class="n">on_detached</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>

<span class="k">except</span> <span class="n">util</span><span class="o">.</span><span class="n">CommError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span>
<span class="k">pass</span>

<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.25</span><span class="p">)</span>

</div></div></div>
<div class="viewcode-block" id="AD2USB"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB">[docs]</a><span class="k">class</span> <span class="nc">AD2USB</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> High-level wrapper around AD2USB/AD2SERIAL devices.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="c"># High-level Events</span>
<span class="n">on_status_changed</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the panel status changes.&#39;</span><span class="p">)</span>
<span class="n">on_power_changed</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when panel power switches between AC and DC.&#39;</span><span class="p">)</span>
<span class="n">on_alarm</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the alarm is triggered.&#39;</span><span class="p">)</span>
<span class="n">on_bypass</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a zone is bypassed.&#39;</span><span class="p">)</span>
<span class="n">on_boot</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device finishes bootings.&#39;</span><span class="p">)</span>
<span class="n">on_config_received</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device receives its configuration.&#39;</span><span class="p">)</span>

<span class="c"># Mid-level Events</span>
<span class="n">on_message</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a message has been received from the device.&#39;</span><span class="p">)</span>

<span class="c"># Low-level Events</span>
<span class="n">on_open</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device has been opened.&#39;</span><span class="p">)</span>
<span class="n">on_close</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when the device has been closed.&#39;</span><span class="p">)</span>
<span class="n">on_read</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when a line has been read from the device.&#39;</span><span class="p">)</span>
<span class="n">on_write</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">&#39;Called when data has been written to the device.&#39;</span><span class="p">)</span>

<span class="c"># Constants</span>
<span class="n">F1</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">F2</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">F3</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="n">F4</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">device</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">device</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span> <span class="o">=</span> <span class="bp">None</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_settings</span> <span class="o">=</span> <span class="p">{}</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_address_mask</span> <span class="o">=</span> <span class="mh">0xFF80</span> <span class="c"># TEMP</span>

<div class="viewcode-block" id="AD2USB.open"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB.open">[docs]</a> <span class="k">def</span> <span class="nf">open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">baudrate</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Opens the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_wire_events</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="n">baudrate</span><span class="o">=</span><span class="n">baudrate</span><span class="p">,</span> <span class="n">interface</span><span class="o">=</span><span class="n">interface</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="n">index</span><span class="p">,</span> <span class="n">no_reader_thread</span><span class="o">=</span><span class="n">no_reader_thread</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AD2USB.close"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB.close">[docs]</a> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Closes the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="bp">None</span>
</div>
<div class="viewcode-block" id="AD2USB.get_config"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB.get_config">[docs]</a> <span class="k">def</span> <span class="nf">get_config</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Retrieves the configuration from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&quot;C</span><span class="se">\r</span><span class="s">&quot;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="AD2USB.set_config"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB.set_config">[docs]</a> <span class="k">def</span> <span class="nf">set_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets configuration entries on the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">pass</span>
</div>
<div class="viewcode-block" id="AD2USB.reboot"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB.reboot">[docs]</a> <span class="k">def</span> <span class="nf">reboot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Reboots the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)</span>
</div>
<span class="nd">@property</span>
<div class="viewcode-block" id="AD2USB.id"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.AD2USB.id">[docs]</a> <span class="k">def</span> <span class="nf">id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">id</span>
</div>
<span class="k">def</span> <span class="nf">_wire_events</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Wires up the internal device events.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_open</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_open</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_close</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_close</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_read</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_read</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">on_write</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_on_write</span>

<span class="k">def</span> <span class="nf">_handle_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parses messages from the panel.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">None</span>

<span class="n">msg</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">if</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;!&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">Message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_address_mask</span> <span class="o">&amp;</span> <span class="n">msg</span><span class="o">.</span><span class="n">mask</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update_internal_states</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">else</span><span class="p">:</span> <span class="c"># specialty messages</span>
<span class="n">header</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span>

<span class="k">if</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!EXP&#39;</span> <span class="ow">or</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!REL&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!RFX&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">RFMessage</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!LRR&#39;</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="n">LRRMessage</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;!Ready&#39;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_boot</span><span class="p">()</span>
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;!CONFIG&#39;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_handle_config</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">return</span> <span class="n">msg</span>

<span class="k">def</span> <span class="nf">_handle_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="n">_</span><span class="p">,</span> <span class="n">config_string</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;&gt;&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">setting</span> <span class="ow">in</span> <span class="n">config_string</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;&amp;&#39;</span><span class="p">):</span>
<span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">setting</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_settings</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>

<span class="bp">self</span><span class="o">.</span><span class="n">on_config_received</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_settings</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_update_internal_states</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">ac_power</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_power_changed</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_power_status</span><span class="p">)</span>

<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">alarm_sounding</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_alarm</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_alarm_status</span><span class="p">)</span>

<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span><span class="p">,</span> <span class="n">old_status</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="n">zone_bypassed</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span>

<span class="k">if</span> <span class="n">old_status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_bypass</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_bypass_status</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_open</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for opening the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for closing the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_close</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_read</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for reading from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_read</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>

<span class="n">msg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_handle_message</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="k">if</span> <span class="n">msg</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_message</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_on_write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Internal handler for writing to the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a message from the alarm panel.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="bp">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cursor_location</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

<span class="bp">self</span><span class="o">.</span><span class="n">_regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">&#39;(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*),(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*),(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*),(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*)&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parse the message from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_regex</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">&#39;Received invalid message: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>

<span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">,</span> <span class="n">alpha</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">3</span><span class="o">+</span><span class="mi">8</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">7</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">9</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">11</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">11</span><span class="p">:</span><span class="mi">12</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="n">alpha</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s">&#39;&quot;&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">19</span><span class="p">:</span><span class="mi">21</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> <span class="o">&amp;</span> <span class="mh">0x01</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cursor_location</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">21</span><span class="p">:</span><span class="mi">23</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> <span class="c"># Alpha character index that the cursor is on.</span>

<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String conversion operator.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;msg &gt; {0:0&lt;9} [{1}{2}{3}] -- ({4}) {5}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">),</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="ExpanderMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.ExpanderMessage">[docs]</a><span class="k">class</span> <span class="nc">ExpanderMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a message from a zone or relay expansion module.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ZONE</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">RELAY</span> <span class="o">=</span> <span class="mi">1</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String conversion operator.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">expander_type</span> <span class="o">=</span> <span class="s">&#39;UNKWN&#39;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span><span class="p">:</span>
<span class="n">expander_type</span> <span class="o">=</span> <span class="s">&#39;ZONE&#39;</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span><span class="p">:</span>
<span class="n">expander_type</span> <span class="o">=</span> <span class="s">&#39;RELAY&#39;</span>

<span class="k">return</span> <span class="s">&#39;exp &gt; [{0: &lt;5}] {1}/{2} -- {3}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">expander_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parse the raw message from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">header</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="n">address</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>

<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">address</span>
<span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="n">channel</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>

<span class="k">if</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!EXP&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span>
<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!REL&#39;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span>
</div>
<div class="viewcode-block" id="RFMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.RFMessage">[docs]</a><span class="k">class</span> <span class="nc">RFMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represents a message from an RF receiver.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String conversion operator.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;rf &gt; {0}: {1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parses the raw message from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>

<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LRRMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.ad2usb.LRRMessage">[docs]</a><span class="k">class</span> <span class="nc">LRRMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Represent a message from a Long Range Radio.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Constructor</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_partition</span> <span class="o">=</span> <span class="bp">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="bp">None</span>

<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> String conversion operator.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s">&#39;lrr &gt; {0} @ {1} -- {2}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Parses the raw message from the device.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>

<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_partition</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span></div>
</pre></div>

</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="../index.html" >Module code</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Author.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
</div>
</body>
</html>

+ 2
- 2
docs/_build/html/_sources/index.txt View File

@@ -3,7 +3,7 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to pyad2usb's documentation!
Welcome to pyad2's documentation!
====================================

Contents:
@@ -11,7 +11,7 @@ Contents:
.. toctree::
:maxdepth: 4

pyad2usb
pyad2


Indices and tables


+ 2
- 2
docs/_build/html/_sources/modules.txt View File

@@ -1,7 +1,7 @@
pyad2usb
pyad2
========

.. toctree::
:maxdepth: 4

pyad2usb
pyad2

docs/pyad2usb.event.rst → docs/_build/html/_sources/pyad2.event.txt View File

@@ -4,7 +4,7 @@ event Package
:mod:`event` Package
--------------------

.. automodule:: pyad2usb.event
.. automodule:: pyad2.event
:members:
:undoc-members:
:show-inheritance:
@@ -12,7 +12,7 @@ event Package
:mod:`event` Module
-------------------

.. automodule:: pyad2usb.event.event
.. automodule:: pyad2.event.event
:members:
:undoc-members:
:show-inheritance:

docs/pyad2usb.rst → docs/_build/html/_sources/pyad2.txt View File

@@ -1,10 +1,10 @@
pyad2usb Package
pyad2 Package
================

:mod:`ad2usb` Module
:mod:`ad2` Module
--------------------

.. automodule:: pyad2usb.ad2usb
.. automodule:: pyad2.ad2
:members:
:undoc-members:
:show-inheritance:
@@ -12,7 +12,7 @@ pyad2usb Package
:mod:`devices` Module
---------------------

.. automodule:: pyad2usb.devices
.. automodule:: pyad2.devices
:members:
:undoc-members:
:show-inheritance:
@@ -20,7 +20,7 @@ pyad2usb Package
:mod:`util` Module
------------------

.. automodule:: pyad2usb.util
.. automodule:: pyad2.util
:members:
:undoc-members:
:show-inheritance:
@@ -28,7 +28,7 @@ pyad2usb Package
:mod:`zonetracking` Module
--------------------------

.. automodule:: pyad2usb.zonetracking
.. automodule:: pyad2.zonetracking
:members:
:undoc-members:
:show-inheritance:
@@ -36,7 +36,7 @@ pyad2usb Package
:mod:`panels` Module
--------------------

.. automodule:: pyad2usb.panels
.. automodule:: pyad2.panels
:members:
:undoc-members:
:show-inheritance:
@@ -44,7 +44,7 @@ pyad2usb Package
:mod:`messages` Module
----------------------

.. automodule:: pyad2usb.messages
.. automodule:: pyad2.messages
:members:
:undoc-members:
:show-inheritance:
@@ -54,5 +54,5 @@ Subpackages

.. toctree::

pyad2usb.event
pyad2.event


+ 2
- 2
docs/_build/html/_sources/pyad2usb.event.txt View File

@@ -4,7 +4,7 @@ event Package
:mod:`event` Package
--------------------

.. automodule:: pyad2usb.event
.. automodule:: pyad2.event
:members:
:undoc-members:
:show-inheritance:
@@ -12,7 +12,7 @@ event Package
:mod:`event` Module
-------------------

.. automodule:: pyad2usb.event.event
.. automodule:: pyad2.event.event
:members:
:undoc-members:
:show-inheritance:


+ 7
- 7
docs/_build/html/_sources/pyad2usb.txt View File

@@ -1,10 +1,10 @@
pyad2usb Package
================

:mod:`ad2usb` Module
:mod:`ad2` Module
--------------------

.. automodule:: pyad2usb.ad2usb
.. automodule:: pyad2.ad2
:members:
:undoc-members:
:show-inheritance:
@@ -12,7 +12,7 @@ pyad2usb Package
:mod:`devices` Module
---------------------

.. automodule:: pyad2usb.devices
.. automodule:: pyad2.devices
:members:
:undoc-members:
:show-inheritance:
@@ -20,7 +20,7 @@ pyad2usb Package
:mod:`util` Module
------------------

.. automodule:: pyad2usb.util
.. automodule:: pyad2.util
:members:
:undoc-members:
:show-inheritance:
@@ -28,7 +28,7 @@ pyad2usb Package
:mod:`zonetracking` Module
--------------------------

.. automodule:: pyad2usb.zonetracking
.. automodule:: pyad2.zonetracking
:members:
:undoc-members:
:show-inheritance:
@@ -36,7 +36,7 @@ pyad2usb Package
:mod:`panels` Module
--------------------

.. automodule:: pyad2usb.panels
.. automodule:: pyad2.panels
:members:
:undoc-members:
:show-inheritance:
@@ -44,7 +44,7 @@ pyad2usb Package
:mod:`messages` Module
----------------------

.. automodule:: pyad2usb.messages
.. automodule:: pyad2.messages
:members:
:undoc-members:
:show-inheritance:


+ 187
- 129
docs/_build/html/genindex.html View File

@@ -7,7 +7,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Index &mdash; pyad2usb documentation</title>
<title>Index &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
@@ -24,7 +24,7 @@
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="index.html" />
<link rel="top" title="pyad2 documentation" href="index.html" />
</head>
<body>
<div class="related">
@@ -36,7 +36,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -74,13 +74,13 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB">AD2USB (class in pyad2usb.ad2usb)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2">AD2 (class in pyad2.ad2)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.event.html#pyad2usb.event.event.EventHandler.add">add() (pyad2usb.event.event.EventHandler method)</a>
<dt><a href="pyad2.event.html#pyad2.event.event.EventHandler.add">add() (pyad2.event.event.EventHandler method)</a>
</dt>

</dl></td>
@@ -90,18 +90,22 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.BATTERY_TIMEOUT">BATTERY_TIMEOUT (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.messages.BaseMessage">BaseMessage (class in pyad2.messages)</a>
</dt>

<dt><a href="pyad2.html#pyad2.ad2.AD2.BATTERY_TIMEOUT">BATTERY_TIMEOUT (pyad2.ad2.AD2 attribute)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.BAUDRATE">BAUDRATE (pyad2usb.devices.SerialDevice attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.BAUDRATE">BAUDRATE (pyad2.devices.SerialDevice attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.BAUDRATE">(pyad2usb.devices.USBDevice attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.BAUDRATE">(pyad2.devices.USBDevice attribute)</a>
</dt>

</dl></dd>
@@ -112,47 +116,51 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.CHECK">CHECK (pyad2usb.zonetracking.Zone attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zone.CHECK">CHECK (pyad2.zonetracking.Zone attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.CLEAR">CLEAR (pyad2usb.zonetracking.Zone attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zone.CLEAR">CLEAR (pyad2.zonetracking.Zone attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.clear_zone">clear_zone() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.clear_zone">clear_zone() (pyad2.ad2.AD2 method)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.close">close() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.close">close() (pyad2.ad2.AD2 method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.close">(pyad2usb.ad2usb.Overseer method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.close">(pyad2.ad2.Overseer method)</a>
</dt>

<dt><a href="pyad2.html#pyad2.devices.Device.close">(pyad2.devices.Device method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.close">(pyad2usb.devices.SerialDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.close">(pyad2.devices.SerialDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.SocketDevice.close">(pyad2usb.devices.SocketDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.close">(pyad2.devices.SocketDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.close">(pyad2usb.devices.USBDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.close">(pyad2.devices.USBDevice method)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.util.CommError">CommError</a>
<dt><a href="pyad2.html#pyad2.util.CommError">CommError</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.create">create() (pyad2usb.ad2usb.Overseer class method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.create">create() (pyad2.ad2.Overseer class method)</a>
</dt>

</dl></td>
@@ -162,17 +170,21 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device">Device (class in pyad2usb.devices)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.description">description (pyad2.devices.USBDevice attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.Device.ReadThread">Device.ReadThread (class in pyad2usb.devices)</a>
<dt><a href="pyad2.html#pyad2.devices.Device">Device (class in pyad2.devices)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.devices">devices() (pyad2usb.ad2usb.Overseer class method)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.ReadThread">Device.ReadThread (class in pyad2.devices)</a>
</dt>

<dt><a href="pyad2.html#pyad2.ad2.Overseer.devices">devices() (pyad2.ad2.Overseer class method)</a>
</dt>

</dl></td>
@@ -182,21 +194,21 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.event.html#pyad2usb.event.event.Event">Event (class in pyad2usb.event.event)</a>
<dt><a href="pyad2.event.html#pyad2.event.event.Event">Event (class in pyad2.event.event)</a>
</dt>

<dt><a href="pyad2usb.event.html#pyad2usb.event.event.EventHandler">EventHandler (class in pyad2usb.event.event)</a>
<dt><a href="pyad2.event.html#pyad2.event.event.EventHandler">EventHandler (class in pyad2.event.event)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.messages.ExpanderMessage">ExpanderMessage (class in pyad2usb.messages)</a>
<dt><a href="pyad2.html#pyad2.messages.ExpanderMessage">ExpanderMessage (class in pyad2.messages)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.EXPIRE">EXPIRE (pyad2usb.zonetracking.Zonetracker attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zonetracker.EXPIRE">EXPIRE (pyad2.zonetracking.Zonetracker attribute)</a>
</dt>

</dl></td>
@@ -206,63 +218,63 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.F1">F1 (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.F1">F1 (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.F2">F2 (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.F2">F2 (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.F3">F3 (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.F3">F3 (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.F4">F4 (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.F4">F4 (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.FAULT">FAULT (pyad2usb.zonetracking.Zone attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zone.FAULT">FAULT (pyad2.zonetracking.Zone attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.fault_zone">fault_zone() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.fault_zone">fault_zone() (pyad2.ad2.AD2 method)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.find_all">find_all() (pyad2usb.ad2usb.Overseer class method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.find_all">find_all() (pyad2.ad2.Overseer class method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.find_all">(pyad2usb.devices.SerialDevice static method)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.find_all">(pyad2.devices.SerialDevice static method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.find_all">(pyad2usb.devices.USBDevice static method)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.find_all">(pyad2.devices.USBDevice static method)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.event.html#pyad2usb.event.event.EventHandler.fire">fire() (pyad2usb.event.event.EventHandler method)</a>
<dt><a href="pyad2.event.html#pyad2.event.event.EventHandler.fire">fire() (pyad2.event.event.EventHandler method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.FIRE_TIMEOUT">FIRE_TIMEOUT (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.FIRE_TIMEOUT">FIRE_TIMEOUT (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware">Firmware (class in pyad2usb.util)</a>
<dt><a href="pyad2.html#pyad2.util.Firmware">Firmware (class in pyad2.util)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.FTDI_PRODUCT_ID">FTDI_PRODUCT_ID (pyad2usb.devices.USBDevice attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.FTDI_PRODUCT_ID">FTDI_PRODUCT_ID (pyad2.devices.USBDevice attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.FTDI_VENDOR_ID">FTDI_VENDOR_ID (pyad2usb.devices.USBDevice attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.FTDI_VENDOR_ID">FTDI_VENDOR_ID (pyad2.devices.USBDevice attribute)</a>
</dt>

</dl></td>
@@ -272,13 +284,13 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.get_config">get_config() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.get_config">get_config() (pyad2.ad2.AD2 method)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.get_device">get_device() (pyad2usb.ad2usb.Overseer method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.get_device">get_device() (pyad2.ad2.Overseer method)</a>
</dt>

</dl></td>
@@ -288,23 +300,37 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.id">id (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.id">id (pyad2.ad2.AD2 attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.id">(pyad2usb.devices.Device attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.id">(pyad2.devices.Device attribute)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.util.InvalidMessageError">InvalidMessageError</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.interface">interface (pyad2.devices.SerialDevice attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.interface">(pyad2.devices.SocketDevice attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.devices.USBDevice.interface">(pyad2.devices.USBDevice attribute)</a>
</dt>

</dl></dd>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.is_reader_alive">is_reader_alive() (pyad2usb.devices.Device method)</a>
<dt><a href="pyad2.html#pyad2.util.InvalidMessageError">InvalidMessageError</a>
</dt>

<dt><a href="pyad2.html#pyad2.devices.Device.is_reader_alive">is_reader_alive() (pyad2.devices.Device method)</a>
</dt>

</dl></td>
@@ -314,7 +340,7 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.messages.LRRMessage">LRRMessage (class in pyad2usb.messages)</a>
<dt><a href="pyad2.html#pyad2.messages.LRRMessage">LRRMessage (class in pyad2.messages)</a>
</dt>

</dl></td>
@@ -324,7 +350,7 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.messages.Message">Message (class in pyad2usb.messages)</a>
<dt><a href="pyad2.html#pyad2.messages.Message">Message (class in pyad2.messages)</a>
</dt>

</dl></td>
@@ -334,7 +360,7 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.util.NoDeviceError">NoDeviceError</a>
<dt><a href="pyad2.html#pyad2.util.NoDeviceError">NoDeviceError</a>
</dt>

</dl></td>
@@ -344,143 +370,151 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_alarm">on_alarm (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_alarm">on_alarm (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_arm">on_arm (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_arm">on_arm (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.on_attached">on_attached (pyad2usb.ad2usb.Overseer attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.on_attached">on_attached (pyad2.ad2.Overseer attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_boot">on_boot (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_boot">on_boot (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_bypass">on_bypass (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_bypass">on_bypass (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_close">on_close (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_close">on_close (pyad2.ad2.AD2 attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.on_close">(pyad2usb.devices.Device attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.on_close">(pyad2.devices.Device attribute)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_config_received">on_config_received (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_config_received">on_config_received (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.on_detached">on_detached (pyad2usb.ad2usb.Overseer attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.on_detached">on_detached (pyad2.ad2.Overseer attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_disarm">on_disarm (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_disarm">on_disarm (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.on_fault">on_fault (pyad2usb.zonetracking.Zonetracker attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zonetracker.on_fault">on_fault (pyad2.zonetracking.Zonetracker attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_fire">on_fire (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_fire">on_fire (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_low_battery">on_low_battery (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_low_battery">on_low_battery (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_lrr_message">on_lrr_message (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_lrr_message">on_lrr_message (pyad2.ad2.AD2 attribute)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_message">on_message (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_message">on_message (pyad2.ad2.AD2 attribute)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_open">on_open (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_open">on_open (pyad2.ad2.AD2 attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.on_open">(pyad2usb.devices.Device attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.on_open">(pyad2.devices.Device attribute)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_panic">on_panic (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_panic">on_panic (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_power_changed">on_power_changed (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_power_changed">on_power_changed (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_read">on_read (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_read">on_read (pyad2.ad2.AD2 attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.on_read">(pyad2usb.devices.Device attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.on_read">(pyad2.devices.Device attribute)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.on_restore">on_restore (pyad2usb.zonetracking.Zonetracker attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_relay_changed">on_relay_changed (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_write">on_write (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zonetracker.on_restore">on_restore (pyad2.zonetracking.Zonetracker attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.ad2.AD2.on_rfx_message">on_rfx_message (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.ad2.AD2.on_write">on_write (pyad2.ad2.AD2 attribute)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.on_write">(pyad2usb.devices.Device attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.on_write">(pyad2.devices.Device attribute)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_zone_fault">on_zone_fault (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_zone_fault">on_zone_fault (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_zone_restore">on_zone_restore (pyad2usb.ad2usb.AD2USB attribute)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.on_zone_restore">on_zone_restore (pyad2.ad2.AD2 attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.open">open() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.open">open() (pyad2.ad2.AD2 method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.open">(pyad2usb.devices.SerialDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.open">(pyad2.devices.SerialDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.SocketDevice.open">(pyad2usb.devices.SocketDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.open">(pyad2.devices.SocketDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.open">(pyad2usb.devices.USBDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.open">(pyad2.devices.USBDevice method)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer">Overseer (class in pyad2usb.ad2usb)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer">Overseer (class in pyad2.ad2)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.DetectThread">Overseer.DetectThread (class in pyad2usb.ad2usb)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.DetectThread">Overseer.DetectThread (class in pyad2.ad2)</a>
</dt>

</dl></td>
@@ -490,37 +524,37 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#module-pyad2usb.ad2usb">pyad2usb.ad2usb (module)</a>
<dt><a href="pyad2.html#module-pyad2.ad2">pyad2.ad2 (module)</a>
</dt>

<dt><a href="pyad2usb.html#module-pyad2usb.devices">pyad2usb.devices (module)</a>
<dt><a href="pyad2.html#module-pyad2.devices">pyad2.devices (module)</a>
</dt>

<dt><a href="pyad2usb.event.html#module-pyad2usb.event">pyad2usb.event (module)</a>
<dt><a href="pyad2.event.html#module-pyad2.event">pyad2.event (module)</a>
</dt>

<dt><a href="pyad2usb.event.html#module-pyad2usb.event.event">pyad2usb.event.event (module)</a>
<dt><a href="pyad2.event.html#module-pyad2.event.event">pyad2.event.event (module)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#module-pyad2usb.messages">pyad2usb.messages (module)</a>
<dt><a href="pyad2.html#module-pyad2.messages">pyad2.messages (module)</a>
</dt>

<dt><a href="pyad2usb.html#module-pyad2usb.panels">pyad2usb.panels (module)</a>
<dt><a href="pyad2.html#module-pyad2.panels">pyad2.panels (module)</a>
</dt>

<dt><a href="pyad2usb.html#module-pyad2usb.util">pyad2usb.util (module)</a>
<dt><a href="pyad2.html#module-pyad2.util">pyad2.util (module)</a>
</dt>

<dt><a href="pyad2usb.html#module-pyad2usb.zonetracking">pyad2usb.zonetracking (module)</a>
<dt><a href="pyad2.html#module-pyad2.zonetracking">pyad2.zonetracking (module)</a>
</dt>

</dl></td>
@@ -530,62 +564,62 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.read">read() (pyad2usb.devices.SerialDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.read">read() (pyad2.devices.SerialDevice method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SocketDevice.read">(pyad2usb.devices.SocketDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.read">(pyad2.devices.SocketDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.read">(pyad2usb.devices.USBDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.read">(pyad2.devices.USBDevice method)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.read_line">read_line() (pyad2usb.devices.SerialDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.read_line">read_line() (pyad2.devices.SerialDevice method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SocketDevice.read_line">(pyad2usb.devices.SocketDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.read_line">(pyad2.devices.SocketDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.read_line">(pyad2usb.devices.USBDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.read_line">(pyad2.devices.USBDevice method)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.ReadThread.READ_TIMEOUT">READ_TIMEOUT (pyad2usb.devices.Device.ReadThread attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.ReadThread.READ_TIMEOUT">READ_TIMEOUT (pyad2.devices.Device.ReadThread attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.reboot">reboot() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.reboot">reboot() (pyad2.ad2.AD2 method)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.messages.ExpanderMessage.RELAY">RELAY (pyad2usb.messages.ExpanderMessage attribute)</a>
<dt><a href="pyad2.html#pyad2.messages.ExpanderMessage.RELAY">RELAY (pyad2.messages.ExpanderMessage attribute)</a>
</dt>

<dt><a href="pyad2usb.event.html#pyad2usb.event.event.EventHandler.remove">remove() (pyad2usb.event.event.EventHandler method)</a>
<dt><a href="pyad2.event.html#pyad2.event.event.EventHandler.remove">remove() (pyad2.event.event.EventHandler method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.messages.RFMessage">RFMessage (class in pyad2usb.messages)</a>
<dt><a href="pyad2.html#pyad2.messages.RFMessage">RFMessage (class in pyad2.messages)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.DetectThread.run">run() (pyad2usb.ad2usb.Overseer.DetectThread method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.DetectThread.run">run() (pyad2.ad2.Overseer.DetectThread method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.ReadThread.run">(pyad2usb.devices.Device.ReadThread method)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.ReadThread.run">(pyad2.devices.Device.ReadThread method)</a>
</dt>

</dl></dd>
@@ -596,67 +630,91 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.save_config">save_config() (pyad2usb.ad2usb.AD2USB method)</a>
<dt><a href="pyad2.html#pyad2.ad2.AD2.save_config">save_config() (pyad2.ad2.AD2 method)</a>
</dt>

<dt><a href="pyad2.html#pyad2.ad2.AD2.send">send() (pyad2.ad2.AD2 method)</a>
</dt>

<dt><a href="pyad2.html#pyad2.devices.USBDevice.serial_number">serial_number (pyad2.devices.USBDevice attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice">SerialDevice (class in pyad2usb.devices)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice">SerialDevice (class in pyad2.devices)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.SocketDevice">SocketDevice (class in pyad2usb.devices)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice">SocketDevice (class in pyad2.devices)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_BOOT">STAGE_BOOT (pyad2usb.util.Firmware attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.ssl">ssl (pyad2.devices.SocketDevice attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_DONE">STAGE_DONE (pyad2usb.util.Firmware attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.ssl_ca">ssl_ca (pyad2.devices.SocketDevice attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_LOAD">STAGE_LOAD (pyad2usb.util.Firmware attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.ssl_certificate">ssl_certificate (pyad2.devices.SocketDevice attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_START">STAGE_START (pyad2usb.util.Firmware attribute)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.ssl_key">ssl_key (pyad2.devices.SocketDevice attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.util.Firmware.STAGE_BOOT">STAGE_BOOT (pyad2.util.Firmware attribute)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_UPLOADING">STAGE_UPLOADING (pyad2usb.util.Firmware attribute)</a>
<dt><a href="pyad2.html#pyad2.util.Firmware.STAGE_DONE">STAGE_DONE (pyad2.util.Firmware attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.util.Firmware.STAGE_LOAD">STAGE_LOAD (pyad2.util.Firmware attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.util.Firmware.STAGE_START">STAGE_START (pyad2.util.Firmware attribute)</a>
</dt>

<dt><a href="pyad2.html#pyad2.util.Firmware.STAGE_UPLOADING">STAGE_UPLOADING (pyad2.util.Firmware attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_WAITING">STAGE_WAITING (pyad2usb.util.Firmware attribute)</a>
<dt><a href="pyad2.html#pyad2.util.Firmware.STAGE_WAITING">STAGE_WAITING (pyad2.util.Firmware attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.start">start() (pyad2usb.ad2usb.Overseer method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.start">start() (pyad2.ad2.Overseer method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.STATUS">STATUS (pyad2usb.zonetracking.Zone attribute)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zone.STATUS">STATUS (pyad2.zonetracking.Zone attribute)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.stop">stop() (pyad2usb.ad2usb.Overseer method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.stop">stop() (pyad2.ad2.Overseer method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.DetectThread.stop">(pyad2usb.ad2usb.Overseer.DetectThread method)</a>
<dt><a href="pyad2.html#pyad2.ad2.Overseer.DetectThread.stop">(pyad2.ad2.Overseer.DetectThread method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.Device.ReadThread.stop">(pyad2usb.devices.Device.ReadThread method)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.ReadThread.stop">(pyad2.devices.Device.ReadThread method)</a>
</dt>

</dl></dd>
<dt><a href="pyad2usb.html#pyad2usb.devices.Device.stop_reader">stop_reader() (pyad2usb.devices.Device method)</a>
<dt><a href="pyad2.html#pyad2.devices.Device.stop_reader">stop_reader() (pyad2.devices.Device method)</a>
</dt>

</dl></td>
@@ -666,7 +724,7 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.util.TimeoutError">TimeoutError</a>
<dt><a href="pyad2.html#pyad2.util.TimeoutError">TimeoutError</a>
</dt>

</dl></td>
@@ -676,17 +734,17 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.update">update() (pyad2usb.zonetracking.Zonetracker method)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zonetracker.update">update() (pyad2.zonetracking.Zonetracker method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.upload">upload() (pyad2usb.util.Firmware static method)</a>
<dt><a href="pyad2.html#pyad2.util.Firmware.upload">upload() (pyad2.util.Firmware static method)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice">USBDevice (class in pyad2usb.devices)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice">USBDevice (class in pyad2.devices)</a>
</dt>

</dl></td>
@@ -696,16 +754,16 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.write">write() (pyad2usb.devices.SerialDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SerialDevice.write">write() (pyad2.devices.SerialDevice method)</a>
</dt>

<dd><dl>
<dt><a href="pyad2usb.html#pyad2usb.devices.SocketDevice.write">(pyad2usb.devices.SocketDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.SocketDevice.write">(pyad2.devices.SocketDevice method)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.devices.USBDevice.write">(pyad2usb.devices.USBDevice method)</a>
<dt><a href="pyad2.html#pyad2.devices.USBDevice.write">(pyad2.devices.USBDevice method)</a>
</dt>

</dl></dd>
@@ -716,17 +774,17 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone">Zone (class in pyad2usb.zonetracking)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zone">Zone (class in pyad2.zonetracking)</a>
</dt>

<dt><a href="pyad2usb.html#pyad2usb.messages.ExpanderMessage.ZONE">ZONE (pyad2usb.messages.ExpanderMessage attribute)</a>
<dt><a href="pyad2.html#pyad2.messages.ExpanderMessage.ZONE">ZONE (pyad2.messages.ExpanderMessage attribute)</a>
</dt>

</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker">Zonetracker (class in pyad2usb.zonetracking)</a>
<dt><a href="pyad2.html#pyad2.zonetracking.Zonetracker">Zonetracker (class in pyad2.zonetracking)</a>
</dt>

</dl></td>
@@ -768,7 +826,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


+ 23
- 23
docs/_build/html/index.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to pyad2usb’s documentation! &mdash; pyad2usb documentation</title>
<title>Welcome to pyad2’s documentation! &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
@@ -23,8 +23,8 @@
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="#" />
<link rel="next" title="pyad2usb Package" href="pyad2usb.html" />
<link rel="top" title="pyad2 documentation" href="#" />
<link rel="next" title="pyad2 Package" href="pyad2.html" />
</head>
<body>
<div class="related">
@@ -37,9 +37,9 @@
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="pyad2usb.html" title="pyad2usb Package"
<a href="pyad2.html" title="pyad2 Package"
accesskey="N">next</a> |</li>
<li><a href="#">pyad2usb documentation</a> &raquo;</li>
<li><a href="#">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -48,22 +48,22 @@
<div class="bodywrapper">
<div class="body">
<div class="section" id="welcome-to-pyad2usb-s-documentation">
<h1>Welcome to pyad2usb&#8217;s documentation!<a class="headerlink" href="#welcome-to-pyad2usb-s-documentation" title="Permalink to this headline">¶</a></h1>
<div class="section" id="welcome-to-pyad2-s-documentation">
<h1>Welcome to pyad2&#8217;s documentation!<a class="headerlink" href="#welcome-to-pyad2-s-documentation" title="Permalink to this headline">¶</a></h1>
<p>Contents:</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="pyad2usb.html">pyad2usb Package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.ad2usb"><tt class="docutils literal"><span class="pre">ad2usb</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.devices"><tt class="docutils literal"><span class="pre">devices</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.util"><tt class="docutils literal"><span class="pre">util</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.zonetracking"><tt class="docutils literal"><span class="pre">zonetracking</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.panels"><tt class="docutils literal"><span class="pre">panels</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.messages"><tt class="docutils literal"><span class="pre">messages</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="pyad2usb.event.html">event Package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyad2usb.event.html#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyad2usb.event.html#module-pyad2usb.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="pyad2.html">pyad2 Package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.ad2"><tt class="docutils literal"><span class="pre">ad2</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.devices"><tt class="docutils literal"><span class="pre">devices</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.util"><tt class="docutils literal"><span class="pre">util</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.zonetracking"><tt class="docutils literal"><span class="pre">zonetracking</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.panels"><tt class="docutils literal"><span class="pre">panels</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.messages"><tt class="docutils literal"><span class="pre">messages</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="pyad2.event.html">event Package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyad2.event.html#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyad2.event.html#module-pyad2.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
</ul>
</li>
</ul>
@@ -90,15 +90,15 @@
<div class="sphinxsidebarwrapper">
<h3><a href="#">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Welcome to pyad2usb&#8217;s documentation!</a><ul>
<li><a class="reference internal" href="#">Welcome to pyad2&#8217;s documentation!</a><ul>
</ul>
</li>
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
</ul>

<h4>Next topic</h4>
<p class="topless"><a href="pyad2usb.html"
title="next chapter">pyad2usb Package</a></p>
<p class="topless"><a href="pyad2.html"
title="next chapter">pyad2 Package</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/index.txt"
@@ -131,9 +131,9 @@
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="pyad2usb.html" title="pyad2usb Package"
<a href="pyad2.html" title="pyad2 Package"
>next</a> |</li>
<li><a href="#">pyad2usb documentation</a> &raquo;</li>
<li><a href="#">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


+ 17
- 17
docs/_build/html/modules.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pyad2usb &mdash; pyad2usb documentation</title>
<title>pyad2 &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="index.html" />
<link rel="top" title="pyad2 documentation" href="index.html" />
</head>
<body>
<div class="related">
@@ -35,7 +35,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -44,21 +44,21 @@
<div class="bodywrapper">
<div class="body">
<div class="section" id="pyad2usb">
<h1>pyad2usb<a class="headerlink" href="#pyad2usb" title="Permalink to this headline">¶</a></h1>
<div class="section" id="pyad2">
<h1>pyad2<a class="headerlink" href="#pyad2" title="Permalink to this headline">¶</a></h1>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="pyad2usb.html">pyad2usb Package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.ad2usb"><tt class="docutils literal"><span class="pre">ad2usb</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.devices"><tt class="docutils literal"><span class="pre">devices</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.util"><tt class="docutils literal"><span class="pre">util</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.zonetracking"><tt class="docutils literal"><span class="pre">zonetracking</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.panels"><tt class="docutils literal"><span class="pre">panels</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.messages"><tt class="docutils literal"><span class="pre">messages</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="pyad2usb.event.html">event Package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyad2usb.event.html#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyad2usb.event.html#module-pyad2usb.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
<li class="toctree-l1"><a class="reference internal" href="pyad2.html">pyad2 Package</a><ul>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.ad2"><tt class="docutils literal"><span class="pre">ad2</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.devices"><tt class="docutils literal"><span class="pre">devices</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.util"><tt class="docutils literal"><span class="pre">util</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.zonetracking"><tt class="docutils literal"><span class="pre">zonetracking</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.panels"><tt class="docutils literal"><span class="pre">panels</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#module-pyad2.messages"><tt class="docutils literal"><span class="pre">messages</span></tt> Module</a></li>
<li class="toctree-l2"><a class="reference internal" href="pyad2.html#subpackages">Subpackages</a><ul>
<li class="toctree-l3"><a class="reference internal" href="pyad2.event.html">event Package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="pyad2.event.html#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li>
<li class="toctree-l4"><a class="reference internal" href="pyad2.event.html#module-pyad2.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
</ul>
</li>
</ul>
@@ -106,7 +106,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


BIN
docs/_build/html/objects.inv View File


+ 13
- 13
docs/_build/html/py-modindex.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Python Module Index &mdash; pyad2usb documentation</title>
<title>Python Module Index &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
@@ -23,7 +23,7 @@
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="index.html" />
<link rel="top" title="pyad2 documentation" href="index.html" />


@@ -38,7 +38,7 @@
<li class="right" >
<a href="#" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -62,47 +62,47 @@
<td><img src="_static/minus.png" class="toggler"
id="toggle-1" style="display: none" alt="-" /></td>
<td>
<tt class="xref">pyad2usb</tt></td><td>
<tt class="xref">pyad2</tt></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.html#module-pyad2usb.ad2usb"><tt class="xref">pyad2usb.ad2usb</tt></a></td><td>
<a href="pyad2.html#module-pyad2.ad2"><tt class="xref">pyad2.ad2</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.html#module-pyad2usb.devices"><tt class="xref">pyad2usb.devices</tt></a></td><td>
<a href="pyad2.html#module-pyad2.devices"><tt class="xref">pyad2.devices</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.event.html#module-pyad2usb.event"><tt class="xref">pyad2usb.event</tt></a></td><td>
<a href="pyad2.event.html#module-pyad2.event"><tt class="xref">pyad2.event</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.event.html#module-pyad2usb.event.event"><tt class="xref">pyad2usb.event.event</tt></a></td><td>
<a href="pyad2.event.html#module-pyad2.event.event"><tt class="xref">pyad2.event.event</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.html#module-pyad2usb.messages"><tt class="xref">pyad2usb.messages</tt></a></td><td>
<a href="pyad2.html#module-pyad2.messages"><tt class="xref">pyad2.messages</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.html#module-pyad2usb.panels"><tt class="xref">pyad2usb.panels</tt></a></td><td>
<a href="pyad2.html#module-pyad2.panels"><tt class="xref">pyad2.panels</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.html#module-pyad2usb.util"><tt class="xref">pyad2usb.util</tt></a></td><td>
<a href="pyad2.html#module-pyad2.util"><tt class="xref">pyad2.util</tt></a></td><td>
<em></em></td></tr>
<tr class="cg-1">
<td></td>
<td>&nbsp;&nbsp;&nbsp;
<a href="pyad2usb.html#module-pyad2usb.zonetracking"><tt class="xref">pyad2usb.zonetracking</tt></a></td><td>
<a href="pyad2.html#module-pyad2.zonetracking"><tt class="xref">pyad2.zonetracking</tt></a></td><td>
<em></em></td></tr>
</table>

@@ -138,7 +138,7 @@
<li class="right" >
<a href="#" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


+ 146
- 0
docs/_build/html/pyad2.event.html View File

@@ -0,0 +1,146 @@
<!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/html; charset=utf-8" />
<title>event Package &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyad2 documentation" href="index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="event-package">
<h1>event Package<a class="headerlink" href="#event-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="id1">
<h2><tt class="xref py py-mod docutils literal"><span class="pre">event</span></tt> Package<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<span class="target" id="module-pyad2.event"></span></div>
<div class="section" id="module-pyad2.event.event">
<span id="event-module"></span><h2><tt class="xref py py-mod docutils literal"><span class="pre">event</span></tt> Module<a class="headerlink" href="#module-pyad2.event.event" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyad2.event.event.Event">
<em class="property">class </em><tt class="descclassname">pyad2.event.event.</tt><tt class="descname">Event</tt><big>(</big><em>doc=None</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#Event"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.Event" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
</dd></dl>

<dl class="class">
<dt id="pyad2.event.event.EventHandler">
<em class="property">class </em><tt class="descclassname">pyad2.event.event.</tt><tt class="descname">EventHandler</tt><big>(</big><em>event</em>, <em>obj</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
<dl class="method">
<dt id="pyad2.event.event.EventHandler.add">
<tt class="descname">add</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Add new event handler function.</p>
<p>Event handler function must be defined like func(sender, earg).
You can add handler also by using &#8216;+=&#8217; operator.</p>
</dd></dl>

<dl class="method">
<dt id="pyad2.event.event.EventHandler.remove">
<tt class="descname">remove</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler.remove"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler.remove" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove existing event handler function.</p>
<p>You can remove handler also by using &#8216;-=&#8217; operator.</p>
</dd></dl>

<dl class="method">
<dt id="pyad2.event.event.EventHandler.fire">
<tt class="descname">fire</tt><big>(</big><em>earg=None</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler.fire"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler.fire" title="Permalink to this definition">¶</a></dt>
<dd><p>Fire event and call all handler functions</p>
<p>You can call EventHandler object itself like e(earg) instead of
e.fire(earg).</p>
</dd></dl>

</dd></dl>

</div>
</div>


</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">event Package</a><ul>
<li><a class="reference internal" href="#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li>
<li><a class="reference internal" href="#module-pyad2.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
</ul>
</li>
</ul>

<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/pyad2.event.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2013, Author.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
</div>
</body>
</html>

+ 1297
- 0
docs/_build/html/pyad2.html
File diff suppressed because it is too large
View File


+ 18
- 31
docs/_build/html/pyad2usb.event.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>event Package &mdash; pyad2usb documentation</title>
<title>event Package &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
@@ -23,9 +23,7 @@
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyad2usb documentation" href="index.html" />
<link rel="up" title="pyad2usb Package" href="pyad2usb.html" />
<link rel="prev" title="pyad2usb Package" href="pyad2usb.html" />
<link rel="top" title="pyad2 documentation" href="index.html" />
</head>
<body>
<div class="related">
@@ -37,11 +35,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="pyad2usb.html" title="pyad2usb Package"
accesskey="P">previous</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="pyad2usb.html" accesskey="U">pyad2usb Package</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -54,37 +48,37 @@
<h1>event Package<a class="headerlink" href="#event-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="id1">
<h2><tt class="xref py py-mod docutils literal"><span class="pre">event</span></tt> Package<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h2>
<span class="target" id="module-pyad2usb.event"></span></div>
<div class="section" id="module-pyad2usb.event.event">
<span id="event-module"></span><h2><tt class="xref py py-mod docutils literal"><span class="pre">event</span></tt> Module<a class="headerlink" href="#module-pyad2usb.event.event" title="Permalink to this headline">¶</a></h2>
<span class="target" id="module-pyad2.event"></span></div>
<div class="section" id="module-pyad2.event.event">
<span id="event-module"></span><h2><tt class="xref py py-mod docutils literal"><span class="pre">event</span></tt> Module<a class="headerlink" href="#module-pyad2.event.event" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pyad2usb.event.event.Event">
<em class="property">class </em><tt class="descclassname">pyad2usb.event.event.</tt><tt class="descname">Event</tt><big>(</big><em>doc=None</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#Event"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.Event" title="Permalink to this definition">¶</a></dt>
<dt id="pyad2.event.event.Event">
<em class="property">class </em><tt class="descclassname">pyad2.event.event.</tt><tt class="descname">Event</tt><big>(</big><em>doc=None</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#Event"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.Event" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
</dd></dl>

<dl class="class">
<dt id="pyad2usb.event.event.EventHandler">
<em class="property">class </em><tt class="descclassname">pyad2usb.event.event.</tt><tt class="descname">EventHandler</tt><big>(</big><em>event</em>, <em>obj</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler" title="Permalink to this definition">¶</a></dt>
<dt id="pyad2.event.event.EventHandler">
<em class="property">class </em><tt class="descclassname">pyad2.event.event.</tt><tt class="descname">EventHandler</tt><big>(</big><em>event</em>, <em>obj</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">object</span></tt></p>
<dl class="method">
<dt id="pyad2usb.event.event.EventHandler.add">
<tt class="descname">add</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler.add" title="Permalink to this definition">¶</a></dt>
<dt id="pyad2.event.event.EventHandler.add">
<tt class="descname">add</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler.add"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler.add" title="Permalink to this definition">¶</a></dt>
<dd><p>Add new event handler function.</p>
<p>Event handler function must be defined like func(sender, earg).
You can add handler also by using &#8216;+=&#8217; operator.</p>
</dd></dl>

<dl class="method">
<dt id="pyad2usb.event.event.EventHandler.remove">
<tt class="descname">remove</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler.remove"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler.remove" title="Permalink to this definition">¶</a></dt>
<dt id="pyad2.event.event.EventHandler.remove">
<tt class="descname">remove</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler.remove"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler.remove" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove existing event handler function.</p>
<p>You can remove handler also by using &#8216;-=&#8217; operator.</p>
</dd></dl>

<dl class="method">
<dt id="pyad2usb.event.event.EventHandler.fire">
<tt class="descname">fire</tt><big>(</big><em>earg=None</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler.fire"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler.fire" title="Permalink to this definition">¶</a></dt>
<dt id="pyad2.event.event.EventHandler.fire">
<tt class="descname">fire</tt><big>(</big><em>earg=None</em><big>)</big><a class="reference internal" href="_modules/pyad2/event/event.html#EventHandler.fire"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2.event.event.EventHandler.fire" title="Permalink to this definition">¶</a></dt>
<dd><p>Fire event and call all handler functions</p>
<p>You can call EventHandler object itself like e(earg) instead of
e.fire(earg).</p>
@@ -105,14 +99,11 @@ e.fire(earg).</p>
<ul>
<li><a class="reference internal" href="#">event Package</a><ul>
<li><a class="reference internal" href="#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li>
<li><a class="reference internal" href="#module-pyad2usb.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
<li><a class="reference internal" href="#module-pyad2.event.event"><tt class="docutils literal"><span class="pre">event</span></tt> Module</a></li>
</ul>
</li>
</ul>

<h4>Previous topic</h4>
<p class="topless"><a href="pyad2usb.html"
title="previous chapter">pyad2usb Package</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/pyad2usb.event.txt"
@@ -144,11 +135,7 @@ e.fire(earg).</p>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="pyad2usb.html" title="pyad2usb Package"
>previous</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="pyad2usb.html" >pyad2usb Package</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


+ 407
- 276
docs/_build/html/pyad2usb.html
File diff suppressed because it is too large
View File


+ 4
- 4
docs/_build/html/search.html View File

@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search &mdash; pyad2usb documentation</title>
<title>Search &mdash; pyad2 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
@@ -24,7 +24,7 @@
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/searchtools.js"></script>
<link rel="top" title="pyad2usb documentation" href="index.html" />
<link rel="top" title="pyad2 documentation" href="index.html" />
<script type="text/javascript">
jQuery(function() { Search.loadIndex("searchindex.js"); });
</script>
@@ -43,7 +43,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>

@@ -94,7 +94,7 @@
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="index.html">pyad2usb documentation</a> &raquo;</li>
<li><a href="index.html">pyad2 documentation</a> &raquo;</li>
</ul>
</div>
<div class="footer">


+ 1
- 1
docs/_build/html/searchindex.js
File diff suppressed because it is too large
View File


+ 37
- 0
docs/_build/text/index.txt View File

@@ -0,0 +1,37 @@

Welcome to pyad2's documentation!
*********************************

Contents:

* pyad2 Package

* "ad2" Module

* "devices" Module

* "util" Module

* "zonetracking" Module

* "panels" Module

* "messages" Module

* Subpackages

* event Package

* "event" Package

* "event" Module


Indices and tables
******************

* *Index*

* *Module Index*

* *Search Page*

+ 25
- 0
docs/_build/text/modules.txt View File

@@ -0,0 +1,25 @@

pyad2
*****

* pyad2 Package

* "ad2" Module

* "devices" Module

* "util" Module

* "zonetracking" Module

* "panels" Module

* "messages" Module

* Subpackages

* event Package

* "event" Package

* "event" Module

+ 39
- 0
docs/_build/text/pyad2.event.txt View File

@@ -0,0 +1,39 @@

event Package
*************


"event" Package
===============


"event" Module
==============

class class pyad2.event.event.Event(doc=None)

Bases: "object"

class class pyad2.event.event.EventHandler(event, obj)

Bases: "object"

add(func)

Add new event handler function.

Event handler function must be defined like func(sender, earg).
You can add handler also by using '+=' operator.

remove(func)

Remove existing event handler function.

You can remove handler also by using '-=' operator.

fire(earg=None)

Fire event and call all handler functions

You can call EventHandler object itself like e(earg) instead of
e.fire(earg).

+ 784
- 0
docs/_build/text/pyad2.txt View File

@@ -0,0 +1,784 @@

pyad2 Package
*************


"ad2" Module
============

Provides the full AD2USB class and factory.

class class pyad2.ad2.Overseer(attached_event=None, detached_event=None)

Bases: "object"

Factory for creation of AD2USB devices as well as provides
attach/detach events."

on_attached

Called when an AD2USB device has been detected.

on_detached

Called when an AD2USB device has been removed.

classmethod find_all()

Returns all AD2USB devices located on the system.

Returns:
list of devices found

Raises :
util.CommError

classmethod devices()

Returns a cached list of AD2USB devices located on the system.

Returns:
cached list of devices found.

classmethod create(device=None)

Factory method that returns the requested AD2USB device, or the
first device.

Parameters:
**device** (*tuple*) -- Tuple describing the USB device to
open, as returned by find_all().

Returns:
AD2USB object utilizing the specified device.

Raises :
util.NoDeviceError

close()

Clean up and shut down.

start()

Starts the detection thread, if not already running.

stop()

Stops the detection thread.

get_device(device=None)

Factory method that returns the requested AD2USB device, or the
first device.

Parameters:
**device** (*tuple*) -- Tuple describing the USB device to
open, as returned by find_all().

class class DetectThread(overseer)

Bases: "threading.Thread"

Thread that handles detection of added/removed devices.

stop()

Stops the thread.

run()

The actual detection process.

class class pyad2.ad2.AD2(device)

Bases: "object"

High-level wrapper around AD2USB/AD2SERIAL devices.

on_arm

Called when the panel is armed.

on_disarm

Called when the panel is disarmed.

on_power_changed

Called when panel power switches between AC and DC.

on_alarm

Called when the alarm is triggered.

on_fire

Called when a fire is detected.

on_bypass

Called when a zone is bypassed.

on_boot

Called when the device finishes bootings.

on_config_received

Called when the device receives its configuration.

on_zone_fault

Called when the device detects a zone fault.

on_zone_restore

Called when the device detects that a fault is restored.

on_low_battery

Called when the device detects a low battery.

on_panic

Called when the device detects a panic.

on_relay_changed

Called when a relay is opened or closed on an expander board.

on_message

Called when a message has been received from the device.

on_lrr_message

Called when an LRR message is received.

on_rfx_message

Called when an RFX message is received.

on_open

Called when the device has been opened.

on_close

Called when the device has been closed.

on_read

Called when a line has been read from the device.

on_write

Called when data has been written to the device.

F1 = u'\x01\x01\x01'

Represents panel function key #1

F2 = u'\x02\x02\x02'

Represents panel function key #2

F3 = u'\x03\x03\x03'

Represents panel function key #3

F4 = u'\x04\x04\x04'

Represents panel function key #4

BATTERY_TIMEOUT = 30

Timeout before the battery status reverts.

FIRE_TIMEOUT = 30

Timeout before the fire status reverts.

id

The ID of the AD2USB device.

Returns:
The identification string for the device.

open(baudrate=None, no_reader_thread=False)

Opens the device.

Parameters:
* **baudrate** (*int*) -- The baudrate used for the device.

* **interface** (*varies depends on device type.. FIXME*)
-- The interface used for the device.

* **index** (*int*) -- Interface index.. can probably
remove. FIXME

* **no_reader_thread** (*bool*) -- Specifies whether or not
the automatic reader thread should be started or not

close()

Closes the device.

send(data)

get_config()

Retrieves the configuration from the device.

save_config()

Sets configuration entries on the device.

reboot()

Reboots the device.

fault_zone(zone, simulate_wire_problem=False)

Faults a zone if we are emulating a zone expander.

Parameters:
* **zone** (*int*) -- The zone to fault.

* **simulate_wire_problem** (*bool*) -- Whether or not to
simulate a wire fault.

clear_zone(zone)

Clears a zone if we are emulating a zone expander.

Parameters:
**zone** (*int*) -- The zone to clear.


"devices" Module
================

Contains different types of devices belonging to the AD2USB family.

class class pyad2.devices.Device

Bases: "object"

Generic parent device to all AD2USB products.

on_open

Called when the device has been opened

on_close

Called when the device has been closed

on_read

Called when a line has been read from the device

on_write

Called when data has been written to the device

id

Retrieve the device ID.

Returns:
The identification string for the device.

is_reader_alive()

Indicates whether or not the reader thread is alive.

Returns:
Whether or not the reader thread is alive.

stop_reader()

Stops the reader thread.

close()

Closes the device.

class class ReadThread(device)

Bases: "threading.Thread"

Reader thread which processes messages from the device.

READ_TIMEOUT = 10

Timeout for the reader thread.

stop()

Stops the running thread.

run()

The actual read process.

class class pyad2.devices.USBDevice(interface=(None, 0))

Bases: "pyad2.devices.Device"

AD2USB device exposed with PyFTDI's interface.

FTDI_VENDOR_ID = 1027

Vendor ID used to recognize AD2USB devices.

FTDI_PRODUCT_ID = 24577

Product ID used to recognize AD2USB devices.

BAUDRATE = 115200

Default baudrate for AD2USB devices.

static find_all()

Returns all FTDI devices matching our vendor and product IDs.

Returns:
list of devices

Raises :
util.CommError

interface

Retrieves the interface used to connect to the device.

Returns:
the interface used to connect to the device.

serial_number

Retrieves the serial number of the device.

Returns:
The serial number of the device.

description

Retrieves the description of the device.

Returns:
The description of the device.

open(baudrate=115200, no_reader_thread=False)

Opens the device.

Parameters:
* **baudrate** (*int*) -- The baudrate to use.

* **no_reader_thread** (*bool*) -- Whether or not to
automatically start the reader thread.

Raises :
util.NoDeviceError

close()

Closes the device.

write(data)

Writes data to the device.

Parameters:
**data** (*str*) -- Data to write

Raises :
util.CommError

read()

Reads a single character from the device.

Returns:
The character read from the device.

Raises :
util.CommError

read_line(timeout=0.0, purge_buffer=False)

Reads a line from the device.

Parameters:
* **timeout** (*float*) -- Read timeout

* **purge_buffer** (*bool*) -- Indicates whether to purge
the buffer prior to reading.

Returns:
The line that was read.

Raises :
util.CommError, util.TimeoutError

class class pyad2.devices.SerialDevice(interface=None)

Bases: "pyad2.devices.Device"

AD2USB or AD2SERIAL device exposed with the pyserial interface.

BAUDRATE = 19200

Default baudrate for Serial devices.

static find_all(pattern=None)

Returns all serial ports present.

Parameters:
**pattern** (*str*) -- Pattern to search for when retrieving
serial ports.

Returns:
list of devices

Raises :
util.CommError

interface

Retrieves the interface used to connect to the device.

Returns:
the interface used to connect to the device.

open(baudrate=19200, no_reader_thread=False)

Opens the device.

Parameters:
* **baudrate** (*int*) -- The baudrate to use with the
device.

* **no_reader_thread** (*bool*) -- Whether or not to
automatically start the reader thread.

Raises :
util.NoDeviceError

close()

Closes the device.

write(data)

Writes data to the device.

Parameters:
**data** (*str*) -- The data to write.

Raises :
util.CommError

read()

Reads a single character from the device.

Returns:
The character read from the device.

Raises :
util.CommError

read_line(timeout=0.0, purge_buffer=False)

Reads a line from the device.

Parameters:
* **timeout** (*float*) -- The read timeout.

* **purge_buffer** (*bool*) -- Indicates whether to purge
the buffer prior to reading.

Returns:
The line read.

Raises :
util.CommError, util.TimeoutError

class class pyad2.devices.SocketDevice(interface=('localhost', 10000))

Bases: "pyad2.devices.Device"

Device that supports communication with an AD2USB that is exposed
via ser2sock or another Serial to IP interface.

interface

Retrieves the interface used to connect to the device.

Returns:
the interface used to connect to the device.

ssl

Retrieves whether or not the device is using SSL.

Returns:
Whether or not the device is using SSL.

ssl_certificate

Retrieves the SSL client certificate path used for
authentication.

Returns:
The certificate path

ssl_key

Retrieves the SSL client certificate key used for
authentication.

Returns:
The key path

ssl_ca

Retrieves the SSL Certificate Authority certificate used for
authentication.

Returns:
The CA path

open(baudrate=None, no_reader_thread=False)

Opens the device.

Parameters:
* **baudrate** (*int*) -- The baudrate to use

* **no_reader_thread** (*bool*) -- Whether or not to
automatically open the reader thread.

Raises :
util.NoDeviceError, util.CommError

close()

Closes the device.

write(data)

Writes data to the device.

Parameters:
**data** (*str*) -- The data to write.

Returns:
The number of bytes sent.

Raises :
util.CommError

read()

Reads a single character from the device.

Returns:
The character read from the device.

Raises :
util.CommError

read_line(timeout=0.0, purge_buffer=False)

Reads a line from the device.

Parameters:
* **timeout** (*float*) -- The read timeout.

* **purge_buffer** (*bool*) -- Indicates whether to purge
the buffer prior to reading.

Returns:
The line read from the device.

Raises :
util.CommError, util.TimeoutError


"util" Module
=============

Provides utility classes for the AD2USB devices.

exception exception pyad2.util.NoDeviceError

Bases: "exceptions.Exception"

No devices found.

exception exception pyad2.util.CommError

Bases: "exceptions.Exception"

There was an error communicating with the device.

exception exception pyad2.util.TimeoutError

Bases: "exceptions.Exception"

There was a timeout while trying to communicate with the device.

exception exception pyad2.util.InvalidMessageError

Bases: "exceptions.Exception"

The format of the panel message was invalid.

class class pyad2.util.Firmware

Bases: "object"

Represents firmware for the AD2USB/AD2SERIAL devices.

STAGE_START = 0

STAGE_WAITING = 1

STAGE_BOOT = 2

STAGE_LOAD = 3

STAGE_UPLOADING = 4

STAGE_DONE = 5

static upload(dev, filename, progress_callback=None)

Uploads firmware to an AD2USB/AD2SERIAL device.

Parameters:
* **filename** (*str*) -- The firmware filename

* **progress_callback** (*function*) -- Callback function
used to report progress.

Raises :
util.NoDeviceError, util.TimeoutError


"zonetracking" Module
=====================

Provides zone tracking functionality for the AD2USB device family.

class class pyad2.zonetracking.Zone(zone=0, name='', status=0)

Bases: "object"

Representation of a panel zone.

CLEAR = 0

Status indicating that the zone is cleared.

FAULT = 1

Status indicating that the zone is faulted.

CHECK = 2

Status indicating that there is a wiring issue with the zone.

STATUS = {0: 'CLEAR', 1: 'FAULT', 2: 'CHECK'}

class class pyad2.zonetracking.Zonetracker

Bases: "object"

Handles tracking of zone and their statuses.

on_fault

Called when the device detects a zone fault.

on_restore

Called when the device detects that a fault is restored.

EXPIRE = 30

Zone expiration timeout.

update(message)

Update zone statuses based on the current message.

Parameters:
**message** (*Message or ExpanderMessage*) -- Message to use
to update the zone tracking.


"panels" Module
===============

Representations of Panels and their templates.


"messages" Module
=================

Message representations received from the panel through the AD2USB.

class class pyad2.messages.BaseMessage

Bases: "object"

Base class for messages.

class class pyad2.messages.Message(data=None)

Bases: "pyad2.messages.BaseMessage"

Represents a message from the alarm panel.

class class pyad2.messages.ExpanderMessage(data=None)

Bases: "pyad2.messages.BaseMessage"

Represents a message from a zone or relay expansion module.

ZONE = 0

RELAY = 1

class class pyad2.messages.RFMessage(data=None)

Bases: "pyad2.messages.BaseMessage"

Represents a message from an RF receiver.

class class pyad2.messages.LRRMessage(data=None)

Bases: "pyad2.messages.BaseMessage"

Represent a message from a Long Range Radio.


Subpackages
===========

* event Package

* "event" Package

* "event" Module

+ 8
- 8
docs/conf.py View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# pyad2usb documentation build configuration file, created by
# pyad2 documentation build configuration file, created by
# sphinx-quickstart on Sat Jun 8 14:38:46 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
@@ -40,7 +40,7 @@ source_suffix = '.rst'
master_doc = 'index'

# General information about the project.
project = u'pyad2usb'
project = u'pyad2'
copyright = u'2013, Author'

# The version info for the project you're documenting, acts as replacement for
@@ -167,7 +167,7 @@ html_static_path = ['_static']
#html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'pyad2usbdoc'
htmlhelp_basename = 'pyad2doc'


# -- Options for LaTeX output --------------------------------------------------
@@ -186,7 +186,7 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'pyad2usb.tex', u'pyad2usb Documentation',
('index', 'pyad2.tex', u'pyad2 Documentation',
u'Author', 'manual'),
]

@@ -216,7 +216,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pyad2usb', u'pyad2usb Documentation',
('index', 'pyad2', u'pyad2 Documentation',
[u'Author'], 1)
]

@@ -230,8 +230,8 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'pyad2usb', u'pyad2usb Documentation',
u'Author', 'pyad2usb', 'One line description of project.',
('index', 'pyad2', u'pyad2 Documentation',
u'Author', 'pyad2', 'One line description of project.',
'Miscellaneous'),
]

@@ -251,7 +251,7 @@ texinfo_documents = [
# -- Options for Epub output ---------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = u'pyad2usb'
epub_title = u'pyad2'
epub_author = u'Author'
epub_publisher = u'Author'
epub_copyright = u'2013, Author'


+ 2
- 2
docs/index.rst View File

@@ -3,7 +3,7 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to pyad2usb's documentation!
Welcome to pyad2's documentation!
====================================

Contents:
@@ -11,7 +11,7 @@ Contents:
.. toctree::
:maxdepth: 4

pyad2usb
pyad2


Indices and tables


+ 2
- 2
docs/modules.rst View File

@@ -1,7 +1,7 @@
pyad2usb
pyad2
========

.. toctree::
:maxdepth: 4

pyad2usb
pyad2

+ 19
- 0
docs/pyad2.event.rst View File

@@ -0,0 +1,19 @@
event Package
=============

:mod:`event` Package
--------------------

.. automodule:: pyad2.event
:members:
:undoc-members:
:show-inheritance:

:mod:`event` Module
-------------------

.. automodule:: pyad2.event.event
:members:
:undoc-members:
:show-inheritance:


+ 58
- 0
docs/pyad2.rst View File

@@ -0,0 +1,58 @@
pyad2 Package
================

:mod:`ad2` Module
--------------------

.. automodule:: pyad2.ad2
:members:
:undoc-members:
:show-inheritance:

:mod:`devices` Module
---------------------

.. automodule:: pyad2.devices
:members:
:undoc-members:
:show-inheritance:

:mod:`util` Module
------------------

.. automodule:: pyad2.util
:members:
:undoc-members:
:show-inheritance:

:mod:`zonetracking` Module
--------------------------

.. automodule:: pyad2.zonetracking
:members:
:undoc-members:
:show-inheritance:

:mod:`panels` Module
--------------------

.. automodule:: pyad2.panels
:members:
:undoc-members:
:show-inheritance:

:mod:`messages` Module
----------------------

.. automodule:: pyad2.messages
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::

pyad2.event


Loading…
Cancel
Save