Skip to content

Commit 70d6e63

Browse files
committed
re-read first article
1 parent 5e53f35 commit 70d6e63

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

docs/beginners-guide/articles/servers.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mandatory argument to be supplied to the `Thing` parent. Non-experts may use str
1717
characters, numbers, forward slashes etc., which looks like a part of a browser URL, but the general definition is
1818
that `id` should be a URI compatible string:
1919

20-
```py title="ID" linenums="1" hl_lines="3"
20+
```py title="Thing ID" linenums="1" hl_lines="3"
2121
--8<-- "docs/beginners-guide/code/thing_basic_example.py:130:137"
2222
```
2323

@@ -76,42 +76,42 @@ running multiple requests at once to different properties or actions. If a singl
7676

7777
To overload the get-set of properties to directly apply property values onto devices, one may supply a custom getter & setter method:
7878

79-
```py title="Property Get Set Overload" linenums="1"
80-
--8<-- "docs/beginners-guide/code/thing_basic_example.py:8:12"
81-
--8<-- "docs/beginners-guide/code/thing_basic_example.py:37:52"
79+
```py title="Property Get Set Overload" linenums="1" hl_lines="19 24"
80+
--8<-- "docs/beginners-guide/code/thing_basic_example.py:177:202"
8281
```
8382

8483
Properties follow the python descriptor protocol. In non expert terms, when a custom get-set method is not provided,
8584
properties look like class attributes however their data containers are instantiated at object instance level by default.
8685
For example, the [`serial_number`](#__codelineno-2-9) property defined
8786
previously as `String`, whenever set/written, will be complied to a string and assigned as an attribute to each instance
8887
of the `OceanOpticsSpectrometer` class. This is done with an internally generated name. It is not necessary to know this
89-
internally generated name as the property value can be accessed again in any python logic, say, <br>
88+
internally generated name as the property value can be accessed again in any python logic using the dot operator, say, <br>
9089
[`self.device = Spectrometer.from_serial_number(self.serial_number)`](#__codelineno-3-17)
9190
<br>
9291

9392
However, to avoid generating such an internal data container and instead apply the value on the device, one may supply
94-
custom get-set methods using the fget and fset argument. This is generally useful as the hardware is a better source
93+
custom get-set methods. This is generally useful as the hardware is a better source
9594
of truth about the value of a property. Further, the write value of a property may not always correspond to a read
96-
value due to hardware limitations. Say, the write value of `integration_time` requested by the user is `1000.2`, however, the device adjusted it to `1000.0` automatically.
95+
value due to hardware limitations. Say, the write value of `referencing_run_frequency` requested by the user is `1050`, however, the device adjusted it to `1000` automatically.
9796

98-
### Push Events
97+
### Publish Events
9998

10099
Events are to be used to asynchronously push data to clients. For example, one can supply clients with the
101100
measured data using events:
102101

103102
```py title="Events" linenums="1" hl_lines="19"
104103
--8<-- "docs/beginners-guide/code/thing_basic_example.py:2:2"
105104
--8<-- "docs/beginners-guide/code/thing_basic_example.py:7:11"
106-
--8<-- "docs/beginners-guide/code/thing_basic_example.py:71:85"
105+
--8<-- "docs/beginners-guide/code/thing_basic_example.py:84:97"
107106
```
108107

109108
Data may also be polled by the client repeatedly but events save network time or allow sending data which cannot be timed,
110-
like alarm messages. Arbitrary payloads are supported, as long as the data is serializable.
109+
like alarm messages. Arbitrary payloads are supported, as long as the data is serializable. One can also specify the payload structure using
110+
[pydantic or JSON schema](#event-payload-schema)
111111

112112
To start the capture method defined above, to receive the events, one may thread it as follows:
113113

114-
```py title="Events" linenums="1" hl_lines="8"
114+
```py title="Events" linenums="1"
115115
--8<-- "docs/beginners-guide/code/thing_basic_example.py:7:12"
116-
--8<-- "docs/beginners-guide/code/thing_basic_example.py:86:100"
116+
--8<-- "docs/beginners-guide/code/thing_basic_example.py:90:104"
117117
```

docs/beginners-guide/code/thing_basic_example.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_integration_time(self, value: float):
5151
def get_integration_time(self) -> float:
5252
try:
5353
return self._integration_time
54-
except:
54+
except AttributeError:
5555
return 1000.0
5656

5757
trigger_mode = Selector(
@@ -84,7 +84,7 @@ def get_trigger_mode(self):
8484
measurement_event = Event(
8585
name="intensity-measurement-event",
8686
doc="""event generated on measurement of intensity,
87-
max 30 per second even if measurement is faster.""",
87+
max 30 per second even if measurement is faster.""",
8888
)
8989

9090
def capture(self):
@@ -176,28 +176,26 @@ def start_https_server():
176176

177177
class Axis(Thing):
178178
"""
179-
Represents a single stepper module of a Phytron Phymotion Control Rack
179+
Represents a single axis of stepper module controlling a linear stage
180180
"""
181181

182182
def execute(self, command):
183183
# implement device driver logic to send command to hardware
184184
...
185185

186+
referencing_run_frequency = Number(
187+
bounds=(0, 40000),
188+
inclusive_bounds=(False, True),
189+
step=100,
190+
doc="""Run frequency during initializing (referencing), in Hz (integer value).
191+
I1AM0x: 40 000 maximum, I4XM01: 4 000 000 maximum""",
192+
)
193+
194+
@referencing_run_frequency.getter
186195
def get_referencing_run_frequency(self):
187196
resp = self.execute("P08R")
188197
return int(resp)
189198

199+
@referencing_run_frequency.setter
190200
def set_referencing_run_frequency(self, value):
191201
self.execute("P08S{}".format(value))
192-
193-
referencing_run_frequency = Number(
194-
bounds=(0, 40000),
195-
inclusive_bounds=(False, True),
196-
step=100,
197-
URL_path="/frequencies/referencing-run",
198-
fget=get_referencing_run_frequency,
199-
fset=set_referencing_run_frequency,
200-
doc="""Run frequency during initializing (referencing),
201-
in Hz (integer value).
202-
I1AM0x: 40 000 maximum, I4XM01: 4 000 000 maximum""",
203-
)

docs/stylesheets/extra.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,16 @@
8888

8989

9090
/* Apply same font to LEFT SIDEBAR (primary navigation) */
91-
.md-sidebar--primary .md-nav__title,
91+
.md-sidebar--primary nav.md-nav .md-nav__item {
92+
font-family: Delius;
93+
font-size: 20px;
94+
font-weight: 700;
95+
} /* not working as intended */
96+
9297
.md-sidebar--primary .md-nav__link {
93-
font-family: var(--heading-font);
94-
font-weight: 600;
98+
font-family: var(--heading-font);
99+
font-size: 16.8px;
100+
font-weight: 600;
95101
}
96102

97103
/* Apply same font to RIGHT SIDEBAR (page table of contents) */

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ theme:
159159
font:
160160
text: Delius
161161
heading: Lexend
162+
# Other useful fonts that we may use:
162163
# Lexend Deca
163164
# Recursive
164-
# Google Sans Code
165+
# Google Sans Code (Used for titles and headers)
165166
# Funnel Sans
166167
# Comme
167168
code: Roboto Mono

0 commit comments

Comments
 (0)