Skip to content

Commit 10a4973

Browse files
committed
Added Connections doc page
1 parent ecfccf8 commit 10a4973

File tree

5 files changed

+148
-53
lines changed

5 files changed

+148
-53
lines changed

docs/connections.rst

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
.. _page_connections:
2+
3+
Connections
4+
===========
5+
6+
Total stations and digital levels usually support a serial connection
7+
with RS232. Some instruments come with additional connection methods, like
8+
bluetooth as well.
9+
10+
Serial Line
11+
-----------
12+
13+
The RS232 serial line is the main method of connection. The main primitive
14+
is the :class:`~geocompy.communication.SerialConnection` class, that acts as a
15+
wrapper around a :class:`~serial.Serial` object that implements the actual
16+
low level serial communication.
17+
18+
.. code-block:: python
19+
:caption: Simple serial connection
20+
:linenos:
21+
22+
from serial import Serial
23+
from geocompy.communication import SerialConnection
24+
25+
26+
port = Serial("COM1", timeout=15)
27+
com = SerialConnection(port)
28+
com.send("some message")
29+
com.close() # Closes the wrapped serial port
30+
31+
.. caution::
32+
:class: warning
33+
34+
It is strongly recommended to set a ``timeout`` on the connection. Without
35+
a ``timeout`` set, the connection may end up in a perpetual waiting state
36+
if the instrument becomes unresponsive. A too small value however might
37+
result in premature timeout issues when using slow commands (e.g.
38+
motorized functions, measurements).
39+
40+
The :class:`~geocompy.communication.SerialConnection` can also be used as a
41+
context manager, that automatically closes the serial port when the context
42+
is left.
43+
44+
.. code-block:: python
45+
:caption: Serial connection as context manager
46+
:linenos:
47+
48+
from serial import Serial
49+
from geocompy.communication import SerialConnection
50+
51+
52+
port = Serial("COM1", timeout=15)
53+
with SerialConnection(port) as com:
54+
com.send("some message")
55+
56+
To make the connection creation simpler, a utility function is also included
57+
that can be used similarly to the :func:`open` function of the standard
58+
library.
59+
60+
.. code-block:: python
61+
:caption: Creating connection with the utility function
62+
:linenos:
63+
64+
from geocompy.communication import open_serial
65+
66+
67+
with open_serial("COM1", timeout=15) as com:
68+
com.send("some message")
69+
70+
If a time consuming request has to be executed, that might exceed the normal
71+
connection timeout, it is possible to run it with a temporary override.
72+
73+
.. code-block:: python
74+
:caption: Timeout override for slow requests
75+
:linenos:
76+
77+
from geocompy.communication import open_serial
78+
79+
80+
with open_serial("COM1", timeout=5) as com:
81+
ans = com.exchage("message")
82+
# normal operation
83+
84+
# request that might time out
85+
with com.timeout_override(20):
86+
ans = com.exchange("blocking message")
87+
88+
# resumed normal operation
89+
90+
Bluetooth
91+
---------
92+
93+
Newer instruments (particularly robotic total stations) might come with
94+
built-in or attachable bluetooth connection capabilities (e.g. Leica TS15
95+
with radio handle). These instruments communicate over Serial Port Profile
96+
Bluetooth Classic, that emulates a direct line serial connection.
97+
98+
To initiate a connection like this, the instrument first has to be paired
99+
to the controlling computer, and the bluetooth address of the instrument
100+
must be bound to an RFCOMM port as well.
101+
102+
On windows machines this can be done manually through the Devices and
103+
Printers in the Control Panel. These RFCOMM devices will typically get one
104+
of the higher numbered ports, like ``COM9``.
105+
106+
Linux systems will typically use something like
107+
`bluetoothctl <https://documentation.ubuntu.com/core/explanation/system-snaps/bluetooth/pairing/index.html>`_
108+
to handle the pairing process, and then ``rfcomm`` command to bind a device
109+
to an RFCOMM port.
110+
111+
Once the pairing and binding is complete, the connection over bluetooth can
112+
be opened just like a normal serial line.
113+
114+
.. code-block:: python
115+
:caption: Opening connection through an RFCOMM port
116+
:linenos:
117+
118+
from geocompy.communication import open_serial
119+
120+
121+
with open_serial("COM9") as com:
122+
com.send("some message")
123+
124+
.. note::
125+
126+
In case of Leica instruments and GeoCom, the GeoCom interface on the
127+
instrument has to be manually switched to the bluetooth device,
128+
before initiating a connection. Make sure to sync the port parameters
129+
(e.g. speed, parity) between the instrument and the computer!
130+
131+
.. seealso::
132+
133+
https://youtu.be/6Z4PXct8Rg0?si=db53q6F6NRi2M4BF
134+
Video explaining the pairing process between a Raspberry PI and
135+
a windows PC. It shows how to properly add an RFCOMM device in
136+
the Control Panel.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Content
4848

4949
overview
5050
introduction
51+
connections
5152
examples
5253

5354
.. toctree::

docs/introduction.rst

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,11 @@ a direct serial connection (RS232). This is available on almost all products.
1212
Newer equipment might also come with built-in, or attachable bluetooth
1313
connection capabilities.
1414

15-
Currently the package only supports serial connections, for which the
16-
necessary primitives are implemented. Other communication formats may be
17-
added later.
18-
1915
Communication related definitions can be found in the
20-
:mod:`~geocompy.communication` module. The main primitive is the
21-
:class:`~geocompy.communication.SerialConnection` class, that acts as a
22-
wrapper around a :class:`~serial.Serial` object that implements the actual
23-
low level serial communication.
24-
25-
.. code-block:: python
26-
:caption: Simple serial connection
27-
:linenos:
28-
29-
from serial import Serial
30-
from geocompy.communication import SerialConnection
16+
:mod:`~geocompy.communication` module.
3117

32-
33-
port = Serial("COM1", timeout=15)
34-
conn = SerialConnection(port)
35-
conn.send("some message")
36-
conn.close() # Closes the wrapped serial port
37-
38-
.. caution::
39-
:class: warning
40-
41-
It is strongly recommended to set a ``timeout`` on the connection. Without
42-
a ``timeout`` set, the connection may end up in a perpetual waiting state
43-
if the instrument becomes unresponsive. A too small value however might
44-
result in premature timeout issues when using slow commands (e.g.
45-
motorized functions, measurements).
46-
47-
The :class:`~geocompy.communication.SerialConnection` can also be used as a
48-
context manager, that automatically closes the serial port when the context
49-
is left.
50-
51-
.. code-block:: python
52-
:caption: Serial connection as context manager
53-
:linenos:
54-
55-
from serial import Serial
56-
from geocompy.communication import SerialConnection
57-
58-
59-
port = Serial("COM1", timeout=15)
60-
with SerialConnection(port) as conn:
61-
conn.send("some message")
62-
63-
To make the connection creation simpler, a utility function is also included
64-
that can be used similarly to the :func:`open` function of the standard
65-
library.
18+
A utility function can be used to open the serial connection, that works
19+
similarly to the :func:`open` function of the standard library.
6620

6721
.. code-block:: python
6822
:caption: Creating connection with the utility function
@@ -71,8 +25,12 @@ library.
7125
from geocompy.communication import open_serial
7226
7327
74-
with open_serial("COM1", timeout=15) as conn:
75-
conn.send("some message")
28+
with open_serial("COM1", timeout=15) as com:
29+
com.send("some message")
30+
31+
.. seealso::
32+
33+
Connection methods are discussed in more detail in :ref:`page_connections`.
7634

7735
Protocols
7836
---------

docs/latexindex.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ GeoComPy
1111

1212
overview
1313
introduction
14+
connections
1415
examples
1516

1617
*****************

src/geocompy/protocols.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ def parse_response(
358358
) = None
359359
) -> GeoComResponse[Any]:
360360
"""
361-
Parses RPC response and constructs :class:`GeoComResponse`
362-
instance.
361+
Parses RPC response and constructs `GeoComResponse` instance.
363362
364363
Parameters
365364
----------

0 commit comments

Comments
 (0)