Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
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:
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:
// Retrieve sub model (created by factory) with SDK connector // - Connect to sub model using lower-level VAB interface VABElementProxy connSubModel1 = this.connManager.connectToVABElement("sm-001VAB"); Map<String, Object> submodel = (Map<String, Object>) connSubModel1.getModelPropertyValue(""); Map<String, Object> smId = (Map<String, Object>) submodel.get(Identifiable.IDENTIFICATION); // - Read properties Map<String, Object> prop1 = (Map<String, Object>) connSubModel1.getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop1"); Map<String, Object> prop2 = (Map<String, Object>) connSubModel1.getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop2"); Map<String, Object> prop11 = (Map<String, Object>) connSubModel1.getModelPropertyValue("submodelElements/prop2/prop11"); Map<String, Object> prop3 = (Map<String, Object>) connSubModel1.getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop3"); // - Change property value using VAB primitive connSubModel1.setModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop1/value", 456); // - Read value back using VAB primitive Map<String, Object> changedProp1 = (Map<String, Object>) connSubModel1 .getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop1");
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 sub model properties "prop1", "prop2", "prop11" and "prop3" from the connected sub-model.
// - Read properties Map<String, Object> prop1 = (Map<String, Object>) connSubModel1.getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop1"); Map<String, Object> prop2 = (Map<String, Object>) connSubModel1.getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop2"); Map<String, Object> prop11 = (Map<String, Object>) connSubModel1.getModelPropertyValue("submodelElements/prop2/prop11"); Map<String, Object> prop3 = (Map<String, Object>) connSubModel1.getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop3");
The following code change the value of "prop1" to 456 via the VAB, and verify the changed value by reading the property using VAB primative.
// - Change property value using VAB primitive connSubModel1.setModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop1/value", 456); // - Read value back using VAB primitive Map<String, Object> changedProp1 = (Map<String, Object>) connSubModel1 .getModelPropertyValue(SubmodelElementProvider.PROPERTIES + "/prop1");
The following code verifies the id-short and the value of the accessed properties "prop1", "prop2", "prop11" and "prop3".
// - Check results assertEquals("sm-001", smId.get(Identifier.ID)); assertEquals("smName", submodel.get(Referable.IDSHORT)); assertEquals("prop1", prop1.get(Referable.IDSHORT)); assertEquals(234, prop1.get(Property.VALUE)); // old value of prop1 has been stored locally assertEquals(456, changedProp1.get(Property.VALUE)); // new value is 456 assertEquals("prop2", prop2.get(Referable.IDSHORT)); assertEquals("prop11", prop11.get(Referable.IDSHORT)); assertEquals(123, prop11.get(Property.VALUE)); assertEquals("prop3", prop3.get(Referable.IDSHORT)); assertEquals(17, prop3.get(Property.VALUE));
The complete, executable code is available in the basyx.examples project in package org.eclipse.basyx.examples.snippets.aas.submodels.
BaSyx project links: Project BaSyx main wiki page | What is BaSyx? | BaSyx Developer Documentation |