Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "BaSyx.Examples.Snippets.AASConnection.Java"

(Initial page)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
This code snippet illustrates the connection to an Asset Administration Shell (AAS) sub model using the Java SDK with the <code>ConnectedAssetAdministrationShellManager</code> class. It illustrates the connection to a sub model with a known ID, as well as reading and updating of properties. It also illustrates connection to meta properties.  
+
This code snippet illustrates the connection to an Asset Administration Shell (AAS) using the Java SDK with the <code>ConnectedAssetAdministrationShellManager</code> class. It illustrates the connection to an AAS with a known ID, as well as reading and updating of properties.  
  
 
The BaSys setup for this code snippet is the following:
 
The BaSys setup for this code snippet is the following:
  
 
{|style="text-align: center; width: 100%"
 
{|style="text-align: center; width: 100%"
|[[File:BaSyx.Snippet.AASConnectorConnection.Java.png|center|512px]]
+
|[[File:BaSyx.Snippet.AASConnectorConnectionAAS.Java.png|center|512px]]
 
|}
 
|}
  
  
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:
+
The BaSys setup consists of a Apache Tomcat server that runs BaSyx Servlets. It contains an asset administration shell provider that exports an example Asset Administration Shell (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 following application code accesses the AAS:
  
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
 
// Create manager using the directory stub an the HTTPConnectorProvider
 
// Create manager using the directory stub an the HTTPConnectorProvider
 
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(connManager);
 
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(connManager);
 
 
+
// Retrieve dummy AAS (created by factory) with SDK connector
// Create and connect SDK connector
+
IAssetAdministrationShell shell = manager.retrieveAAS("aas-001");
ISubModel subModel = manager.retrieveSM("sm-001");
+
// - Retrieve AAS values and compare to expected values
+
assertTrue(shell.getId().equals("aas-001"));
// - Retrieve sub model values and compare to expected values
+
assertTrue(subModel.getId().equals("sm-001"));
+
assertTrue(subModel.getProperties().get("prop1").getId().equals("prop1"));
+
assertTrue((int) ((ISingleProperty) subModel.getProperties().get("prop1")).get() == 234);
+
assertTrue((int) ((ISingleProperty) subModel.getProperties().get("prop3")).get() == 17);
+
assertTrue(subModel.getProperties().get("prop2").getId().equals("prop2"));
+
assertTrue((int) ((ISingleProperty) ((IContainerProperty) subModel.getProperties().get("prop2")).getProperties().get("prop11")).get() == 123);
+
 
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
  
The code first creates a connected Asset Administration Shell manager that creates connections to Asset Administration Shells and AAS sub models. It uses a ConnectionManager class to create the connection and to resolve AAS and sub model IDs:
+
The code first creates a connected Asset Administration Shell manager that creates connections to Asset Administration Shells. It uses a ConnectionManager class to create the connection and to resolve AAS and sub model IDs:
  
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
<syntaxhighlight lang="java" style="margin-left: 4em">
Line 40: Line 31:
  
  
The following code connects to the sub model with ID "sm-001". It returns a ISubModel instance that provides a local proxy for the remote sub model.
+
The following code connects to the AAS with ID "aas-001". It returns a <code>IAssetAdministrationShell</code> instance that provides a local proxy for the remote AAS.  
 
+
<syntaxhighlight lang="java" style="margin-left: 4em">
+
// Create and connect SDK connector
+
ISubModel subModel = manager.retrieveSM("sm-001");
+
</syntaxhighlight>
+
 
+
 
+
 
+
The following code accesses the meta property idShort of the sub model and compares its value to the expected value "sm-001"
+
 
+
<syntaxhighlight lang="java" style="margin-left: 4em">
+
// - Retrieve sub model values and compare to expected values
+
assertTrue(subModel.getId().equals("sm-001"));
+
</syntaxhighlight>
+
 
+
 
+
 
+
The following code accesses the meta property idShort of the sub model property "prop1" and compares its value to the expected value "prop1"
+
 
+
<syntaxhighlight lang="java" style="margin-left: 4em">
+
// - Retrieve sub model values and compare to expected values
+
assertTrue(subModel.getProperties().get("prop1").getId().equals("prop1"));
+
</syntaxhighlight>
+
 
+
 
+
 
+
The following code accesses the values of properties "prop1" and "prop3" of the connected sub model compares their values to expected values.
+
  
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
<syntaxhighlight lang="java" style="margin-left: 4em">
// - Retrieve sub model values and compare to expected values
+
// Retrieve dummy AAS (created by factory) with SDK connector
assertTrue((int) ((ISingleProperty) subModel.getProperties().get("prop1")).get() == 234);
+
IAssetAdministrationShell shell = manager.retrieveAAS("aas-001");
assertTrue((int) ((ISingleProperty) subModel.getProperties().get("prop3")).get() == 17);
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
  
  
The following code accesses the idShort meta property of property "prop2", as well as the contained property "prop11". Both requested values are compared to expected values.
+
The following code accesses the meta property idShort of the AAS and compares its value to the expected value "aas-001"
  
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
<syntaxhighlight lang="java" style="margin-left: 4em">
assertTrue(subModel.getProperties().get("prop2").getId().equals("prop2"));
+
// - Retrieve AAS values and compare to expected values
assertTrue((int) ((ISingleProperty) ((IContainerProperty) subModel.getProperties().get("prop2")).getProperties().get("prop11")).get() == 123);
+
assertTrue(shell.getId().equals("aas-001"));
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 19:43, 12 June 2019

This code snippet illustrates the connection to an Asset Administration Shell (AAS) using the Java SDK with the ConnectedAssetAdministrationShellManager class. It illustrates the connection to an AAS with a known ID, as well as reading and updating of properties.

The BaSys setup for this code snippet is the following:

BaSyx.Snippet.AASConnectorConnectionAAS.Java.png


The BaSys setup consists of a Apache Tomcat server that runs BaSyx Servlets. It contains an asset administration shell provider that exports an example Asset Administration Shell (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 following application code accesses the AAS:

// Create manager using the directory stub an the HTTPConnectorProvider
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(connManager);
 
// Retrieve dummy AAS (created by factory) with SDK connector
IAssetAdministrationShell shell = manager.retrieveAAS("aas-001");
// - Retrieve AAS values and compare to expected values
assertTrue(shell.getId().equals("aas-001"));


The code first creates a connected Asset Administration Shell manager that creates connections to Asset Administration Shells. It uses a ConnectionManager class to create the connection and to resolve AAS and sub model IDs:

// Create manager using the directory stub an the HTTPConnectorProvider
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(connManager);


The following code connects to the AAS with ID "aas-001". It returns a IAssetAdministrationShell instance that provides a local proxy for the remote AAS.

// Retrieve dummy AAS (created by factory) with SDK connector
IAssetAdministrationShell shell = manager.retrieveAAS("aas-001");


The following code accesses the meta property idShort of the AAS and compares its value to the expected value "aas-001"

// - Retrieve AAS values and compare to expected values
assertTrue(shell.getId().equals("aas-001"));


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

Back to the top