23.11.2012 Views

2 Visual Components Manuals

2 Visual Components Manuals

2 Visual Components Manuals

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The C editor is opened by double−clicking on the 'visu.c' file in the Software view.<br />

You will create the actual program in the next step.<br />

4.2.3.5 Visapi − Tutorial − Finishing the C Example<br />

A rectangle, a line, and an ellipse should be drawn in this example. A text should also be output.<br />

To do this, input the following program code in the 'visu.c' file:<br />

#include<br />

#include #include _LOCAL UINT ready; _LOCAL UINT x1; _LOCAL<br />

UINT x2; _LOCAL UINT y1; _LOCAL UINT y2; _LOCAL USINT fill; _LOCAL USINT color; _LOCAL UINT heigth;<br />

_LOCAL UINT width; _LOCAL UDINT VC_HANDLE; _INIT void Initialization(void) { x1 = 150; y1 = 100; x2<br />

= 100; y2 = 150; fill = 255; /* Transparent */ color = 0; /* Black */ heigth = 40; width = 80; ready<br />

= 0; } _CYCLIC void Cyclic(void) { if (!ready) { VC_HANDLE = VA_Setup(1 , "vga"); if (VC_HANDLE) ready<br />

= 1; } if (ready) { if (!VA_Saccess(1,VC_HANDLE)) /* Reserves access to the visualization */ {<br />

VA_Rect (1,VC_HANDLE,x1,y1,x2,y2,fill,color); /* Draw rectangle */ VA_Line<br />

(1,VC_HANDLE,x1,y1,x2,y2,color); /* Draw line */ VA_Ellipse<br />

(1,VC_HANDLE,x2,y2,height,width,fill,color); /* Draw ellipse */ /* Text output */ VA_Textout<br />

(1,VC_HANDLE,1,50,50,color,fill,"A rectangle, a line, and an ellipse"); VA_Srelease(1,VC_HANDLE);<br />

/* Releases the visualization */ } } }<br />

You can naturally use the Windows Clipboard to copy this source code into Automation Studio.<br />

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 />

Introduction to <strong>Visual</strong> <strong>Components</strong> 2.3<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 />

270 4.2.3.5 Visapi − Tutorial − Finishing the C Example

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

Saved successfully!

Ooh no, something went wrong!