So here's the current server constraints:
- We have multiple devices that are dynamically created at runtime based on data provided by a 'DeviceService' the NodeManager uses (We'll say there are 100 devices for example).
- At some interval (maybe every 5 seconds) we'll check for new devices and create a new node and in-memory object to represent this device's metadata (We'll say it just has a DeviceId(string) for now).
- This same service also provides 'events' that are tied to one of the devices by the DeviceId (We'll say the events are composed of DeviceId(string), State(enum), Timestamp(DateTime), Notes(string)).
- In our NodeManager then, we would like use our DeviceService by getting a set of new events and updating our respective node values with this data. This should trigger any subscribed clients to receive new data for these devices.
- Clients will never be able to write to these device nodes, and will only ever receive these 'events' by subscribing to a device node.
I’m looking for the simplest approach to creating models for the devices and events that takes into account what I highlighted above. After using the SDK and finding several lengthy ways to approach designing the server, I’m running into some issues with complex data types like my model above so want to start from scratch. There seems to be some complexity in using structured data types, so trying to avoid adding additional complexity if it isn’t warranted.
Is there an example in the DemoServer that I should consider for my usage?
Recommended variable structure for Subscription-based server
Moderator: uasdknet
-
- Jr. Member
- Posts: 2
- Joined: 21 May 2018, 19:36
-
- Jr. Member
- Posts: 2
- Joined: 21 May 2018, 19:36
Re: Recommended variable structure for Subscription-based se
Maybe I can elaborate a bit on where I'm stuck with the DemoServer...
I can see that a WorkOrder is strictly defined in XML, where the Variable, DataType, and even instance are all defined at compile-time. And this seems to make the code backing it all rather simple:
Since the WorkOrder is defined as a DataType, as a Variable, and a definition of where it belongs within the namespace (Demo.WorkOrder has a HasComponent of WorkOrderVariable and WorkOrderVariable2), the above code is all we need to then bind a an in-memory instance of WorkOrderType to the Variable.
What I'm failing to see is where this HasComponent could be defined dynamically, so that rather than pre-defining a WorkOrderVariable and WorkOrderVariable2 we could find out how many WorkOrderVariable Nodes we need to create at runtime instead. I like how some of the VariableNodes in the demo are backed by a DataSource collection, but I haven’t seen an example where all of these criteria I mentioned are part of one object. I’m hoping I can find a solution where everything is driven by code rather than XML, so I can easily see what my NodeManager is doing behind the scenes. Although, I’ll settle for any implementation that works at this point.
I can see that a WorkOrder is strictly defined in XML, where the Variable, DataType, and even instance are all defined at compile-time. And this seems to make the code backing it all rather simple:
Code: Select all
NodeId WorkOrderId = new NodeId(Model.Variables.Demo_WorkOrder_WorkOrderVariable, DefaultNamespaceIndex);
Model.WorkOrderType value = new Model.WorkOrderType();
SetVariableDefaultValue(WorkOrderId, new Variant(value));
Model.WorkOrderVariableModel model = new Model.WorkOrderVariableModel()
{
Value = value
};
LinkModelToNode(WorkOrderId, model, null, null, 0);
WorkOrderId = new NodeId(Model.Variables.Demo_WorkOrder_WorkOrderVariable2, DefaultNamespaceIndex);
value = new Model.WorkOrderType();
SetVariableDefaultValue(WorkOrderId, new Variant(value));
model = new Model.WorkOrderVariableModel()
{
Value = value
};
LinkModelToNode(WorkOrderId, model, null, null, 0);
What I'm failing to see is where this HasComponent could be defined dynamically, so that rather than pre-defining a WorkOrderVariable and WorkOrderVariable2 we could find out how many WorkOrderVariable Nodes we need to create at runtime instead. I like how some of the VariableNodes in the demo are backed by a DataSource collection, but I haven’t seen an example where all of these criteria I mentioned are part of one object. I’m hoping I can find a solution where everything is driven by code rather than XML, so I can easily see what my NodeManager is doing behind the scenes. Although, I’ll settle for any implementation that works at this point.