OpenSMI-Server 0.3.1__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/PKG-INFO +4 -2
  2. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/README.md +2 -0
  3. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/docs/development.md +0 -2
  4. opensmi_server-0.4.1/docs/events.md +73 -0
  5. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/docs/faq.md +0 -2
  6. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/docs/migration.md +69 -4
  7. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/docs/skills.md +64 -43
  8. opensmi_server-0.4.1/docs/variables.md +180 -0
  9. opensmi_server-0.4.1/examples/structures/README.md +44 -0
  10. opensmi_server-0.4.1/examples/structures/client.py +62 -0
  11. opensmi_server-0.4.1/examples/structures/server.py +104 -0
  12. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/pyproject.toml +1 -1
  13. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/OpenSMI_Server.egg-info/PKG-INFO +4 -2
  14. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/OpenSMI_Server.egg-info/SOURCES.txt +9 -0
  15. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/OpenSMI_Server.egg-info/requires.txt +1 -1
  16. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/OpenSMI_Server.egg-info/scm_file_list.json +16 -0
  17. opensmi_server-0.4.1/src/OpenSMI_Server.egg-info/scm_version.json +8 -0
  18. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/__init__.py +2 -0
  19. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/_history.py +34 -2
  20. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/_server.py +78 -26
  21. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/access_control.py +20 -9
  22. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_skill.py +119 -13
  23. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/common.py +6 -5
  24. opensmi_server-0.4.1/src/opensmi/server/data_types.py +171 -0
  25. opensmi_server-0.4.1/src/opensmi/server/docstrings.py +38 -0
  26. opensmi_server-0.4.1/src/opensmi/server/errors.py +11 -0
  27. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/interfaces.py +6 -8
  28. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/description_mixin.py +3 -3
  29. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/skill_logic_mixins.py +106 -81
  30. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/notification.py +30 -3
  31. opensmi_server-0.4.1/src/opensmi/server/structures.py +390 -0
  32. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/ua_variable.py +254 -45
  33. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/ua_variable_containers.py +174 -11
  34. opensmi_server-0.3.1/src/OpenSMI_Server.egg-info/scm_version.json +0 -8
  35. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/.github/workflows/api-docs.yml +0 -0
  36. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/.github/workflows/checks.yml +0 -0
  37. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/.github/workflows/python-publish.yml +0 -0
  38. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/.gitignore +0 -0
  39. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/.pre-commit +0 -0
  40. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/.pre-commit-config.yaml +0 -0
  41. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/LICENSE +0 -0
  42. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/LICENSES/CC0-1.0.txt +0 -0
  43. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/LICENSES/MIT.txt +0 -0
  44. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/MANIFEST.in +0 -0
  45. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/docs/machinery_item.md +0 -0
  46. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/docs/methods.md +0 -0
  47. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/check/main.py +0 -0
  48. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dictionary_entries/main.py +0 -0
  49. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/__init__.py +0 -0
  50. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/composite_skill.py +0 -0
  51. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/config.toml +0 -0
  52. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/continuous_skill.py +0 -0
  53. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/continuous_skill_self_halting.py +0 -0
  54. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/dummy_component.py +0 -0
  55. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/dummy_machine.py +0 -0
  56. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/dummy_method.py +0 -0
  57. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/dummy_skill.py +0 -0
  58. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/dummy_skill_resources.py +0 -0
  59. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/dummy_skill_simple.py +0 -0
  60. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/main.py +0 -0
  61. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/resources.py +0 -0
  62. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/startup_skill.py +0 -0
  63. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/dummy/suspendable_dummy_skill.py +0 -0
  64. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/quick_start/main.py +0 -0
  65. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/examples/rsl/main.py +0 -0
  66. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/setup.cfg +0 -0
  67. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/OpenSMI_Server.egg-info/dependency_links.txt +0 -0
  68. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/OpenSMI_Server.egg-info/top_level.txt +0 -0
  69. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_callable.py +0 -0
  70. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_feasibility_check.py +0 -0
  71. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_machine.py +0 -0
  72. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_machinery_item.py +0 -0
  73. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_method.py +0 -0
  74. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_precondition_check.py +0 -0
  75. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/base_startup_skill.py +0 -0
  76. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/config.py +0 -0
  77. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/lock.py +0 -0
  78. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/__init__.py +0 -0
  79. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/lockable_mixin.py +0 -0
  80. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/notification_mixins.py +0 -0
  81. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/parent_mixin.py +0 -0
  82. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/requirements_mixin.py +0 -0
  83. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/spatial_object_mixin.py +0 -0
  84. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/ua_object_container_mixins.py +0 -0
  85. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/mixins/ua_variable_container_mixins.py +0 -0
  86. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/protocols.py +0 -0
  87. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/resource.py +0 -0
  88. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/spatial_object.py +0 -0
  89. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/ua_dictionary_entry.py +0 -0
  90. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/ua_fsm.py +0 -0
  91. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/ua_object.py +0 -0
  92. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/ua_object_containers.py +0 -0
  93. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/src/opensmi/server/user.py +0 -0
  94. {opensmi_server-0.3.1 → opensmi_server-0.4.1}/tools/create_password.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: OpenSMI-Server
3
- Version: 0.3.1
3
+ Version: 0.4.1
4
4
  Summary: Asynchronous Python framework for building Smart Machine Interface-compliant OPC UA servers.
5
5
  Author-email: Carsten Harms <Carsten.Harms@dfki.de>, Simon Jungbluth <Simon.Jungbluth@smartfactory.de>
6
6
  License-Expression: MIT
@@ -26,7 +26,7 @@ Classifier: Typing :: Typed
26
26
  Requires-Python: >=3.11
27
27
  Description-Content-Type: text/markdown
28
28
  License-File: LICENSES/MIT.txt
29
- Requires-Dist: OpenSMI-Core<0.8,>=0.7
29
+ Requires-Dist: OpenSMI-Core<0.9,>=0.8.1
30
30
  Requires-Dist: asyncua<3,>=2.0.1
31
31
  Requires-Dist: transitions<1,>=0.9
32
32
  Requires-Dist: structlog>=26
@@ -186,6 +186,8 @@ See [here](examples) for more OpenSMI server examples.
186
186
  | [**Machines**](docs/machinery_item.md#machines) | The top-level unit a client addresses as "the machine," e.g. a robot + storage + transport port. A single server can expose several machines. |
187
187
  | [**Skills**](docs/skills.md) | Asynchronous, stateful capabilities — finite (run once, complete) or continuous (run indefinitely), atomic or composite. |
188
188
  | [**Methods**](docs/methods.md) | Synchronous, quick operations — no state machine, just `call()` in, result out. |
189
+ | [**Variables**](docs/variables.md) | Values that belong together: structures as dataclasses, their fields as child variables, and groups of variables. |
190
+ | [**Events**](docs/events.md) | Messages as OPC UA events: info, warning and error notifications and their history. |
189
191
 
190
192
  ## Project Status
191
193
 
@@ -146,6 +146,8 @@ See [here](examples) for more OpenSMI server examples.
146
146
  | [**Machines**](docs/machinery_item.md#machines) | The top-level unit a client addresses as "the machine," e.g. a robot + storage + transport port. A single server can expose several machines. |
147
147
  | [**Skills**](docs/skills.md) | Asynchronous, stateful capabilities — finite (run once, complete) or continuous (run indefinitely), atomic or composite. |
148
148
  | [**Methods**](docs/methods.md) | Synchronous, quick operations — no state machine, just `call()` in, result out. |
149
+ | [**Variables**](docs/variables.md) | Values that belong together: structures as dataclasses, their fields as child variables, and groups of variables. |
150
+ | [**Events**](docs/events.md) | Messages as OPC UA events: info, warning and error notifications and their history. |
149
151
 
150
152
  ## Project Status
151
153
 
@@ -3,8 +3,6 @@
3
3
  > [!important]
4
4
  > You do **not** need to read this if you just want to use this as a normal Python library!
5
5
 
6
- [[_TOC_]]
7
-
8
6
  ## Design Goals
9
7
 
10
8
  - API as simple to use as possible, ideally little to no asyncua contact for end users
@@ -0,0 +1,73 @@
1
+ # Events
2
+
3
+ Machines, and components that have their own `Notification`, report messages as OPC UA events. Clients receive them by
4
+ subscribing to the events of the `Notification` object, and can read past events from its event history.
5
+
6
+ ## Notifications
7
+
8
+ A `Notification` is a child object of a machinery item. Machines always have one (via `NotificationMixin`); components
9
+ either have their own (via `NotificationMixin`) or forward their messages to their parent (via
10
+ `NotificationForwarderMixin`), as do skills and methods.
11
+
12
+ Log a message with one of these methods of the machinery item, skill or method:
13
+
14
+ | Method | Event type | Default `Severity` |
15
+ |--------------------|-----------------|--------------------|
16
+ | `ua_log_info()` | `BaseEventType` | 0 |
17
+ | `ua_log_warning()` | `BaseEventType` | 555 |
18
+ | `ua_log_error()` | `AlertType` | 999 |
19
+
20
+ `ua_log_error()` also takes a `code`, sent in the `ErrorCode` field of the event.
21
+
22
+ Every event is emitted by the `Notification` object. `SourceNode` and `SourceName` name the object the message is
23
+ about: the `source` argument if given, else the machinery item the `Notification` belongs to.
24
+
25
+ ## Event history
26
+
27
+ The server keeps the events of every `Notification` in its event history, which clients read with `HistoryRead`
28
+ (e.g. `node.read_event_history()` in asyncua). How many events it keeps depends on the history storage, set by
29
+ `history_db` in the `[ua_server]` section of the server configuration:
30
+
31
+ | `history_db` | Kept events |
32
+ |----------------------|----------------------------------------------------------------------------------------------|
33
+ | `"memory"` (default) | The last 1000 events, none older than 7 days. Lost when the server stops. |
34
+ | `"sqlite"` | All events of the last 7 days, in `data/opcua_history.sql` below the working directory. |
35
+
36
+ The storages differ because asyncua implements them differently: its in-memory storage applies both the count and the
37
+ period, its SQLite storage only the period. The limits are `Notification.HISTORY_EVENT_COUNT` and
38
+ `Notification.HISTORY_EVENT_PERIOD`.
39
+
40
+ ## Advanced: own event types
41
+
42
+ Most machines only need `ua_log_info()`, `ua_log_warning()` and `ua_log_error()`. This section is for integrations that
43
+ define their own event types in a NodeSet and emit them from a `Notification`.
44
+
45
+ Create the generator for such an event type with `Notification.add_event_generator()`, not with
46
+ `ua_server.get_event_generator()`:
47
+
48
+ ```python
49
+ from collections.abc import AsyncGenerator
50
+
51
+ from asyncua.server.event_generator import EventGenerator
52
+ from opensmi.core.lifecycle_mixin import lifecycle
53
+
54
+ from opensmi.server import BaseMachine
55
+ from opensmi.server.mixins import NotificationMixin
56
+
57
+
58
+ class MyMachine(BaseMachine):
59
+ _my_events: EventGenerator
60
+
61
+ @lifecycle(after=NotificationMixin.lifecycle_notification)
62
+ async def lifecycle_my_events(self) -> AsyncGenerator[None]:
63
+ self._my_events = await self.notification.add_event_generator(self.server.ua_get_node_id(MY_EVENT_TYPE))
64
+ yield
65
+ ```
66
+
67
+ The event history only stores the fields of the event types the `Notification` generates when its history is set up.
68
+ `add_event_generator()` sets it up again, so the fields of the new event type are stored as well. A generator created
69
+ with `ua_server.get_event_generator()` emits its events, but their fields specific to the new type are missing from
70
+ the history.
71
+
72
+ Add event types during setup, before the machine emits events: events emitted shortly before or while
73
+ `add_event_generator()` runs can be missing from the history.
@@ -1,7 +1,5 @@
1
1
  # Frequently Asked Questions
2
2
 
3
- [[_TOC_]]
4
-
5
3
  ## How can I fix the "Event loop is too busy" warning(s)?
6
4
 
7
5
  These warnings are generated, if the [Async Event Loop](https://docs.python.org/3/library/asyncio-eventloop.html) is
@@ -3,10 +3,75 @@
3
3
  This guide helps you upgrade to the newest version of OpenSMI-Server. Sections are ordered newest first. If you skip
4
4
  versions, apply every section between your version and the newest one, oldest first.
5
5
 
6
- - [OpenSMI v0.2 -> v0.3 (unreleased)](#opensmi-v02---v03-unreleased)
6
+ - [OpenSMI v0.3 -> v0.4](#opensmi-v03---v04)
7
+ - [OpenSMI v0.2 -> v0.3](#opensmi-v02---v03)
7
8
  - [OpenSMI v0.1 -> v0.2](#opensmi-v01---v02)
8
9
 
9
- ## OpenSMI v0.2 -> v0.3 (unreleased)
10
+ ## OpenSMI v0.3 -> v0.4
11
+
12
+ ### Dependencies
13
+
14
+ - OpenSMI-Server requires `OpenSMI-Core>=0.8.1,<0.9`.
15
+
16
+ ### Skills: transitions follow the nodeset
17
+
18
+ The skill state machine is now built from `SkillStateMachineType` (via `opensmi.core.skill_state_machine`) instead of
19
+ a hand-written table, see [Skills](skills.md#the-state-machine-in-the-address-space). Changes in behavior:
20
+
21
+ - `reset()` works only from `Halted` and `Completed`, no longer from `Starting` or `Suspended`. Halt a starting or
22
+ suspended skill first.
23
+ - `halt()` also works from `Completing`.
24
+ - A finite skill whose `_handle_running()` returns while it is `Suspending` no longer halts: it finishes suspending
25
+ and completes once it is started again.
26
+ - Work paused at `_suspend_point()` continues only once the skill is `Running` again, not already while `Starting`
27
+ (where finishing work halted the skill).
28
+ - A skill created with `suspendable=False` has no suspend transitions; `suspend()` on it raises
29
+ `UaStatusCodeError(BadNotImplemented)` right away.
30
+
31
+ Only if you subclass skills beyond the `_handle_*` hooks and `_condition_*_allowed` conditions:
32
+
33
+ - `_condition_is_suspendable()` was removed; overriding it has no effect. Pass `suspendable` to the constructor.
34
+ - `AbstractSkill` has a new abstract property `is_suspendable`. `BaseSkill` implements it.
35
+ - The internal triggers are `<state>_done` (`resetting_done`, `halting_done`, `starting_done`, `running_done`,
36
+ `completing_done`, `suspending_done`); `done_internal` is gone.
37
+
38
+ ### Skills: new nodes for clients
39
+
40
+ Every skill's state machine now has `CurrentState/Number` and `LastTransition` with its `Id`, and fills
41
+ `CurrentState/Id`, `AvailableStates` and `AvailableTransitions`. Nothing to do; clients may use them.
42
+
43
+ ### Enum types
44
+
45
+ - Two different `IntEnum` classes of one name are refused: `server.ensure_enum()` raises `TypeConflictError`
46
+ (`opensmi.server.errors`, also exported from `opensmi.server`) for the second instead of creating a second DataType
47
+ with the same BrowseName. The same holds for an enum and a structure of one name. Rename one of them.
48
+ - `server.register_enum()` is now `async`: `await server.register_enum(...)`. It compares the members of the enum with
49
+ what the DataType publishes and raises `TypeConflictError` if they differ. Binding the same enum to the same DataType
50
+ again no longer raises; binding it to another DataType still needs `overwrite=True`.
51
+ - An enum DataType the server creates has the NodeId `ns=1;s=<EnumName>` instead of a numeric one that depended on the
52
+ order enums were created in (like `ns=1;i=3012`). Clients that find enum types by BrowseName, as OpenSMI-Client does,
53
+ are not affected; update code or NodeSet exports that stored the numeric NodeIds. A machine of the same name as an
54
+ enum now clashes with it, as with structures: adding the machine after the enum fails with an unrelated looking
55
+ `UaStatusCodeError`, creating the enum after the machine with `BadNodeIdExists`. Rename one of them.
56
+
57
+ ### Variables: bad status
58
+
59
+ - A write with a bad status is no longer checked, since it has no value: every variable accepts it, also one that is
60
+ not `optional_ok`, and its `write_check_callback` is not called. A client still needs the access level and the
61
+ lock to write it. Replace dummy
62
+ values that were only written to get a bad status through the check by the new `UaVariable.write_status()`:
63
+ `await variable.write_status(ua.StatusCodes.BadNoCommunication)`.
64
+
65
+ ### Notifications: own event types
66
+
67
+ - Only if you create generators for your own event types on a `Notification` with `ua_server.get_event_generator()`:
68
+ switch to the new `Notification.add_event_generator()`, see
69
+ [Advanced: own event types](events.md#advanced-own-event-types). Until then the event history stores these events
70
+ without the fields specific to their type.
71
+ - The SQLite history storage adds missing event field columns to an existing table, so a database written by an
72
+ earlier version also stores them from now on.
73
+
74
+ ## OpenSMI v0.2 -> v0.3
10
75
 
11
76
  ### Dependencies
12
77
 
@@ -81,8 +146,8 @@ Clients that matched incoming events to their subscription by `SourceNode` no lo
81
146
  Match by the monitored item instead, e.g. by `event.server_handle` in asyncua. OpenSMI-Core v0.7.0 and older match by
82
147
  `SourceNode`, so clients based on them (OpenSMI-Client up to now) need OpenSMI-Core v0.7.1 or newer.
83
148
 
84
- Notification events are now also kept in the server's event history (up to 1000 per `Notification` object) and can be
85
- read with `HistoryRead`.
149
+ Notification events are now also kept in the server's event history and can be read with `HistoryRead`. How many
150
+ are kept depends on the history storage, see [Event history](events.md#event-history).
86
151
 
87
152
  ### Other API changes
88
153
 
@@ -1,11 +1,9 @@
1
1
  # Skills
2
2
 
3
- [[_TOC_]]
4
-
5
3
  ## Basics
6
4
 
7
- Each skill is a self-contained capability exposed over OPC-UA with `start()`/`suspend()`/`reset()`/`halt()` methods and
8
- a standard state machine. They have
5
+ Each skill is a self-contained capability exposed over OPC-UA with `start()`/`reset()`/`halt()` methods (and
6
+ `suspend()` for skills created with `suspendable=True`) and a standard state machine. They have
9
7
 
10
8
  - **`ParameterSet`** — the inputs a skill needs to do its work, written by a caller before or during `start`. For
11
9
  example a "MoveTo" skill's target position, or a "Drilling" skill's hole diameter and depth.
@@ -27,28 +25,26 @@ final position and result data until reset for the next move.
27
25
  ```mermaid
28
26
  stateDiagram-v2
29
27
  [*] --> Halted
30
- Halted --> Resetting: reset()
31
- Starting --> Resetting: reset()
32
- Suspended --> Resetting: reset()
33
- Completed --> Resetting: reset()
34
- Resetting --> Ready: _internal_
35
- Ready --> Halting: halt()
36
- Running --> Halting: halt()
37
- Suspended --> Halting: halt()
38
- Starting --> Halting: halt()
39
- Resetting --> Halting: halt()
40
- Suspending --> Halting: halt()
41
- Completed --> Halting: halt()
28
+ Halted --> Operational: reset()
29
+ Operational --> Halting: halt()
42
30
  Halting --> Halted: _internal_
43
- Ready --> Starting: start()
44
- Suspended --> Starting: start()
45
- Starting --> Running: _internal_
46
- Running --> Suspending: suspend()
47
- Suspending --> Suspended: _internal_
48
- Running --> Completing: _internal_
49
- Completing --> Completed: _internal_
31
+
32
+ state Operational {
33
+ [*] --> Resetting
34
+ Resetting --> Ready: _internal_
35
+ Ready --> Starting: start()
36
+ Starting --> Running: _internal_
37
+ Running --> Suspending: suspend()
38
+ Suspending --> Suspended: _internal_
39
+ Suspended --> Starting: start()
40
+ Running --> Completing: _internal_
41
+ Completing --> Completed: _internal_
42
+ Completed --> Resetting: reset()
43
+ }
50
44
  ```
51
45
 
46
+ `Suspending` and `Suspended` exist only for skills created with `suspendable=True`.
47
+
52
48
  - `Halted`: A halted skill is in a failed/safe-ish state. E.g. a motor should apply fail-safe brakes, cut power etc. and
53
49
  no longer move.
54
50
  - `Halting`: A halting skill is currently transitioning into `Halted`, but has not reached the safe-ish state yet. E.g.
@@ -69,6 +65,8 @@ stateDiagram-v2
69
65
  - `Suspended`: A suspended skill has paused at a safe point and is holding its state, ready to resume from exactly
70
66
  where it left off. Unlike `Halted`, this isn't a failure/safe-mode — actuators may still be powered and holding
71
67
  position. E.g. a robot arm is stationary between cycles, gripper still closed on a part, waiting to continue.
68
+ `start()` resumes it through `Starting`, so `_handle_starting()` runs again before the paused work continues in
69
+ `Running`.
72
70
  - `Completing` *(finite skills only)*: A completing skill has finished its primary work and is performing final
73
71
  cleanup or result reporting before being marked done. E.g. a gripper releases the part it just placed, or final
74
72
  measurement data is written to the result record.
@@ -76,16 +74,20 @@ stateDiagram-v2
76
74
  final results until it is reset for the next run. E.g. a part has been placed and the skill is reporting success
77
75
  while awaiting a `reset()` before it can `start()` again.
78
76
 
77
+ `Operational` is only a box in the diagram, not a state: `halt()` works from every state in it, and `reset()` from
78
+ `Halted` enters it at `Resetting`. A finite skill completes only from `Running`. If `_handle_running()` returns while
79
+ the skill is `Suspending`, the skill finishes suspending and completes once it is started again.
80
+
79
81
  > [!note]
80
82
  > The \*ing states (`Halting`, `Resetting`, `Starting`, `Suspending`, `Completing`) all share the same shape: they're
81
- the "in transition, doing async work" counterparts to their target steady state, and each is driven by a _handle_* hook
82
- that skill authors override.
83
+ > the "in transition, doing async work" counterparts to their target steady state, and each is driven by a `_handle_*`
84
+ > hook that skill authors override.
83
85
 
84
86
  ### Continuous Skills
85
87
 
86
88
  A continuous skill is a skill with no terminal "done" state — its `Running` state has no `Completed` counterpart at
87
- all. Once started, it keeps working until it is explicitly `suspend()`ed (paused, resumable) or `halt()`ed (stopped,
88
- non-resumable), rather than finishing on its own.
89
+ all. Once started, it keeps working until it is explicitly `halt()`ed (stopped, non-resumable) or, if created with
90
+ `suspendable=True`, `suspend()`ed (paused, resumable), rather than finishing on its own.
89
91
 
90
92
  For example, a "ConveyorFeed" skill that drives a belt to keep feeding parts downstream: `Running` means the motor
91
93
  is actively driving, for as long as the line needs material moved — there is no single unit of work after which the
@@ -94,25 +96,44 @@ skill would consider itself "done."
94
96
  ```mermaid
95
97
  stateDiagram-v2
96
98
  [*] --> Halted
97
- Halted --> Resetting: reset()
98
- Starting --> Resetting: reset()
99
- Suspended --> Resetting: reset()
100
- Resetting --> Ready: _internal_
101
- Ready --> Halting: halt()
102
- Running --> Halting: halt()
103
- Suspended --> Halting: halt()
104
- Starting --> Halting: halt()
105
- Resetting --> Halting: halt()
106
- Suspending --> Halting: halt()
99
+ Halted --> Operational: reset()
100
+ Operational --> Halting: halt()
107
101
  Halting --> Halted: _internal_
108
- Ready --> Starting: start()
109
- Suspended --> Starting: start()
110
- Starting --> Running: _internal_
111
- Running --> Suspending: suspend()
112
- Suspending --> Suspended: _internal_
113
102
 
103
+ state Operational {
104
+ [*] --> Resetting
105
+ Resetting --> Ready: _internal_
106
+ Ready --> Starting: start()
107
+ Starting --> Running: _internal_
108
+ Running --> Suspending: suspend()
109
+ Suspending --> Suspended: _internal_
110
+ Suspended --> Starting: start()
111
+ }
114
112
  ```
115
113
 
114
+ `Suspending` and `Suspended` exist only for skills created with `suspendable=True`.
115
+
116
+ As for finite skills, `halt()` works from every state in the `Operational` box.
117
+
118
+ ### The state machine in the address space
119
+
120
+ The transitions are those of `SkillStateMachineType` in the MachineSet nodeset; OpenSMI-Core provides them as
121
+ `opensmi.core.skill_state_machine`, which the server builds its state machine from and clients use to know which
122
+ commands a state allows (`allowed_commands()`). Suspending is opt-in: a skill created without `suspendable=True` (the
123
+ default is `False`) has no `Suspend` method in the address space and never reaches `Suspending` or `Suspended`; calling
124
+ its Python `suspend()` raises `BadNotImplemented`.
125
+
126
+ Besides the text of `CurrentState`, every skill's state machine publishes:
127
+
128
+ - `CurrentState/Id` and `CurrentState/Number`: NodeId and number of the state in `SkillStateMachineType`.
129
+ - `LastTransition` and `LastTransition/Id`: name and NodeId of the transition that led to the current state, empty
130
+ until the first transition after startup. The `SourceTimestamp` is the time of the transition. `LastTransition` has
131
+ no `Number`, as the nodeset defines none.
132
+ - `AvailableStates` and `AvailableTransitions`: the NodeIds of the states and transitions this skill can reach,
133
+ depending on whether it is finite and suspendable.
134
+
135
+ `CurrentState` and `LastTransition` change together, with the same timestamp.
136
+
116
137
  ## Advanced
117
138
 
118
139
  ### Composite Skills
@@ -128,7 +149,7 @@ and "Open"/"Close" skills.
128
149
 
129
150
  > [!Note]
130
151
  > The composite/atomic distinction is purely about what a skill's handlers do, not a different code path in the OpenSMI
131
- framework.
152
+ > framework.
132
153
 
133
154
  ### Feasibility Check
134
155
 
@@ -0,0 +1,180 @@
1
+ # Variables
2
+
3
+ Machinery items, skills and methods hold their values in `UaVariable`s inside the variable containers `ParameterSet`,
4
+ `Monitoring` and `FinalResultData` (see [Machinery Items](machinery_item.md)). This page covers their descriptions,
5
+ values without a valid value, and values that belong together: structures, and groups of variables.
6
+
7
+ ## Descriptions
8
+
9
+ The docstring right after a variable (or group) in its container class becomes the OPC UA `Description` of its node,
10
+ just like the docstring of a skill, component or machine class becomes the description of its object:
11
+
12
+ ```python
13
+ class Results(FinalResultData):
14
+ Count = UaVariable(0)
15
+ """Number of parts produced since server start."""
16
+ ```
17
+
18
+ Descriptions are Markdown, and plain text is fine. The lines of a paragraph are joined, so wrap docstrings as usual;
19
+ paragraphs and list items keep their own lines. They are read by clients, so describe the value for an operator or
20
+ integrator, not the Python API.
21
+
22
+ ## Bad status
23
+
24
+ When a variable has no valid value, e.g. because the connection to its data source is lost, mark it with a bad
25
+ status instead of leaving the last value. Clients then see the status and no value:
26
+
27
+ ```python
28
+ from asyncua import ua
29
+
30
+ await self.monitoring.Temperature.write_status(ua.StatusCodes.BadNoCommunication)
31
+ ...
32
+ await self.monitoring.Temperature.write(21.5) # valid again: the status is Good
33
+ ```
34
+
35
+ `write_status()` accepts bad statuses only; a good or uncertain status comes with a value, so use `write()`. A bad
36
+ status is not checked: every variable accepts it, also one that is not `optional_ok`, and its `write_check_callback`
37
+ is not called.
38
+
39
+ ## Structures
40
+
41
+ A variable whose `initial_value` is a dataclass instance holds a structure. The server creates the OPC UA DataType
42
+ from the dataclass when the variable is created, and the variable reads and writes instances of it:
43
+
44
+ ```python
45
+ from dataclasses import dataclass, field
46
+
47
+ from opensmi.server import ParameterSet, UaVariable
48
+
49
+
50
+ @dataclass
51
+ class Dimensions:
52
+ length: float = 0.0
53
+ width: float = 0.0
54
+
55
+
56
+ @dataclass
57
+ class Workpiece:
58
+ id: str = ""
59
+ dimensions: Dimensions = field(default_factory=Dimensions)
60
+
61
+
62
+ class Parameters(ParameterSet):
63
+ CurrentWorkpiece = UaVariable(initial_value=Workpiece("W-001", Dimensions(120.0, 80.0)))
64
+ """The workpiece in the machine."""
65
+ ```
66
+
67
+ Fields are `float`, `int`, `str`, `bool`, `bytes`, another dataclass, or a `list` of one of these. A list of dataclass
68
+ instances is a variable too; if it starts empty, name the class with `variable_type`. Every write is checked: the
69
+ variable accepts only an instance of its class (or a list of them) and refuses anything else with `BadTypeMismatch`.
70
+
71
+ A client needs no class of its own. asyncua's `Client.load_data_type_definitions()` builds one from the
72
+ `DataTypeDefinition` the server publishes. The module docstring of `opensmi.server.structures` has the details, e.g.
73
+ how to pick other OPC UA number types for a field.
74
+
75
+ ## Complex variables
76
+
77
+ A variable that holds one structure (not a list) is a complex variable: below the variable is one child variable per
78
+ field, and below a nested structure its fields again. The browse name of a child is its field name in PascalCase:
79
+
80
+ ```
81
+ ParameterSet
82
+ CurrentWorkpiece Workpiece (the whole structure)
83
+ Id String
84
+ Dimensions Dimensions (complex again)
85
+ Length Double
86
+ Width Double
87
+ ```
88
+
89
+ A list, also of dataclass instances, is one child of its own, without children for its elements.
90
+
91
+ Clients can read, subscribe to and write each child like any other variable, so a client without the structure's
92
+ class can still show and change `CurrentWorkpiece/Dimensions/Length`. In Python, `variable.children` maps the names to
93
+ the child variables, and `variable["Dimensions"]["Length"]` is one of them:
94
+
95
+ ```python
96
+ length = self.parameter_set.CurrentWorkpiece["Dimensions"]["Length"]
97
+ await length.write(95.0)
98
+ ```
99
+
100
+ To change one field from server code, write the child rather than reading, changing and writing the whole structure.
101
+ A write to a child is merged into the current structure while other writes to the variable wait, so a concurrent
102
+ write to another field, e.g. by a client, is kept. Between your `read()` and `write()` of the whole structure,
103
+ another write can land, and yours would undo it.
104
+
105
+ The variable and its children always agree:
106
+
107
+ - A write to the variable also writes all its children, and a write to a child also writes the variable and the
108
+ structures on the way up. All of them get one `SourceTimestamp` and the status of the write.
109
+ - A bad status (e.g. `BadNoCommunication`, see [Bad status](#bad-status)) has no value and is not checked. Written to
110
+ the variable or to any child, it reaches the variable and all its children, and none of them has a value.
111
+ - Every write is checked once, by the variable that holds the whole structure, on the whole new structure. Its
112
+ `write_check_callback` therefore also sees writes to a child and can check rules across fields. A refused write
113
+ changes nothing. A `write_check_callback` only checks: it must not write any variable.
114
+ - The children share the access of the variable: `writable`, `bypass_lock` and `minimum_access_level`, also after
115
+ `set_writable()`. They have no `write_check_callback` of their own.
116
+ - While the variable has a bad status, a write to a child is refused with that status, since there is no structure to
117
+ change. Write the whole structure first.
118
+
119
+ ## Groups
120
+
121
+ A `VariableGroup` is an Object in a variable container that holds variables and further groups, for variables that
122
+ belong together but are not one structure. Declare it like a variable:
123
+
124
+ ```python
125
+ from opensmi.server import ParameterSet, UaVariable, VariableGroup
126
+
127
+
128
+ class FollowPath(VariableGroup):
129
+ MaxVelX = UaVariable(initial_value=0.5)
130
+ """Maximum forward velocity in m/s."""
131
+
132
+
133
+ class Controller(VariableGroup):
134
+ UseSimTime = UaVariable(initial_value=False)
135
+ """Whether the controller uses the simulation time."""
136
+
137
+ FollowPath = FollowPath()
138
+
139
+
140
+ class Parameters(ParameterSet):
141
+ Controller = Controller()
142
+ ```
143
+
144
+ Clients browse it as `ParameterSet/Controller/FollowPath/MaxVelX`. A group takes the writability and the
145
+ `minimum_access_level` of its container, so the variables declared in it are writable in a `ParameterSet` and
146
+ read-only in `Monitoring`, as if they were declared in the container itself.
147
+
148
+ Add and remove groups while the server runs with `add_group()` and `remove_group()`. Removing a group removes
149
+ everything below it:
150
+
151
+ ```python
152
+ sensors = await self.monitoring.add_group("Sensors")
153
+ await sensors.add(UaVariable(initial_value=0.0, name="Level"))
154
+ ...
155
+ await self.monitoring.remove_group("Sensors")
156
+ ```
157
+
158
+ In Python, a declared group is an attribute of its container (`parameters.Controller.FollowPath.MaxVelX`), and
159
+ `container.groups` maps the names of all groups to them, declared or added. The rest of the container interface covers
160
+ its variables only: `container["MaxVelX"]`, `"MaxVelX" in container`, `len(container)` and `for variable in
161
+ container` do not see groups. `read_all()`, `write_all()` and `reset_all()` include the groups, as nested mappings:
162
+
163
+ ```python
164
+ await parameters.read_all()
165
+ # {"Controller": {"UseSimTime": False, "FollowPath": {"MaxVelX": 0.5}}}
166
+ ```
167
+
168
+ `reset_all()` skips variables created with `resettable=False`, e.g. counters since server start; their own `reset()`
169
+ still resets them.
170
+
171
+ ## Structure or group?
172
+
173
+ A complex variable is one value: it is valid as a whole or not at all. A bad status on any of its nodes reaches all
174
+ of them, and a client can read it atomically. A group is only a namespace: each variable in it has its own value and
175
+ status, and the group itself has none.
176
+
177
+ - Use a **structure** for values that arrive and are valid together, from one source, e.g. a workpiece record or a
178
+ pose read from the controller in one go.
179
+ - Use a **group** for values that come from independent sources and can fail separately, e.g. the readings of two
180
+ sensors. Then one lost sensor marks only its own variables bad, and the others stay readable.
@@ -0,0 +1,44 @@
1
+ # Structures
2
+
3
+ Shows structured values defined as dataclasses. The machine has two parameters: `CurrentWorkpiece`, a `Workpiece`
4
+ (id, material and nested `Dimensions`), and `Measurements`, a list of `Measurement` (name, value, in tolerance). They
5
+ are declared like any other variable, with a dataclass instance as `initial_value`. The structure types are created on
6
+ the server when the variables are created, and the server reads and writes the dataclass objects directly. Every
7
+ write is checked: `CurrentWorkpiece` accepts only a `Workpiece` and `Measurements` only a list of `Measurement` (a
8
+ list that starts empty names its class with `variable_type`). The server changes the workpiece once after it starts.
9
+
10
+ A dataclass value is a complex variable: the variable holds the whole structure, and below it is one child variable per
11
+ field (`CurrentWorkpiece/Dimensions/Length`), recursively. The browse name of a child is the field name in PascalCase,
12
+ its display name is the field name. A client can read, write or subscribe to a single field, and the structure always
13
+ agrees with its fields. A write is checked once, at the parent, so a `write_check_callback` always sees the whole
14
+ structure. In Python, `variable["Dimensions"]["Length"]` is the child variable.
15
+
16
+ The parameters also hold a declared group, `Gripper` (a `VariableGroup`, an Object that holds variables), and the
17
+ server adds a group named `station 1: left` to the monitoring at runtime. A name that comes from runtime data is added
18
+ with `runtime_keyed=True`, which only requires a valid path segment (not empty, no `/`) instead of the naming rule.
19
+
20
+ `client.py` is plain asyncua and knows none of the classes. It calls `load_data_type_definitions`, which builds them
21
+ from the `DataTypeDefinition` the server published, reads the workpiece, reads and writes its length through the child
22
+ variable, reads the workpiece again, browses the two groups, adds a measurement and tries to write a `Workpiece` into
23
+ `Measurements`.
24
+
25
+ Run the server in one terminal and the client in another, from the repository root:
26
+
27
+ ```
28
+ python examples/structures/server.py
29
+ python examples/structures/client.py
30
+ ```
31
+
32
+ The server logs its startup and ends with the line `Serving on opc.tcp://0.0.0.0:4841/server`.
33
+ The client prints:
34
+
35
+ ```
36
+ Workpiece: W-002 (aluminium), 90.0 x 60.0 x 5.0 mm
37
+ Length: 90.0 mm
38
+ Workpiece now: 95.0 mm long
39
+ Gripper: ['Force']
40
+ Monitoring group 'station 1: left': ['Temperature']
41
+ Measurements: ['length']
42
+ Measurements now: ['length', 'width']
43
+ Writing a workpiece to Measurements was refused: BadTypeMismatch
44
+ ```