IntroductionThe SimplexOPC UA Server SDK implements the common elements of the OPC UAspecification and provides APIs that allow users to add their ownfunctionality. Create OPC UAserverClass TOpcUaServer implements the functionalityof the OPC UA server. The record SpxServerConfig contains the OPC UA server parameters. For server-sidecallbacks, use the class inherited from SpxServerCallback. An example of how to create OPC UA server: ... … TSimplexServerTest =class(SpxServerCallback) … var OpcUaServer: TOpcUaServer; ServerConfig: SpxServerConfig; SimplexServerTest:TSimplexServerTest; Create namespaceNamespace is required to uniquely identify OPCUA server data. To create the namespace, use: function TOpcUaServer.CreateNamespace(ANamespaceUri: SpxString): SpxUInt16;
An example of how to create namespace: const Namespace ='http://www.simplexopcua.com/SimplexOpcUaServer'; … NamespaceIndex := OpcUaServer.CreateNamespace(Namespace); Create folderFolders are necessary for hierarchicalorganization of data. To create the folder, use: function TOpcUaServer.CreateFolder(ANodeId: SpxNodeId; ABrowseName: SpxString; ADisplayName,ADescription: SpxLocalizedText;AParentNodeId: SpxNodeId): SpxBoolean;
An example of how to create folder: var FolderNodeId, ParentNodeId: SpxNodeId; DisplayName, Description: SpxLocalizedText; … FolderNodeId.NamespaceIndex := NamespaceIndex; FolderNodeId.IdentifierType := SpxIdentifierType_Numeric; ParentNodeId.NamespaceIndex := 0; ParentNodeId.IdentifierType := SpxIdentifierType_Numeric; DisplayName.Locale := 'en'; OpcUaServer.CreateFolder(FolderNodeId, 'MyFolder', DisplayName, Description, ParentNodeId);
Create variable ofinteger typeVariables provide real data. To create the variable, use: function TOpcUaServer.CreateVariable(ANodeId:SpxNodeId; ABrowseName:SpxString;ADisplayName, ADescription: SpxLocalizedText;AParentNodeId: SpxNodeId; ADataType: SpxDataType;AAllowWrite,AAllowHistory: SpxBoolean): SpxBoolean;
An example of how to create variable ofinteger type: var VarNodeId: SpxNodeId; DisplayName, Description: SpxLocalizedText; DataType: SpxDataType; … VarNodeId.NamespaceIndex := NamespaceIndex; VarNodeId.IdentifierType := SpxIdentifierType_Numeric; DisplayName.Locale := 'en'; DataType.ValueRank := SpxValueRanks_Scalar; To set the value of variable, use: function TOpcUaServer.SetVariableValue(ANodeId: SpxNodeId; ADataValue: SpxDataValue): SpxBoolean;
An example of how to set the value ofvariable: var DataValue: SpxDataValue; … DataValue.Value.ValueRank := SpxValueRanks_Scalar;
Create variable of string typeAn example of how to create variable of string type: var VarNodeId: SpxNodeId; DisplayName, Description: SpxLocalizedText; DataType: SpxDataType; … VarNodeId.NamespaceIndex := NamespaceIndex; VarNodeId.IdentifierType := SpxIdentifierType_Numeric; DisplayName.Locale := 'en'; DataType.ValueRank := SpxValueRanks_Scalar;
An example of how to set the value of variable: var DataValue: SpxDataValue; … DataValue.Value.ValueRank := SpxValueRanks_Scalar; Createvariable of enumeration typeAn enumeration type provides an efficient way to define a set ofstrings that may be assigned to a variable. An example of how to create an enumeration type: vat TypeNodeId: SpxNodeId; EnumStrings: SpxLocalizedTextArray; DisplayName, Description: SpxLocalizedText; i: integer; … TypeNodeId.NamespaceIndex := NamespaceIndex; TypeNodeId.IdentifierType :=SpxIdentifierType_Numeric; SetLength(EnumStrings, 3); begin EnumStrings[i].Text :=Format('Value%d', [i]); end; Description.Locale := 'en';
An example of how to create variable of enumeration type: var VarNodeId: SpxNodeId; DataType: SpxDataType; DisplayName, Description: SpxLocalizedText; … VarNodeId.NamespaceIndex := NamespaceIndex; VarNodeId.IdentifierType :=SpxIdentifierType_Numeric; DisplayName.Locale := 'en'; Description.Locale := 'en';
Createvariable of enumeration type with valuesAn example of how to create an enumeration type with values: var TypeNodeId: SpxNodeId; EnumValues: SpxEnumValues; DisplayName, Description: SpxLocalizedText; i: integer; … TypeNodeId.NamespaceIndex := NamespaceIndex; TypeNodeId.IdentifierType := SpxIdentifierType_Numeric; SetLength(EnumValues, 3); EnumValues[i].Name.Text :=Format('Value%d', [i]); EnumValues[i].Description.Text:= Format('Value%d', [i]); DisplayName.Locale := 'en'; Description.Locale := 'en';
An example of how to create variable of enumeration type with values: var VarNodeId: SpxNodeId; DataType: SpxDataType; DisplayName, Description: SpxLocalizedText; ... VarNodeId.NamespaceIndex := NamespaceIndex; VarNodeId.IdentifierType := SpxIdentifierType_Numeric; DisplayName.Locale := 'en'; Description.Locale := 'en';
Create methodMethods are “lightweight” functions, whosescope is bounded by an owning Object, similar to the methods of a class inobject-oriented programming or an owning ObjectType, similar to static methodsof a class. Methods are invoked by a client, proceed to completion on theServer and return the result to the client. The lifetime of the Method’sinvocation instance begins when the client calls the Method and ends when theresult is returned. To create the method, use: function TOpcUaServer.CreateMethod(ANodeId:SpxNodeId; ABrowseName: SpxString; ADisplayName, ADescription:SpxLocalizedText; AParentNodeId: SpxNodeId; AInputArguments, AOutputArguments:SpxArguments): SpxBoolean;
An example of how to create method: var VarNodeId: SpxNodeId; DisplayName, Description: SpxLocalizedText; InputArguments, OutputArguments: SpxArguments; … VarNodeId.NamespaceIndex := NamespaceIndex; VarNodeId.IdentifierType := SpxIdentifierType_Numeric; DisplayName.Locale := 'en'; Description.Locale := 'en'; InputArguments[i].Description.Text :=Format('Argument %d for testing', [i]); OutputArguments[0].Description.Text := 'Output argument fortesting';
Change nodeThe node can be changed. Youcan change the following properties: BrowseName, DisplayName,Description, DataType, AllowWrite, AllowHistory. To change the node, use: function TOpcUaServer.ChangeNode(ANodeId: SpxNodeId; AChangeNodeParams:SpxChangeNodeParams): SpxBoolean;
An example of how to change node: var ChangeNodeParams: SpxChangeNodeParams; ... ChangeNodeParams.ChangeType :=spxChange_DisplayName; ChangeNodeParams.DisplayName.Text :='MyMethod123';
Delete nodeThe node can be deleted. To delete the node, use: function TOpcUaServer.DeleteNode(ANodeId: SpxNodeId): SpxBoolean;
An example of how to delete node: OpcUaServer.DeleteNode(VarNodeId); |
Email: support@simplexopcua.com