Hi, this is a interesting question and i’m curious how others solve this kind of issue.
I wrote an example how I do based on your data.
I think it’s important that the code is flexible and it’s easy for endusers to read and modify the code.
With my method I can change the record structure (amount of setpoint_types or what’s included in a setpoint_type) and only have to update the syntax in 3 datas.
And I would not have to do any changes to the programs that don’t need the new changes.
Splitting the code in different modules also make’s it easier to handle.
First I would create a module called records that looks like this:
!***********
!*** MODULE RECORDS
!***********
RECORD Programdata
string Name;
string SetupProc;
ENDRECORD
RECORD SettingsData
setpoints_type_1 spd1;
setpoints_type_2 spd2;
setpoints_type_3 spd3;
setpoints_type_4 spd4;
setpoints_type_5 spd5;
setpoints_type_6 spd6;
ENDRECORD
RECORD SetpointData
string type_name;
num speed;
num zone;
num acceleration;
bool calc_speed;
ENDRECORD
ALIAS SetpointData setpoints_type_1;
ALIAS SetpointData setpoints_type_2;
ALIAS SetpointData setpoints_type_3;
ALIAS SetpointData setpoints_type_4;
ALIAS SetpointData setpoints_type_5;
ALIAS SetpointData setpoints_type_6;
I also like to have a module for all my data declarations, so I would put these datas there.
!***********
!*** MODULE DATAS
!***********
CONST SetpointData spdNull:=["",0,0,0,FALSE];
CONST SettingsData sdNull:=[["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE]];
PERS SettingsData sdCurrent:=[["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE],["",0,0,0,FALSE]];
PERS Programdata pdActive:=["",""];
Next I would have a module for my programs.
This is the module where endusers would create / edit programs.
!***********
!*** MODULE PROGRAMS
!***********
CONST Programdata pdProgram1:=["Program 1","pdsetup_Program1"];
CONST Programdata pdProgram2:=["Program 2","pdsetup_Program2"];
PROC pdsetup_Program1()
sdCurrent:= sdNull;
pdActive:= pdProgram1;
!Setup SetpointData #1
!Reserved
!Setup SetpointData #2
sdCurrent.spd2.type_name:="TYPE2";
sdCurrent.spd2.speed:=100;
sdCurrent.spd2.zone:=10;
sdCurrent.spd2.acceleration:=10;
sdCurrent.spd2.calc_speed:=TRUE;
!Setup SetpointData #3
!Reserved
!Setup SetpointData #4
!Reserved
!Setup SetpointData #5
!Reserved
!Setup SetpointData #6
!Reserved
ENDPROC
PROC pdsetup_Program2()
sdCurrent:= sdNull;
pdActive:= pdProgram2;
!Setup SetpointData #1
sdCurrent.spd2.type_name:="TYPE1";
sdCurrent.spd2.speed:=200;
sdCurrent.spd2.zone:=30;
sdCurrent.spd2.acceleration:=1;
sdCurrent.spd2.calc_speed:=FALSE;
!Setup SetpointData #2
sdCurrent.spd2.type_name:="TYPE2";
sdCurrent.spd2.speed:=100;
sdCurrent.spd2.zone:=10;
sdCurrent.spd2.acceleration:=10;
sdCurrent.spd2.calc_speed:=TRUE;
!Setup SetpointData #3
sdCurrent.spd2.type_name:="TYPE3";
sdCurrent.spd2.speed:=80;
sdCurrent.spd2.zone:=5;
sdCurrent.spd2.acceleration:=20;
sdCurrent.spd2.calc_speed:=FALSE;
!Setup SetpointData #4
!Reserved
!Setup SetpointData #5
!Reserved
!Setup SetpointData #6
!Reserved
ENDPROC
Then in my actual jobProcs I would check the data like this:
PROC rType1Job()
IF sdCurrent.spd1 = spdNull RETURN;
ENDPROC
PROC rType2Job()
IF sdCurrent.spd2 = spdNull RETURN;
ENDPROC
PROC rType3Job()
IF sdCurrent.spd3 = spdNull RETURN;
ENDPROC
PROC rType4Job()
IF sdCurrent.spd4 = spdNull RETURN;
ENDPROC
PROC rType5Job()
IF sdCurrent.spd5 = spdNull RETURN;
ENDPROC
PROC rType6Job()
IF sdCurrent.spd6 = spdNull RETURN;
ENDPROC
Has anyone found a different solution?
The biggest drawback of this method is that the users can edit the programs with “ProgramData” on the flexpendant. But they learn quickly to do it with ProgramEditor.
I like the ability to quickly add more data to the settings, and not have to update old programs that dosen’t need the changes.