Commands
A CommandNode specifies an action that can be performed inside the node space.
Following attributes define a command:
Attribute | Description | Data Type |
---|---|---|
Id | Id of the command. Not used for dynamic instantiation of schema nodes | System.Guid |
Name | Name of the command | System.String |
Properties | Properties of the commands | System.String |
Arguments | A list of input and output arguments | TArgumentInfo[] |
Type | Command node type | ECommandNodeType |
ECommandNodeType
defines following command types:
Type | Description |
---|---|
CommandNode | Generic command used by UHAL Driver Plugins |
CSharpScriptCommandNode | Command using a script file as action part. |
InstantiationCommandNode | Command used to instantiate a schema by proactive action. |
CommandProxyNode | Command proxy to an C# implementation in a plugin |
Arguments
Arguments specify how to pass or return values from commands.
Attribute | Description | Data Type |
---|---|---|
Name | Argument name | System.String |
DataType | Data type of the argument | System.Type |
Description | Optional description | System.String |
Type | Argument type:
| EArgumentType |
MinMaxConstraint | Optional min and max value constraint | TMinMaxConstraintInfo |
RegExpConstraint | Optional regular expression constraint | TRegExpConstraintInfo |
Example of MinMaxConstraint:
{
"Id": "F80F0B87-40DA-4DA2-B5A2-0DD853CCC082",
"Name": "MyCommand",
"Type": "CommandNode",
"Arguments": [
{
"Name": "Value",
"Type": "Input",
"DataType": "System.Int32",
"MinMaxConstraint": {
"MinValue": 0,
"MaxValue": 99
}
}
]
}
Example with a regular expression:
{
"Id": "F80F0B87-40DA-4DA2-B5A2-0DD853CCC082",
"Name": "MyCommand",
"Type": "CommandNode",
"Arguments": [
{
"Name": "Value",
"Type": "Input",
"DataType": "System.Int32",
"RegExpConstraint": {
"IgnoreCase": true,
"Pattern": "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
}
}
]
}
Scripted Commands
This command type allows to add a command directly to the node space. The command action is provided by a C# script file.
- Attribute Type is set to
CSharpScriptCommandNode
- The property list must contain the property
ScriptFileName
.
Property | Description | Data Type |
---|---|---|
ScriptFileName | name of script file | System.String |
The script file must be located in
$(ConfigPath)\Scripts\Commands\
Example
Declaration of the command:
{
"Id": "F80F0B87-40DA-4DA2-B5A2-0DD853CCC082",
"Name": "MyCommand",
"Type": "CSharpScriptCommandNode",
"Properties": [
{
"Name": "ScriptFileName",
"Value": "TCommand_MyCommand.cs"
}
],
"Arguments": [
{
"Name": "Id",
"Type": "Input",
"DataType": "System.Guid"
},
{
"Name": "Stream",
"Type": "Output",
"DataType": "System.Byte[]"
}
]
}
The command script class must be derived from TAbstractCommandScriptObject
:
/// <summary>
/// Command script
/// </summary>
public class TCommand_MyCommand : TAbstractCommandScriptObject
{
/// <see cref="TAbstractCommandScriptObject"/>
public override TCommandResult executeCommand(ICommandNode CommandNode,
Dictionary<string, object> dicInputArguments,
Dictionary<string, object> dicOutputArguments)
{
TCommandResult Retval = new TCommandResult();
INodeSpace Space = (INodeSpace)CommandNode.Relations.First(n => n is INodeSpace);
…
return Retval;
}
}
Instantiation Command
The instantiation command is used to create dynamically nodes from a schema.
- Attribute Type is set to
InstantiationCommandNode
. - Property
SchemaId
must be set
Property | Description | Data Type |
---|---|---|
SchemaId | Id of the schema to instantiate | System.Guid |
ExecuteMode | If the ExecuteMode = true, all workflows in the schema are automatically started. | System.Boolean |
Example
{
"Id": "F80F0B87-40DA-4DA2-B5A2-0DD853CCC082",
"Name": "MyCommand",
"Type": "InstantiationCommandNode",
"Properties": [
{
"Name": "SchemaId",
"DataType": "System.Guid",
"Value": "D395F890-03C1-44F3-9CF7-1FF34FEEDA5F"
}
]
}
Command Proxy Node
The command proxy node allows to call C# compiled code of a HumanOS plugin.
- Attribute Type is set to
InstantiationCommandNode
. - Property
CommandType
must be set
Property | Description | Data Type |
---|---|---|
CommandType | C# class type and assembly name of the command implementation | System.Type |
Example
{
"Name": "HumanOS.Service.IdentityService.SessionCleanupCommand",
"Id": "CB00EE4E-AAE6-4C01-A9D8-C8E949D5AC6F",
"Type": "CommandProxyNode",
"Properties": [
{
"Name": "CommandType",
"Value": "HumanOS.Service.IdentityService.EntityModel.Commands.TSessionCleanupCommand, HumanOS.Service.IdentityService.EntityModel"
}
]
}
CommandNode Extension for UHAL Plugins
For device information model, only the command type CommandNode
is supported.
Attribute | Description | Data Type |
---|---|---|
Address | Device address | System.String |
ScriptFile | [OPT] If address is empty, a script file can be specified. This allows to implement some kind of a UHAL logic. | System.String |
Example of a device command:
{
"Id": "8FEDA09C-C947-4A56-9703-59A6662B0E9F",
"Name": "WriteMDI",
"Type": "CommandNode",
"Address": "Nc1.writeMDI",
"Arguments": [
{
"Name": "Content",
"Type": "Input",
"DataType": "System.String",
"Description": "Content"
}
]
}
Example of a UHAL logic command:
{
"Id": "1247ECB2-A5C2-4793-B5C8-3A8B816458BD",
"Name": "WriteToolToTag",
"Type": "CommandNode",
"ScriptFile": "Balluff_Logic_WriteToolToTag.cs",
"Arguments": [
{
"Name": "Id",
"Type": "Input",
"DataType": "System.Guid"
},
{
"Name": "TagId",
"Type": "Input",
"DataType": "System.String"
}
]
}
Troubleshooting
Wrong command type
If you receive a message like Command of type 'CommandNode' does not contain executable code
(depending on your command type), check if you selected the correct command type.
For example this can happen, if you have a script command node but declared the command as CommandNode
, whereas the correct type would be CSharpScriptCommandNode
.