24.01.2015 Views

CoDeSys on CCP XS for Bromma Conquip - Research

CoDeSys on CCP XS for Bromma Conquip - Research

CoDeSys on CCP XS for Bromma Conquip - Research

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

Student<br />

Joel Ek<br />

Supervisor at CC-Systems<br />

Fredrik Löwenhielm<br />

Dok Nr<br />

1.0<br />

Date<br />

2006-08-08<br />

Rev<br />

PA1<br />

Säk klass<br />

F<br />

Filname<br />

Thesis.doc<br />

CODESYS ON <strong>CCP</strong> <strong>XS</strong> FOR BROMMA CONQUIP<br />

Figure 20: Showing the declarati<strong>on</strong> of structs and functi<strong>on</strong>s in ANSI C<br />

The thing we need to focus <strong>on</strong> is the code representing the classes and the structure of a class<br />

(fig. 21). A class can hold functi<strong>on</strong>s and variables; these functi<strong>on</strong>s and variables are a part of the<br />

class and are called class members. When an instance is created from a class it can access its<br />

own member variables and can use its class functi<strong>on</strong>s to alter its variables.<br />

Figure 21: Showing the structure of a class in C++<br />

The counterpart to the object oriented C++ class is in ANSI C the Structure abbreviated to Struct.<br />

The Struct is a way to combine simple data types into a complex <strong>on</strong>e. Compared to the class it<br />

does not hold any functi<strong>on</strong>s <strong>on</strong>ly the variables types that that is part of the Struct. The <strong>for</strong>mat of<br />

the Struct is generated automatically when we produce an external library in <str<strong>on</strong>g>CoDeSys</str<strong>on</strong>g> (fig. 20).<br />

The member functi<strong>on</strong>s must instead be normal functi<strong>on</strong>s that can be called by any<strong>on</strong>e, this leads<br />

to some changes:<br />

- The name of the functi<strong>on</strong>, if all comp<strong>on</strong>ents have a functi<strong>on</strong> called calculate that now is open<br />

<strong>for</strong> every<strong>on</strong>e to use, the program will not know which calculate bel<strong>on</strong>gs to which Struct.<br />

- Variables in the functi<strong>on</strong>, a member functi<strong>on</strong> have direct access to the member variables.<br />

The names of the functi<strong>on</strong>s have got to change, preferably to the name of the specific comp<strong>on</strong>ent<br />

represented by the class appended with the member-functi<strong>on</strong> name.<br />

34 (55)

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

Saved successfully!

Ooh no, something went wrong!