Hello all,
since I’m about to start a new projectI’d like to use this opportunity to find a better way to work with VC4 as I’m rather unhappy with how I used to access VC4 before.
In my past projects, all visu elements were organized in one huge global structure, something like:
gVC4.pageMainMenu.layerMessage.but_abort <TYPE_CTRL_BUTTON>
gVC4.pageMainMenu.layerMessage.str_enterSerial <TYPE_CTRL_STRINPUT>
.
.
.
gVC4.pageMaintenance.layerOperatingTimes.numRuntimeMotr <TYPE_CTRL_NUMERIC1>
With TYPE_CTRL_BUTTON, TYPE_CTRL_BUTTON, … being other structues defined like:
TYPE_CTRL_NUMERIC1 : STRUCT
status : UDINT;
completion : UDINT;
minVal : REAL;
maxVal : REAL;
value : REAL;
isLocked : BOOL;
bitmapIndex : USINT;
colorIndex : USINT;
END_STRUCT;
While putting all elements into one structure may have its own quirks,
what really bugs me is, how handling of VC4 elements clutters the statemaschines.
For example:
CASE someSM OF
...
STATE_INIT_PROCESS:
//lock all buttons:
gVC4.pageMainMenu.but_startProcess.isLocked := 1; // disable button
gVC4.pageMainMenu.but_startProcess.bitmapIndex := 3; // grey out button icon
gVC4.pageMainMenu.but_startProcess.colorIndex := 2; // grey out button text
... (8 elements like this)
// send axis to initial position
axisctrl.cmd := MOVE_HOME;
// next step
someSM := STATE_INIT_PROCESS_WAIT
STATE_INIT_PROCESS_WAIT:
IF axisCtrl.stat = MOVE_DONE THEN
//unlock all buttons:
gVC4.pageMainMenu.but_startProcess.isLocked := 0;
gVC4.pageMainMenu.but_startProcess.bitmapIndex := 1; // enable button
gVC4.pageMainMenu.but_startProcess.colorIndex := 1; // black color
... (8 elements like this)
ELSIF axisCtrl.stat = MOVE_ERROR THEN
// many lines of code opening a layer, setting its elements
someSM := STATE_PROCESS_ERROR
END_IF
STATE_PROCESS_IDLE:
// wait for user input
IF gVC4.pageMainMenu.but_startProcess.completion = 1 THEN
gVC4.pageMainMenu.but_startProcess.completion = 0:
//(lots of more rows locking buttons, changing status texts indices, ...
someSM := STATE_PROCESS_START_AUTO;
ELSIF gVC4.pageMainMenu.but_startManualMode.completion = 1 THEN
gVC4.pageMainMenu.but_startManualMode.completion = 0:
//(lots of more rows locking buttons, changing status texts indices, ...
someSM := STATE_PROCESS_START_MANUAL;
ELSIF gVC4.pageMainMenu.but_startMaintenanceMode.completion = 1 THEN
gVC4.pageMainMenu.but_startMaintenanceMode.completion = 0:
//(lots of more rows locking buttons, changing status texts indices, ...
someSM := STATE_PROCESS_START_MAINTENANCE;
...
END_IF
END_CASE
You get the idea. Using styleclasses may help spare some lines, but I was wondering if creating a dedicated VC4 controller, that can send/receive commands/stats/parameters, and takes care of all elements would help to de-clutter the SM.
For the states in statemachines in general I’d like to see what actually happens concerning the process and the transitions to other states since this is the most important code that makes the machine work.
All the VC4 code makes it rather unreadable and hard to maintain. I, as the developer may cope with it, but if my colleaque would have to take a look and fix a bug under time pressue this becomes a problem.
So … I’m looking for a more elegant solution to work with VC4 and would be grateful if someone could share their approach.
Many thanks!