Skip to main content
Jump to: navigation, search

BaSyx.Examples.Snippets.VABAASConnection.Java

This code snippet illustrates the connection to an Asset Administration Shell (AAS) sub model using the Java SDK with Virtual Automation Bus (VAB) communication. In contrast to the ConnectedAssetAdministrationShellManager class, the virtual automation bus provides low-level access to VAB objects and therefore requires the user to know about AAS and sub model meta models. In particular, the property names for meta properties, values, and substructures must be explictly known. The VAB is therefore meant as implementation layer for implementing the ConnectedAssetAdministrationShellManager and for implementing gateways to legacy machines using native protocols that are not directly supported by the BaSyx SDK. The following code illustrates the use of VAB communication.

The BaSys setup for this code snippet is the following:

BaSyx.Snippet.AASConnectorConnection.Java.png


The BaSys setup consists of a Apache Tomcat server that runs BaSyx Servlets. It contains a sub model provider that exports an example sub model (see here for example). The snippet code runs in context of an application. The application contains the example code and a precompiled BaSyx directory that is used for resolving AAS and sub model IDs to network addresses. The application code accesses the AAS sub model:

// Connect to sub model using lower-level VAB interface
VABElementProxy connSubModel1 = this.connManager.connectToVABElement("sm-001VAB");
 
// - Read property values and compare with expected values
assertTrue((int) connSubModel1.readElementValue("properties/prop1/value") == 234);
assertTrue((int) connSubModel1.readElementValue("properties/prop3/value") == 17);
assertTrue(((Map<String, Object>) connSubModel1.readElementValue("properties/prop1")).get("idShort").equals("prop1"));
assertTrue(((Map<String, Object>) connSubModel1.readElementValue("properties/prop2")).get("idShort").equals("prop2"));
assertTrue((int) connSubModel1.readElementValue("properties/prop2/properties/prop11/value") == 123);


The snippet first creates a VABElementProxy that connects to the sub model as VAB object. The connection manager uses HTTP REST communication, as illustrated in <<<>>>. The following code connects to the sub model with ID "sm-001VAB":

// Connect to sub model using lower-level VAB interface
VABElementProxy connSubModel1 = this.connManager.connectToVABElement("sm-001VAB");


The following code accesses the values of properties "prop1" and "prop3" of the connected sub model compares their values to expected values.

// - Retrieve sub model values and compare to expected values
assertTrue((int) connSubModel1.readElementValue("properties/prop1/value") == 234);
assertTrue((int) connSubModel1.readElementValue("properties/prop3/value") == 17);


The following code accesses the meta property idShort of sub model properties "prop1" and "prop3" and compares its value to the expected values

// - Retrieve sub model values and compare to expected values
assertTrue(((Map<String, Object>) connSubModel1.readElementValue("properties/prop1")).get("idShort").equals("prop1"));
assertTrue(((Map<String, Object>) connSubModel1.readElementValue("properties/prop2")).get("idShort").equals("prop2"));


The following code accesses the value of contained property "prop11" in container "prop2".

assertTrue((int) connSubModel1.readElementValue("properties/prop2/properties/prop11/value") == 123);


The complete, executable code is available in the basyx.examples project in package <<<>>>.


BaSyx project links: Project BaSyx main wiki page | What is BaSyx? | BaSyx Developer Documentation

Copyright © Eclipse Foundation, Inc. All Rights Reserved.