Skip to content

#679 PLCgen: Cleanup and fix variable handling

Albert Hofkamp requested to merge 679-fix-siemens-variable-handling into develop

Siemens targets need an additional prefix for persistent state variables which I ignored until now.

While figuring out what to do I noticed cif2plc uses the local and temp variables of the main program for state respectively temporary variables. Assuming the writers are aligned to this use, I dropped the global state variable list, and moved those variables to the local variables of the main program POU. This caused large moves in variable declarations in the test output.

Also I cleaned up the writers a bit to use proper data values rather than to rely on magic name matching or completely ignore the input from the generator (in case of S7 timers). In addition some hard-coded additions were deleted. Adding local variables to a function now crashes rather than sneakily moving them to a semantically different variable group (since we don't have PLC functions, nothing crashed).

Finally added a prefix for variables generically, and used that for adding a non-empty prefix to state variables for S7 targets. While testing I found presets for continuous variables were in the wrong table, and moved those as well. Introducing the prefix caused large code changes in the main programs of S7 targets.

Readable by commit.

Addresses #679

Merge request reports