|
1 | 1 | .. 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> |
3 | 3 |
|
4 | 4 | Permission is granted to copy, distribute and/or modify this |
5 | 5 | document under the terms of the GNU Free Documentation License, |
|
13 | 13 | Examples |
14 | 14 | ******** |
15 | 15 |
|
16 | | -Run servers with `python -m microscope.deviceserver SERVERS` and then |
17 | | -run the example with `python example.py` |
18 | | - |
19 | | - |
20 | 16 | Experiments |
21 | 17 | =========== |
22 | 18 |
|
23 | | -.. code:: python |
| 19 | +Simple experiments can be ran with Python only. For a simple time |
| 20 | +series experiment: |
24 | 21 |
|
25 | | - from microscope import clients |
| 22 | +.. code:: python |
26 | 23 |
|
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 |
29 | 26 |
|
| 27 | + laser = CoboltLaser(com='/dev/ttyS0') |
30 | 28 | laser.enable() |
31 | 29 | laser.set_power_mw(30) |
32 | 30 |
|
| 31 | + camera = AndorAtmcd(uid='9146') |
33 | 32 | camera.enable() |
34 | 33 | camera.set_exposure_time(0.15) |
35 | 34 |
|
36 | 35 | data = [] |
37 | | -
|
38 | 36 | for i in range(10): |
39 | 37 | data.append(camera.trigger_and_wait()) |
40 | 38 | print("Frame %d captured." % i) |
41 | | -
|
42 | 39 | print(data) |
43 | 40 |
|
44 | 41 | laser.disable() |
45 | 42 | camera.disable() |
46 | 43 |
|
47 | | -
|
48 | | -Configurations |
| 44 | +Remote devices |
49 | 45 | ============== |
50 | 46 |
|
| 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 | + |
51 | 52 | .. code:: python |
52 | 53 |
|
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 |
54 | 71 |
|
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. |
57 | 79 | """ |
58 | | - ## Function to create record for each device. |
| 80 | + # The 'device' function creates device definitions. |
59 | 81 | 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 | +
|
61 | 126 | from microscope.testsuite.devices import TestCamera |
62 | 127 | from microscope.testsuite.devices import TestLaser |
63 | 128 | from microscope.testsuite.devices import TestFilterWheel |
64 | 129 |
|
65 | 130 | DEVICES = [ |
66 | | - device(TestCamera, '127.0.0.1', 8005, {'buffer_length' : 0}), |
| 131 | + device(TestCamera, '127.0.0.1', 8005), |
67 | 132 | device(TestLaser, '127.0.0.1', 8006), |
68 | 133 | 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')]}), |
70 | 136 | ] |
0 commit comments