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.

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

4.11.12 General/Drawing − VISAPI<br />

This is an example of a small VISAPI program in the B&R Automation Basic programming language, followed by<br />

an explanation:<br />

1:<br />

2:<br />

3:<br />

4:<br />

5:<br />

6:<br />

7:<br />

8:<br />

9:<br />

10:<br />

11:<br />

12:<br />

13:<br />

14:<br />

15:<br />

16:<br />

17:<br />

18:<br />

19:<br />

20:<br />

21:<br />

22:<br />

23:<br />

24:<br />

25:<br />

26:<br />

27:<br />

28:<br />

29:<br />

30:<br />

31:<br />

(* cyclic program *)<br />

x1 = 100<br />

y1 = 150<br />

x2 = 250<br />

y2 = 250<br />

height = 40<br />

width = 80<br />

fill = 255 ; Transparent<br />

color = 0 ; Black<br />

If ready 1 Then<br />

VC_HANDLE = VA_Setup(1 , "vga")<br />

If VC_HANDLE 0 Then<br />

ready = 1<br />

EndIf<br />

EndIf<br />

If ready = 1 Then<br />

If VA_Saccess(1,VC_HANDLE)= 0 Then<br />

VA_Rect (1,VC_HANDLE,x1,y1,x2,y2,fill,color)<br />

VA_Line (1,VC_HANDLE,x1,y1,x2,y2,color)<br />

;Draws a rectangle<br />

;Draws a line<br />

VA_Ellipse(1,VC_HANDLE,x2,y2,heigth,width,fill,color) ;Draws an ellipse<br />

VA_Textout (1,VC_HANDLE,1,100,100,color,fill,"a rectangle, a line and an ellipse");Outputs a te<br />

VA_Srelease(1,VC_HANDLE)<br />

EndIf<br />

EndIf<br />

This program draws a rectangle, a line, an ellipse, and outputs text. The following steps are required to do this:<br />

Line(s) Description<br />

3 − 10 Initializes variables<br />

12 This flag stores whether the VISAPI has already been successfully initialized.<br />

13<br />

16<br />

Initializes the VISAPI and establishes the connection to the specifed project ('vga' in this example). If<br />

the project name is valid and the VISAPI library is initialized, then a handle is returned which is stored<br />

in the VC_HANDLE variable.<br />

VC_HANDLE is valid, since it is 0. Therefore, the initialization flag can be set to 1 to prevent<br />

repeated initializations and let the rest of the task continue.<br />

19 Checks whether the VISAPI is initialized.<br />

20 Calls VA_Saccess since drawing should now begin.<br />

21 − 27 VA_Saccess did not return any errors, therefore drawing can take place.<br />

29 After a successful VA_Saccess(...) call, VA_Srelease absolutely has to be called.<br />

4.12 Tips and Tricks<br />

Many functions are tightly integrated in <strong>Visual</strong> <strong>Components</strong> and can be used right away. This section gives more<br />

information about additional <strong>Visual</strong> <strong>Components</strong> options.<br />

Usually, only a few lines of code are necessary to implement striking effects and completely new functions.<br />

4.12.1 A Few Tips<br />

• Configuring a Help Picture<br />

• Input Field Cursor Navigation<br />

• Blinking Text (or Button)<br />

4.11.12 General/Drawing − VISAPI 425

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

Saved successfully!

Ooh no, something went wrong!