Variables

abb_rws_client_python_rw6.highlevel.variables

High-level RAPID variable read/write for ABB RWS RobotWare 6.

Author: Clement RACINET

Composed operations built exclusively from atomic rws/ functions. No HTTP calls are made directly in this module.

All functions are async and require an open RWSClient instance.

get_variable(client, *, symbolurl) async

Read a RAPID variable value.

Wraps get_rapid_symbol_data and extracts the value field from the response body.

Route (delegated): GET /rw/rapid/symbol/data/{symbolurl}

ABB constraints
  • No mastership required for reads.
  • symbolurl format: RAPID/T_ROB1/MainModule/my_var
Parameters:
  • client (RWSClient) –

    Open RWSClient instance.

  • symbolurl (str) –

    Full RAPID symbol path, e.g. "RAPID/T_ROB1/MainModule/counter".

Returns:
  • str –

    The variable value as a string, exactly as returned by the

  • str –

    controller (e.g. "42", "TRUE",

  • str –

    "[[250,0,300],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]]").

Raises:
Example
async with RWSClient(host="192.168.125.1") as client:
    val = await get_variable(
        client,
        symbolurl="RAPID/T_ROB1/MainModule/counter",
    )
    print("counter =", val)
Source code in abb_rws_client_python_rw6/highlevel/variables.py
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
async def get_variable(
    client: RWSClient,
    *,
    symbolurl: str,
) -> str:
    """Read a RAPID variable value.

    Wraps ``get_rapid_symbol_data`` and extracts the ``value`` field
    from the response body.

    Route (delegated): ``GET /rw/rapid/symbol/data/{symbolurl}``

    ABB constraints:
        - No mastership required for reads.
        - ``symbolurl`` format: ``RAPID/T_ROB1/MainModule/my_var``

    Args:
        client: Open ``RWSClient`` instance.
        symbolurl: Full RAPID symbol path, e.g.
            ``"RAPID/T_ROB1/MainModule/counter"``.

    Returns:
        The variable value as a string, exactly as returned by the
        controller (e.g. ``"42"``, ``"TRUE"``,
        ``"[[250,0,300],[1,0,0,0],[0,0,0,0],[9E9,9E9,9E9,9E9,9E9,9E9]]"``).

    Raises:
        RWSAuthenticationError: On HTTP 401.
        RWSNotFoundError: On HTTP 404.
        RWSHTTPError: On any other HTTP >= 400.
        ValueError: If the value cannot be parsed from the response.

    Example:
        ```python
        async with RWSClient(host="192.168.125.1") as client:
            val = await get_variable(
                client,
                symbolurl="RAPID/T_ROB1/MainModule/counter",
            )
            print("counter =", val)
        ```
    """
    response = await get_rapid_symbol_data(client, symbolurl=symbolurl)
    return _parse_symbol_value(response)

set_variable_with_mastership(client, *, symbolurl, value, domain='rapid') async

Write a RAPID variable value, acquiring and releasing mastership.

Composes:

  1. post_mastership_domain_request(domain, action="request")
  2. update_rapid_variable_current_value(action="set", value=value)
  3. post_mastership_domain_release(domain, action="release")

Mastership is always released in a finally block, even if the write fails, to avoid leaving the controller locked.

Route (delegated): - POST /rw/mastership/{domain} (action=request) - POST /rw/rapid/symbol/data/{symbolurl} (action=set) - POST /rw/mastership/{domain} (action=release)

ABB constraints
  • Requires AUTO mode for mastership.
  • symbolurl format: RAPID/T_ROB1/MainModule/my_var
  • domain must be one of: "rapid", "cfg", "motion".
Parameters:
  • client (RWSClient) –

    Open RWSClient instance.

  • symbolurl (str) –

    Full RAPID symbol path, e.g. "RAPID/T_ROB1/MainModule/counter".

  • value (str) –

    New value as a string. Numeric types must be pre-converted: str(42), str(3.14).

  • domain (str, default: 'rapid' ) –

    Mastership domain. Defaults to "rapid".

Returns:
  • None –

    None. Expects HTTP 204 on the write call.

Raises:
Example
async with RWSClient(host="192.168.125.1") as client:
    await set_variable_with_mastership(
        client,
        symbolurl="RAPID/T_ROB1/MainModule/target_x",
        value="250.0",
    )
Source code in abb_rws_client_python_rw6/highlevel/variables.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
async def set_variable_with_mastership(
    client: RWSClient,
    *,
    symbolurl: str,
    value: str,
    domain: str = "rapid",
) -> None:
    """Write a RAPID variable value, acquiring and releasing mastership.

    Composes:

    1. ``post_mastership_domain_request(domain, action="request")``
    2. ``update_rapid_variable_current_value(action="set", value=value)``
    3. ``post_mastership_domain_release(domain, action="release")``

    Mastership is **always** released in a ``finally`` block, even if
    the write fails, to avoid leaving the controller locked.

    Route (delegated):
        - ``POST /rw/mastership/{domain}`` (action=request)
        - ``POST /rw/rapid/symbol/data/{symbolurl}`` (action=set)
        - ``POST /rw/mastership/{domain}`` (action=release)

    ABB constraints:
        - Requires AUTO mode for mastership.
        - ``symbolurl`` format: ``RAPID/T_ROB1/MainModule/my_var``
        - ``domain`` must be one of: ``"rapid"``, ``"cfg"``, ``"motion"``.

    Args:
        client: Open ``RWSClient`` instance.
        symbolurl: Full RAPID symbol path, e.g.
            ``"RAPID/T_ROB1/MainModule/counter"``.
        value: New value as a string. Numeric types must be
            pre-converted: ``str(42)``, ``str(3.14)``.
        domain: Mastership domain. Defaults to ``"rapid"``.

    Returns:
        None. Expects HTTP 204 on the write call.

    Raises:
        RWSAuthenticationError: On HTTP 401.
        RWSNotFoundError: On HTTP 404.
        RWSHTTPError: On any other HTTP >= 400.

    Example:
        ```python
        async with RWSClient(host="192.168.125.1") as client:
            await set_variable_with_mastership(
                client,
                symbolurl="RAPID/T_ROB1/MainModule/target_x",
                value="250.0",
            )
        ```
    """
    # Acquire mastership on the specified domain
    await post_mastership_domain_request(client, domain=domain, action="request")
    try:
        await update_rapid_variable_current_value(
            client,
            symbolurl=symbolurl,
            action="set",
            value=value,
        )
        logger.debug("Variable %s set to %r", symbolurl, value)
    finally:
        # Always release — even on exception — to avoid locking the controller
        await post_mastership_domain_release(client, domain=domain, action="release")

set_variables_with_mastership(client, *, values, domain='rapid') async

Write multiple RAPID variables while holding mastership once.

Requests mastership a single time, writes every symbolurl -> value pair sequentially, then releases mastership in a finally block. More efficient than calling set_variable_with_mastership in a loop, which would request/release mastership once per variable.

Route (delegated): - POST /rw/mastership/{domain} (action=request) - POST /rw/rapid/symbol/data/{symbolurl} (action=set), once per entry - POST /rw/mastership/{domain} (action=release)

ABB constraints
  • Requires AUTO mode for mastership.
  • domain must be one of: "rapid", "cfg", "motion".
Parameters:
  • client (RWSClient) –

    Open RWSClient instance.

  • values (dict[str, str]) –

    Mapping of symbolurl -> value. Values must already be pre-converted to strings.

  • domain (str, default: 'rapid' ) –

    Mastership domain. Defaults to "rapid".

Returns:
  • None –

    None. Expects HTTP 204 on each write call.

Raises:
Example
async with RWSClient(host="192.168.125.1") as client:
    await set_variables_with_mastership(
        client,
        values={
            "RAPID/T_ROB1/M/x": "1",
            "RAPID/T_ROB1/M/y": "2",
        },
    )
Source code in abb_rws_client_python_rw6/highlevel/variables.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
async def set_variables_with_mastership(
    client: RWSClient,
    *,
    values: dict[str, str],
    domain: str = "rapid",
) -> None:
    """Write multiple RAPID variables while holding mastership once.

    Requests mastership a single time, writes every ``symbolurl -> value``
    pair sequentially, then releases mastership in a ``finally`` block.
    More efficient than calling ``set_variable_with_mastership`` in a
    loop, which would request/release mastership once per variable.

    Route (delegated):
        - ``POST /rw/mastership/{domain}`` (action=request)
        - ``POST /rw/rapid/symbol/data/{symbolurl}`` (action=set), once per entry
        - ``POST /rw/mastership/{domain}`` (action=release)

    ABB constraints:
        - Requires AUTO mode for mastership.
        - ``domain`` must be one of: ``"rapid"``, ``"cfg"``, ``"motion"``.

    Args:
        client: Open ``RWSClient`` instance.
        values: Mapping of ``symbolurl -> value``. Values must already
            be pre-converted to strings.
        domain: Mastership domain. Defaults to ``"rapid"``.

    Returns:
        None. Expects HTTP 204 on each write call.

    Raises:
        RWSAuthenticationError: On HTTP 401.
        RWSNotFoundError: On HTTP 404.
        RWSHTTPError: On any other HTTP >= 400 — mastership is still
            released before the exception propagates.

    Example:
        ```python
        async with RWSClient(host="192.168.125.1") as client:
            await set_variables_with_mastership(
                client,
                values={
                    "RAPID/T_ROB1/M/x": "1",
                    "RAPID/T_ROB1/M/y": "2",
                },
            )
        ```
    """
    await post_mastership_domain_request(client, domain=domain, action="request")
    try:
        for symbolurl, value in values.items():
            await update_rapid_variable_current_value(
                client,
                symbolurl=symbolurl,
                action="set",
                value=value,
            )
            logger.debug("Variable %s set to %r", symbolurl, value)
    finally:
        await post_mastership_domain_release(client, domain=domain, action="release")