WebControl Data Access
There exist two kinds of data access:
- calling a command indirectly and processing the data from the response. See Data Access with Commands
- processing a HTTP stream using the task processor. See Processor Info.
Data Access with Commands
The plugin supports to asynchronously read data from a web source using the data access info node.
- To access data points on a web source,, first a corresponding command must be crated (see 3.2 Commands).
- Create a DataAccessInfo referencing the CommandInfo object.
The address of the data access is: Command.<command_id>.<output_argument>
Input argument of the command must be specified as properties.
Use the name Command.Input.<name>
to specify a specific input argument.
Only one data node per call can be updated. Note that this is inefficient if a REST call returns data for many different data nodes.
Example:
Monitors the output argument "Context" of the web command {56516249-915A-4B3E-9137-FBDF953B4343}
.
{
"Id": "739D92D7-87D0-45DC-91F1-4F4A1F349397",
"Name": "CurrentContext",
"DataType": "System.String",
"Address": "Command.{56516249-915A-4B3E-9137-FBDF953B4343}.Context",
"Properties": [
{
"Name": "Command.Input.Id",
"Value": "my_id"
}
],
"Access": {
"Read": true,
"Receive": true
}
}
Data Access with Processor Info
With the processor info specification, a http stream handler script can be defined to manage complex data exchange with WebServers.
Often this is used to write value to multiple data nodes or alarms at once.
{
"TaskProcessors": [
{
"Id": "DABEA01B-CDA0-4DCD-9135-0FE1C17A46AE",
"Name": "MainTaskProcessor",
"ScriptFile": "RestAPIHandler.cs"
}
]
}
Note that the data nodes don't need any address specified. The data nodes are directly addressed by the script.
The script class must be derived from TAbstractHttpStreamScriptObject.
Following method can be overwritten:
Method | Action |
---|---|
handleStream | Handles the http stream in a cyclic manner. This method MUST be implementedArguments: (Kernel: HumanOS® Kernel access; Logger: Logger instance of the driver; DeviceInfo: device info file; DataStream: stream interface to http client) |
Example:
/// <summary>
/// Implements the processor script object
/// </summary>
public class TProcessorScript : TAbstractHttpStreamScriptObject
{
///<see cref="TAbstractHttpStreamScriptObject"/>
public override void handleStream(IKernelAccess Kernel,
ILogger Logger,
TDeviceInfo DeviceInfo,
IHttpStream DataStream)
{
IDataNode<string> Node1 = Kernel.NodeSpace.getNode<IDataNode<string>>(DeviceInfo.DataNodes.First(n => n.Name == "Value1").Id);
IDataNode<int> Node2 = Kernel.NodeSpace.getNode<IDataNode<int>>(DeviceInfo.DataNodes.First(n => n.Name == "Value2").Id);
IDataNode<double> Node3 = Kernel.NodeSpace.getNode<IDataNode<double>>(DeviceInfo.DataNodes.First(n => n.Name == "Value3").Id);
THttpResponse Response = DataStream.request("test2", "GET", "", "text/xml",
new Dictionary<string, string>());
XElement DataNode = XElement.Parse(Response.Content);
//Set node3 first
Node3.passState(EDataState.Good);
Node3.passValue(TValueConverter.convert<double>(DataNode.XPathSelectElement("./Node3").Value), false);
Node1.passValue(DataNode.XPathSelectElement("./Node1").Value, false);
Node1.passState(EDataState.Good);
Node2.passValue(TValueConverter.convert<int>(DataNode.XPathSelectElement("./Node2").Value), false);
Node2.passState(EDataState.Good);
}
}