Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

BaSyx / Introductory Examples / Java / Example 6

< BaSyx ‎ | Introductory Examples
Revision as of 06:57, 16 March 2021 by Unnamed Poltroon (Talk) (Created page with "= Example 6 - Hello World = The "Hello World" example is a very basic client/server demonstration of BaSyx. It can be found in the BaSyx repository in ''examples/basyx.hello_w...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Example 6 - Hello World

The "Hello World" example is a very basic client/server demonstration of BaSyx. It can be found in the BaSyx repository in examples/basyx.hello_world. The "Hello World" project consists of two parts: Client and Server.

Server Class

public class Server {
	// Server URLs
	public static final String REGISTRYPATH = "http://localhost:4000/registry";
	public static final String AASSERVERPATH = "http://localhost:4001/aasServer";
 
	// AAS/Submodel/Property Ids
	public static final IIdentifier OVENAASID = new CustomId("eclipse.basyx.aas.oven");
	public static final IIdentifier DOCUSMID = new CustomId("eclipse.basyx.submodel.documentation");
	public static final String MAXTEMPID = "maxTemp";
 
	public static void main(String[] args) {
		// Create Infrastructure
		startRegistry();
		startAASServer();
 
		// Create Manager - This manager is used to interact with an AAS server
		ConnectedAssetAdministrationShellManager manager = 
				new ConnectedAssetAdministrationShellManager(new AASRegistryProxy(REGISTRYPATH));
 
		// Create AAS and push it to server
		Asset asset = new Asset("ovenAsset", new CustomId("eclipse.basyx.asset.oven"), AssetKind.INSTANCE);
		AssetAdministrationShell shell = new AssetAdministrationShell("oven", OVENAASID, asset);
 
		// The manager uploads the AAS and registers it in the Registry server
		manager.createAAS(shell, AASSERVERPATH);
 
		// Create submodel
		SubModel documentationSubmodel = new SubModel("documentationSm", DOCUSMID);
 
		// - Create property
		Property maxTemp = new Property(MAXTEMPID, 1000);
 
		// Add the property to the Submodel
		documentationSubmodel.addSubModelElement(maxTemp);
 
		// - Push the Submodel to the AAS server
		manager.createSubModel(shell.getIdentification(), documentationSubmodel);
	}
 
	/**
	 * Starts an empty registry at "http://localhost:4000"
	 */
	private static void startRegistry() {
		BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(4000, "/registry");
		BaSyxRegistryConfiguration registryConfig = new BaSyxRegistryConfiguration(RegistryBackend.INMEMORY);
		RegistryComponent registry = new RegistryComponent(contextConfig, registryConfig);
 
		// Start the created server
		registry.startComponent();
	}
 
	/**
	 * Startup an empty server at "http://localhost:4001/"
	 */
	private static void startAASServer() {
		BaSyxContextConfiguration contextConfig = new BaSyxContextConfiguration(4001, "/aasServer");
		BaSyxAASServerConfiguration aasServerConfig = new BaSyxAASServerConfiguration(AASServerBackend.INMEMORY, "", REGISTRYPATH);
		AASServerComponent aasServer = new AASServerComponent(contextConfig, aasServerConfig);
 
		// Start the created server
		aasServer.startComponent();
	}
}



This is the server class. Its main method starts an AAS server and a Registry server. The AAS server gets populated by an AAS and a Submodel, which contains the Property “maxTemp” with the value 1000.

If the server started successfully, the last line of console output will be:
AASRegistryProxy - AAS with Id eclipse.basyx.aas.oven created


Client Class

public class Client {
	public static void main(String[] args) {
		// Create Manager
		ConnectedAssetAdministrationShellManager manager =
				new ConnectedAssetAdministrationShellManager(new AASRegistryProxy(Server.REGISTRYPATH));
 
		// Retrieve submodel
		ISubModel submodel = manager.retrieveSubModel(Server.OVENAASID, Server.DOCUSMID);
 
		// Retrieve MaxTemp Property
		ISubmodelElement maxTemp = submodel.getSubmodelElement(Server.MAXTEMPID);
 
		// Print value
		System.out.println(maxTemp.getIdShort() + " is " + maxTemp.getValue());
	}
}



This is the second part of the “Hello World” example, the client. It connects to the AAS server started in the first part of this project and retrieves the Submodel. Next, it prints the idShort of the contained Property and its value to the console.

If the client is successful in connecting to the server and retrieving the Submodel, the following output will be written to the console:
maxTemp is 1000

Back to the top