cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Python Runtime App: is subscribe() to datalayer nodes possible?

Python Runtime App: is subscribe() to datalayer nodes possible?

LunatiX
New Contributor

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?

7 REPLIES 7

Sgilk
Frequent Contributor

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.

LunatiX
New Contributor

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:

  • datalayer.browse
  • datalayer.read
  • datalayer.write
  • datalayer.create
  • datalayer.remove
  • datalayer.read_json
  • datalayer.write_json
  • datalayer.create_json

See: Script Parser/Interpreter (Python) - Bosch Rexroth Produktinformationsportal

See my short example too, which is working well with datalayer.read() and datalayer.write():

LunatiX_0-1713446662871.png

But the question is, are there any commands to subscribe?

Sgilk
Frequent Contributor

@LunatiX ,

The examples have multiple files, but they can be run outside of the snap context. See this article on running the samples directly in the IDE app.

The library you are using does not have a subscribe function.

bostroemc
Occasional Contributor

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:

2024-04-18_16h10_37.png

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/

Reto_0-1713503617353.png

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")

 

 

  • Running the code in the IDE as single file (Debug: Python: current file): All fine, no error.
  • Running the code in the Python script engine (Debug: Launch Python in Script Egnine):
    OSError('libcomm_datalayer.so: cannot open shared object file: No such file or directory')

Is this the correct way to establish a subscription to multiple data layer items?
What am I missing?

Regards
Reto

 

bostroemc
Occasional Contributor

@Reto :

From the documentation for the Python Runtime Environment:

2024-04-19_03h40_46.png

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.

 

@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.

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist