Skip to content

Commit eba9109

Browse files
committed
doc: expand the examples section
1 parent f122f67 commit eba9109

File tree

1 file changed

+86
-20
lines changed

1 file changed

+86
-20
lines changed

doc/examples.rst

Lines changed: 86 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.. Copyright (C) 2017 Mick Phillips <mick.phillips@gmail.com>
2-
Copyright (C) 2017 David Pinto <david.pinto@bioch.ox.ac.uk>
2+
Copyright (C) 2019 David Miguel Susano Pinto <david.pinto@bioch.ox.ac.uk>
33
44
Permission is granted to copy, distribute and/or modify this
55
document under the terms of the GNU Free Documentation License,
@@ -13,58 +13,124 @@
1313
Examples
1414
********
1515

16-
Run servers with `python -m microscope.deviceserver SERVERS` and then
17-
run the example with `python example.py`
18-
19-
2016
Experiments
2117
===========
2218

23-
.. code:: python
19+
Simple experiments can be ran with Python only. For a simple time
20+
series experiment:
2421

25-
from microscope import clients
22+
.. code:: python
2623
27-
camera = clients.DataClient('PYRO:TestCamera@127.0.0.1:8005')
28-
laser = clients.Client('PYRO:TestLaser@127.0.0.1:8006')
24+
from microscope.lasers.cobolt import CoboltLaser
25+
from microscope.cameras.atmcd import AndorAtmcd
2926
27+
laser = CoboltLaser(com='/dev/ttyS0')
3028
laser.enable()
3129
laser.set_power_mw(30)
3230
31+
camera = AndorAtmcd(uid='9146')
3332
camera.enable()
3433
camera.set_exposure_time(0.15)
3534
3635
data = []
37-
3836
for i in range(10):
3937
data.append(camera.trigger_and_wait())
4038
print("Frame %d captured." % i)
41-
4239
print(data)
4340
4441
laser.disable()
4542
camera.disable()
4643
47-
48-
Configurations
44+
Remote devices
4945
==============
5046

47+
Microscope was designed around the idea that the multiple devices are
48+
distributed over the network. To accomplish this, the device objects
49+
can be replaced with ``Client`` and ``DataClient`` instances. For
50+
example, to run the previous experiment with remote devices:
51+
5152
.. code:: python
5253
53-
"""Config file for devicebase.
54+
import microscope.clients
55+
56+
camera_uri = 'PYRO:TestCamera@127.0.0.1:8005'
57+
laser_uri = 'PYRO:TestLaser@127.0.0.1:8006'
58+
59+
camera = microscope.clients.DataClient(camera_uri)
60+
laser = microscope.clients.Client(laser_uri)
61+
...
62+
63+
64+
Device server
65+
=============
66+
67+
The device server requires a configuration file defining the different
68+
devices to be initialised. It can be started with::
69+
70+
python -m microscope.deviceserver PATH-TO-CONFIG-FILE
5471

55-
Import device classes, then define entries in DEVICES as:
56-
devices(CLASS, HOST, PORT, other_args)
72+
The device server configuration file is a Python script that defines a
73+
``DEVICES`` list. Each element in the list corresponds to one
74+
device. For example:
75+
76+
.. code:: python
77+
78+
"""Configuration file for deviceserver.
5779
"""
58-
## Function to create record for each device.
80+
# The 'device' function creates device definitions.
5981
from microscope.devices import device
60-
## Import device modules/classes here.
82+
83+
# Import required device classes
84+
from microscope.lasers.cobolt import CoboltLaser
85+
from microscope.cameras.atmcd import AndorAtmcd
86+
87+
# host is the IP address (or hostname) from where the device will be
88+
# accessible. If everything is on the same computer, then host will
89+
# be '127.0.0.1'. If devices are to be available on the network,
90+
# then it will be the IP address on that network.
91+
host = '192.168.1.2'
92+
93+
# Each element in the DEVICES list identifies a device that will be
94+
# served on the network. Each device is defined like so:
95+
#
96+
# device(cls, host, port, conf)
97+
# cls: class of the device that will be served
98+
# host: ip or hostname where the device will be accessible.
99+
# This will be the same value for all devices.
100+
# port: port number where the device will be accessible.
101+
# Each device must have its own port.
102+
# conf: a dict with the arguments to construct the device
103+
# instance. See the individual class documentation.
104+
#
105+
# This list, initialises two cobolt lasers and one Andor camera.
106+
DEVICES = [
107+
device(CoboltLaser, host, 7701,
108+
{'com' : '/dev/ttyS0'}),
109+
device(CoboltLaser, host, 7702,
110+
{'com' : '/dev/ttyS1'}),
111+
device(AndorAtmcd, host, 7703,
112+
{'uid' : '9146'}),
113+
]
114+
115+
116+
Test devices
117+
------------
118+
119+
Microscope includes multiple test devices. These are meant to support
120+
development by providing a fake device for testing purposes.
121+
122+
.. code:: python
123+
124+
from microscope.devices import device
125+
61126
from microscope.testsuite.devices import TestCamera
62127
from microscope.testsuite.devices import TestLaser
63128
from microscope.testsuite.devices import TestFilterWheel
64129
65130
DEVICES = [
66-
device(TestCamera, '127.0.0.1', 8005, {'buffer_length' : 0}),
131+
device(TestCamera, '127.0.0.1', 8005),
67132
device(TestLaser, '127.0.0.1', 8006),
68133
device(TestFilterWheel, '127.0.0.1', 8007,
69-
{'filters' : [(0, 'GFP', 525), (1, 'RFP'), (2, 'Cy5')]}),
134+
{'filters' : [(0, 'GFP', 525),
135+
(1, 'RFP'), (2, 'Cy5')]}),
70136
]

0 commit comments

Comments
 (0)