FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important
information on the platform change.
04-18-2024 03:07 PM
Is it possible to use subscription() to datalayer nodes inside a *.py file?
Or could we only use datalayer.read() and we have to poll it?
Solved! Go to Solution.
04-18-2024 03:13 PM
Hi @LunatiX ,
Absolutely! See the python datalayer client subscription sample in the SDK.
Please let me know if you have any questions on the example.
04-18-2024 03:29 PM
When I build a own python app, then it's clear for me. But I would like to use the Python Runtime App with a simple *.py file and I only see this commands here:
See: Script Parser/Interpreter (Python) - Bosch Rexroth Produktinformationsportal
See my short example too, which is working well with datalayer.read() and datalayer.write():
But the question is, are there any commands to subscribe?
04-18-2024 11:08 PM
04-18-2024 11:34 PM
The code below, which creates a subscription and dumps the result into the diagnostics log, is similar to the source code of the library in question. You can run this directly with the Python Runtime app.
import requests
from urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
session = requests.Session()
session.verify = False
response = session.post("https://localhost/identity-manager/api/v2/auth/token", json={"name":"boschrexroth","password":"boschrexroth"}).json()
token = response['access_token']
data = {"Authorization": f"Bearer {token}"}
with session.get("https://localhost/automation/api/v2/events?nodes=framework/metrics/system/cpu-utilisation-percent&publishIntervalMs=5000", headers=data, stream=True) as stream:
for line in stream.iter_lines():
tmp = line.decode("utf-8").split(":",1)
if len(tmp) > 1 and tmp[0] == 'data':
print(tmp[1], flush=True)
Output:
04-19-2024 07:28 AM - edited 04-19-2024 07:30 AM
I tried a simillar aproche like @LunatiX without success:
Starting point is the documentation here https://docs.automation.boschrexroth.com/doc/289678356/introduction-and-overview/latest/en/
I tried to use the subscription methods from the ctrlxdatalayer library:
create_properties to generate the Rulset
and then the subscription_async class for the subscription
However, I already run into a problem with the following simple code:
from ctrlxdatalayer import subscription
print("Make subscription to one node")
itemProperty = subscription.create_properties("opcuaclient/SPS/i=85/ns=2;s=Logic/ns=2;s=.I40_PartIndetifier", 100, 60000, 10000)
print(str(itemProperty))
print("Property done")
Is this the correct way to establish a subscription to multiple data layer items?
What am I missing?
Regards
Reto
04-19-2024 11:13 AM
@Reto :
From the documentation for the Python Runtime Environment:
The library providing datalayer access that is integrated into the Python Runtime App - the one that @LunatiX refers to in his original post - is built on REST calls using the requests module. Because ctrlxdatalayer requires libcomm_datalayer.so, as far as I know there is no way to use it in this context.
To create multiple subscriptions in a single REST call, see @CodeShepherd's post here.
04-19-2024 01:28 PM
@bostroemc
Thanks for the clarification. I was aware of the binary limitation, but thought it only applied to external, user-uploaded libraries, not those supplied by Rexroth.