23.11.2012 Views

2 Visual Components Manuals

2 Visual Components Manuals

2 Visual Components Manuals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

eplaces the old recipe number and the control variable is set to 1.<br />

In order to avoid invalid memory accesses, recipe number input is checked for the max. available recipes.<br />

The second IF−statement is fulfilled if the control variable 0. In other words, the dynamic variable references<br />

the current recipe number.<br />

(* cyclic program *)<br />

if (recipeNrAct recipeNrOld) then<br />

if (recipeNrAct > 5) then<br />

recipeNrAct = 5;<br />

endif<br />

recipeChanged = 1;<br />

recipeNrOld = recipeNrAct;<br />

endif<br />

if (recipeChanged > 0) then<br />

pRec access adr(rec_arr[recipeNrAct−1]);<br />

recipeChanged = 0;<br />

endif<br />

Read the Notes at the end of the chapter.<br />

4.12.7.4 Code in ANSI C<br />

The code described above in C:<br />

#include<br />

#include struct recipe { unsigned long elem1; unsigned long elem2;<br />

unsigned long elem3; unsigned long elem4; unsigned long elem5; }; struct recipe rec_arr[5]; _GLOBAL<br />

unsigned char recipeNrAct; _GLOBAL unsigned char recipeNrOld; _GLOBAL unsigned char recipeChanged;<br />

_LOCAL struct recipe *pRec; _INIT init_func(void) { int i; for(i = 0; i < 5; i++) { rec_arr[i].elem1<br />

= 100 * i + 1; rec_arr[i].elem2 = 100 * i + 2; rec_arr[i].elem3 = 100 * i + 3; rec_arr[i].elem4 =<br />

100 * i + 4; rec_arr[i].elem5 = 100 * i + 5; } recipeNrAct = 1; recipeNrOld = 0; recipeChanged = 0;<br />

} _CYCLIC cyc_func(void) { if(recipeNrAct != recipeNrOld) { if(recipeNrAct > 5) { recipeNrAct = 5; }<br />

recipeChanged = 1; recipeNrOld = recipeNrAct; } if(recipeChanged > 0) { pRec =<br />

&rec_arr[recipeNrAct−1]; recipeChanged = 0; } }<br />

4.12.7.4.1 Important notes<br />

A dynamic variable does not limit itself to referencing static variables of the same data type; rather, it can<br />

reference any memory address. However, this can lead to big problems. When using dynamic variables, it<br />

should be noted that they should already be initialized when first accessed (null pointer error) and not pointed to<br />

an invalid memory range during runtime.<br />

If limits were not set for the max. recipe number in the above example, a value of another variable or even<br />

program code could have possibly been overwritten. This can crash a program or cause invalid data to be<br />

displayed.<br />

4.12.8 VC System Tuning<br />

All <strong>Visual</strong> <strong>Components</strong> runtime modules are tied to the system as non−cyclic tasks with lower priority than cyclic<br />

tasks. Cyclic user tasks (task classes) are therefore not influenced by runtime performance. <strong>Visual</strong> <strong>Components</strong><br />

runtime modules run in the system idle time with low priority.<br />

A simple and clear definition of timing performance is difficult because of the different ways that application<br />

software loads down the CPU. This is mainly due to the lower priority of <strong>Visual</strong> <strong>Components</strong> runtime modules.<br />

If a system does not have much idle time available, then display speed and key reaction are slower on the target<br />

system. Therefore, attention should be paid to how much idle time is available on the system. An 'unfavorable'<br />

configuration example will show how this works in practice.<br />

We will use the following configuration:<br />

Introduction to <strong>Visual</strong> <strong>Components</strong> 2.3<br />

432 4.12.7.4 Code in ANSI C

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!