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.

The program is very short and constrained on purpose to encourage experimentation. It would be best to<br />

compile the program now and load it to Automation Runtime. But first change the 'vga' string variable in the<br />

VA_Setup function in the cyclic part and replace it with the name of the visualization project to which output<br />

should take place.<br />

Expand the program to include more output or change the parameters either in the program or using the Watch<br />

command in Automation Studio. If necessary, use the Visapi Documentation in the reference manual to refer to<br />

details.<br />

The following is a brief overview of the example code:<br />

• Some variables are defined in the Initialization part of the task which mostly serve as place holders for<br />

the position and color of the elements to be drawn. An exception is the ready variable. This variable<br />

makes a note of whether the Visapi library was completely and successfully initialized.<br />

• Using VA_Setup, the first part of the program establishes a connection to the <strong>Visual</strong> <strong>Components</strong><br />

interpreter or to its management routine (aplib.br), the runtime. This is necessary, since both the<br />

interpreter and the Visapi functions access the same resources, and accessing these resources must be<br />

managed.<br />

• If the function is successful, a unique VCHandle is returned. This is necessary since several <strong>Visual</strong><br />

<strong>Components</strong> projects can run at the same time. Therefore an exact differentiation must be made<br />

regarding the destination of the Visapi functions (to which project and also to which display).<br />

Subsequently, the handle must be transferred with every other Visapi function.<br />

• If VA_Setup fails (returns 0) , then the function in the example is called cyclically until a valid handle is<br />

returned. As soon as VA_Setup was successfully executed and a handle is available, the ready<br />

variable is set to 1 and the actual working part of the task is 'released'.<br />

• Once a handle is available, then the panel resources are requested using VA_Saccess. It is possible for<br />

drawing operations to be carried out only after a successful call (return value is 0).<br />

• If the panel resources can be successfully requested with VA_Saccess, then the drawing function can<br />

be called. The function names display the respective tasks, and parameters are listed in the<br />

documentation for the respective function in the reference manual.<br />

(Click the corresponding function in the Library Manager and press F1 to receive help).<br />

• Finally, the resources are released by the program with VA_Srelease.<br />

Warning:<br />

Only call VA_Srelease if VA_Saccess has returned 0.<br />

Warning:<br />

Always call VA_Srelease if VA_Saccess was successfully executed! Otherwise the <strong>Visual</strong> <strong>Components</strong><br />

editor can no longer output to the display and the visualization freezes.<br />

4.2.3.4 Visapi − Tutorial − Preparing the C Example<br />

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

If you decided to use an ANSI C implementation, then a dialog box opens with the title 'Add C Files'. First you<br />

create a new C file which contains the program. To do this, input 'visu.c' under File Name (without the single<br />

quotes) and confirm with Add.<br />

268 4.2.3.4 Visapi − Tutorial − Preparing the C Example

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

Saved successfully!

Ooh no, something went wrong!