communication_langage_protocol.html 17.1 KB

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Communication protocols for astromecca mounts &#8212; Mount Control Software 1.0.0 documentation</title>
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
    
    <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
    <script src="_static/jquery.js"></script>
    <script src="_static/underscore.js"></script>
    <script src="_static/doctools.js"></script>
    
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="User guide to program with mount Python classes" href="using_mount_classes.html" />
    <link rel="prev" title="First steps with the Mount Control Software" href="using_mount_control_software.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <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 class="right" >
          <a href="using_mount_classes.html" title="User guide to program with mount Python classes"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="using_mount_control_software.html" title="First steps with the Mount Control Software"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Mount Control Software 1.0.0 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Communication protocols for astromecca mounts</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="communication-protocols-for-astromecca-mounts">
<h1>Communication protocols for astromecca mounts<a class="headerlink" href="#communication-protocols-for-astromecca-mounts" title="Permalink to this headline">¶</a></h1>
<p>This section describes how to use a client software to communicate with
a running astromecca server.</p>
<p>Available protocol transports are:</p>
<blockquote>
<div><ul class="simple">
<li><p>Serial RS232.</p></li>
<li><p>Ethernet TCP.</p></li>
</ul>
</div></blockquote>
<p>Available protocol langages are:</p>
<blockquote>
<div><ul class="simple">
<li><p>LX200. The classical Meade LX200 syntax.</p></li>
<li><p>ASCOM. ASCOM driver for Astromecca mounts</p></li>
<li><p>MCS. Json based messages to allow any operation with the mount.</p></li>
</ul>
</div></blockquote>
<p>The default configuration of the MCS script is to run using ASCOM protocol
via serial port RS232 (driver astromecca, 115200 bauds).</p>
<p>It is possible to mix any protocol transport with any protocol langage.
However, do not forget that LX200 langage protocol is usually used
with a RS232 serial transport at 9600 bauds.</p>
<div class="section" id="serial-port-and-lx200-protocol">
<h2>1. Serial port and LX200 protocol<a class="headerlink" href="#serial-port-and-lx200-protocol" title="Permalink to this headline">¶</a></h2>
<p>The client must connect a serial wire between its computer and the astromecca computer.
For example, you can use an ASCOM or INDI client to communicate with the astromecca server.
You have configure ASCOM or INDI to the protocol langage LX200 and the serial transport protocol as 9600 bauds.</p>
<p>If you want to write a Python code to create client, you can use the class MountremoteClient
which wraps the serial protocol. When the MountremoteClient is instanciated the method
putread_chan send the command and receive the response.
The following example gets the declination of the mount via the LX200 command :GD:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mountremote</span> <span class="k">import</span> <span class="n">MountremoteClient</span>
<span class="n">remote_client</span> <span class="o">=</span> <span class="n">MountremoteClient</span><span class="p">(</span><span class="s2">&quot;SERIAL&quot;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="s2">&quot;COM1&quot;</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="s2">&quot;LX200&quot;</span><span class="p">,</span> <span class="n">baud</span><span class="o">=</span><span class="mi">9600</span><span class="p">)</span>
<span class="n">command</span> <span class="o">=</span> <span class="s1">&#39;:GD#&#39;</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">remote_client</span><span class="o">.</span><span class="n">putread_chan</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Command = </span><span class="si">{}</span><span class="se">\n</span><span class="s2">Result = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">command</span><span class="p">,</span><span class="n">result</span><span class="p">))</span>
<span class="k">del</span><span class="p">(</span><span class="n">remote_client</span><span class="p">)</span>
</pre></div>
</div>
<p>The implemented LX200 commands described in <a class="reference external" href="https://www.meade.com/support/LX200CommandSet.pdf">https://www.meade.com/support/LX200CommandSet.pdf</a> are:
:CM, :Gc, :GC, :GD, :Gg, :GL, :Gm, :GR, :Gt, :H,  :Me, :Mn, :Ms,  :Mw, :MS, :P,
:Qe, :Qn, :Qs, :Qw, :Q,  :RC, :RG, :RM, :RS, :Sr, :Sd, :Sg, :Sts, :U.</p>
</div>
<div class="section" id="ethernet-tcp-port-and-mcs-protocol">
<h2>2. Ethernet TCP port and MCS protocol<a class="headerlink" href="#ethernet-tcp-port-and-mcs-protocol" title="Permalink to this headline">¶</a></h2>
<p>The client must connect an Ethernet wire or establish a wifi connection between its computer and the astromecca computer.
Configure the TCP transport protocol to send messages on the port 1111.</p>
<p>The following example gets the right ascension, the declination and the peer side of the mount via the astromecca command get radec.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mountremote</span> <span class="k">import</span> <span class="n">MountremoteClient</span>
<span class="n">remote_client</span> <span class="o">=</span> <span class="n">MountremoteClient</span><span class="p">(</span><span class="s2">&quot;TCP&quot;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">1111</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="s2">&quot;MCS&quot;</span><span class="p">)</span>
<span class="n">command</span> <span class="o">=</span> <span class="s2">&quot;{&#39;req&#39;: {&#39;get&#39;: &#39;radec&#39;}}&quot;</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">remote_client</span><span class="o">.</span><span class="n">putread_chan</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Command = </span><span class="si">{}</span><span class="se">\n</span><span class="s2">Result = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">command</span><span class="p">,</span><span class="n">result</span><span class="p">))</span>
<span class="k">del</span><span class="p">(</span><span class="n">remote_client</span><span class="p">)</span>
</pre></div>
</div>
<p>The most useful command is ‘exec’ which allow to execute
any python command of the mount thread. By this way it is possible
to drive the mount with only this command. The following example show
how to call directly the method which returns the radec coordinates:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mountremote</span> <span class="k">import</span> <span class="n">MountremoteClient</span>
<span class="n">remote_client</span> <span class="o">=</span> <span class="n">MountremoteClient</span><span class="p">(</span><span class="s2">&quot;TCP&quot;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">1111</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="s2">&quot;MCS&quot;</span><span class="p">)</span>
<span class="n">command</span> <span class="o">=</span> <span class="s2">&quot;{&#39;req&#39;: {&#39;do&#39;: {&#39;exec&#39; , &#39;self.radec_coord()&#39;}}}&quot;</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">remote_client</span><span class="o">.</span><span class="n">putread_chan</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Command = </span><span class="si">{}</span><span class="se">\n</span><span class="s2">Result = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">command</span><span class="p">,</span><span class="n">result</span><span class="p">))</span>
<span class="k">del</span><span class="p">(</span><span class="n">remote_client</span><span class="p">)</span>
</pre></div>
</div>
<p>You can execute a GOTO action:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">mountremote</span> <span class="k">import</span> <span class="n">MountremoteClient</span>
<span class="n">remote_client</span> <span class="o">=</span> <span class="n">MountremoteClient</span><span class="p">(</span><span class="s2">&quot;TCP&quot;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">1111</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="s2">&quot;MCS&quot;</span><span class="p">)</span>
<span class="n">command</span> <span class="o">=</span> <span class="s2">&quot;{&#39;req&#39;: {&#39;do&#39;: {&#39;exec&#39; , &#39;self.radec_goto(&quot;</span><span class="mi">4</span><span class="n">h45m</span><span class="p">,</span><span class="s2">&quot;+05d18m&quot;</span><span class="p">)</span><span class="s1">&#39;}}}&quot;</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">remote_client</span><span class="o">.</span><span class="n">putread_chan</span><span class="p">(</span><span class="n">command</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Command = </span><span class="si">{}</span><span class="se">\n</span><span class="s2">Result = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">command</span><span class="p">,</span><span class="n">result</span><span class="p">))</span>
<span class="k">del</span><span class="p">(</span><span class="n">remote_client</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="the-mcs-langage-protocol">
<h2>3. The MCS langage protocol<a class="headerlink" href="#the-mcs-langage-protocol" title="Permalink to this headline">¶</a></h2>
<p>The messages are Json formated. Basically the hierarchy is defined as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">command</span> <span class="o">=</span> <span class="s2">&quot;{typemsg: {action: {cmd: val}}}&quot;</span>
</pre></div>
</div>
<p>The following combinations can be used:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 23%" />
<col style="width: 23%" />
<col style="width: 21%" />
<col style="width: 34%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>typemsg</p></th>
<th class="head"><p>action</p></th>
<th class="head"><p>cmd</p></th>
<th class="head"><p>val</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>req</p></td>
<td><p>do</p></td>
<td><p>exec</p></td>
<td><p><em>Python command</em></p></td>
</tr>
<tr class="row-odd"><td><p>req</p></td>
<td><p>get</p></td>
<td><p>radec</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p>req</p></td>
<td><p>get</p></td>
<td><p>hadec</p></td>
<td></td>
</tr>
</tbody>
</table>
<p>The reponse is also a Json structure for which the keys reflect
those of the request (but ‘req’ is replaced by ‘res’):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Command</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;req&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;get&#39;</span><span class="p">:</span> <span class="s1">&#39;radec&#39;</span><span class="p">}}</span>
<span class="n">Result</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;res&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;get&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;radec&#39;</span><span class="p">:</span> <span class="p">[{</span><span class="s1">&#39;ra&#39;</span><span class="p">:</span> <span class="mf">93.77897552123532</span><span class="p">,</span> <span class="s1">&#39;dec&#39;</span><span class="p">:</span> <span class="mf">0.007976942637754572</span><span class="p">,</span> <span class="s1">&#39;side&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">}]}}}</span>
</pre></div>
</div>
<p>Note the val is a list or any other kind of type in case of (req,de,exec).</p>
</div>
</div>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Communication protocols for astromecca mounts</a><ul>
<li><a class="reference internal" href="#serial-port-and-lx200-protocol">1. Serial port and LX200 protocol</a></li>
<li><a class="reference internal" href="#ethernet-tcp-port-and-mcs-protocol">2. Ethernet TCP port and MCS protocol</a></li>
<li><a class="reference internal" href="#the-mcs-langage-protocol">3. The MCS langage protocol</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="using_mount_control_software.html"
                        title="previous chapter">First steps with the Mount Control Software</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="using_mount_classes.html"
                        title="next chapter">User guide to program with mount Python classes</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/communication_langage_protocol.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <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 class="right" >
          <a href="using_mount_classes.html" title="User guide to program with mount Python classes"
             >next</a> |</li>
        <li class="right" >
          <a href="using_mount_control_software.html" title="First steps with the Mount Control Software"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">Mount Control Software 1.0.0 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">Communication protocols for astromecca mounts</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021, astromecca.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.4.0.
    </div>
  </body>
</html>