Vous êtes sur la page 1sur 26

Next Generation Scripting

Martin Koller, April 2016

Siemens AG 2016 All rights reserved. siemens.com/answers


Introduction Who?

Name:
Martin Koller

at ETM since:
1988

Current role:
Software Engineer

Main responsibility:
User Interface, CTRL Scripting, Mobile UI,
HTTP Server

Siemens AG 2016 All rights reserved.


Page 2 April 2016 DF PL DER HMI ETM
CTRL language current situation

CTRL is an imperative language


based on ANSI C syntax
functions
fixed set of data types (int, float, dyn_...)
no data structures (except mapping)
Siemens AG 2016 All rights reserved.
Page 3 April 2016 DF PL DER HMI ETM
CTRL language Whats missing

Data Structuring

User Defined Data Types

Encapsulation (Data and Code)


Object Orientation

Siemens AG 2016 All rights reserved.


Page 4 April 2016 DF PL DER HMI ETM
CTRL language Evolution

CTRL going CTRL++


or Introducing User Defined Data Types

enum classes

struct and class


Use them like the std. integrated types

Siemens AG 2016 All rights reserved.


Page 5 April 2016 DF PL DER HMI ETM
CTRL++ enum

Type safe enumeration values (constants)


enum EngineState
{
On,
Off,
Automatic
};
Usage
EngineState state = EngineState::Automatic;
Siemens AG 2016 All rights reserved.
Page 6 April 2016 DF PL DER HMI ETM
CTRL++ enum Details

Values can be predefined

Stored as int

enum EngineState
{
On = 2,
Off = 4,
Automatic // will be 5 last+1
};

int x = EngineState::On; // not allowed different type!


int x = (int)EngineState::On; // casting needed

EngineState s = 2; // allowed, since 2 is in EngineState


EngineState s = 3; // NOT allowed

Siemens AG 2016 All rights reserved.


Page 7 April 2016 DF PL DER HMI ETM
CTRL++ struct / class Object Orientation

Aggregation of data and functions


class Engine
{
public start() { state = EngineState::On; }
EngineState state;
};
Usage
Engine engine1;
engine1.start();
Siemens AG 2016 All rights reserved.
Page 8 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class

Access modifiers: public, protected, private

struct defaults to public


class defaults to private

Both can contain member variables and member functions


class Name
{
public string getName() { return name; }
public void setName(const string &n) { name = n; }

string name; // defaults to private


};

Siemens AG 2016 All rights reserved.


Page 9 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class - contructor

Special Function: Constructor


class Engine
{
public Engine() { state = EngineState::Off; }

public start() { state = EngineState::On; }

EngineState state;
string name;
};

Engine e1; // state is now Off

Siemens AG 2016 All rights reserved.


Page 10 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class - contructor

Special Function: Constructor


class Engine
{
public Engine(const string &n) { name = n; }

public start() { state = EngineState::On; }

EngineState state;
string name;
};

Engine e1 = Engine(Motor1);
Engine e2 = Engine(Motor2);

Siemens AG 2016 All rights reserved.


Page 11 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class static members

Members can be static they exist without an instance

class Engine
{
public Engine() { counter++; }
public static int getInstanceCount() { return counter; }

static int counter;


};

Engine e1, e2, e3;


DebugN(Engine::getInstanceCount()); // prints 3

Siemens AG 2016 All rights reserved.


Page 12 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class Single Inheritance

class Valve
{
public open() { ... }
public close() { ... }

error() { DebugN(base error); }


};

class SlideValve : Valve


{
public openTo(float percentage) { ... }

error() { DebugN(slide error); Valve::error(); }


};

Siemens AG 2016 All rights reserved.


Page 13 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class Polymorphism (virtual functions)

class Valve
{
public open() { dpSet(dpe, true); } // boolean true = open
};

class SlideValve : Valve


{
public open() { dpSet(dpe, 100.0); } // float = 100% fully open
};

handleValve(Valve &valve)
{
valve.open();
}

Valve v; handleValve(v); // will call Valve::open()


SlideValve sv; handleValve(sv); // will call SlideValve::open()

Siemens AG 2016 All rights reserved.


Page 14 April 2016 DF PL DER HMI ETM
CTRL++ - struct / class RTTI (runtime type information)

class Valve { };
class Engine { };
enum EngineState { };

main()
{
Valve v;
Engine e;
EngineState s;

getType(v); getType(e); getType(s); // all return CLASS_VAR

getTypeName(v); // class Valve


getTypeName(e); // class Engine
getTypeName(s); // enum EngineState
}

Siemens AG 2016 All rights reserved.


Page 15 April 2016 DF PL DER HMI ETM
Wait theres more ?

What about UI ?
Status now:

Panel instances as Panel References

Arguments passed as string $-Parameters

No Script interaction from/to outside


Siemens AG 2016 All rights reserved.
Page 16 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels

UI Panels going Object Oriented


Introducing

Public Functions

Panel Events

Panel Properties
Siemens AG 2016 All rights reserved.
Page 17 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Public Functions

ScopeLib currently only private functions


New: public functions

Example:

public void startTheMachine() { dpSet(); }


public bool hasPermission(string user) { }

Siemens AG 2016 All rights reserved.


Page 18 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Public Functions

public void startTheMachine() { dpSet(); }


public bool hasPermission(string user) { }

Usage:
if ( Machine17.hasPermission(user) )
Machine17.startTheMachine();

Siemens AG 2016 All rights reserved.


Page 19 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Events

PanelRef shall be able to trigger events so


Users can react on them
Solution:

#event valueChanged(int value)


#event buttonClicked()

Siemens AG 2016 All rights reserved.


Page 20 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Events - Gedi

#event valueChanged(int value)


#event buttonClicked()

Such events are shown in Gedis Property Editor


extended Tab as new Events, which the User can script

Siemens AG 2016 All rights reserved.


Page 21 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Events - Scripting

#event valueChanged(int value)

in Panel: triggerEvent("valueChanged", current);

Where used:
uiConnect(callback, REF0.valueChanged);

callback(int value)
{
this.text = value;
}

Siemens AG 2016 All rights reserved.


Page 22 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Scripting

Public Functions, Events are shown in Script Editors


completion box

Siemens AG 2016 All rights reserved.


Page 23 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Properties

#property int minimum


#property int maximum

public int getMinimum() { ... }


public int getMaximum() { ... }
public void setMinimum(int i) { ... }
public void setMaximum(int i) { ... }

Notation:
#property <type> <name>

<type>: int, uint, float, bool, string, color, pen, fill, font
and any user defined enum class
Siemens AG 2016 All rights reserved.
Page 24 April 2016 DF PL DER HMI ETM
UI Evolution OO Panels Properties

On instances of such OO-PanelRefs,


properties are shown in Gedis Property Editor extended Tab
and stored in the panel

Siemens AG 2016 All rights reserved.


Page 25 April 2016 DF PL DER HMI ETM
Summary

Introducing Object Orientation in

Scripts

enum / struct / class

Panels

public functions

#event

#property

Siemens AG 2016 All rights reserved.


Page 26 April 2016 DF PL DER HMI ETM

Vous aimerez peut-être aussi