there is a missing PVICOM (C) functionality in PVI services (C#). At PVICOM I could read and write PVI structures at once, including all the nested strctures, all I had to do is make sure the struct
is the same at both sides.
But in C# I cant find the same option. This forces me to drill down recursivly the nested structed until I reach the primitive types.
Am I missing something?
Hi,
I’m not a PVIServices expert, but I’m pretty sure you’re right: it’s not possible with PVIServicesNET to make a 1:1 “mapping” of PLC structure variables to C# variables, like it’s possible with PVICOM and C++ for example.
To be honest, I’m not sure if the following information is helpful, or if you already have used it in your recursive function?
As I understood, a ServicesNET variable object can be connected directly to a PLC structure variable.
If connecting successfully to a structure variable, the property VariableStructureMembers should contain all nested members of the structure variable, not only the first nesting level.
And with property VariableChangedStructMembers you can access an array of the member names who have changed.
Best regards!
If you connect a structure variable in C# then the whole variable will be read / written. It might appear different because of the property struct_variable.WriteValueAutomatic which is true by default and causes writes of the whole structure whenever a member is written to.
To prevent this and manually write the whole sturcture when you are ready, you can either set struct_variable.WriteValueAutomatic = false; or you can assign values instead of writing them.
e.g.
struct_variable.WriteValueAutomatic = false;
struct_variable.Value[“member1”] = 1;
struct_variable.Value[“member2”] = 1;
struct_variable.WriteValue();
OR
struct_variable.WriteValueAutomatic = true;
struct_variable.Value[“member1”].Assign(1);
struct_variable.Value[“member2”].Assign(2);
struct_variable.WriteValue();
Notice that in both cases you have to write the variable by calling WriteValue() on the actual struct variable not its members.
Variable instances under struct_variable.Members are not registered with the PviManager as individual variables by themselves and only serve to represent the member in .NET.