Changes
Page history
Added article "Mal python snippets"
authored
May 17, 2023
by
Marcus Schilling
Show whitespace changes
Inline
Side-by-side
KnowledgeBase/CII.md
View page @
f68e460c
...
...
@@ -1377,6 +1377,44 @@ A test application showing its use is here:
<https://gitlab.eso.org/cosylab/elt-cii/mal/mal-test/-/blob/develop/cpp/mal-test-performance/opcua/mal-opcua-da-speed/src/common.cpp>
---
---
---
### Request-Reply Python Snippets \[MAL Python\]
To interact with any MAL based remote service, you can use the python shell to connect to the remote object and invoke its methods and process the return values.
The whole lifecycle (including clean-up) looks like this:
```
python
# connect
import
elt.pymal
malfact
=
elt
.
pymal
.
loadMalForUri
(
"
zpb.rr://
"
,
{})
import
ModStdif.Stdif.StdCmds
client
=
malfact
.
getClient
(
"
zpb.rr://127.0.0.1:12081/StdCmds
"
,
ModStdif
.
Stdif
.
StdCmds
.
StdCmdsSync
,
elt
.
pymal
.
rr
.
qos
.
DEFAULT
,
{})
# interact
print
(
client
.
getState
())
# disconnect
malfact
.
unregisterMal
(
"
zpb
"
)
```
**Side-note**
: For what it's worth, this can be done as a one-liner:
```
plaintext
python <<< 'import elt.pymal ; malfact = elt.pymal.loadMalForUri("zpb.rr://", {}) ; import ModStdif.Stdif.StdCmds ; client = malfact.getClient("zpb.rr://127.0.0.1:12081/StdCmds", ModStdif.Stdif.StdCmds.StdCmdsSync, elt.pymal.rr.qos.DEFAULT, {}) ; print (client.GetState()) ; malfact.unregisterMal ("zpb") '
```
... which would be equivalent to this msgsend call:
```
msgsend -t 60 -u zpb.rr://127.0.0.1:12081/StdCmds ::stdif::StdCmds::GetState
```
### ------------------------------------------------------
### \[OLDB\]
...
...
...
...