TCP Data Access
A task processor with payload handling is needed to access data over a native TCP connection.
Task Processor
The payload processing must be declared in a processor information within the device info file.
The payload script is typically placed in the folder:
$(ConfigPath)\HumanOS.UHAL.TcpClientControl
Example
"TaskProcessors": [
{
"Id": "9bd3ec86-f5fe-4679-8621-751540d602a2",
"Name": "MainTaskProcessor",
"ScriptFile": "TcpBridgeCommunicator.cs",
"Properties": []
}
]
Further information about DataStream Scripting.
A detailed example for native TCP connections.
Builtin Addresses
Following data node addresses are provided by the plugin. The Stream
namespace is used:
Address | Description | Data Type |
---|---|---|
Stream::Available | Returns the available flag. true if the data stream is open. | System.Boolean |
Stream::SignOfLife | Sign of life. Toggles in 1Hz if the data stream is open. | System.Boolean |
Other DataNodes
All other data nodes might have an address of your choice.
If there is no address provided, the default behavior of the plugin will not set the data state to BadNotActive if the connection is lost.
Accessing Address Information
The address can be accessed in your payload script by the property Address
.
Note that there might be other nodes, such as Commands, Processors, Rules, etc. Filter the nodes you want to use for communication. If using the NodeSpace directly to filter nodes, make sure you only query nodes from this device (property
DeviceId
).
Example
The following example illustrates how to filter nodes based to the DeviceId
and Address
.
///<see cref="TAbstractStreamScriptObject"/>
public override EProcessingState connectToDevice(IKernelAccess Kernel, TDeviceSchemaInfo DeviceInfo, IDataStream DataStream)
{
EProcessingState eRetval = EProcessingState.Good;
try
{
foreach (INode Node in Kernel.NodeSpace.queryNodes(n => n.hasProperty("DeviceId", DeviceInfo.Id)))
{
string strAddress = Node.getProperty("Address", "");
Logger.writeInfo($"Node found: {Node.Name}");
if (strAddress != "")
{
//TODO Setup node for receiving data
}
else
{
Logger.writeDebug($"Node '{Node.Name}' has no address. Ignored.");
}
}
}
catch (Exception Exc)
{
eRetval = EProcessingState.BadConnection;
}
return eRetval;
}