Access/read Plugin-Data via C# DSF-API
-
Good evening,
after solving my previous issue with populating the ObjectModel with Plugin-related data, I am now facing a related situation.
I am developing a C#-based HMI-Application to control the CNC-machine and would like to show/present different IOs of my Plugin (which interfaces the IO-Board).
If I got the documentation right, I should use ObjectModel.Plugins["MyPlugin"].Data to read the Plugin-Data.
In my case this Dictionary is empty, although I have 8 IOs/Variables registered with the Plugin itself (and visible in the DWC-Objectmodel Plugin).Am I missing something here (doc says something about 'registration of Variables before using SetPluginData', but I want to read existing vars)?
Any hint/help is appreciated
Regards,
Reiner -
@rero Your custom data needs to be registered using the
data
property and since you seem to be able to see it using the DWC OM browser, that should be alright. How are you trying to read your custom data keys? -
I am using a SubcribeConnection to access/update the ObjectModel:
// connect and retrieve first complete ObjectModel await _subscriptionConnection.Connect(SubscriptionMode.Patch); _objectModel = await _subscriptionConnection.GetObjectModel(); // periodically get ObjectModel-changes while (true) { using JsonDocument wModelPatch = await _subscriptionConnection.GetObjectModelPatch(); _objectModel?.UpdateFromJson(wModelPatch.RootElement); }
The code to access the Plugin-data, looks like this:
if (_modelObserver.ObjectModel is not null) { _plugin = _modelObserver.ObjectModel.Plugins["IOExample"]; if (_plugin is not null) { //iterate over data-keys foreach (String key in _plugin.Data.Keys) { PluginInfo += $"Data/Json-Property '{key}': '{_plugin.Data[key]}'"; } } }
This works as expected, but the Plugin.Data member is empty in this case (while I can see the Data-variables in the DWC-ObjectModel-Plugin).
-
@rero What DSF version are you using?
-
@chrishamm I am using DSF version 3.5.4
-
@rero I could reproduce this problem and I'm looking into it. Version 3.6.0-beta.4 does not appear to be affected.
PS: I've got a bug fix ready for the next 3.5 version.
-
@chrishamm thanks for checking the issue.
One thing I observed today: a similar/identical(?) problem exists also with ObjectModel.Global: this ModelDictionary also doesn't contain any entry ... while the variables are available via DWC/ObjectModel-Plugin.
I tried 3.6-beta4 last week, but was not able to compile it - there were some issues with your new SourceGenerator, I will try again when I have more time / finished the basic stuff with DSF/RRF 3.5.