FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
07-10-2024 06:12 PM - edited 07-10-2024 06:22 PM
I am using KVD app to save a JSON object in the DataLayer. My goal is to have a JSON object in a "parent" node and then each pair key/value of the JSON in a "nested" node. Similar to the node: system/resources/memory/available:
I have tried to creat nodes of type both Resource as Variable, and I only get the "parent" node (TestResource & TestVariable), and not the "nested" nodes (Var1, Var2 & Var3).
My .fbs file is the following:
// IDL file for sample schema.
namespace sample.schema;
table TestFlatbuffer {
Var1:double;
Var2:string;
Var3:uint64;
}
root_type TestFlatbuffer;
And inside the App Data -> kvd Folder, I have modified the file nodes.json file with the following code:
"types": [
{
"address": "types/test-schema",
"type": "test-schema.bfbs",
"metadata": {
"nodeClass": "Type"
}
}
],
"nodes": [
{
"address": "Test/TestResource",
"type": "types/test-schema",
"value": {
"Var1": 0,
"Var2": "string",
"Var3": 0
},
"metadata": {
"nodeClass": "Resource",
"description": "This node is of the custom flatbuffers type"
}
},
{
"address": "Test/TestVariable",
"type": "types/test-schema",
"value": {
"Var1": 0,
"Var2": "string",
"Var3": 0
},
"metadata": {
"nodeClass": "Variable",
"description": "This node is of the custom flatbuffers"
}
},
I looked in the Application Manual and in the following guide, and I cound't find a reference to this topic. Is it possible? How can I get the result I want using KVD?
Thanks in advance! 😊
Solved! Go to Solution.
07-10-2024 08:21 PM
Hi @star_board ,
I tried to replicate this as well and the only method I found is by manually creating the child nodes in the nodes.json. Keep in mind that the data behind these nodes is not linked and therefore updating the child will no update the parent. Example...
{
"address": "test/memory",
"type": "types/system/resources/memory",
"value": {
"total": 16772329472,
"used": 459796480,
"free": 15236046848,
"buffer": 41381888,
"cache": 1035104256,
"available": 16044298240
},
"mode": "read-only",
"metadata": {
"nodeClass": "Variable",
"description": "This variable node is of built-in flatbuffers type 'system-resources-memory'."
}
},
{
"address": "test/memory/total",
"type": "int32",
"value": 12,
"mode": "read-only",
"metadata": {
"nodeClass": "Variable"
}
},
{
"address": "test/memory/used",
"type": "int32",
"value": 123,
"mode": "read-only",
"metadata": {
"nodeClass": "Variable"
}
}
I copied the same type as the memory resource example you gave and the child nodes are not created. I believe they are using some recursive logic behind the scenes to create those nodes and it is not a built in feature of the datalayer. I agree this would be a useful function, but to the best of my knowledge, it is not currently available using KVD. Hopefully someone proves me wrong!
Do you absolutely need the top level JSON object representation along with the child nodes for each key-value pair? If not, see the model examples.
07-11-2024 08:06 PM
Using a .yaml file I did manage to create child nodes:
$schema: ./schemas/datalayer.v1.0.schema.json
name: test
version: 0.0.1
elements:
var1:
description: description.
nodeClass: Variable
mode: read-write
value: 23
typeSchema:
type: int32
var2:
description: description.
nodeClass: Variable
mode: read-write
value: 99
typeSchema:
type: int32
var3:
description: description.
nodeClass: Variable
mode: read-write
value: 99
typeSchema:
type: int32
But now, the "parent" node doesn't show a JSON object:
07-11-2024 08:29 PM
Right. This is the behavior I saw as well and is what is shown in the samples. Like I said above, I believe there is logic being executed while providing the memory status nodes that is outside of the scope of the KVD capability.
07-16-2024 06:38 PM - edited 07-17-2024 09:14 AM
I manage to get the result I wanted using PLC Engineering DUT objects and making them available on the Datalayer. This approach could potentially serve as a solution for those pursuing similar results:
But it seems that , contrary to Sgilk's initial beliefs, this "nested" nodes might be a built in feature of the datalayer... And might be achievable using KVD app.
One think I noticed is that upon examining the corresponding Type nodes (PLC vs KVD), they seem to be identical.