There is an example for reading/writing to GDS array and struct variables on the controller using the read method from IDataAccessService. Link to example below.
CppExamples/Examples/DataAccess/DataAccess.pcwlx at master · PLCnext/CppExamples Collection of various C++ sample code for PLCnext Technology controllers. - PLCnext/CppExamples Example will read the values and output them to the log file. The values written to controller are unrelated to the values read.
How can I access the data read to update it in my program and then write the updated values back to the controller? The read method(line 364 in DataAccessComponent.cpp) says it returns a vector object of ReadItem however I am having trouble seeing how to access this vector object or how to pass it on to the write method(line 368 in DataAccessComponent.cpp).
The read method(line 364 in DataAccessComponent.cpp) says it returns a vector object of ReadItem however I am having trouble seeing how to access this vector objectThe Read method on the DataAccess service takes two delegates as parameters. In the example, the second parameter is a delegate that refers to the ReadResult method (line 35). In the ReadResult method you can see how to get data out of the ReadEnumerator for variables of different types including Arrays and Structs.
… or how to pass it on to the write method(line 368 in DataAccessComponent.cpp).The Write method on the DataAccess service takes two delegates as parameters. In the example, the first parameter is a delegate that refers to the WriteData method (line 121).
I can’t think of a way of passing data directly from the ReadResult method to the WriteData method. I’m thinking that you will need your own underlying structured or unstructured variables to store your „process data“. In your version of the ReadResult method you would copy the data from the enumerator to your own variables, then you would modify the values of that „process data“ if necessary, then in your version of the WriteData method you would copy the data in your variables back to the enumerator.
As an alternative solution, if you know the names and types of all the GDS variables at compile time, you could simply create port variables on your Component and connect them to the corresponding GDS variables using a .gds.config file. Then the data exchange will happen automatically, without needing to use the DataAccess RSC service.
Thanks for the info, was able to pass data between write and read method with the suggestion above. Will also try using Port variables.
