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"

Line 12: Line 12:
 
<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);
+
// - Connect to VAB object by ID. The connection manager looks up this ID in
 +
//  its directory
 +
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(registry,
 +
// We connect via HTTP
 +
new HTTPConnectorProvider());
 
 
// Retrieve dummy AAS (created by factory) with SDK connector
+
// Retrieve the AAS from the AAS server with SDK connector
IAssetAdministrationShell shell = manager.retrieveAAS("aas-001");
+
// - IAssetAdministrationShell is the interface for the local AAS proxy
// - Retrieve AAS values and compare to expected values
+
IAssetAdministrationShell shell = manager
assertTrue(shell.getId().equals("aas-001"));
+
.retrieveAAS(new ModelUrn("aas-001"));
 +
// - Retrieve AAS values and compare to expected values
 +
Object propertyId = shell.getIdShort();
 +
 +
 +
// Check result
 +
assertTrue(propertyId.equals("aas-001"));
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 26: Line 36:
 
<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);
+
// - Connect to VAB object by ID. The connection manager looks up this ID in
 +
//  its directory
 +
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(registry,
 +
// We connect via HTTP
 +
new HTTPConnectorProvider());
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 34: Line 48:
  
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
<syntaxhighlight lang="java" style="margin-left: 4em">
// Retrieve dummy AAS (created by factory) with SDK connector
+
// Retrieve the AAS from the AAS server with SDK connector
IAssetAdministrationShell shell = manager.retrieveAAS("aas-001");
+
// - IAssetAdministrationShell is the interface for the local AAS proxy
 +
IAssetAdministrationShell shell = manager
 +
.retrieveAAS(new ModelUrn("aas-001"));
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 44: Line 60:
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
<syntaxhighlight lang="java" style="margin-left: 4em">
 
// - Retrieve AAS values and compare to expected values
 
// - Retrieve AAS values and compare to expected values
assertTrue(shell.getId().equals("aas-001"));
+
Object propertyId = shell.getIdShort();
 +
assertTrue(propertyId.equals("aas-001"));
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Revision as of 09:46, 18 August 2020

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
// - Connect to VAB object by ID. The connection manager looks up this ID in
//   its directory
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(registry,
		// We connect via HTTP
		new HTTPConnectorProvider());
 
	// Retrieve the AAS from the AAS server with SDK connector
	// - IAssetAdministrationShell is the interface for the local AAS proxy
	IAssetAdministrationShell shell = manager
		.retrieveAAS(new ModelUrn("aas-001"));
	// - Retrieve AAS values and compare to expected values
	Object propertyId = shell.getIdShort();
 
 
	// Check result
	assertTrue(propertyId.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
// - Connect to VAB object by ID. The connection manager looks up this ID in
//   its directory
ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(registry,
	// We connect via HTTP
	new HTTPConnectorProvider());


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 the AAS from the AAS server with SDK connector
// - IAssetAdministrationShell is the interface for the local AAS proxy
IAssetAdministrationShell shell = manager
	.retrieveAAS(new ModelUrn("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
Object propertyId = shell.getIdShort();
assertTrue(propertyId.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