training manual lasal class 2 -...

564
CONTENTS Version 5.0 Page 1 Training Manual LASAL CLASS 2 Contents 1 The LASAL 2 Concept ............................................................... 9 1.1 Information about the manual .................................................................. 9 1.1.1 Construction and scope of this manual ............................................ 9 1.1.2 Tips for working in LASAL CLASS 2 ................................................ 9 1.1.3 Notes on example programs .......................................................... 10 1.2 What is LASAL? ....................................................................................... 10 1.2.1 All in one ......................................................................................... 10 1.3 Why LASAL CLASS 2? ............................................................................ 11 1.3.1 Object Oriented Programming With LASAL CLASS 2 ................... 11 1.3.2 Advantages Over Normal Programming......................................... 11 1.3.3 Open Data Interface ....................................................................... 11 1.3.4 Project Creation Through Scripting ................................................ 12 1.3.5 LASAL CLASS 2 Library................................................................. 12 1.3.6 Multilanguage Programming Tool................................................... 12 1.3.7 Multitasking System........................................................................ 12 2 The Design Environment ........................................................ 13 2.1 Hard and Software Requirements .......................................................... 13 2.2 The LASAL CLASS 2 Design Environment ........................................... 14 2.2.1 The Design Surface Environment................................................... 14 2.2.2 Layout ............................................................................................. 15 2.2.3 Menu Bar ........................................................................................ 16 2.2.4 Tools/Symbol Bars (Overview) ....................................................... 22 2.2.5 Project Tree .................................................................................... 25 2.2.6 Status Bar ....................................................................................... 31 2.2.7 Debugger Window .......................................................................... 32 2.2.8 Output Window ............................................................................... 35 2.2.9 Python Script Window..................................................................... 37 2.2.10 Properties Window.......................................................................... 38 2.3 LASAL CLASS 2 File Types .................................................................... 39 2.3.1 Project Files .................................................................................... 39 2.3.2 Source Code Files .......................................................................... 39

Upload: hoangmien

Post on 11-May-2018

407 views

Category:

Documents


62 download

TRANSCRIPT

Page 1: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Version 5.0 Page 1

Training Manual LASAL CLASS 2 Contents 1 The LASAL 2 Concept............................................................... 9

1.1 Information about the manual .................................................................. 9 1.1.1 Construction and scope of this manual ............................................ 9 1.1.2 Tips for working in LASAL CLASS 2 ................................................ 9 1.1.3 Notes on example programs .......................................................... 10

1.2 What is LASAL? ....................................................................................... 10

1.2.1 All in one ......................................................................................... 10

1.3 Why LASAL CLASS 2? ............................................................................ 11 1.3.1 Object Oriented Programming With LASAL CLASS 2 ................... 11 1.3.2 Advantages Over Normal Programming......................................... 11 1.3.3 Open Data Interface ....................................................................... 11 1.3.4 Project Creation Through Scripting ................................................ 12 1.3.5 LASAL CLASS 2 Library................................................................. 12 1.3.6 Multilanguage Programming Tool................................................... 12 1.3.7 Multitasking System........................................................................ 12

2 The Design Environment ........................................................ 13

2.1 Hard and Software Requirements .......................................................... 13

2.2 The LASAL CLASS 2 Design Environment ........................................... 14 2.2.1 The Design Surface Environment................................................... 14 2.2.2 Layout ............................................................................................. 15 2.2.3 Menu Bar ........................................................................................ 16 2.2.4 Tools/Symbol Bars (Overview) ....................................................... 22 2.2.5 Project Tree .................................................................................... 25 2.2.6 Status Bar ....................................................................................... 31 2.2.7 Debugger Window .......................................................................... 32 2.2.8 Output Window ............................................................................... 35 2.2.9 Python Script Window..................................................................... 37 2.2.10 Properties Window.......................................................................... 38

2.3 LASAL CLASS 2 File Types .................................................................... 39

2.3.1 Project Files .................................................................................... 39 2.3.2 Source Code Files .......................................................................... 39

Page 2: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Page 2 Version 5.0

2.3.3 Project Administration File.............................................................. 40 2.3.4 Temporary Files.............................................................................. 41 2.3.5 Text File .......................................................................................... 41

3 Introduction to Object Orientation ......................................... 42

3.1 OOP Basics (Object Oriented Programming) ....................................... 42 3.1.1 Important Concepts in OOP ........................................................... 43 3.1.2 Advantages of OOP........................................................................ 46

3.2 OOP in LASAL CLASS 2.......................................................................... 47

3.2.1 Classes and Objects in LASAL CLASS 2....................................... 47 3.2.2 Class Definitions ............................................................................. 56 3.2.3 Multitask System............................................................................. 58 3.2.4 Assigning a CyWork Task .............................................................. 60 3.2.5 Basic Information on Method Types (Global, Private, Virtual Global) ...................................................... 62 3.2.6 Standard Methods .......................................................................... 64

4 Structured Text Language Basics with LASAL CLASS 2 ... 70

4.1 Basic Syntax in Structured Text............................................................. 70 4.1.1 The Semicolon................................................................................ 70 4.1.2 Upper and Lower Case Writing ...................................................... 71 4.1.3 Program Design and Structure ....................................................... 72 4.1.4 Commentary ................................................................................... 74 4.1.5 Commentary in the Program Code................................................. 75

4.2 Number Systems...................................................................................... 76

4.3 Variables and Data Types ....................................................................... 79

4.3.1 Defining Variables........................................................................... 79 4.3.2 Local Variables in LASAL CLASS 2 ............................................... 79 4.3.3 Private Variables in LASAL CLASS 2............................................. 80 4.3.4 Description of variables .................................................................. 80 4.3.5 Data Types ..................................................................................... 81 4.3.6 Special Variable Forms................................................................... 84

4.4 Operators .................................................................................................. 87

4.4.1 Comparison Operators ................................................................... 87 4.4.2 Arithmetic Operators....................................................................... 87

Page 3: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Version 5.0 Page 3

4.4.3 Assignment Operators .................................................................... 88 4.4.4 Bit wise Operators .......................................................................... 88 4.4.5 Logic Operators .............................................................................. 89 4.4.6 Example: Incrementing a Server (Count up) .................................. 90 4.4.7 Online Settings with TCP/IP ........................................................... 93 4.4.8 Read and Write Methods of Servers ............................................ 101 4.4.9 Connecting Clients and Servers ................................................... 113

4.5 Instructions.............................................................................................115

4.5.1 The if-instruction ........................................................................... 115

4.6 Automatically placing Read and Write methods ................................131

4.7 LASAL CLASS 2 Library........................................................................135 4.7.1 Overview of the LASAL CLASS 2 Library..................................... 135 4.7.2 Importing Classes ......................................................................... 138 4.7.3 Introduction to Hardware Class Principles.................................... 140 4.7.4 Ram Class Applications................................................................ 145 4.7.5 Bit Operator Applications.............................................................. 150 4.7.6 The Case Instruction..................................................................... 155 4.7.7 Network Overlapping Object Connections.................................... 167

4.8 Topical Exercises...................................................................................174

4.8.1 Conveyor Belt Project ................................................................... 174 4.8.2 Traffic Light Poject ........................................................................ 176 4.8.3 Run light........................................................................................ 177

4.9 Program Loops.......................................................................................178

4.9.1 The For-Loop ................................................................................ 178 4.9.2 The while-Loop ............................................................................. 178 4.9.3 The Repeat-Loop.......................................................................... 179 4.9.4 Interrupt instructions for Loops ..................................................... 179

4.10 Data Fields ..............................................................................................181

4.10.1 Declaration of an Array................................................................. 181 4.10.2 Accessing Array Elements............................................................ 182 4.10.3 Initialization of an Array ................................................................ 183 4.10.4 Memory Map of an Array .............................................................. 183

4.11 Topical Exercises...................................................................................189

4.11.1 Search .......................................................................................... 189 4.11.2 Multidimensional Array ................................................................. 190

Page 4: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Page 4 Version 5.0

4.12 Additional Exercise Examples..............................................................195

4.12.1 Lotto Generator............................................................................. 195

4.13 LASAL CLASS 2 Operating System Variables....................................196 4.13.1 The Operating System Variable _Firstscan and ops.tAbsolute.... 196 4.13.2 _Firstscan and Ops.tAbsolute Application.................................... 198

4.14 Topical Exercises...................................................................................205

4.14.1 Delay Off Switch ........................................................................... 205 4.14.2 On/Off Delay Switch ..................................................................... 206 4.14.3 Filter .............................................................................................. 207

5 Classes and Objects in LASAL CLASS 2 ............................ 208

5.1 Methods of a Class ................................................................................208 5.1.1 The Standard Methods of a Class ................................................ 208 5.1.2 The Constructor in a Class ........................................................... 208 5.1.3 Init-Method of a Class................................................................... 209 5.1.4 The CyWork, RtWork and Background Methods ......................... 210 5.1.5 Start Up Phase (constructor, Init,...) ............................................. 212 5.1.6 Transfer and Return Values of a Method ..................................... 213 5.1.7 Calling Methods Over an Object Channel .................................... 224 5.1.8 Overwriting the Read and Write Methods of a Server.................. 229

5.2 Complex Objects....................................................................................236

5.3 Creating Complex Objects ....................................................................237

5.3.1 Virtual Methods............................................................................. 247 5.3.2 Derivation of Classes and Overwriting Methods .......................... 247

5.4 Topical Exercises...................................................................................259

5.4.1 Simple Signal Generator .............................................................. 259 6 Additional Components of Structured Text Programming 260

6.1 Working with Pointers ...........................................................................260 6.1.1 What is a pointer?......................................................................... 260 6.1.2 Definition of a Pointer ................................................................... 260 6.1.3 Important Instructions for Working with Pointers.......................... 261 6.1.4 Conversion and Casting of Type .................................................. 266 6.1.5 Transferring a pointer to a Method ............................................... 272

Page 5: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Version 5.0 Page 5

6.1.6 Using a Pointer as the Return Parameter of a Method ................ 279 6.1.7 Summary ...................................................................................... 285

6.2 Topical Exercises...................................................................................285

6.2.1 Pointer Field.................................................................................. 285 6.2.2 Pointer-Copy................................................................................. 286

6.3 Operating System (OS) Functions .......................................................287

6.3.1 OS Classes in the Library............................................................. 287 6.3.2 Linking and Applying OS Classes ................................................ 287 6.3.3 Using _StdLib Operations............................................................. 289 6.3.4 Using _FileSys Operations ........................................................... 304

6.4 Working with Tables ..............................................................................316

6.4.1 What are tables used for? ............................................................ 316 6.4.2 Important Information over Tables................................................ 316 6.4.3 Syntax for Text and Numbers in Tables ....................................... 316 6.4.4 Creating Tables in a Class ........................................................... 318 6.4.5 Tables Containing Text................................................................. 319 6.4.6 Tables Containing Numbers or Constants.................................... 326 6.4.7 STRING processing via the SIGMATEK classes String and StringRAM ............................................................................. 329

6.5 Pre-Processor Instructions...................................................................333

6.5.1 General Notes............................................................................... 333 6.5.2 Predefined Constants ................................................................... 333 6.5.3 Available Pre Processor Instructions............................................ 339 6.5.4 Pragma Instructions...................................................................... 344 6.5.5 Include Instruction......................................................................... 357

6.6 Linking Header Files..............................................................................359

6.6.1 When and Why Header Files are Used........................................ 359 6.6.2 The Difference Between Class-Oriented and Global Header Files ...................................................................... 359 6.6.3 Class-Oriented Header Files ........................................................ 360 6.6.4 Global Header Files ...................................................................... 364

7 Instruction List Programming .............................................. 368

7.1 Advantages of an Instruction List Program ........................................368

7.2 Principle Construction of Memory .......................................................368

Page 6: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Page 6 Version 5.0

7.3 The Most Important Information Concerning a CPU ..........................370

7.3.1 Universal Registers....................................................................... 371 7.3.2 2 Index Registers and 2 Pointer Registers ................................... 371 7.3.3 Segment Register ......................................................................... 372 7.3.4 Special Register............................................................................ 373

7.4 Instruction List Programming in LASAL CLASS 2 .............................374

7.5 Important Information Over the Stack .................................................375

7.6 Instruction Groups for Programming with IL......................................376

7.6.1 Data Transfer Instructions ............................................................ 376 7.6.2 Logic Instructions.......................................................................... 377 7.6.3 Comparison Instructions............................................................... 379 7.6.4 Shift Instructions ........................................................................... 380 7.6.5 Jump Instructions.......................................................................... 381 7.6.6 Arithmetic Instructions .................................................................. 383 7.6.7 Status Register Manipulation........................................................ 383 7.6.8 Special Instructions....................................................................... 384

7.7 Example Applications in SL..................................................................385

7.7.1 Creating an IL Method .................................................................. 385

7.8 Topical Exercises...................................................................................391 7.8.1 Arithmetic Operation..................................................................... 391 7.8.2 Arithmetic Operation..................................................................... 392 7.8.3 Jump Points and Loops in AWL ................................................... 393 7.8.4 Method Calls and Shift Instructions in IL ...................................... 401

7.9 Topical Exercises...................................................................................407

7.9.1 Pump Work ................................................................................... 407 7.9.2 Read and Write Methods for Clients in IL..................................... 408 7.9.3 Calling and Reading Tables in IL.................................................. 413

8 Trouble Shooting................................................................... 418

8.1 Debugging Programs.............................................................................418 8.1.1 What is Debugging ....................................................................... 418 8.1.2 General Information on Debugging .............................................. 418 8.1.3 Debugging of a Program............................................................... 419 8.1.4 AWL-Trigger ................................................................................. 431 8.1.5 Debugging with Conditional Breakpoints...................................... 432

Page 7: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Version 5.0 Page 7

8.1.6 Debugging with Data Breakpoints ................................................ 438

8.2 Compiler Errors......................................................................................443

8.2.1 Error Message: Different types..................................................... 444 8.2.2 Error Message: Undefined function .............................................. 445 8.2.3 Error Message: Value ’. . .’ out of range....................................... 446 8.2.4 Error Message: Missing ’END_IF’ instead of ’END_FUNCTION’.447

8.3 General Information Over the Status Display .....................................448

8.4 Examples of Error Diagnosis................................................................449

8.4.1 The Access Exception Error Message ......................................... 449 8.4.2 The Division Error Message ......................................................... 459 8.4.3 The Run Time Error Message ...................................................... 464

9 Contact Plan (COP) in LASAL CLASS 2 .............................. 473

9.1 What is a contact plan?.........................................................................473

9.2 Fundamentals for creating a contact plan...........................................473

9.3 Contact Plan Tools.................................................................................482 9.3.1 Contact Types............................................................................... 482

9.4 Coil Types ...............................................................................................485

9.4.1 Additional Contact Plan Tools ...................................................... 489

9.5 Important Display Modes and/or Settings...........................................491 9.5.1 Switch Status Display in the Contact Plan ................................... 491 9.5.2 Class Properties with a Contact Plan ........................................... 492 9.5.3 Inputs and/or Outputs as Alarm displays...................................... 493 9.5.4 Application of User-Created Objects in a Contact Plan................ 494

10 Using C-Files.......................................................................... 499

10.1 Application..............................................................................................499

10.2 Important details when using C-Files ..................................................499

10.3 Creating and Linking a C-File in LASAL CLASS 2..............................501

Page 8: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTENTS

Page 8 Version 5.0

11 Scripting (Batchfile – Python) .............................................. 509

11.1 What is Scripting....................................................................................509

11.2 Introduction to Python...........................................................................509

11.3 LASAL CLASS 2 Commands ................................................................510 11.3.1 Description of Script Instructions .................................................. 520

12 Online with the Control ......................................................... 525

12.1 Introduction ............................................................................................525

12.2 Contents..................................................................................................525

12.3 Basics......................................................................................................526

12.4 Connection Types ..................................................................................529 12.4.1 Connection Over the Serial Interface ........................................... 530 12.4.2 Connecting Over the CAN Bus..................................................... 531 12.4.3 Connecting Over TCP/IP .............................................................. 535 12.4.4 AUTOEXEC.LSL........................................................................... 539 12.4.5 Connecting via Modem................................................................. 544

12.5 LARS........................................................................................................553

13 FAQ’s...................................................................................... 556

13.1 Overview .................................................................................................556

Page 9: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE LASAL 2 CONCEPT

Version 5.0 Page 9

1 The LASAL 2 Concept 1.1 Information about the manual 1.1.1 Construction and scope of this manual This training manual was created to introduce the reader to the basics of the LASAL CLASS 2 project tool as well as its functions and features. The material in this manual was structured to enable successful self-study. Numerous examples are used to help the user learn quickly and acquire a variety of knowledge. 1.1.2 Tips for working in LASAL CLASS 2 To make working with the LASAL class 2 training manual simpler and more comfortable, different symbols were included. These symbols should simplify navigation through the manual as well as supply additional information, emphasize important sections and intro-duce examples. The meanings of the four symbols are as follows:

Attention When you see this symbol, the lines following are Very Important and should be given your complete attention. It is recommended that the paragraph next to this symbol be thoroughly read.

Tip The pencil is the symbol for a helpful tip for how something can be faster or better done.

Example This symbol indicates the beginning of an example

FAQ This symbol shows the answer to a frequently asked question.

Page 10: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE LASAL 2 CONCEPT

Page 10 Version 5.0

1.1.3 Notes on example programs The examples in the LASAL class 2 training manual are categorized in 2 groups: Examples; whose solutions (from creation of the project to loading it to the target sys-tem) are fully explained and illustrated. In the first chapters, simple examples are worked through to enable the user to easier apply the concepts. In addition, the first examples build on one another to improve the interaction and knowledge of LASAL 2 gradually. Reoccurring basic procedures are also intentionally re-explained.

Exercise examples on CD are referenced in this manual. At the end of each chapter, exercise examples are listed that are available on CD and worked through completely. These can be used for practice purposes in order to increase learning success.

The symbol indicates that an exercise example is available on CD. 1.2 What is LASAL? LASAL is a user program package for creating projects and visualization for machine proc-esses. Using the LASAL software tools, the development time can be significantly reduced and machine concepts can be realized simply and quickly. 1.2.1 All in one The LASAL package encompasses all functions required for the creation of automated tasks.

Programming tool to create application projects

Software tool for control of axles

Visualization tool for graphic terminals

Visualization tool for text terminals

With LASAL class 2, all programs for machine process control are prepared. Therefore the complete SIGMTEK product palette such as CPUs, terminals and industrial PCs are sup-ported. A change of the target platform (within the SIGMATEK product line) is possible at any time with which little or no changes required in the LASAL CLASS 2 project.

Page 11: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE LASAL 2 CONCEPT

Version 5.0 Page 11

1.3 Why LASAL CLASS 2? 1.3.1 Object Oriented Programming With LASAL CLASS 2 Through the Object Oriented Programming (OOP) used in LASAL CLASS 2, projects can be created safely and easily. With the placement and visualization of objects in a network, the interaction between the individual objects is more clear and easier to understand. The reusability and modularity of the classes can also reduce the total software costs. Further-more, the software in LASAL CLASS 2 is easier and more efficiently tested. Defined interfaces (connections) that can send and receive messages are available for the exchange of information. In order to easier understand classes and objects: Programs are defined under classes; objects actively work with the program of a class. 1.3.2 Advantages Over Normal Programming The advantage of creating programs with LASAL CLASS 2 is that programming is signifi-cantly clearer and more efficient. Through the use of classes, functions can be tested as an independent unit. Therefore, the programming is easier to orient than programs written in a long chain of calls and instructions. The multiple testing of several user programs is unnecessary and saves development time. Functioning classes can be reused as needed and controlled over their connections after being tested only once. Through the classes in LASAL CLASS 2, the reusability of the software increases. 1.3.3 Open Data Interface For individual data exchange using external programs, an OPC server (OLE for Process Control) with a standard interface is available. It is then possible for the use to link process data in visualization, control system or in Excel and generate individual evaluations, for example.

Page 12: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE LASAL 2 CONCEPT

Page 12 Version 5.0

1.3.4 Project Creation Through Scripting With scripting, projects can be generated automatically. Here, pre-assembled classes from a library and/or entire object networks from several projects can be joined in a new project. Through the automatic background generation, the possibility exists for the user to imple-ment further operations. 1.3.5 LASAL CLASS 2 Library LASAL CLASS 2 has a library collection of components, which is expanded regularly. Com-ponents imported from the library can be linked in the project and used to implement appli-cations. The library contains such components as memory, time and date, controllers, logic components, triggers and much more. The possibility also exists to create and centrally manage an individual library. Should a change in a library component be necessary, it must be made only once in the library. The user can then decide whether to update the library manually or let it be updated automati-cally. 1.3.6 Multilanguage Programming Tool In LASAL CLASS 2, applications can be created in different program languages: Structured Text (ST), Instruction list (AWL), Sequential Function Chart (Interpreter) and in C 1.3.7 Multitasking System Multitasking is the ability of an operating system or software to execute several tasks simul-taneously meaning various processes are alternated in such short intervals that it seems they are implemented at the same time. The LASAL operating system is a multitasking capable operating system, which is especial optimal for minimum reactions times. The most frequently used method is currently the preemptive multitasking, by which the operating system controls the execution of individual processes and stops a process after a specific execution time in support of other processes. The preemptive task is a form of multitasking, with which the operating system maintains control (priority) over the tasks to be executed. The operating system can then allocate these tasks to individual applications or cancel them.

Page 13: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 13

2 The Design Environment 2.1 Hard and Software Requirements To ensure fault free operation in LASAL CLASS 2, your PC should meet the minimum hard and software requirements: Pentium CPU 128 MB RAM A minimum of 30 MB of free hard drive space Connections for online communication:

• Serial interface • Parallel interface • Network interface

LASAL CLASS 2 is supported by the following operating systems: Win98, Win98SE WinME WinNT 4.0 with Service Pack 6 Win2000 WinXP Windows VISTA

LASAL CLASS 2 runs with the Internet Explorer version 5.5 and higher.

Page 14: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 14 Version 5.0

2.2 The LASAL CLASS 2 Design Environment 2.2.1 The Design Surface Environment At start up of LASAL CLASS 2, the surface should appear as follows:

If a window must be changed in size or shifted while working in LASAL CLASS 2, the standard layout can be restored by selecting View, Layout, Reset Layout in the menu list.

Page 15: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 15

2.2.2 Layout It's possible in LASAL CLASS 2 to store different layouts of the program interface and recall it later via a list menu. That means, on the LASAL CLASS 2 program interface windows can be shifted, positioned and stored as desired. For this purpose open the Layout Manager through selecting View, Layout, Layout Manager… in the menu bar:

Click on to define a new layout. Through selecting Capture Layout the current layout of the LASAL CLASS 2 program interface (the current positions of the windows) is stored with the defined name (here: Layout_01). Under Description: a statement to the respec-tive layout can be insert.

With the symbols the stored layouts can be changed in order as desired. The se-

lected layout can be deleted with . In the Layout Manager symbol bar the desired layout can be selected.

A further possibility to change the layout gives the View, Graphical User Interface menu. With Lock Toolbar Moving the shifting of the tool bars can be prevented. The shifting of windows can be avoided with Lock Pane Moving. Under Theme the look of the program interface can be changed corresponding to the selected menu entry.

Page 16: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 16 Version 5.0

2.2.3 Menu Bar The menu bar in LASAL CLASS 2 contains 9 menus with various LASAL CLASS 2 instruc-tions and applications. On the following pages, all 9 menus are illustrated in sequence. There are so-called Shortcuts for several instructions listed to the right in the corresponding menu window. Using these keystroke combinations, the instruction can be called without having to select the menu. File

Edit

Edit, Bookmark

NetEdit

Active only with an opened network window!

Page 17: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 17

View

View, Trees

View, Toolbars

View, Layout

Page 18: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 18 Version 5.0

View, Graphical User Interface

View, Graphical User Interface, Theme

Project

Build

Page 19: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 19

Debug

Debug, Step & Instructionpointer

Debug, Breakpoint(s)

Debug, Settings

Debug, Extras

Debug, Tools

Page 20: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 20 Version 5.0

Debug, Interpreter

Tools

Tools, Support

Tools, Scripts

Page 21: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 21

Tools, Cleanup

Tools, EasyCase Import

Window

Help

Page 22: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 22 Version 5.0

2.2.4 Tools/Symbol Bars (Overview) This overview shows all toolbars available in LASAL Class; this helps with navigation through LASAL CLASS 2. There are 6 toolbars, which can be blended in and out under the menu item View Toolbars. Each toolbar contains symbols to call their various instructions. Further short cuts are given for several of the instructions that can be called using these symbols. In the following tables, the shortcuts are to the right of the corresponding symbol. Standard Toolbar

Strg+N Create a new project Strg + P Printing

Strg + Shift + O

Open a file Strg + X Cut

Close a file Strg + C Copy

Strg + S Saves a file Strg + V Paste

Strg + O Open a project Strg + Z Undo

Strg + S Save a project Strg + Y Redo

Close the actual project

Page 23: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 23

Net Edit Toolbar

Select item

Zoom

Hand Tool

Zoom all

Insert Text

Zoom area

Build Toolbar

F9 Compile project changes

Strg+ Scroll+ Caps lock

Abort compilation process

Strg + F9 Compile complete project

Start linking process

Toolbox

Opens the Data Analyzer

Opens the DiasDrive

environment

Opens the Interpreter

environment

Page 24: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 24 Version 5.0

Layout Manager

Shows a list including all stored layouts. Select View, Layout, Layout Manager… from the menu list to save a layout. Debug Toolbar

Alt + F6 Online / Offline AWL Trigger on/off

F6 Download Project

Display all current instruc-tions (Goto instruction pointer)

F7 Start/ Reset

F5 Step Into

F8 Reset

Alt + F5 Step Over

F4 Toggle Breakpoint

Shift+ F5 Step Out

Set conditional break-point

Set actual instruction (set instruction pointer)

Clear all Breakpoints

Page 25: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 25

2.2.5 Project Tree The project tree is normally placed on the right side of the LASAL 2 surface and contains 5 areas with different contents (Lib, File, Global, Net, Class). As can be seen in the illustra-tion below, each of these areas can be selected using tabs to open the respective window.

The Tabs can also be shifted as desired. Simply move the mouse pointer to a tab, press and hold the left mouse button to shift the tab to the de-sired position.

The following pages give an overview of how the individual components in the various pro-ject tree windows are organized. In the course of this manual, the use and application of the individual windows and their contents are explained using examples.

Tabs

Page 26: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 26 Version 5.0

Class The tab, Class, is selected in order to open the Class View window. In this window, the project classes and the corresponding components such as clients, servers or variables are created and managed. With a right click on the project name (here: LearningLASAL2) and then selecting Create Class, a new class (here: Hysterese) can be created. With a right click on the class (here: Hysterese), the context menu is opened. In this menus the individ-ual components can be created.

The illustration above Servers primarily to bring several important con-cepts in LASAL CLASS 2 previously mentioned back to the forefront.

Page 27: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 27

Libraries When the Lib register tab is selected, the Libraries window is opened. Here various librar-ies can be loaded and their classes added. To load a new library open it with a right click on the project name (here: LearningLASAL2) then the context menu and select a library.

To add a class to a project, select it with a right mouse click to open the context menu. You now have 3 possibilities in which to use the selected class:

Page 28: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 28 Version 5.0

Net Selecting the Net tab opens the Networks View window. In this window, a network is cre-ated in which an object of a user created class can be placed as well as those from the SIGMATEK class library. Open the context menu with a right mouse click on the project name and select New Network to create a new network.

Next, double click on the network itself (here: Network0) to open the network window.

To place a class in the network, switch to the Project Tree and select the tab Classes. Then place the desired class in the network using the Drag& Drop method. The object of the class is also created and placed in the network.

Page 29: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 29

Global Click on the Global tab to open the Global View window and create a list of global types.

Here, only global types are managed. Class related types are created and managed in their respective classes in the Class View window (more information is found under Classes). A class related type is created for a class only and can only be used by the class for which it was created. A global type can be used by all classes in a project.

A click on the + next to a specific type opens the list of the types classified under it. To create a new type, click on either the project name (here: LearningLASAL2) or a desired type and select New Type in the context window. To delete a type, select Delete Type. If the context menu of subordinate type is called using the right mouse button, the position of the selected type can be still be changed in addition to the known entries by selecting Move Up or Move Down.

Page 30: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 30 Version 5.0

File Open the register card, File, for an overview in the File Explorer window of all project data.

To add a new file, right click on the respective folder and select Add File… from the context menu. Header Files Header Files are identified by .h on the end of the file name. Source Files These files are identified by the extensions .st, .c and .cpp. Network Files These files carry the extension .Icn. Object Files File names that end with .lob are object files. Library Files Under library files, the libraries used in the project are listed. The file extension .lcp identi-fies the libraries used in LASAL 2 projects and are linked to the actual project. Changes cannot be made in these files.

Page 31: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 31

Dias Drive Files Dias Drive Files are identified by .xml on the end of the file name. 2.2.6 Status Bar The status bar is located on the lower margin of the LASAL 2 surface and provides infor-mation on the actual process status and displays keyboard instructions.

Page 32: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 32 Version 5.0

2.2.7 Debugger Window The debugger window should be on the bottom of the LASAL CLASS 2 surface. It contains 5 different output windows, which are called using tabs located at the lower left of the de-bugging window. The debugging window contains the following output windows: THIS Watch Register Breakpoints Call Stack

If the debugger window is not visible in the LASAL 2 surface, it can be activated by selecting the View Debugger pane in the menu bar.

Tabs

Page 33: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 33

THIS

The THIS window is used to show all variables, clients and servers of an object. By clicking on the name of an object in the network, the object will be displayed in the debugger win-dow. Watch

To track values from different objects, variables can be place in these windows to view their current values. Simply click on Click to add new and enter the corresponding variable name. The Watch windows can only be used with debugging. Register

This output window is used mainly for debugging Instruction List programs. The Register window allows the process registers to be tracked.

Page 34: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 34 Version 5.0

Breakpoints

In this window, all breakpoints used for debugging are shown in addition to the lines in the program and source code (*.st file). Call Stack

In this window, the program run sequence and the actual program line to be processed is shown.

Page 35: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 35

2.2.8 Output Window The Output Window is located on the lower middle border of the LASAL CLASS 2 surface and contains 4 different output windows. These are called over the tabs located in the lower left of the output window. The output window contains the following output displays: Output Logging Debugger Trace Find Results

Output

The Compiler translates the written code to machine language. If errors or warnings occur, the output window will display them. With a double click on an error message, the compiler will automatically jump to the program line in the code where the error occurred.

Tabs

Page 36: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 36 Version 5.0

Logging

Here, the instruction and actions in LASAL CLASS 2 are logged. Debugger Trace

Here, the Trace Messages sent by the control are shown. Find Results

In this window, the search results of the Find in Files… functions are shown and can be selected under the menu item Edit. With a double click on a search result, the cursor springs to the line in the program code where the desired information is found.

Page 37: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 37

2.2.9 Python Script Window

This represents the python interpreter input window. Here, the Python Instructions can be entered and executed.

Page 38: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 38 Version 5.0

2.2.10 Properties Window The Properties Window is located under the Class View window. This window is used to enter the settings for components in the project tree. The available settings in the properties window vary depending on the selection in the project tree. To display the properties, select the component in the project tree (here: the classes Hysterese in the Class View window).

With the keystroke combination Strg + D one can switch from the project tree to the properties windows. The combination Strg + T returns and changes between the individual registers within the project tree.

Up to this point, the various setting possibilities have not been discussed in depth. During the course of this manual, the individual component setting will be explained more clearly through the use of examples.

Page 39: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 39

2.3 LASAL CLASS 2 File Types The Files used in LASAL CLASS 2 are organized in the following Types: • Project files • Source code files • Project Administration files • Temporary files • Text files 2.3.1 Project Files *.lcp Project files is a list of elements, which are components of the project: Classes and other sources Networks Object files

Project specific settings are also stored in these files (e.g. online connection, compiler set-tings, etc..). The project files format is XML. 2.3.2 Source Code Files *.ST The preferred program language in LASAL is Structured Text (ST). The definitions of this language are explained under the IEC 61131 standard and object oriented language ele-ments were included for LASAL. The source code from LASAL classes are usually saved with the *.ST extension. An ST file can be combined within text programming languages (ST, IL) created by SIGMATEK. If no other language is specified, the functions of an ST file must be programmed in structured text. *.AWL (Instruction List) The Language Instruction List can be used in files with the extension *.AWL. When no other language is specified, the Language Instruction List must be used as the programming language for functions in AWL files. Here, ST and AWL can also be combined in a file

Page 40: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Page 40 Version 5.0

*.IPR Interpreter code is stored in files with the extension *.IPR and is used to define the run sequence of a machine control system. IPR is a LASAL specific programming language *.H The user can link many header files to a project. Afterwards, whether the definitions in the header file are global or accessible only to a particular class can be determined. By linking to a class, the header file is included when the class is copied as long as it’s in the project folder. *.C, *.CPP LASAL also offers the possibility to program functions is C. the support for C contains the compiler, which supplies the outputs in the Common Object File Format (COFF). The COFF is a standard for construction of an OBJ file. A GNU compiler is provided automatically with LASAL. *.lcn In this file, the object networks information (ON) is stored. The user changes this file when graphically editing the file. The network file format is XML. 2.3.3 Project Administration File *.py Commands in the form of Python Scripts can be transmitted to LASAL CLASS 2 with the help of PY files. Using these files, a single project can be generated from several individual projects.

Page 41: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

THE DESIGN ENVIRONMENT

Version 5.0 Page 41

2.3.4 Temporary Files *.lcb LCB files contain binary information so the user doesn’t always have to work with ASCII files and the work in LASAL CLASS 2 is accelerated. LCB files exist for the project as well as for classes and networks. *.lob LASAL object files are created as the output files of a compiler process using an ST for AWL file. They contain the code and debugging information. *.obj This is the output file from a C (C++) compiler. LASAL converts OBJ files to LOB files. These files must correspond to the Common Object File Format (COFF). The COFF is a standard for the construction of an OBJ file. *.ldi This file contains global debug information for debugging a project. *.bin Files of this type are located in the ProjectInternal folder and contain binary and temporary information. 2.3.5 Text File *.txt This file contains the listing of all servers and objects used in a project. Text files are used as a reference file for importing the server to the LSE project for visualization of a variable (maeexp).

Page 42: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 42 Version 5.0

3 Introduction to Object Orientation 3.1 OOP Basics (Object Oriented Programming) To begin with OOP, it’s best to consider the read world. The real world consists of objects. For example, houses, machines, people, plants and animals, etc.

Each of these objects (sports car, truck, bus) has certain characteristics. The user, how-ever, doesn’t have to be familiar with all of them in order to operate the respective vehicle. It is enough, at first, to be familiar only with the outer components of an object and to know what task it performs. To understand the world externally, one must be familiar with the functions of various objects and know how they communicate. It would seem logical then, to apply the object oriented concept to programs. A program is comprised of objects that are independent parts responsible for specific tasks. Each object contains specific information, which represents its current condition. This data is represented using variables. The tasks and actions of an object are represented by func-tions. These are described in OOP as methods. One distinguishes: - The internal construction of an object - The externally visible properties (connections) of an object as well as the external func-

tion It is only necessary to understand the total function of an object last. How an object per-forms its tasks is an internal issue.

Page 43: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 43

3.1.1 Important Concepts in OOP In this section, the most important concepts that an object oriented program user should know in OOP are discussed. Classes A Class represents a user defined data type and is the most significant language element of object-oriented programming. A class is the description of an object. When developing classes, the following questions are raised: what is needed to describe an object exactly and which properties must the object exhibits? What does it do? To meet these requirements, classes with status describing properties (attributes) and methods are provided. Objects An object in the world of object-oriented concepts is nothing more than a variable of the type from a specific class. It is practically a realization of a class description, which pos-sesses attributes and methods. In order to work with an object in program, it must be instantiated. Instantiation A specific object is generated with the instantiation of a class. That means, for a class to be usable, an object of this class must be created. Each object is an instance of a specific class. In OOP, a class has a number of objects (Copies, Instances) with the same attributes and methods.

Page 44: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 44 Version 5.0

Attributes Each object of a class has the same attributes, but can work with different data for these attributes.

Objects Sports car Truck Bus Attributes: Max. Speed 280 km/h 140 km/h 120 km/h Color Red Grey Orange Wheels 4 8 6 Length 3,5 m 8,4 m 10,2 m Methods Methods execute actions and status changes of objects. Methods specify the “behavior” of a class object. Data Encapsulation Objects cannot read or change the internal status of other objects. Only the method of an object should be able to access its own internal status. The access of an object externally is only possible using public methods (global methods). A class therefore, insulates data from direct access.

Page 45: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 45

Inheritance Objects, which are by nature from different sorts, can have common features. Imagine, for example, that you must implement three classes (students, workers, pensioners) in a pro-ject. All classes, among other things, have the following properties in common: - Gender - Address - Nationality - Place of birth It seems logical to define a single class, People, which contains only the common charac-teristics. A student would be a special type from the class “people” as well as workers and pensioners. Classes can also be defined based on classes already available. A class, whose properties are available to other classes, is identified as a Base Class. A class the takes on the prop-erties of a base class is identified as a Derived Classes. Derived classes take on the prop-erties and methods of the base class but expand the inherited characteristics with type specific properties. The advantages of inheritance are: • The reduction of program code as the common properties and methods must be imple-

mented once in the base class. • Common properties of classes only exist in one place in the program and must only be

tested or changed once if required. Polymorphism Polymorphism means that different classes can have a method with the same name but different contents. Polymorphism is implemented since an object can change an inherited method to react differently. This process is also known as overwriting a method.

Page 46: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 46 Version 5.0

3.1.2 Advantages of OOP The reusability of classes through importation from the library to a new project.

Defined interfaces of a class determine which data an object should process.

Simply expandability of classes through reusability => derivation => inheritance.

Simplified programming. It is easier imagine an object with properties, functions and

interfaces than working with a long continuous chain of instructions.

Page 47: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 47

3.2 OOP in LASAL CLASS 2 3.2.1 Classes and Objects in LASAL CLASS 2 On the following pages, the creation of Classes and Objects are shown using an example. To actually create classes and objects, a new project must be started. Select File, New Project... in the Menu Bar.

Page 48: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 48 Version 5.0

This opens the Create New Project window.

Enter a project name under Project Name: (here: Counter) and select the path in which the project will be saved under Location:.

With the entry of a project name under Project Name:, a destination folder is entered under Location: with the same name as the project. The path can also be determined as desired by the user.

If the entered directory already exists, a window appears to decide weather the existing directory should be overwritten (Ja) or not (Nein).

Page 49: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 49

In the Class View window of the project tree, the created project can be seen. Click on the project name (here: Counter) with the right mouse button to activate the context menu and select Create Class to create a new class.

Assign a name to your class (here: CounterClass) and confirm it with Enter.

Select Add Folder in the context menu to create user defined folders in order to centralize classes.

Page 50: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 50 Version 5.0

Select the tab Net in the project tree to open the Network View window.

Open the context menu with a right mouse click on the project name and select New Net-work to create a new object network.

Assign a name (here: ObjectNetwork) and confirm with Enter.

Also in the Network View window folders can be created by selecting Add Folder in the context menu of the project.

Page 51: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 51

With the right mouse button, click on the network name and select Edit from the context menu to open the network in the network window.

The process described above can be executed faster and easier by sim-ply double clicking on the network name or marking it and pressing the Enter button.

The network window now appears (here: ObjectNetwork).

Page 52: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 52 Version 5.0

Next, return to the Class View window and select the tab, Class. To create an object of this class and place it in the network, select the class with the left mouse button and place it in the network using the Drag & Drop method as shown below.

As can be seen, the object is now placed in the object network. An object name must now be assigned (here: CountObj) and confirmed with the Enter button. To later change the name of an object, click on the selected object name with a delayed double click or press the F2 button.

Page 53: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 53

The illustration below shows the object of the class CounterClass placed in the object network.

The creation of the class automatically assigns the server, ClassSvr (also shown below). This server is the interface of a class.

Next, select the object name (here: CountObj) in the network to open the Properties win-dow. Under comment, the user can include a comment (here: with Object of my class) the object.

Class name

Object name

Class name

Object name

Page 54: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 54 Version 5.0

To display the commentary, place the mouse pointer on the object in the network for short time. A bubble help window with the object name and the commentary will appear.

In a LASAL 2 project, the name of a class can only be assigned once. Several objects of a class, however, can be placed in one or more object networks. Every object must in turn have its own name. That also applies to objects of classes with different names.

Page 55: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 55

You’re sure to have noticed the star next to the network name.

Now is the time to save the project.

For this, press the button or select File, Save Project in the menu bar.

When the star is no longer present next to the network name, the project has been saved.

Page 56: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 56 Version 5.0

3.2.2 Class Definitions The Client-Server Model An essential characteristic of LASAL Class2 in the object oriented programming with graphic representation. In a Client-Server model, a server provides specific services to other clients in the net-work. Clients can also call these services as well as transfer services to a server. A class can have several clients or servers. A client of a class is always located on the left side and a server on the right.

Objects placed and connected in an object network can exchange and process data. An overview of the project, data traffic and interfaces are obtained at a glance.

Clients of the classServer of the class

Page 57: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 57

The function of the Client-server model in LASAL CLASS 2 is explained with the following schematic diagram:

The object Obj1 has the server provide, which contains 3 spheres. In the object, Obj2, two clients (pick up und deliver) are defined. The pick up client collects the three spheres from the server provide. The Client, pick up, in the object, obj2, now contains 3 spheres also. Obj2 is assigned the task of subtracting a sphere from the obtained value (3 spheres). The result (2 spheres), are then transferred to the server receive of obj3 from the Client de-liver. Server => Provides and receives information. Client => Collects and transfers Information.

Page 58: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 58 Version 5.0

3.2.3 Multitask System The SIGMATEK operating system for LASAL is a multitasking-capable operating system, which is essential in control technology. The operating system is responsible for processing various tasks from the objects assigned by the user. In addition, it has to ensure that all assigned objects are processed within their specified period. In the following graphic, the priority of the different tasks is clearly shown. Real time tasks have the highest priority. Cyclic tasks are processed next. With the remaining time, the operating system calls the background tasks. Short description of the graphic: Rt => Real time work Cy => Cyclic work Bg => Background

This cycle is dependant on the control and normally averages 1ms for industrial PCs and 2ms for processor modules. According to this diagram, Rt1, Cy1 and Cy2 are processed every cycle while Rt2, Cy3 and Cy4 are processed every second cycle.

Page 59: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 59

The next graphic shows when a process, in the event a task with a long running program, must be interrupted. The task Cy5, can require more time when copying data. Here the task is interrupted and the Rt1 task is processed. Cy5 is then continued after Rt1 is complete.

Page 60: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 60 Version 5.0

3.2.4 Assigning a CyWork Task To set a CyWork Task, first select the class name in the Class View window to open the class Properties window then set CyclicTask to true. The CyclicTask is now activated.

As soon as CyclicTask is set to true the DefaultCyclic field appears. Here you can define a default Cyclic time.

The value defined under DefaultCyclic is used for each placed object of the class. If no value is set here (off), at least directly at the placed object of the class a CyclicTime has to be defined! If objects of a class are al-ready placed in the network (as in our case) before a DefaultCyclic value is defined here, these objects are uninfluenced of the set value! All objects placed after a DefaultCyclic value has been set, accept this value as CyclicTime.

Page 61: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 61

Next, switch to the object network window and select the object name (here: CountObj) to open the object properties window. Then, under CyclicTime, set the cycle time (here: 500) for the object. As can be seen in the following illustration, the color of the object header in the network has changed with the setting of the cyclic time.

Save the project.

Press the button or select File, Save Project in the menu bar.

Page 62: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 62 Version 5.0

3.2.5 Basic Information on Method Types (Global, Private, Virtual

Global) To strengthen the modularity of a class, methods can be defined for an explicit area of validity. Methods can be defined with the properties public (global and/of virtual global) or private (private). Private Methods The methods defined as private can only be accessed within the class in which it’s defined. That means, private methods are valid only with the class and cannot be called by another class. A method in a class assigned in as private, has the function header shown below and can appear in the program code as follows: FUNCTION Regulator::Heat END_FUNCTION The name Regulator is the class name in this case and Heat is the name of the method. Global Method Global methods of a class are valid with in the entire class and can also be called by other classes. A global method of a class can appear in the program code editor as follows: FUNCTION GLOBAL Regulator::Cool END_FUNCTION Here, the class name is Regulator and Cool is the name of the Method.

Page 63: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 63

Virtual Global Method Virtual global methods of a class are valid with in the entire class and can also be called by other classes. A virtual global method of a class can appear in the program code editor as follows: FUNCTION VIRTUAL GLOBAL Regulator::SetRegulator END_FUNCTION The name Regulator is again the class name and SetRegulator is the method name. Virtual global methods can be overwritten in derived class. With virtual methods, the methods of the base or derived class are called using a methods table, but only if they were overwritten.

Page 64: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 64 Version 5.0

3.2.6 Standard Methods The term, method, is another description for an operation and/or function. The description method is the object-oriented name for a function. A method is always an element of a class. The following standard methods are available in a class: Init, CyWork, RtWork and Background, Constructor

The CyWork method is inactive in this menu, because it has been acti-vated already in the properties window of the CounterClass class (CyclicTask = true)!

The Constructor standard method is only assigned for one class and therefore can only be created as private method!

Page 65: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 65

Init The Init method can be used for initialization. At this point, connections to other objects exist so data from other objects can be accessed for the first time. This method is called 12 times by the operating system. If several objects in a project are called by the operating system, the init method will call the first object then the second and so on. The init method of each object is called 12 times. When the init method process in complete (12 times), the RtWork, CyWork or background tasks are called cyclically.

The standard constructor of a class is always called once. If an additional constructor is assigned for the initialization of a class, it will also be called only once. Afterwards, the Init method is called 12 times. Project oriented means: In the start up phase, the control will call all constructors first. When this process is complete then all Init methods are executed in sequence 12 times each.

Page 66: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 66 Version 5.0

CyWork (Cyclic Work => Cyclic time) Every Cywork method in the object of a class is called by the operating system when a cycle time is set to a value greater than 0. The priority of the Cywork method lies between the Rtwork and Background methods.

Application of the Cyclic work method: E.g. process control for different time periods.

Open now with a click on the + in front of the class name, in front of Methods and in front of Global the Global Methods folder to display the already created CyWork method in the project tree.

To display the program code of this method in the program code editor, open the context menu with a right click on CyWork and select Edit Method.

Page 67: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 67

The now described process can be done faster and easier by double clicking on CyWork or simply marking CyWork and pushing the Enter key.

Now the program code of the CyWork method is displayed in the program code editor:

Page 68: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Page 68 Version 5.0

RtWork (Realtime Work => Realtime) Every RtWork method in an object of a class is called by the operating system when the real time of the object is set to a value greater than 0. This method has the highest priority and is processed before the CyWork and Background tasks.

Application of the Realtime Work method: E.g. Axle controls.

Background Every Background method in the object of a class is called by the operating system when the background time is set to a value greater than 0. The Background method has the low-est priority in comparison to the RtWork and CyWork methods.

Application of the Background Method: E.g.: To query an export process or execute visualization tasks.

Page 69: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INTRODUCTION TO OBJECT ORIENTATION

Version 5.0 Page 69

Constructor This is a special method of a class, which is responsible for the initialization all properties of an object. The constructor is called by the operating system only once per object, directly following the generation of the memory area for data. This method is used to initialize private variables in a class. That means only variables that affect the class can be initialized in the constructor. No operations can be run in the constructor that can affect another object.

The constructor name of a class is always the same as the class itself.

Up to this point, no connection to other objects exists. Therefore no other object can be accessed in the constructor.

Page 70: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 70 Version 5.0

4 Structured Text Language Basics with LASAL CLASS 2

4.1 Basic Syntax in Structured Text 4.1.1 The Semicolon Programs consist of a number of instructions, which are executed in sequence. Instructions specify what the program has to do and how they must occur as well as the type. MaximalTemperature := 65; Each instruction requires a marking that signals the end of the instruction. In Structured Text, a semicolon is used. If the semicolon is forgotten, compiler warning occurs. Because an instruction is clearly ended by a semicolon, several instructions can be written in a line. Conversely, instructions can be divided over several lines without a compiler prob-lem. Because the program code would be difficult to read, the following writing technique should be avoided: MaximalTemperature := 65; MinimalTemperature := 10;

Page 71: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 71

4.1.2 Upper and Lower Case Writing With Structured Text programming in LASAL CLASS 2, no difference is made between upper and lower case letters (not case sensitive). It is recommended however, to use the same writing technique as the definition for clients, servers, variables or methods in the program code. When these components are placed in the program code from the project tree using the drag and drop method, they are identically written. In keeping with the upper and lower case writing style, the clarity and readability of the program increases.

Page 72: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 72 Version 5.0

4.1.3 Program Design and Structure The program structure in LASAL CLASS 2 is class oriented, whereas the classes are fur-ther divided (or can be divided) into methods. Each method can contain any number of instructions. The program code in a method is always written between FUNCTION and End_FUNCTION. The following illustration shows a method without transfer parameters. FUNCTION ClassName::NewMethode Program code END_FUNCTION If a method has transfer and return parameters, the program code is written between END_VAR and END_FUNCTION: FUNCTION ClassName::NewMethode VAR_INPUT Param1 : DINT; Param2 : DINT; END_VAR VAR_OUTPUT OutParam : DINT; END_VAR

Program code END_FUNCTION

Page 73: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 73

The program code in a method should be designed in a structured and continuous manner to create a clear and easily read program. The following pseudo program code shows two programs with identical functions. It is not necessary to understand the meaning of the program to recognize which writing technique is more clearly formed.

// clearly arranged program code

// not recommended syntax

Page 74: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 74 Version 5.0

4.1.4 Commentary One should not be too generous with commentary. Commentary helps the user to better understand the program code. You not only do others a favor but yourself as well when dealing with your code. What characterizes this variable, which function is behind each method? Spare yourself and others the unnecessary and time-consuming search for the answer. It is possible to write commentary in the program code to serve as information for the pro-grammer, which is not seen by the compiler. This information must be commented out as follows: There are two possibilities: // All text in a line following these characters is commentary. (* *) All text written between these characters (also over several lines) is irrelevant to the func-tion of the program.

Always try to comment on the meaning of a program line instead of syn-tax!

Page 75: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 75

4.1.5 Commentary in the Program Code

The following example shows how commentary is written correctly in the program code. Here the CyWork method created earlier is used.

Open the program code editor. As shown in the next illustration, commentary was added between END_VAR and state := READY;, which is shown in green contrary to the program code. The commentary can be included as desired following // or between (* *).

The project should now be saved.

To save, press the button or select File, Save in the Menu Bar.

Page 76: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 76 Version 5.0

4.2 Number Systems When creating a program, various number systems are used. The reason for using different number systems is partly due to the process by which the computer searches (logic 0 or 1) and also for the clarity and understandability of the program. The number systems relevant to the software design are the decimal, hexadecimal and binary systems. Decimal Number System The decimal number system is the widest and most commonly known system. In order to make the other number systems easier to understand, the basics of the decimal number system must be reviewed. The decimal number system has 10 different characters with which different number values are represented. These number characters begin with 0. In the decimal number system, the numbers 0 to 9 can be represented. This scale, how-ever, is not large enough for the required range of numbers. For this reason the values are cascaded. Since the number 5 can also be written as 05, after the number 9 is reached, the 0 is incremented to 1 and the value becomes 10. In higher cascades, when the character set is exhausted, the next cascade is incremented and the previous ones restart at 0. E.g.: 00999 + 1 = 01000. The Value of a cascade is raised by an exponent of 10 from right to left starting at 0.

Denomination: 0 1 2 3 4 5 6 7 8 9

Base: 10

Highest denomi-nation:

9

Place values: 100 = 1, 101 = 10, 102 = 100, etc.

103 102 101 100 Dec 1 2 3 7 = Dec 1237

Page 77: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 77

Binary Number Systems Since the CPU and digital I/Os operate with logic conditions (0 and 1), the binary system is the actual number system used by the computer. The binary number system consists of 0 and 1. The calculation process is the same as with the decimal system, the difference being that only the characters 0 and 1 are utilized. The disadvantage of this system is that larger numbers quickly become long and complex. The advantage, however, is that the individual bits in binary variables can be easily identified as High (1) or Low (0).

Denomination: 0 und 1

Base: 2

Highest denomi-nation:

1

Place values: 20 = 1, 21 = 2, 22 = 4, etc.

210 29 28 27 26 25 24 23 22 21 20 1024 512 256 128 64 32 16 8 4 2 1

Bin 1 0 0 1 1 0 1 0 1 0 1 = Dec 1237 1024 + 128 + 64 + 16 + 4 + 1 = 1237

Page 78: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 78 Version 5.0

Hexadecimal Number System The hexadecimal number system is favored most for the creation of programs because it combines the properties of both previously mentioned number systems. Large binary num-bers have the disadvantage of being complex. As a remedy the hexadecimal system was created. In this system, 4 bits of a binary number are replaced with a hexadecimal charac-ter. Since a 4 bit binary number represents 16 conditions and we only know 10 decimal characters, 6 letters were added in the hexadecimal system. The hexadecimal number system consists of 16 characters. The known number characters were expanded with letter characters. Denomination: 0 1 2 3 4 5 6 7 8 9 A B C D E F

Base: 16

Largest denomina-tion:

F

Place value: 160 = 1, 161 = 16, 162 = 256, etc.

162 161 160 Hex 4 D 5 = Dec 1237 Because the cascaded weighting is part of the binary system, one can convert back to the binary number system. Each hexadecimal place contains 4 binary places:

4 D 5 Bin 0100 1101 0101 = Dec 1237

Page 79: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 79

4.3 Variables and Data Types 4.3.1 Defining Variables In a program, there are many changeable number values that can contain specific machine or equipment information (position, temperature, etc.) or intermediate results. These num-ber values are called variables. Nearly every program requires user-defined data to produce a specific output. Variables are used to represent values. Therefore, a variable stands for an address in the computers main memory. Based on this address, a specific number of bytes are reserved. A variable can represent many different types of data, from a simple number to a large floating point number, a single character or a character string, etc. The variable name, also called the identifier, Servers to identify the memory address in the program code with a simple name. It is nothing more than a synonym or placeholder for a specific memory location. Variables must be defined. Under a variable definition, the variable name as well as the data type is entered in the system. 4.3.2 Local Variables in LASAL CLASS 2 Local variables are only valid within a function. This means, local variables are only valid in the function, in which they have been defined. Local variables are always defined by the user himself in LASAL CLASS 2. To create a local variable simply insert the text VAR and END_VAR under the function declaration. In-between the variable name and the variable type have to be entered (e.g. index : USINT;). Of course it can be defined several variables between VAR and END_VAR. FUNCTION ClassName::NewMethode VAR index : USINT; Local Variable END_VAR

Program code END_FUNCTION

At the beginning local variables have no valid values when a function is called. It is always necessary to assign a valid value to a local variable in order to work with it!

Page 80: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 80 Version 5.0

4.3.3 Private Variables in LASAL CLASS 2 Private variables are valid for the complete class in contrary to local variables. This means a private variable can be used in each function of a class.

Private variable of a class

If once a value has been assigned to a private variable, this value can then be used for each function of the class!

4.3.4 Description of variables The description of a variable can be selected freely. However, there are several special rules concerning the assignment of variable names. The name of a variable can only contain alphanumeric characters, an underscore and a number. Spaces and other special characters such as +, -, #, §, $ etc, cannot be used in a variable name. A number at the beginning of a variable name is also not possible in LASAL CLASS 2. The definition of a variable should be clear. A variable name cannot be the same as a key-word, method, class or object name. When a variable name appears in red when assigned, it is either a keyword or a name that has already been assigned.

To make your program code more readable, select descriptive names. Simple names, such as x or y are vague and can later cause confusion. Only number variables in loops are mostly assigned short names.

Page 81: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 81

4.3.5 Data Types For variables, there are several things to define that are relevant to the variable properties. If a new variable in the system is required, the value range should be considered before the variable is assigned.

If a variable for a number from o to a maximum of 200 is needed, the data type USINT is used (see the following table).

In the table below, the value range (upper and lower limits) and the description of the indi-vidual variable types are shown.

Data Type Lower Limit Upper Limit Description SINT -127 127 Short Integer INT -32767 32767 Integer DINT -2147483647 2147483647 Double Integer USINT 0 255 Unsigned Short Integer UINT 0 65535 Unsigned Integer UDINT 0 4294967295 Unsigned Double Integer REAL -3,4 E+38 +3,4 E+38 Real number, floating point number BOOL 0 (FALSE) 1 (TRUE) Bool CHAR 0 255 Character (ASCII characters) BSINT 0 255 8 Bit Short Integer BINT 0 65535 16 Bit Integer BDINT 0 4294967295 32 Bit Double Integer HSINT 0 255 Hex Short Integer HINT 0 65535 Hex Integer HDINT 0 4294967295 Hex Double Integer ARRAY Data field STRUCT Data structure ENUM Enumeration type

Page 82: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 82 Version 5.0

In the following table, an exact description of the data types and the amount of memory required in the system by a variable of each type is listed.

Type Memory Explanation SINT 1 Byte The data type, Short Integer, consists of both a positive and

negative value range from –128 to +127 and is used with whole number values.

INT 2 Byte The data type, Integer, consists of both a positive and nega-tive value range from –32768 to +32767 and is used with whole number values.

DINT 4 Byte The data type, Double Integer, consists of both a positive and negative value range from –2147483648 to +2147483647 and is used with whole number values.

USINT 1 Byte The data type, Unsigned Short, Integer consists of a positive value range from 0 to 255 and is used with whole number values.

UINT 2 Byte The data type, Unsigned Integer, consists of a positive value range from 0 to 65535 and is used with whole number val-ues.

UDINT 4 Byte The data type, Unsigned Double, Integer consists of a posi-tive value range from 0 to 4294967295 and is used with whole number values.

REAL 4 Byte The data type REAL is a floating-point data type with 1 bit for signs, 8 bits for exponents and 23 bits for number values. Calculations like those with a pocket calculator can be made using this data type. The disadvantage is that calculations are slower with this data type than with others. Numbers with places after the decimal point are also possible.

BOOL 1 Byte With this data type, only the condition 1 (TRUE) and 0 (FASLSE) are possible. This data type is used for logic con-ditions and can be linked to logic operations.

CHAR 1 Byte This data type can be written to with ASCII characters or numbers between 0 and 255. This data type displays ASCII characters only.

BSINT 1 Byte This data type can be loaded with a number value between 0 and 255. In addition, each of the 8 bits in this variable can be identified (provided with a name) and can be used as a Bool variable in the program. The variable display always occurs in the binary number system.

Page 83: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 83

BINT 2 Byte This data type can be loaded with a number value between

0 and 65535. In addition, each of the 16 bits in this variable can be identified (provided with a name) and can be used as a Bool variable in the program. The variable display always occurs in the binary number system.

BDINT 4 Byte This data type can be loaded with a number value between 0 and 42949967295. In addition, each of the 32 bits in this variable can be identified (provided with a name) and can be used as a Bool variable in the program. The variable display always occurs in the binary number system.

HSINT 1 Byte The data type, Hex Short Integer, consists of a positive value range from 0 to 16#FF (255) and is used with whole number values. The variable type is always displayed in hexadecimal.

HINT 2 Byte The data type Hex Short Integer consists of a positive value range from 0 to 16#FFFF (65535) and is used with whole number values. The variable type is always displayed in hexadecimal.

HDINT 4 Byte The data type Hex Double Integer consists of a positive value range from 0 to 16#FFFFFFFF (4294967295) and is used with whole number values. The variable type is always displayed in hexadecimal.

ARRAY Field de-pendant

This data type consists of a one or more dimensional fields of a different data types.

STRUCT Structure dependant

This data type enables the creation of a data structure of different data types.

ENUM Data type dependant

These data types a named allocation of numbers (0 to.).

Page 84: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 84 Version 5.0

4.3.6 Special Variable Forms ENUM This variable is an enumeration type and enables the allocation of names in number values from 0 to … This type of variable is used mostly as a step control for a CASE instruction. Using this type a clear step process can be created.

Page 85: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 85

CHAR A variable of data type CHAR is always displayed as ASCII characters. Either the ASCII characters or the corresponding number variables between 0 and 255 can be written to this variable. ASCII is a standardized code for written and control characters and stands for American Standard Code of Information Interchange. The American Standard Code of Information Interchange determines which number value corresponds to which character. All characters in the range of o to 127 belong to the standard ASCII character set. The ASCII characters 0 to 32 are used as control and/or formatting characters for I/O compo-nents. The expanded ASCII code, which is consists of the ASCII values between 128 and 255, can contain various characters and depends on written or graphic character sets.

Page 86: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 86 Version 5.0

Bit Variable If a variable in the system is assigned as type BSINT, BINT or BDINT, the individual bits can be allocated a name and addressed. Hex Variable If a variable in the system is assigned as type HSINT, HINT of HDINT, the contents are shown as a hexadecimal value.

Page 87: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 87

4.4 Operators Operators are use in programming to execute logic, bit wise and arithmetic operations as well as comparison instructions. 4.4.1 Comparison Operators Comparison operators allow values to be compared so a decision can be made.

< Less than > Greater than

<= Less than or equal to >= Greater than or equal to = Equal

<> Not equal

If ActualTemperature > MaximalTemperature then // Turn on the pump end_if;

4.4.2 Arithmetic Operators With arithmetic operators, calculations can be made.

+ Addition - Subtraction * Multiplication / Division ** Exponentiation

Mod Modulo division

Result := Operator1 + Operator2; Result := Operator1 ** 2; Modulo division: Operator1 = 25 und Operator2 = 7 Result := Operator1 mod Operator2; After this division, the remainder is written in Result => 4 3 * 7 = 21 + 4 (Rest) = 25

Page 88: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 88 Version 5.0

4.4.3 Assignment Operators The following operators are available in structured text for simple and/of combined assign-ments:

:= Simple allocation += Increment variable - = Decrement variable *= Multiply variable /= Divide variable

:= ..... Simple allocation x := 44; += .... Combined allocation x += 1; equals x := x + 1; -= ..... Combined allocation x -= 3; equals x := x – 3; *= ..... Combined allocation x *= 5; equals x := x * 5; /= ..... Combined allocation x /= 2; equals x := x / 2;

4.4.4 Bit wise Operators

- Negation (Two-complement) NOT or ! Bit wise Negation (one-complement)

AND Bit wise AND Operation OR Bit wise OR Operation

XOR Bit wise XOR Operation SHL Bit wise shift to the left SHR Bit wise shift to the right SAR Arithmetic shift to the right ROL Bit wise left rotation ROR Bit wise right rotation

Var := -x; Var := NOT x; corresponds to Var := ! x Var := x AND y; Var := x OR y; Var := x XOR y;

Page 89: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 89

In this shift operation, the newly freed bits are filled with 0:

Var := x SHL y; Var := x SHR y; Example: with SHL Before After

In this operation, the newly freed bits are filled with the bits that have been shifted:

Var := x ROL y; Var := x ROR y; Example: with ROL Before After

4.4.5 Logic Operators

!! Logic Negation, tested with <> 0 & Logic AND Operator | Logic OR Operator

IF (MinTemp1<40) & (MinTemp2>30) THEN // Temperature normal END_IF;

1 1 0 0 0 0 1 11 0 0 0 0 1 1 0

1 1 0 0 0 0 1 11 0 0 0 0 1 1 1

Page 90: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 90 Version 5.0

4.4.6 Example: Incrementing a Server (Count up) To demonstrate how a server is incremented using an example, the Counter project will be reused as an output point. Click on the + next to the Servers folder to display the server ClassSvr.

Insert the server, ClassSvr, into the program code editor from the Class View window using the Drag & Drop method:

Page 91: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 91

To increment a server, the assignment operator += is used. Position the cursor in the pro-gram code after ClassSvr and type: += 1; The full line then reads: ClassSvr += 1; That means the value in ClassSvr will be raised by 1 with each cycle.

Page 92: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 92 Version 5.0

The previously defined CyWork method is now used and will determine the cycle in which the ClassSvr is incremented. For the CyclicTime, 500 was set. This means the server will increment by one every 500ms.

If, for example, you want the server to increment every second, the CyclicTime must be set to 1000.

Now it is time to compile the project. Select Build, Rebuild All from the menu bar or sim-

ply press the in the symbol strip. In the Output Window, the compiler process is displayed. The process should be com-pleted with 0 errors and 0 warnings as shown in the following illustration.

If an error should occur at the end of compiler process, correct the pro-gram code or seek help under Troubleshooting.

When using the Build button (or Build, Build from the menu bar), only changes since the last Rebuild All will be compiled. If a project has not been compiled before and you only use the build function, although the project will be compiled correctly.

Page 93: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 93

4.4.7 Online Settings with TCP/IP To transfer the project to the destination system and actually increment the server, the online settings must first be made.

In the Class View window, select the project name to display the properties window. In the properties window under Online Connection, press the button to open the LASAL Online Configurations window.

Page 94: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 94 Version 5.0

In this example, a TCP/IP connection with the destination system is established.

Further online connection possibilities are covered later in this document under the chapter, Online with the Control.

To assign a new connection, simply press the New button. Assign a name to the connec-tion (here: TPC/IP 10.10.57.65) and under Connect Type and select TCP/IP as the con-nection type. Under IP Address:, enter the IP address of destination system and confirm with OK.

With the IP Scanner button you can search for all controls connected over TCP/IP in a network. As search result a list including all founded controls is displayed in the Network IP Scanner window. Select the de-sired control with the correct IP address and confirm with OK to establish a connection.

Under Online Connection in the Properties window, select the created TCP/IP connection as shown in the illustration below.

To enable the online connection and select Debug, then Online in the menu bar or press

the button.

Page 95: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 95

In the status bar, the following message appears in red:

PLC != PC means that the project in the destination system doesn’t match the project in the PC.

If a problem with the online connection should occur, further information can be found in the chapter Online with the Control.

To download the project in the PC to the destination system, select Debug and then

Download in the menu bar or push the button. Select Download Project & Run in the Download window to transfer the project to the destination system and start automatically. When Download Project is selected, the project is loaded in the destination system but

does not start automatically (the project must be started by pressing the button).

The project can also be started in the destination system with the F7 key.

If the project is now in the destination system, the red in the status bar is replaced with the following display:

PLC = PC means that the project in the PC and in the destination system is the same.

Page 96: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 96 Version 5.0

By selecting Download Module on the Fly in the Debug menu changes can be transferred to the control during runtime, without stopping the pro-gram. More information about this function you can find in the LASAL CLASS 2 documentation, respectively, LASAL CLASS 2 help.

The incrementing of the server can now be observed in the following window: In the Network window...

...and in the Debugger Window, if the corresponding object is selected with the mouse.

Page 97: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 97

This completes the server increment example.

If changes must be made in the project (e.g. change cyclic time), it must

be taken offline using the button. After the changes have been made

recompile the project with the button. Next, go back online and

download the changes with the button. Select Download Changes & Run in the download window to download only the changes to the des-tination system.

Page 98: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 98 Version 5.0

Simple example with floating point numbers (data type REAL): This project converts the Meter unit into the Inch unit.

Create a new project (here: RealProject) with a new class (here: Converter) including two servers (Meter, Inch). Change the data type of the two servers to REAL. The Meter server should not be write protected.

Furthermore create a CyWork method at the class and define a cyclic time of 100ms.

Page 99: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 99

Add the following program code to the CyWork method:

Define a network (here: ConverterNet) and create an object of the class. Compile, download and start your project. The following illustration should now be displayed:

By means of the decimal point you can see the REAL figures.

Page 100: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 100 Version 5.0

If you now insert 7.5 at the Meter server, then the value 292.275604 will be displayed at the Inch server according to the program code.

The resolution of a REAL number is 32 bit in LASAL Class.

In the project properties under Target you can find Use FPU. If this entry is set to TRUE, then the floating-point calculation is done from the existing Co processor by hardware. This leads to speed vantages. Oth-erwise the calculation is done by LASAL Class.

Page 101: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 101

4.4.8 Read and Write Methods of Servers The following example explains the function of Read and Write Methods for servers. The Read Method of a server is used so that data can be retrieved from another object. The write method of a server is used so that data from other objects can be written to the server. Create a new class, by opening the context menu in the Class View window and selecting Create Class.

Assign a name to the new class (here: ReadWriteClass) and confirm with enter.

Page 102: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 102 Version 5.0

For the next Step, 2 clients are required. Open the context menu with a right click on the ReadWriteClass and select New Client.

Assign a name to the client (here: Get) and confirm with enter. Repeat this process to cre-ate a second client (here: Set).

Page 103: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 103

Select the first client, Get, to display the properties window. As shown below, set Required to False. Make the same setting for the other client, Set.

The setting, DINT, as the Data Type of the client means that this client can display a Dou-ble Integer value. The value range is listed in the Data Types chapter. The definition, Data Channel, under Type indicates that only access to read and write methods of another object is allowed.

The reason for this setting is that, for clients, setting Required to False eliminates the need a mandatory connection. If Required set to true, a red X will appear in the network window of the object after it has been placed:

If Required is set to False and no connection to another object over which a value can be read over the Read Method exists. The actual value written in the client is assumed.

Page 104: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 104 Version 5.0

Because the CyWork Method of the CounterClass is no longer necessary for this exam-ple, close the editor containing this program code. Right click on the class name in the window (here: CounterClass) and select Close tab in the context menu.

To display the program code editor for the CyWork Method of the Coun-terClass again, double click on the method under CounterClass in the project tree.

Page 105: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 105

A CyWork Method for the class is now needed. Open the context menu of ReadWrite-Class and select New Std. Methods, CyWork.

To activate the CyWork method, open the properties window of ReadWriteClass and set the CyclicTask to true.

Page 106: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 106 Version 5.0

With a double click on the newly created CyWork Method, the program code editor is opened, which will contain the code for the CyWork method of the ReadWriteClass. Next, type the following program code between END_VAR and state := READY; as shown in the illustration below.

The clients Get and Set can be placed at the desired location in the pro-gram code editor from the project tree, using the Drag & Drop method. Don’t forget to include commentary.

Page 107: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 107

Information on calling the read and write methods Read() The parentheses at the end of Read mean that a method will be called. The Read method always supplies a return value. Write() Calling the Write method functions in the same way, except this method requires a parame-ter be transferred with it. This parameter is set in the parentheses and can appear as fol-lows: Write(34), Write(Set) Explanation of the program code Get := Get.Read(); Here, the read method is called over the client, Get. The read method supplies a return value, which is assigned to the Get client. Set := Get; This line assigns the value of the client, Get, to the Client Set. Set.Write(Set); This line ensures that the value in the parentheses is written to the server of another object over the client, set, using the Write method.

Page 108: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 108 Version 5.0

The following graphic should clarify the interaction between servers and clients and/or the application of the Read and Write methods in this example. Get := Get.Read(); Means the client Get of the object Lumberfactory retrieves the material (data, here 3 wood slats) provided by the server Wood from the object Forrest using the Read method. Set := Get; Means that the data in the client Get is assigned to the client set. In this case, the data is changed (a table is made). Set.Write(Set); Means that the client Set supplies the processed data (Table) to the object House using the Write method of the server Table.

Page 109: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 109

Switch to the Object window using the ObjectNetwork tab then Drag & Drop the class, ReadWriteClass, in the network next to the object CountObj of CounterClass as shown below.

Both objects (CountObj and ReadWriteObj) of both classes (CounterClass and ReadWri-teClass) are now in located in the network. Here, the difference between an object in which a cycle time has been defined (here: CountObj, class name and object are highlighted in blue) and an object whose CyWork method has already been activated but no cyclic time was set can be seen (here: ReadWriteObj, only the class name is highlighted in blue).

Page 110: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 110 Version 5.0

To define a cyclic time for the object, ReadWriteObj, select it either in the network directly or in the project tree to open the Properties window.

Under CyclicTime, set the cycle in milliseconds (here: 100).

As can be seen in the network, the object ReadWriteObj is now also blue.

Page 111: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 111

This is a good point to save the project. Press the button or select File, Save in the menu bar.

To load the project in the destination system, it must first be compiled. Select Build, Re-

build All in the menu bar or press the button.

In the Output Window, the compiler process is listed. There should be 0 error(s) or 0 warning(s) at the end of this list.

Select Debug, Online in the menu bar or push the button to establish an online con-

nection with the destination system. Press the button in the symbol bar to open the Download Window or select Debug, Download in the menu bar.

With Download Project & Run, the project is loaded to the destination system and started automatically.

Page 112: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 112 Version 5.0

The Network Window should now appear as shown in the following illustration:

As can be see in the illustration above, the value (here: 9) entered in the Get client is as-signed to the Set client through the program code.

Open the input field with a doubleclick on 0 under the client, Get andtype the enter number (here: 9).Confirm the input with enter.

Because CounterClass and itsobject, CountObj, were notchanged during the course of thisexercise, the server ClassSvr con-tinues to increment.

Page 113: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 113

4.4.9 Connecting Clients and Servers In the following example, which builds on the previous one, shows how the ClassSvr server of the object CountObj is connected to the Get client of the ReadWriteObj object and the effect this connection has on ReadWriteObj. As previously mentioned, the online connection must be disconnected before changes can

be made. Press the button to go offline. To create a connection between the server, ClassSvr, and the client Get, move the mouse pointer in the direction of ClassSvr until cross hairs appear (see below).

Press and hold the left mouse button and move the mouse in the direction of the client Get until cross hairs appear. Release the mouse button to establish the connection.

Page 114: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 114 Version 5.0

Recompile the project using the button and re-establish an online connection with the

destination system with the button.

Next, press the button to open the download window. Select Download Changes & Run to load the changes to the destination system and start the project immediately.

As shown above, the value for the client Get must no longer be entered manually as was the case previously. The value of ClassSvr, which continues to increment, is now retrieved by Get via the established connection with the help of the Read method. Using the Write method, the value of the client Set can now be written to the server of another object.

A client can only have one connection at a time, while a server can have several connections! Furthermore, clients cannot be connected to other clients and servers to cannot be connected to other servers!

The project should now be stopped via the button and saved to the target system by selecting Debug, Extras, and Save Project on PLC in the menu bar.

Page 115: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 115

4.5 Instructions 4.5.1 The if-instruction The if-instruction serves, depending on a condition, to execute instruction1 or instruction2. If the condition is true, instruction 1 is executed. Otherwise instruction2 after the else-branch is executed if one is assigned, since the else-branch is optional. if (condition) then // Instruction1 else // Instruction2 end_if; After the word if, a condition such as a comparison for example then follows. This compari-son results in either TRUE or FALSE. If the comparison is TRUE, the instruction after the word then is executed. If it is FALSE, the instruction after else is executed (and/or elsif) if provided. The IF- instruction must be ended with end_if. Comparisons can also be linked with one another: „&" stands for a logic „and", „|" stands for a logic „or". if (condition1) & (condition2) then // Instruction end_if;

Page 116: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 116 Version 5.0

Using the following pump work example, the application of the if- instruc-tion is explained. As shown in the following illustration, a liquid flows into a tank. When the maximum fill value is reached, the pump is turned on and the level sinks. If the minimum level is reached, the pump is deacti-vated and the tank begins to refill. If the minimum value is greater or equal to the maximum fill value, an alarm is triggered.

Page 117: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 117

First Implementation without hardware modules For this example, create a new project. Select File, New Project… in the menu bar.

Next, the Create New Project window appears:

Here, assign the project name (in this example: PumpControl). Save the project in the folder C:\Sample and confirm with Enter.

Page 118: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 118 Version 5.0

Your screen should appear as follows:

Page 119: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 119

In the Class-View window of the project tree, the newly created project is displayed. Acti-vate the context menu with a right click on the project name and select Create Class in order to create a new class.

In the opened field, assign a name to the new class (here: Hysterese). Next, in the Proper-ties window, set CyclicTask to true as shown below.

Page 120: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 120 Version 5.0

In the next Step, create 5 Clients for the class Hysterese. Select the class in the Class View window and open the context menu with a right mouse click then select New Client to assign the first client.

Assign the first client a name (here: ActualValue) and assign four additional clients (here: MaxValue, MinValue, Event und Alarm).

Page 121: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 121

As soon as a client is assigned, further clients can be created with a right click on the Clients folder and then selecting New Client.

For the clients ActualValue, Event and Alarm, set the Required property to false. To accomplish this, select all clients to display the properties in the properties window.

With multiple selections of clients (with the ctrl button pressed, multiple clients are selected) these settings can be made in all selected clients simultaneously.

Page 122: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 122 Version 5.0

Next, open the folder, Methods, with a left click on the + symbol then double click on Cy-Work to open the program code editor.

Page 123: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 123

The following code is entered between the lines END_VAR and state:=READY; of the CyWork method in the program code editor (see illus-tration).

To avoid typing errors, it is recommended the client name be placed in the program code editor from the Class View window using the Drag & Drop technique.

It is recommended, at this point, to save the project. Click on the symbol to save the project.

Page 124: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 124 Version 5.0

An object network is now required. Create the object network with a right mouse click on New Network in the context menu of the projects (here: PumpControl) Network View window.

Assign a name (here: PumpControlNet) and confirm with Enter.

Double click on the object network (here: PumpControlNet) to display the network.

Page 125: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 125

Switch back to the Class View window and insert the class (here: Hysterese) into the ob-ject network using the Drag & Drop method. An object of the class Hysterese is also placed through this process.

Page 126: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 126 Version 5.0

Select the object name (objHysterese) in the object network or click on the object name in the Class View window of the project tree, to display the properties listed in the properties window. Here, set the CyclicTime to 100. That means this object will be called by the oper-ating system every 100ms.

As can be seen in the illustration below, the number 0 in the clients MaxValue and Min-Value are red but in the other clients, they’re black. That means the property, Required, for MaxValue and MinValue is set to true and a connection to a server or a defined initial value is mandatory for these clients.

Page 127: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 127

For the next Step, an initial value must be assigned to the clients MaxValue and MinValue. Double click on the number 0, located under MaxValue, to open the input field and assign the value for the maximum fill level (here: 800). For MinValue, assign the value for the minimum fill level (here: 200).

Save the project and compile it with Build, Rebuild All. Create an online connection and load the project to the destination system.

Page 128: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 128 Version 5.0

As soon as the online connection is made, the objHysterese object, ClassSvr and the 5 clients are displayed in the Debugger Window under the THIS tab.

If your THIS window does not appear as the one above, you must deactivate the detailed view of the THIS window in the menu bar under Debug, Set-tings, Detail Modus.

Page 129: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 129

To see what’s happening, change the value of the ActualValue client to 810 in the object network. Because the maximum fill level is set at 800, the value 810 is too high and the pump is activated as a result (the client, Event is changed from 0 to 1).

Page 130: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 130 Version 5.0

The AWL Trigger function provides another possibility to control the process of the program code. To use this function, select Debug, then Settings in the menu bar and activate AWL Trigger. In the program code editor (tab Hysterese), set the cursor before each line of code that you want to ensure the program executes. If the selected program code is executed, the AWL Trigger in the status bar increments. If the cursor is set at the beginning of Alarm := 1;, the AWL remains at 0, rather than count-ing upwards. The reason for this is because the value that has been entered in the object, objHysterese, did not trigger an alarm.

Page 131: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 131

4.6 Automatically placing Read and Write methods To easier implement the Read and Write methods of servers in the program code, it's pos-sible to automatically place them.

This functionality has not been mentioned earlier in this manual, in order to become familiar with the syntax!

The procedure to automatically place Read and Write methods is explained on the basis of the already created Pump control example.

Position the cursor on the place in the program code editor where the Read methods should be insert:

Page 132: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 132 Version 5.0

Afterwards open the context menu with a right-click and select Insert Client-Update Source Code....

Read and Write methods can only be placed within a function!

In the now opened window you can activate the checkbox of those clients your want to use for reading in server values. Select Read in the upper right window and confirm with OK.

Page 133: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 133

After confirmation with OK the methods are automatically placed in the program code edi-tor:

Now place the Write method of the remaining clients in the same way in the program code editor and confirm with OK again.

Page 134: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 134 Version 5.0

The methods to write on other servers are now inserted on the desired position:

Insertion of the Read and Write methods can be done anytime, also when new clients of a class are created!

Page 135: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 135

4.7 LASAL CLASS 2 Library 4.7.1 Overview of the LASAL CLASS 2 Library To use a class from the library, open the Library window, then the context menu and select the desired category.

DiasMaster.lcp This contains all hardware classes that control the SIGMATEK product line for C-Dias and Dias Hardware modules. LadderLib.lcp Contains Standard Function blocks for contact plan classes as switch-on delay, switch-off delay, ramp generator, … Loader.lcp With each LASAL CLASS 2 project the Loader is transferred to the target system. Further-more the Loader is responsible for object creation, interpreter process, for data and com-mand exchange between two controls, aso.

Page 136: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 136 Version 5.0

LseLight.lcp This library contains the visualizations components for monochrome graphic displays. lse_rtk.lcp This category contains the visualization controls and classes for visualizing scroll lists, alarm management, oscilloscope, and language conversion. LslCmdLib.lcp This library contains classes for status and file access to target systems, which are con-nected to the control with a communication interface. LslRemoteLib.lcp This library contains interface classes for the LASAL Remote Manager. Memory.lcp From this library, classes whose objects are use to store remnant data (storage of individual value, strings and larger data blocks) can be included in a project. MiniDisplayLib.lcp This library contains classes to control non-intelligent, monochrome graphic displays. OS Interface.lcp All interfacing available to the operating system is listed under this category, such as CAN, File and graphic operations as well as functions for memory operations. Printer.lcp This library provides classes to control diverse printers.

Page 137: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 137

RTOSlib.lcp Here, the classes File_IO, Graphic, Linker, Math, Rtdb and System are found. These con-sist of functions for file handling, graphic tools, and arithmetic tools as well as functions to request memory or string functions. standard.lcp In this category, classes such as Trigger and Timer, Time and Date, Arithmetic as well as logic, temperature and others are found. USBLib.lcp This library provides classes to control SIGMATEK USB devices. VaranLib.lcp This library provides classes to control SIGMATEK VARAN devices.

Page 138: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 138 Version 5.0

4.7.2 Importing Classes To import a component from the Library, it must be selected from the list and the context menu opened with a right mouse click. Then, Link, Copy or Reference can be selected.

Through selecting Link, Copy or Reference the Import Class window appears. Confirm with OK, because the import type was selected before.

Page 139: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 139

Link The selected class is linked to the project and is therefore updated when changes are made. If a new library version is used, in which the class was changed, the class is auto-matically updated as the project is opened. Copy The selected class is copied into the project. If the class is changed in the library, the copy in the project is not updated. Reference Similar to Copy, however, the path from which the class was imported is marked in LASAL CLASS 2. This means that the class can be updated later on command.

Page 140: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 140 Version 5.0

4.7.3 Introduction to Hardware Class Principles In the DiasMaster category, all hardware classes for the component series Dias and C-Dias are found. In a project, if hardware is accessed, the DiasMasterC class must be imported and one object there from placed in the object network. The DiasMaster object also must have a RealTime and/or CyclicTime setting. As a rule, the RealTime setting is 1ms when using an industrial PC and 2ms for a proces-sor module. Further, as shown below, hardware modules placed in the network are connected to the object of the DiasMasterC class. Here, the MasterConnect clients are connected to the Control server.

Each hardware class in the LASAL CLASS 2 project must be assigned the station number (place), which corresponds to the actual station in the construction of the hardware. The CPUs are generally not given a station number.

Page 141: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 141

The following illustration shows the hardware construction with a CPU and various hard-ware modules distributed over several module carriers. The CIC module serves as a voltage supply and to connect the decentralized C-DIAS mod-ule groups over a DIAS bus. The CIC modules on the decentralized module carriers always have their own station number. The station numbers for the hardware modules to the right of the CIC module always begin with the number 0 and continue in ascending order de-pending on the module carrier.

The station number of the first decentralized module group (8 slots) is 0 (not 4) because the station numbers after the CPU correspond to the C-DIAS bus. The count continues with the decentralized module groups that follow.

Page 142: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 142 Version 5.0

Using the networks below, the station numbers can be assigned according to the actual hardware configuration.

All MasterConnect clients of the CIC modules are connected to Control server of the Di-asMasterC object. In addition, all MasterConnect clients of the hardware classes are con-nected to the Control server of the CIC module

Page 143: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 143

VARAN network All hardware classes of the VARAN type series can be found in the VaranLib library. If C-Dias modules have to be included to a VARAN network, the following 2 classes are required instead of the DiasMasterC class:

• HwControl This object controls the time management of the VaranManager. Here also a Di-asMasterC object (Server DiasMaster) can be connected. If a connection to the DiasMasterC is established, the HwControl also controls the DIAS bus time man-agement in order to be synchronized with the VARAN bus.

• VaranManager_X An object of this class represents a VARAN bus structure in LASAL Class.

The VaranManager classes only differ in the number of VARAN connections (X...number of VaranOut).

Placed hardware modules still have to be connected to the VaranManager class object. Here the VaranIn clients of the hardware objects have to be connected to VaranOut server of the VaranManager objects.

Page 144: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 144 Version 5.0

Connection of C-Dias modules to a VARAN bus structure:

To connect C-Dias modules to a VARAN bus a coupling module is necessary (here the CIV 512 for example). To the CDIAS server C-Dias modules are connected afterwards. Further information of the modules can be found in the respective module documentations.

Page 145: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 145

4.7.4 Ram Class Applications The RAM class is found in the category Memory. This class is used to store remnant val-ues, which are stored in the server (Data) of an object of this class and are null voltage protected. The values can be accessed using the Read() method of another object or a new value can be stored using the Write() method.

Values written in a Ram object are saved as remnants and are available each time the control is started. After the Ram class constructor is processed, the correct value is entered in the server and can be accessed by the Init method of another object.

Page 146: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 146 Version 5.0

Implementation of the Pump work Example with Hardware Modules Import the required hardware from the DiasMaster.Icp library. In this example the following modules will be used: • CTO 163 • CAM 123 Place an object for each of these hardware modules in the object network. An object for the DiasMasterC class must also be placed in the object network. Connect the objects as shown in the following illustration:

For every client indicated with an arrow, enter an initial value as show above. With a double click on the respective Client value, a white field appears where the initial value must be entered. Confirm these inputs with Enter to close the field and store the value. For the analog inputs of the hardware module (CAM 123), an initial value for the clients Al1_Scale (1000) to Al8_Scale (1000) must be entered for scaling.

Page 147: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 147

Client/server connections are created with a left mouse click on the client and/or server. If a node is required in the connection, use the grid (dots) in the object network to set a node with a left click. Complete the connec-tion with a left click on the client and/or server. To change a connection, select it in order to display the node. Move the mouse pointer to the desired point, then press and hold the mouse button to shift the node. Click and hold the mouse button on a node while the ctrl button is pressed to delete a node. To set a new node click the left mouse button on the connection while the ctrl button is pressed.

The objects for the hardware classes (CTO163_IM and CAM123_IM) must have an initial value entered in the client, Place. This defines the position of the hardware module on the module carrier. In this case, the CTO163 is at Place 1 and the CAM123 is at Place 2 on the module carrier.

Add node

Move node

Delete node

Page 148: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 148 Version 5.0

Save the project with and compile it with Rebuild All. Go online and load the project to the destination system.

If the value is changed over an analog input (here: CAM123), the pump work should func-tion immediately (see AI1 in illustration above).

Page 149: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 149

Retentive property at server It is possible to save a server value null voltage safe. For it the server property RETENTIVE has to be set to one of the following values: Sram: Here disk space is reserved in an available SRAM. File: Here the value is saved to a file.

To make the retentive function as fast as possible, it is compared whether the current server value is different to the value that should be written via the write method. That is when the server value has been changed before it has been written. Then no changing has been identified and the server value will not be stored! Example: MyServer := MyServer +1; MyServer.Write(MyServer); It has to be programmed correctly like this: myValue := MyServer + 1; MyServer.Write(myValue); In this case the changing has be identified and the server value is stored.

Page 150: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 150 Version 5.0

4.7.5 Bit Operator Applications

In the following example, the applications possible with bit operators are explained. With the bit operators ROL and ROR bits are shifted to the left and/or right. To shift a bit, a variable of type BSINT in required for this example. To implement this example, the Init method will be used for the first time.

Using the knowledge already gained, create a project. This project should contain a class with a CyWork method, a network and an object of this class placed in the network. A client to determine the direction of the shift operation is also needed. To shift each bit to 1 in half second intervals, set the cyclic time for the object to 500ms. The designation of the assigned components can be taken from the following diagram:

Page 151: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 151

In the next step, a variable is required. Open the context menus in the Class View window (here: MoveBits) and select New Variable.

Assign the variable a name (here: Led) and confirm it with Enter. In the Properties window, under the variable property Type, enter BSINT.

Page 152: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 152 Version 5.0

Through the type, BSINT, the Led variable now has 8 elements. That means the type, BSINT, has 8 bits (further information on type BSINT is found in the chapter, Data types). Assign the 8 elements the names L1 to L8, as shown in the illustration below (with the F2 key a selected element can be renamed).

As previously mentioned, the Init method is required for this example. Right click on the class name to open the context menu. Select New Std. Methods, Init then double click on the methods CyWork and Init in the project tree to display these methods in the program code editor.

Page 153: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 153

As can be seen in the program code editor, the Cywork method is before the Init method. This, however, doesn’t play a role for the program se-quence because the operating system always calls the Init method first and then the Cywork method. To maintain clarity, the Init method can be place before the Cywork method in the program code editor at any time (as shown in the next illustration).

Insert the code for the init and/or Cywork method as shown below:

Explanation of the Init Method Program code Led.L1 := 1;

One bit must be set to 1 in order to start the shift process. In this line of code, the first bit (L1) of the Led variable is set high using the assignment operator :=.

Page 154: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 154 Version 5.0

Explanation of the Program Code for the CyWork Method In summary, this if-instruction means the following: If the SetDir client is 0, the bits of the Led variable are shifted to left by 1. If the value in SetDir is 1, the bits of the Led variable are shifted to the right by 1. Led := Led ROL 1; All bits are rotated to the left by 1 using the ROL instruction (rotate left). This rotation is assigned to the Led variable using the := operator. Led := Led ROR 1; All bits are rotated to the right by one using the ROR instruction (rotate right). This rotation is assigned to the variable Led using the := operator. Save the project and compile with Rebuild All. Go online and load the project to the desti-nation system.

Open the THIS tab in the Debugger Window. There the shifting of the bits in the Variable, Led can now be observed. If in the object (objMoveBits), the value of the SetDir client is set to 1 during online opera-tion, the bits will be shifted to the right.

Page 155: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 155

4.7.6 The Case Instruction The Case instruction is described mostly by software designers as a finite state machine.

In the following example, a finite state machine is created with the help of the Case instruction. That means, with the throwing of switches, specific instructions are executed. To implement this instruction, a variable is created and the data type ENUM is assigned. Later in this example, a RAM class is used.

Create a new project and continue to the point where the following components seen in the Class View window below are created and named.

In the class, CaseClass, set the CyclicTask function to true and assign a CyclicTime of 200ms.

A network in which an object (here: objCaseClass) of a class (here: CaseClass) is placed, can be opened, respectively, displayed through selecting Show in the context menu of the object.

Page 156: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 156 Version 5.0

Import the DiasMasterC and the CDI16X from the Library and place the objects, including the objCaseClass object, in the network as follows. Connect the individual objects as shown below.

To move an object in the object network, select it with the left mouse but-ton until a four arrow cross appears (see picture) hold the mouse button and move the object to the desired position.

Page 157: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 157

In the next Step, a Ram class is required. Switch to the Libraries window and right click on the project name to open the context menu then select Memory.lcp.

Click on the + before Memory and select the entry Copy in the context menu to import the Ram class.

Page 158: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 158 Version 5.0

Switch back to the Class View window and position the Ram class in the network window using the Drag & Drop method as shown in the following illustration. Assign the name CountTime to the object of the class and connect it to the client, TimeSpan.

Save the project.

Page 159: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 159

As mentioned earlier, the data type ENUM is needed. In the Class View window, open the context menu of CaseClass and select New Type.

Assign a name to the type (here: MYSTEP) and select ENUM in the properties window under Type.

Page 160: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 160 Version 5.0

Insert two new entries in the type, MYSTEP, by selecting New Item in the context menu.

Name the entries as shown in the following illustration:

Page 161: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 161

To use the newly created type, a variable is needed. In the context menu of CaseClass, select New Variable.

Assign a name to the variable (here: Fsm) and assign the type MYSTEP in the properties window (see next illustration).

Page 162: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 162 Version 5.0

In the next Step, open the program code for the CyWork method with a double click on CyWork in the Class View window.

Insert the code as shown below. Take caution not to make any typing errors and maintain readability of the program.

Page 163: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 163

Explanation of the Program Code case Fsm of Start: Count: GoToStart: end_case; In the variable, Fsm, in case of Start:, Count: or GoToStart:, the following should occur: Start: if Switch1 = 1 then Fsm := Count; end_if; After the program start, the Case Instruction is set to Start by default since it is the first entry under the ENUM type. If the Case Instruction is on Start and Switch1 is set, the Case Instruction springs to the next step (Count) through Fsm := Count;. Count: if (Switch1 = 1) & (Switch2 = 1) then Counter += 1; if Counter >= TimeSpan then Fsm := GoToStart; end_if; end_if; When Switch2 is set, the instruction Counter += 1; is now executed and the Counter increments. When the counter reaches the value in TimeSpan, the if-instruction is evalu-ated and the Case Instruction is set to GoToStart. GoToStart: if (Switch1 = 0) & (Switch2 = 0) then Counter := 0; Fsm := Start; end_if; Through the reset of Switch1 and Switch2, the counter is set to 0 and the Case Instruc-tion is reset to the Start position.

Page 164: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 164 Version 5.0

Save the project and compile with Rebuild All. Go online and load the project to the desti-nation system. Afterwards start the program and insert at the Data server of the CountTime object a value (here: 40) as time span. This value is stored in the Ram class and read-in from the TimeSpan client of the objCaseClass object.

Open the THIS tab in the Debugger Window to observe the steps of the Case Instruction. As can be see in the illustration below, the Case Instruction is set by default to the start position.

Page 165: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 165

If Switch1 is now set, the Case Instruction springs to the Count step. Switch1 is set from 0 to 1 as shown in the Debugger Window below.

When Switch2 is also set, the Counter starts to increment. When it reaches the value in Timespan, the Case Instructions springs to GoToStart.

By resetting both Switches, the Counter is set to 0 and the Case Instruction springs back to the Start position.

Page 166: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 166 Version 5.0

An alternate type of Case Instruction: If the data type of the Fsm variable was assigned or changed to a USINT, the Case instruc-tion could be constructed as follows: this Case instruction can only contain steps from 0 to a maximum of 255 (the value range of type USINT= 0 – 255). The names of the steps were replaced with number values.

For more complex Case instructions, this variation is not recommended. A description (name of each step) is clearer than a number. For test purposes however, this method has the advantage of being faster to construct.

Page 167: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 167

4.7.7 Network Overlapping Object Connections To form a project more clearly, objects can be distributed over several networks. In the following example, the CaseInstruction project will be used to place the objects of the hardware and user classes in their own network. To begin, switch to the network window CaseNet.

Select both objects of the hardware class with the left mouse button and pres the Del but-ton

Page 168: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 168 Version 5.0

To replace the deleted objects, a new network (here: HardwareNet) must be created.

Open the network, HardwareNet, and insert the objects of the classes DiasMasterC and CDI16X, which were deleted earlier. Also, connect the two objects and define the position (here: 0) of the module on the module carrier.

Page 169: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 169

To connect the server Input1 in the objCDI16X object and the Client Switch1 of objCase-Class, right click on Input1 to open the context menu and select Copy.

Switch back to the network, CaseNet and activate the context menu with a right click on the value 0 in the client Switch1. Select Paste Connection to establish the connection.

Page 170: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 170 Version 5.0

Create a connection between the Input2 server and the client, Switch2 using the same method as above.

The Network overlapping connections between objects are now created To switch from the Client Switch1 (and/or Switch2) to the connected server Input1 (and/or Input2), select Goto Server in the context menu of the client.

Page 171: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 171

The HardwareNet network will appear with the Input1 server, which is connected, to the client Switch1, marked.

It is also possible also to switch from the sever Input1 (and/or Input2) to the client Switch1 (and/of Switch2). Select Goto Client in the context menu of the server (here: Input1).

Page 172: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 172 Version 5.0

To show what would happen when several clients are connected to a server, place an addi-tional object from CaseClass in the CaseNet network as shown below. Using the Copy and Paste Connection again, create a connection between the clients (Switch1 and Switch2) of the newly placed object and the servers of the (Input1 and Input2) modules.

Change to the network HardwareNet and select the entry, Goto Client, in the context menu of the Input1 server. As can be seen, a list window now appears in which the client of the desired object can be selected. To display a client, select one with a double click.

Page 173: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 173

At progressional project expansion it can happen that objects are placed in different net-works and therefore several Client-Server connections occur. Via the Show connected Servers function all connections of clients from other networks to servers are highlighted in the selected network. The context menu including this function can be opened with a right-click on a free area next to objects.

The connected servers thereby are displayed in green letters.

Page 174: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 174 Version 5.0

4.8 Topical Exercises 4.8.1 Conveyor Belt Project Requirements A project should be created by which a package is transported from the output point (start button) to a palleting system over three conveyor belts.

Process First, a package is placed on the first conveyor belt (FB1). When the start button is pressed, the motor (M1) is activated and the conveyor belt begins to move. If the light sensor (L1) at the end of the conveyor is triggered, it is stopped and the cylinder (Zy1) shifts the package to the second conveyor belt (FB2). After a specified time, the cylinder (Zy1) is retracted. The next light sensor (L2) is then triggered and sets the second conveyor belt in motion. The process is now repeated for the second and third conveyor belts.

Page 175: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 175

Tips for completing the task

Since all three-conveyor belts are identical in function, the code for the individual belts does not have to be written 3 times. Here, only one class for the full function of a single conveyor belt is created and an object for each of the actual conveyor is placed in an object network.

This example can be solved easiest with a Case instruction consisting of three steps. Wait_Start: Here, the program waits for the start switch to be pressed to start the motor. Wait_Lightsensor: the program waits for the triggering light sensor to stop the motor and extend the cylinder (counter starts). Wait_Time: waits until the counter reaches the defined time to retract the cylinder and reset the Case instruction to Wait_Start.

Remember the object oriented programming!

Page 176: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 176 Version 5.0

4.8.2 Traffic Light Poject Task A project should be created, which simulates a controlled crosswalk. The start condition of the traffic control is read for the pedestrians and green for the drivers. If the pedestrian pushes a button to cross the street, the control should work as in actual traffic.

Process If one of the two buttons is pushed by the pedestrian, the green traffic light begins to blink 4x with a frequency of 1Hz. After the blink process the traffic light switches to yellow for 3 seconds and then to red. When the traffic light is red, Crossing signal changes to green for five seconds. After these five seconds have elapsed, the Crossing light will blink 4x with a frequency of 1 Hz before switching back to red. When the Crossing light is red, the traffic light will change to red/yellow for two seconds then to green (for the driver). Tips for completing the task

This project can be implemented easiest with a case instruction.

Page 177: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 177

4.8.3 Run light

(Project MoveLight) Task The running light should be started and/or stopped with a switch. The user should be able to set the running speed with a potentiometer.

Process The running light is started using a switch. The outputs (LEDs on the output module) should be connected so that the first LED lights first then turns off and the next LED lights and so on. If either of the outer LEDs is reached, the direction changes. This creates the impres-sion that the light “runs” from on side to the other. Tips for completing the task

To implement this project, the SHL and SHR operators should be used. To activate the individual LEDs, each bit must be assigned to an output. E.g.: Output1 := Led.L1; Output 2 := Led.L2; ↓ Output 1.Write(Output 1); Output 2.Write(Output 2); ↓

The first bit must be set to 1 in the Init method in order to shift it using the shift instructions (SHL and SHR)! When using the shift instructions, the bits are not refilled after being shifted (contrary to the rotate instructions).

Page 178: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 178 Version 5.0

4.9 Program Loops 4.9.1 The For-Loop If the number of times an instruction should be repeated is known, the for-loop is used. The instructions are executed for the range specified in the running variable between (including) the start and end values. The increment between executions can be determined by the user with the addition of by in the instruction. If by is not included, the increment value is 1 by default. The for-instruction is ended with end_for.

An array (field index = 5) should be initialized with a specific value. FOR i := 0 TO 4 BY 1 DO ArrayVar[i] := 0; END_FOR;

4.9.2 The while-Loop In this instruction, the run condition is at the beginning of the loop. The run condition, the expression between while and do, specifies how long the instruction following it is re-peated. The value of the expression is tested before the execution of the instruction; there-fore it is possible that loop is never processed. The comparison operators are identical to those in the if-instruction. The instruction, end_while terminates the loop.

As long as variable X is less the 100, it should be incremented by 10 and the counter is incremented by 1. WHILE (X < 100) DO X += 10; Counter += 1; END_WHILE;

Page 179: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 179

4.9.3 The Repeat-Loop With the repeat-loop, the exit condition is at the end of the loop. With the words repeat and until, the repeated instructions are combined in a group. This instruction group is repeated until the exit condition, the expression after until is met. The repeat-loop must be closed with end_repeat.

Repeat-loops are executed at least once, unlike the while-loop.

The x variable should be doubled until it is greater than 500. If it is greater than 500 at the first loop, it will still be doubled once (unlike the while-loop) repeat X *= 2; until (X > 500) end_repeat;

4.9.4 Interrupt instructions for Loops Exit With the help of the Exit instruction, a loop (for, while and repeat) can be exited early.

for I:=0 to 100 do if s>= 50 then exit; end_if; s:=sum(s1:=s, s2:=1); end_for;

Page 180: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 180 Version 5.0

Return With help from the Return instruction, a method can be exited early. Without Return, the method will run until the END_FUNCTION and/or END_AWL instructions are read.

for end=0 then return; end_if; MaximalTemperature := 65; END_FUNCTION

GoTo The Goto instruction serves to continue at jump destination assigned by a local label. The label must be closed by a colon.

if (condition) then Goto MyLabel; end_if; ... ... MyLabel: ... ...

The use of this instruction doesn’t necessarily help the programmer. Functions should be programmed without this instruction whenever pos-sible.

Page 181: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 181

4.10 Data Fields In programming, data fields are also called arrays. Arrays are a row of variables, arranged sequentially in memory. Arrays are especially useful when large amounts of data from the same type must be processed or the sequence of the data plays a significant role in ad-dressing the index of a field.

Definition: An array is a data structure, which contains a number of data from the same

type. Arrays can contain every possible data type, for example, integers, strings, array types or any other valid data type. The variables contained in an array are called array elements (fields).

4.10.1 Declaration of an Array In the following illustration, the declaration of the array Measure is shown. To assign an array, ARRAY is selected in the Properties window under Type. Under the element Type, INT is selected.

Page 182: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 182 Version 5.0

The limits for the maximum values of possible field entries are between –32768 and 32767 since the type INT was assigned in the Properties window under Element Type. With the setting of the field depth (0..9), the array now has 10 fields or array elements. The settings for Limit Low and Limit High must now be made in the Properties window.

When declaring an array, it’s best to let the index of the array start with 0. That means 0 will be the first field of the array.

4.10.2 Accessing Array Elements If the user wants to access a specific element to evaluate the contents, for example or to assign a new value, this is done over the index. The index is written behind the array in brackets. For clarity, an array named Measure is used. To assign values to the array elements, the following must occur: Measure[0] := -14; Measure[1] := 0; Measure[2] := 25; Measure[3] := 55;

Page 183: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 183

Through the assignment of the index, the element contents are evaluated. Here, the con-tents of the third element are written to a possible variable; MeasureValue: MeasureValue := Measure[2]; 4.10.3 Initialization of an Array The initialization of an array should be done using the previously mentioned For-loop to avoid having to write a value to each array element individually. for index := 0 to 9 do Measure[index] := 0; end_for; 4.10.4 Memory Map of an Array Assume that the first element, Measure[0], reserves the memory address 16#FA1. Then the image of the memory area could appear as show in the following illustration.

Page 184: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 184 Version 5.0

In the following example, a project is created in which a variable is de-fined as an array with 0 to 7 field entries. A client is used to input arbitrary numbers, which are written to the array according to the sequence of the fields. An additional variable will be repeatedly incremented by 1. This ensures that each value is written into a new field.

Create a new project (here: PtrNew) and construct it as shown in the following Class View window:

Create a new variable (here: Number) and define it in the Properties window as Type Array OF DINT. Also create a network (here: One).

Page 185: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 185

Click on the + next to the variable Number and select the Array Field. In the Properties window under Limit High, enter the Value 7. The array will then have 8 fields (0..7).

Double click on the CyWork Method in the Class View window and enter the following program code:

Page 186: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 186 Version 5.0

Number[Index] := GetNumber; Means: The number entered by the client GetNumber, is assigned to the variable Number. Be-cause this variable is defined as an array, a value is assigned to each field of the array defined by the variable array. Since the variable, index, is automatically set to 0 at the start up of the target system, the first value in the client GetNumber is written to Field 0. Index += 1; Means: The Index variable is incremented by one when the client, GetNumber, is unlike 0. This means that each time a new value is written to GetNumber, it will then be written to the next array field. if Index > 7 then Index := 0; end_if; Means: If the variable, Index, reaches the value 7 (the array consists of fields from 0 to 7) then the value of the index is reset to 0. If another value is then written to GetNumber, the current value in Field 0 will be overwritten. Define a cyclic time of 100ms in the object properties. Save the project and compile. Go online and load the project to the destination system and start the program. Enter a number in the Client, GetNumber (here: 78).

Page 187: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 187

Observe in the THIS register of the Debugger Window how the value entered (here: 78) in GetNumber is assigned to field 0 of the Number variable. In addition, the Index variable is incremented by one so the next value will be written to field one.

If an array has 20 or more fields, the Array Range window appears, in which how many array fields from the Number variable should be shown:

Page 188: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 188 Version 5.0

Enter additional values until all array fields are filled. After the next entry, field 7 of the Index variable will be reset to 0.

Observe the number in field 0 (here: 78). When another value is entered in the GetNumber client (here: 48), the current value in Field 0 is overwritten (78 is overwritten by 48).

Page 189: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 189

4.11 Topical Exercises 4.11.1 Search (Project Search) Requirements The following example searches for specific numbers in an array. The project should be constructed so that in the Init method, an array is initialized with values using a for-loop. The array should have 50 entries whereas the number –25 is stored in field [0] and in field [49], the number 24 is written. The search value is entered in a server of the class. An addi-tional server will display the search result. The search for the numbers should be imple-mented using a while-loop.

Process In the server used to perform the search, a value is entered and the search is started. If a positive match is found in the array, the field that contains the number is output to the search result server. If the search value is not found, the search result server will display a –1. Tips for completing the task

Create a help variable before the while-loop, which is set to 0. The while-loop will be executed until the help variable is greater than 49. In the while-loop, the help variable will be incremented by 1. Within the while-loop, the matching value and the contents of the array must be searched. If a match is found, the while-loop can be exited using the Exit instruc-tion.

Page 190: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 190 Version 5.0

4.11.2 Multidimensional Array

The "Matrix" project in the next example includes a 5x5 field large matrix, displayed as a two-dimensional array. The matrix is filled with letters as shown in the illustration. By defining coordinates the ASCII value of the corresponding character is then displayed on a server.

Now create a project using the following Class View window as template:

Also create a network (here: MatrixNet). Define a cyclic time of 100ms at the CyWork method.

Page 191: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 191

The CharArray variable has to be of ARRAY OF CHAR type.

Next open the context menu of the CharArray variable with a right-click and select New Dimension.

Page 192: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 192 Version 5.0

Now insert the following program code to the program code editor:

Page 193: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 193

FUNCTION VIRTUAL GLOBAL Findchar::CyWork if coordinate_X >= 0 & coordinate_X <5 & coordinate_Y >= 0

& coordinate_Y <5 then Ascii:=CharArray[coordinate_X][coordinate_Y]; end_if; Via this IF instruction it is checked whether the values of the clients are within the matrix borders (5x5) or not. In this case on the Ascii server the ASCII value of the founded character is displayed, de-pending on the coordinates. Otherwise 0 is displayed on the Ascii server. FUNCTION VIRTUAL GLOBAL Findchar::Init for y:= 0 to 4 do for x := 0 to 4 do CharArray[x][y] := 65 + x + y*5; end_for; end_for; In this Init method the CharArray matrix is filled with the letters. Save your project now and compile it. Transfer the project to the target system and start the program.

Page 194: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 194 Version 5.0

Afterwards mark the objFindChar object in the object network. Now watch the CharArray variable in the THIS tab of the Debugger window. You can see that each array field of the first element (highlighted in red) also includes the 5 array fields of the second element.

Now insert the values 2 and 3 at the clients coordinate_X and coordinate_Y. As result the ASCII code of the character "R" (corresponds to 82) is returned at the Ascii server.

Page 195: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 195

4.12 Additional Exercise Examples 4.12.1 Lotto Generator

(Project Lotto Generator) Requirements The Lotto number generator to be created should draw 6 out of 45 possible numbers. Here, the class produced should access an array (data field). The selected numbers are then each displayed in individual servers. Using a client, the drawing of a number is triggered. An additional client serves to reset the client and/or array after the drawing of all six numbers is complete. The arbitrary numbers should be generated using the simplest technique possi-ble in which a variable is incremented from 1 – 45 with every program scan. The number currently in this variable is drawn with the pressing of a button.

Process Using a client (Button), the drawing of a number is triggered. This number will be entered in first field of the array, whose contents are then displayed in a server. When the button is pressed again, the next number is drawn. The new number is then compared with the num-bers already drawn. If this number matches a value already stored in the array, it is either manipulated or a new number is drawn automatically. With the second client, all entries can be deleted to perform a new lotto drawing. Tips for completing the task

To avoid the selecting a number more than once, each newly drawn number should be compared with those already selected. If a number is drawn a second time, it must be manipulated or a new value must be automatically selected.

Lotto generator

Page 196: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 196 Version 5.0

4.13 LASAL CLASS 2 Operating System Variables Operating System or OS The LASAL CLASS 2 operating system provides variable, which can be employed by the user. These variables can be processed or evaluated in the user program. 4.13.1 The Operating System Variable _Firstscan and ops.tAbsolute _Firstscan and ops.tAbsolute are the most important operating system variables for the user. _Firstscan The variable, _Firstscan, is set to 1 by the operating system after the program start only for the duration of the last execution of the Init method. That means that the Init method is called by the operating system 12x, in order to ensure that the Init methods of all objects in a LASAL Class project are called at least once. After the 11th call, _Firstscan is set. This variable is designed for initialization and should only used in the Init method. ops.tAbsolute In this variable, the absolute time elapsed since the start of the CPU is shown in millisec-onds. This variable is mainly used to trigger timers.

The ops.tAbsolute cannot be assigned another value when used in the program. General: Operating system variables can only be employed by the user conditionally. An exact listing of operating system variables that can be changed by the user is found in the operating system documentation.

The correct syntax to eliminate errors at transfer of the ops.tAbsolute is the following: E.g.: if (ops.tAbsolute – Timemark) > Time then

Also pay no attention to overflow of the variable. It is an UDINT variable that cannot contain negative values. When the highest possible value has been reached it starts at 0 again. Therefore the expression (ops.tAbsolute – Timemark) cannot be negative.

Page 197: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 197

Example: Timemark = 4294967292 Time = 1000 Current ops.tAbsolute = 4, because overflow took place! The value range of an UDINT number reaches from 0 to 4294967295 (= 2^32-1)! So the following expression would result from it: If ( 4 – 4294967292) > 1000 then ... It corresponds to the following expression: If ( 0 – 4294967288) > 1000 then ... As the number range moves in a circle the value 0 corresponds to 2^32=4294967296 in the UDINT range. If (4294967296 - 4294967288) > 1000 then ... is false and the IF loop is not executed yet.

Page 198: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 198 Version 5.0

4.13.2 _Firstscan and Ops.tAbsolute Application In the following example, the application of these variables is discussed.

In this example, a class should be created that delays the setting of a digital output to 1 by way of a switch. The delay time is defined as an initialization value of a client. All information needed to implement this project can be taken from the time diagram below.

t = time dt = delay time from the turn on of the switch to when the lamp lights.

Page 199: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 199

Create a new project and add the components shown in the Class View window shown below. Place each object as shown in the following object network:

The variable Timemark is of type UDINT.

For the objDelayClass object, set the CyclicTime to10ms.

Page 200: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 200 Version 5.0

Don’t forget to set the Required property in the Properties window of the client, DelayTime, to False since no connection will be made.

Select the client DelayTime in the Class View window to open the Properties window. Under DataType, change the data type to UDINT as show in the illustration below.

If a new client is created, the default data type of this client is DINT. The reason that the data type of the DelayTime client is set to UDINT is be-cause the data type of the variable, ops.tAbsolute is UDINT.

Page 201: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 201

Open the program code editor with a double click on Methods in the Class View window and insert the Init method before the CyWork method.

Insert the following program code into the Init method: if _firstscan = TRUE then Timemark := ops.tAbsolute; end_if; The if-instruction with the operating system variable, _firstscan, means that the program code within the instruction is processed only once. This means, after the 11th run of the Init method, this variable is set to TRUE. Next, since the condition of the if-instruction is now true, the code within is processed once. The variable time mark is then assigned the value in the operating system variable, ops.tAbsolute.

This program code is necessary for the program to function correctly (the defined delay is correct) when the Switch variable is already active at the program start.

Page 202: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 202 Version 5.0

The Cywork method is programmed as follows: Switch := Switch.read(); DelayTime := DelayTime.read(); With help from the Read method, a value is read and assigned to the clients Switch and/or DelayTime. The client, Switch, reads the value of the switch (if it is in the on position, the value is 1 otherwise the value is 0). In the DelayTime client, the initial value is set which is responsible for the delay. if Switch = 1 then if (ops.tAbsolute - Timemark) > DelayTime then Lamp := 1; else Lamp := 0; end_if; else Lamp := 0; Timemark := ops.tAbsolute; end_if; If the switch is activated (set to 1), the second if-instruction is tested. Otherwise the lamp remains off (Lamp = 0) and the value of the Timemark variable is equal to that of ops.tAbsolute. In the second if-instruction, whether the difference between ops.tAbsolute and Timemark is greater than the value of the DelayTime client. If this is true, the lighting of the lamp is de-layed for the initialization value in DelayTime. If not, it remains off (at 0). Lamp.write(Lamp); With help from the Write method of an object, the value of the Lamp client is written to the server of the object.

The ops.tAbsolute OS variable should only be used as follows for time delays: if (ops.tAbsolute - Timemark) > DelayTime then . . . end_if;

Page 203: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 203

The full program code should appear as follows:

Don’t forget to include commentary.

Page 204: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 204 Version 5.0

Save the project and compile. Next, create an online connection and load the project to the destination system and start the program. In the client DelayTime, enter a delay time (here: 2000 = a delay time of 2 seconds). Next, activate the switch in the destination system and observe how the client, Lamp, is set to 1 after the defined delay time.

In the debugger window, how the Timemark counts simultaneously with ops.tAbsolute until the activation of the switch can be observed. If the switch is thrown, the Timemark variable stops counting while ops.tAbsolute continues to run. The difference value is reached with the next program scan; if it is greater than the value in DelayTime (here: 2000), the lamp is set to 1.

Page 205: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 205

4.14 Topical Exercises 4.14.1 Delay Off Switch Requirements In this example, a class should be created that delays the setting a digital output to 0 using a switch. The delay time (dt) is entered over a potentiometer or ram object. All further in-formation needed to implement this task can be taken from the time diagram below. Process

Tips for completing the task

This task should be implemented with the operating system variable ops.tAbsolute.

Page 206: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Page 206 Version 5.0

4.14.2 On/Off Delay Switch Requirements A class should be created that delays the setting of a digital output to 1 and/or 0. The on/off delay time can be set with a potentiometer. All further information needed to implement this task can be taken from the time diagram below. This task should be implemented with the operating system variable ops.tAbsolute Process

Tips for completing this task

For an on/off delay switch, only one time setting should be used.

Page 207: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

STRUCTURED TEXT LANGUAGE BASICS

Version 5.0 Page 207

4.14.3 Filter Requirements In this project, a class should be created which calculates an average. Temperatures are read over the client, Input (simulated with a potentiometer), from which the average is cal-culated. The average should be calculated from 20 values (filter depth) and written to a server. An additional client (FilterTime) serves to adjust the temporal intervals in which the values are entered in the array.

Process An average should be formed from the values read from the client (Input). Depending on the filter time, the current value in the client is read and written to an array with 20 entries. The delay for writing the values to the array should be implemented using FilterTime and the ops.tAbsolute. If the array is completely filled, all values within are added and the sum is divided by the number of entries. The resulting average is written to a server (Average). The array is then reset to zero so further values can be read. Tips for completing the task

Create a time stamp in the Cywork method using the OS variable, ops.tAbsolute and with the filter time, a query to delay the writing of the values in an array. When all array fields contain a value, the average is calculated using a for-loop and then array fields are reset to 0. The val-ues read from the client can again be written to the array fields.

Page 208: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 208 Version 5.0

5 Classes and Objects in LASAL CLASS 2 5.1 Methods of a Class In the following chapter, attention is focused on the methods of a class. The purpose for methods are to create clearer and easier to understand projects and/or classes. The possi-bility exists for a class method to be called from a different class, increasing flexibility. 5.1.1 The Standard Methods of a Class The Standard Methods of a Class are always the Constructor-, Init-, CyWork-, RtWork- and Background Methods. This chapter contains addition important information and simul-taneously reviews the standard methods already introduced.

5.1.2 The Constructor in a Class The constructor, as previously mentioned, executes the initialization of class data. It is used exclusively for the initialization of the class in which it’s contained. The name of the constructor is always the same as its class. After the assignment of the constructor, the program code appears as follows:

Page 209: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 209

The return parameter ret_code has no significance to the user and should be left as ret_code:= C_OK; after the method is assigned.

The operations executed in the constructor do not affect other objects. That means the Read() and Write() Methods are not called over clients to retrieve or transfer data to other objects. Clientname := Clientname.Read(); // not allowed Clientname.Write(Clientname); // not allowed

5.1.3 Init-Method of a Class The Init method can also be used to initialize private variables in a class. At the time the Init method is called by the operating system, connections to other objects already exist. This means they can be accessed using the Read() and Write() methods. Because the Init method is called 12x by the operating system, it is recommended that the if-instruction be used with the OS variable, _firstscan, so that these program lines are processed only once.

In the previous example (delay), the _firstscan variable was already used. In that example the instruction read: if _firstscan = TRUE then. This instruction can also be written as: if _firstscan then.

Page 210: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 210 Version 5.0

5.1.4 The CyWork, RtWork and Background Methods These methods are task dependant, which means they are processed by the operating system within the time frame set in the object of the class.

Here, the method priorities are reviewed.

Highest Priority: RtWork (Realtime Work ) Middle Priority: CyWork (Cyclic Work) Lowest Priority: Background

The program code of these methods differs only by the method name in the code editor. The following program code shows the Rtwork method directly after being assigned:

Page 211: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 211

The transfer and return parameters of this method have no significance to the user. FUNCTION VIRTUAL GLOBAL Calculator::RtWork VAR_INPUT EAX : UDINT; END_VAR VAR_OUTPUT state (EAX) : UDINT; END_VAR

The return parameter state:= READY; should be left as is. The CyWork and Background methods look identical to the RtWork method externally. The difference is only the method description (CyWork and Background). FUNCTION VIRTUAL GLOBAL Calculator::CyWork FUNCTION VIRTUAL GLOBAL Calculator::Background

Page 212: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 212 Version 5.0

5.1.5 Start Up Phase (constructor, Init,...) In the following flow chart, the actual process from the start of the program to the calling of the individual tasks is shown. As can be seen, the constructor is called first then the Init method and finally the cyclic tasks (RtWork, CyWork and Background) of each object is processed.

Page 213: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 213

5.1.6 Transfer and Return Values of a Method

In the following example a project is created, which functions like a pocket calculator. Here, private methods as well as global types are used for the first time. The project is implemented through a class, which has 2 clients and servers. The 2 clients serve as inputs for values with which specific calculations are made. One server is used as an output for the result; the other is used to select the type of arithmetic operation.

Start with a new project and construct it so that it appears as shown in the Class View window:

To deactivate the write protection of the server SelectArithm, set WriteProtected to False in the Properties window.

Page 214: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 214 Version 5.0

Create a new network with the name ArithmOperation.

Switch to the Types View window by selecting the tab, Types, in project tree. Here, open the context menu with a right click on the class name and select New Type to create a new global type.

Assign the name ARITHM to this type. Next, in the Properties window, assign the newly created type as ENUM and under Size, assign the data type UDINT.

Page 215: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 215

Right click on ARITHM and select New Item in the context menu. Repeat this process to create and name the additional types as shown below.

Switch back to the Class View window and in the context menu; select the folder Global for the New Std. Methods and Background methods to create the background method.

Note: For this project, the pocket calculator has no temporal priority. The Background

method was selected instead of the CyWork method for this reason.

Page 216: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 216 Version 5.0

As in the CyWork method, the Background Method must also be acti-vated. Select the class name in the Class View window and in the Prop-erties window, set BackgroundTask to true.

In the next Step, private methods are created. In the context menu of the Methods, Private folder, select New Method. In this way create the private methods illustrated in the follow-ing picture:

The pound sign identifies a private method.

Page 217: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 217

Click on the first private method (here: Multiply) with the right mouse button and in the context menu, select New Input Variable. Assign this variable the name op1 and create an additional input variable with the name op2. An output variable is also required. Create the output variable as shown in the illustration on the right and give it the name retcode.

The Multiply method should now contain the variables as shown below:

Page 218: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 218 Version 5.0

Next, create two input variables (op1 and op2) and an output (retcode) variable for the methods Divide, Addition, Subtract and Modulo. In the Class View window, select the SelectArithm server created at the beginning of the project to display the Properties window. Select, under DataType, the user created global type ARITHM.

Open the network with a double click on the ArithmOperation in the Network View window then Drag & Drop an object (here: objCalculator) in the Network. Select the object and in the Properties window set the BackgroundTime to always using the arrow buttons.

Page 219: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 219

The setting always means that the Background method is called by the operating system as often as possible, however the maximum is every 2ms.

Open the program editor. As can be seen in the following illustration, the private method is shown next to the background method.

Page 220: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 220 Version 5.0

In the next Step, the 5 private methods are programmed. Begin with the Multiply method and insert the following program code between END_VAR and END_FUNCTION. retcode := op1 * op2; This line means that the variables op1 and op2 are multiplied. The result is then written to the variable retcode. FUNCTION Calculator::Multiply VAR_INPUT op1 : DINT; op2 : DINT; END_VAR VAR_OUTPUT retcode : DINT; END_VAR retcode := op1 * op2; END_FUNCTION This same program line is required between END_VAR and END_FUNCTION in the other 4 private methods; only the arithmetic operator must be changed. Divide Method retcode := op1 / op2; Addition Method retcode := op1 + op2; Subtract Method retcode := op1 - op2; Modulo Method retcode := op1 mod op2;

Page 221: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 221

The Background method is now programmed as follows:

A CASE-instruction is created for the server, SelectArithm. Within the Case-instruction, the type of operation executed by the SelectArithm server is determined. The SelectArithm server, of type ARITHM, enables the selection of the arithmetic operation (_Nothing, _Multiply, _Divide, _Addition, _Subtract or _Modulo) to be executed. The first program line in the CASE-instruction is written as follows: _Nothing: That means when the entry _Nothing is selected, no operation is carried out.

Page 222: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 222 Version 5.0

The second program line is as follows: _Multiply: Result := Multiply(op1 := Value1, op2 := Value2); SelectArithm := Nothing; The means when _Multiply is selected, the result of the multiplication is displayed in the Result server. The operation type is then reset to _Nothing. The necessary method can be simply dragged & dropped from the Class View window and placed in the program code editor. The inserted program line appears as follows: Multiply(op1:=, op2:=); Next, the clients (in parenthesis) must be assigned the respective input value used in the calculation. The calculated value is then written to the Result server through the instruction below.

Result := Multiply(op1 := Value1, op2 := Value2);

Page 223: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 223

Save and compile the project. Create an online connection and load the project to the des-tination system then start the program. Enter values in the clients Value1 (here: 100) and Value2 (here: 20) of the object with which the operation will be carried out. Define the operation type (here: _Addition) for the server SelectArithm either directly in the objCalculator object or in the debugger window. The result (here: 120) is displayed in the Result server.

Page 224: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 224 Version 5.0

5.1.7 Calling Methods Over an Object Channel In LASAL CLASS 2, it is possible call methods of one class from another class.

In the next example, a new class is created, which will require the meth-ods of the class, Calculator. So that these methods don’t have to be written separately in the new class, they will be simply called over a cli-ent. That means the server of the Calculator class will be connected to a client of another class. The client of the new class is defined as an object channel so the required methods can be called.

In order for the methods of the Calculator class to be accessible, they must first be defined as global. To change the definition, open the Methods folder in the Class View window and select the first private method, Multiply. In the Properties window, set Global access to true. Through this setting the method is now global, which means this method can be ac-cessed from outside the Calculator class. Set the Global access property to true for the Divide, Addition, Subtract and Modulo methods.

Through switching of Global access from False to true the correspond-ing methods are shifted to the Global folder!

Page 225: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 225

The following lines show how the code in the Multiply method is changed because of the new setting. FUNCTION Calculator::Multiply END_FUNCTION FUNCTION GLOBAL Calculator::Multiply END_FUNCTION Create a new class (here: CallMethode) and add it to the Class View window as seen below.

Place an object (here: objCallMethode) of this class in the object network make a connec-tion between the Result server of the class, Calculator and the client, connect of the Call-Methode class. Set a cyclic time of 10ms.

Private Method

Global Method

Page 226: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 226 Version 5.0

Select the client, Connect, in the Class View window to display the Properties window. Select the Object Channel property under Type and under Class, select Calculator. With these settings the Connect client can now access the Calculator class.

In addition to the Data Channel and the Object Channel, a Command Channel is also available. With this setting, all standard methods of a class can be called. The advantage of the Command Channel is its multi-purpose usability.

The ARITHM type is again used for the server, SelectArithm. This setting is made in the Properties window of the Class View window by selecting the server, SelectArithm.

Page 227: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 227

Open the program code editor to program the CyWork method. Assign the Read method to both clients, Value1 and Value2. As in the previous example, the CASE-instruction is also used to determine which operation type is run via the Selec-tArithm server:

The first program line in the CASE-instruction that calls a method appears as follows: _Multiply: Result := Connect.Multiply(Value1, Value2); This line means that if _Multiply is selected in the SelectArithm server then the calculated value of the Multiply method is called through the Result server.

Page 228: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 228 Version 5.0

With the Program line Connect.Multiply(Value1, Value2) The Multiply method from the class, Calculator is called over the Connect client of the CallMethod class. The result of this method is then output to the Result server through it instruction, Result := Connect.Multiply(Value1, Value2); With SelectArithm := Nothing;, the server is reset to _Nothing. The Divide, Addition, Subtract and Modulo methods are called using this same principle Save and compile the project. Go online and download the project changes to the destina-tion system and test the function of the program as in the previous example:

Page 229: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 229

5.1.8 Overwriting the Read and Write Methods of a Server

For each server of a class, the possibility exists to assign and program a Read and Write method. This is shown in the following example with a project consisting of 2 classes. One class has 2 servers. In one server, the Read method is programmed. In the other, the Write method. These methods will then be read from or written to by the 2 clients of the other class.

Create a new project (here: OverwriteServer) as shown in the following illustration.

Make sure that the write protection is deactivated for the servers WriteServer, ReadServer and Server0!

Page 230: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 230 Version 5.0

Create a network (here: OverwriteServerNet) and place an object from both classes. Con-nect the two classes and enter the cyclic time (here: 10ms).

In the Class View window, select ReadServer and open the context menu with a right mouse click. Select Standard Methods, Read.

Page 231: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 231

Assign the Write method to the server, WriteServer, using the same process.

Double click on either the Read method from ReadServer or the Write method from Write-server to display the program code.

Page 232: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 232 Version 5.0

Read Method for the ReadServer output := ReadServer; means when the Read method of the server is called, the current value in the ReadServer is transferred over the return parameter, output. Insert the following program code: output := ReadServer * 10; If the read method of the server is called by a client then the value in the server, Read-Server is multiplied by 10 and the result is returned. If the value in ReadServer were 5, the client would read the value 50 (5 * 10 = 50). Write Method for the Server, WriteServer WriteServer := input; result := WriteServer; Means that the value from a client is written to the WriteServer through the Write method using the parameter, input. Each Write method supplies the return value, result. Using this return parameter, the proc-essing of the Write method can be controlled. The value of the server is returned by default to the returned value. The user, however, has the ability change the return value in the application. Insert the following program code: WriteServer := input + 100; result := WriteServer; When a value is written to this server from a client using the Write method, it is raised by 100. If the value in WriteServer is 50, the value 150 is entered (50 + 100 = 150).

Page 233: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 233

The program code editor should now contain the following program code:

In the next Step, the CyWork method of the CallMethods class is programmed. Open the program code for this method with a double click on CyWork in the Class View window.

Page 234: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 234 Version 5.0

Insert the following if-instruction in the CyWork method:

Save and compile the project. Create an online connection and download the project to the destination system then start the program.

Enter a value in ReadServer of the objReadWrite object (here: 5). To start the program, enter the value 1 in server0 of the objCallMethods object as defined by the if-instruction.

Page 235: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 235

As can be seen, the input value (here: 5) is multiplied by 10 in the Read method of Read-Server. The method is the called by the Call client and the multiplied value (5 * 10 = 50) is transferred. The value in the Call client (50) is then written to the WriteServer over the client Send, where it is raised by 100 and the result displayed (50 + 100 = 150).

Page 236: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 236 Version 5.0

5.2 Complex Objects The possibility exists to create an object network for a specific class. To accomplish this, a class with its own network is created in which the imbedded object is placed. Behind a complex object is an object network, which contains all the objects represented by the new class. A complex object can possess, by its own discretion, all the clients and servers of the imbedded objects. Therefore a complex object has the functions one or several classes.

In a household, objects are found such as an oven, dishwasher and re-frigerator with which one can cook clean and keep things cool. A kitchen can be seen as a complex object that contains all these functions.

Page 237: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 237

5.3 Creating Complex Objects The actual complex class is defined in a new network created for the class in which other objects will be placed.

In the following example a batch counter is created. To begin, a class is created, which has a server and three clients. In addition, a Ram class and the class Trigger_Plus are used. The Ram class is used to store the number of batches and is retrieved as required. The Trigger_Plus class should trigger a short pulse with the activation of a switch. The objects of these 3 classes will then be combined in a complex object, which will then be placed in the network with the Hardware classes.

Create a new project (here: Complex) as shown in the Class View window below:

Don’t forget to set the DefaultCyclicTime (here: 100ms). From the DIASMasterC.ICP, import the CDI16X class and the Ram class from the library Memory.ICP. Select the Reset client and in the Properties window, set Required to False.

Page 238: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 238 Version 5.0

Here, the Trigger_Plus is needed. Load the Standard Library in the Libraries window.

In the standard library (Standard/ Logic/ Trigger/ Trigger_Plus), select Trigger_Plus and in the context menu click on Copy to import the Trigger_Plus class.

Trigger_Plus is required to generate a short pulse with the initiation of a switch. Without this class, the batch would be counted using the += 1 instruction in the program code and would be dependant on a cyclic time.

Page 239: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 239

Double click on the Methods folder in the Class View window to open the program code editor and program the Init and/or CyWork method:

Read the commentary in the code carefully to better understand the func-tion of the program.

Page 240: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 240 Version 5.0

In the next Step, create a new class (here: PieceCounter). Select Add Network in the context menu of this class to create a new object network (here: PieceCounter).

Double click on the network to open it.

Page 241: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 241

Place the Counter class in the network using the Drag & Drop method to create an object of this class. An object of the Ram class (here: ProducedPieces) and the class, Trig-ger_Plus are also required. Next, set the cyclic time (here: 100 ms) and connect the ob-jects as shown in the illustration below:

The complex object consists of three placed objects, through which the function of the complex object is implemented. To connect the Pieces server to the complex object, start from the server and end with a left click anywhere outside of the complex object as shown below. The server is then con-nected to the complex object.

Page 242: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 242 Version 5.0

The clients, To_Trigger in objTrigger_Plus and Reset in objCounter are connected to the complex object in the same manner. The network should then appear as follows:

Click on the Net tab to display the project tree and open the Network View window. Create a new network (here: CounterNet). Double click on the network to open it.

Page 243: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 243

Place the classes, PieceCounter, CDI16X and DiasMasterC in the network.

Connect the objects as illustrated below. In the properties window of the PieceCounter class, don’t forget to set Required to false for the Reset client.

Page 244: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 244 Version 5.0

The object objPieceCounter of the class, PieceCounter is now a complex object. It con-tains the objects objCounter, ProducedPieces and objTrigger_Plus.

The symbol to the right of the class name represents a complex object.

To display the objects contained in a complex object place the mouse pointer on the upper right corner of the complex object until a downward pointing arrow appears.

Double click on this symbol to display the network containing the objects that comprise the complex object (objPieceCounter). To return to the network containing the complex object, place the mouse pointer on the upper right corner of the complex object. When an upward pointing arrow appears, double click on it.

Page 245: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 245

Save and compile the project. Go online and download the project to the destination system and run the program. When the switch is active for a short time, a pulse is triggered. Depending on how often the switch is activated (here, the switch is activated and deactivated 8 times), the batch counter is incremented and written to the Pieces server. When the value 1 is entered in the client Reset, the batch count is reset to 0.

Observe the process in the network of the opened complex object.

Page 246: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 246 Version 5.0

If the functions of a complex object can be reused if they are needed again later.

Go offline and place a second object of the PieceCounter class in the network:

In the online mode, test the function of second object, which triggers a pulse with switch 2:

Page 247: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 247

5.3.1 Virtual Methods What does VIRTUAL GLOBAL in the methods declaration of a standard method actually mean (except for the constructor)?

FUNCTION VIRTUAL GLOBAL Calculator::CyWork Methods that should be overwritten must be assigned as virtual (VIRTUAL GLOBAL) methods. 5.3.2 Derivation of Classes and Overwriting Methods The Derivation of classes enables a class to take on the characters and process instruc-tions of another class (the so called Base Class). The derived class has, therefore, a rela-tionship to the base class. The advantage of deriving a class is that the methods of the base class can be used. Through the derivation of a class, the new class inherits the meth-ods of the base class.

Only classes are derived, not methods. Methods are overwritten.

Page 248: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 248 Version 5.0

To present the derivation of classes and overwriting of methods in a prac-tical example, the project Derive is created. This project has a class (Subtract), which consists of 2 clients (Value1 and Value2) and a server (Result). The arithmetic operation is entered through the clients. The Calculate method must also be created to execute the operation (sub-traction). Next, the class Add is derived from the class, Subtract and will have the same components as the Subtract class. Only the Calculate method will be overwritten (the operation will be changed from subtrac-tion to addition).

Create and prepare the Derive project mentioned above so it appears as in the following Class View window:

Also create a network (here: DeriveNet).

Make sure the Calculate method has the 2 input (Input1 and Input2) variables and the output (Result) variable. Set Required for both clients to False.

Page 249: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 249

In the Class View window, select the Calculate method to open the Properties window and set Global access to true. The property, Virtual then appears, which must also be set to true.

Global access must be set to true so that the method can be accessed from outside the Subtract class. So that this method can be overwritten when externally accessed, Virtual must also be set to true

Page 250: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 250 Version 5.0

Open the program code editor to program the CyWork and Calculate Methods:

Read the commentary carefully to better understand the program code.

Page 251: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 251

Save and compile the project. Go online and enter a value in the clients Value1 (here: 10) and Value2 (here: 5) to test the function of the program. These values should be subtracted and the difference (10 – 5 = 5) written to the Result server.

In the next Step, a class is derived from the class Subtract. Create a new class (here: DeriveAdd).

Page 252: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 252 Version 5.0

Insert the new class, DeriveAdd, in a network by selecting Add Network in the context menu.

Select the DeriveAdd class in the Class View window to display the Properties window. Under BaseClass, select the Subtract class to link the class DeriveAdd as a derived class of the base class, Subtract.

Page 253: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 253

In the Class View window, the Base folder is found under the DeriveAdd class. When this folder is opened, the Subtract class (base class) is seen with all its components listed under it. These components are inherited by the class, DeriveAdd.

A derivation can be created faster by highlighting the class and selecting Derive Class in the context menu.

Page 254: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 254 Version 5.0

Open the DeriveAdd network with a double click.

Through the assignment of the class Subtract as the base class for DeriveAdd, an object of the base class is automatically placed in the DeriveAdd network. As can be see in the illustration below, the clients must be connected to the derived class.

Page 255: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 255

Select the Network tab in project tree. Open the network, DeriveNet, with a double click or by selecting Edit in the context menu.

Drag & Drop an object of the class DeriveAdd in the network with objSubtract as shown below.

Page 256: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 256 Version 5.0

Don’t forget when connecting the objDeriveAdd object to set the CyclicTime (here: 100 ms) in the properties window.

The derived object now has the same functions as the object of the base class and can be used for the subtract operation. The object of the DeriveAdd class should be used for addi-tion operations. That means the Calculator method must still be changed (overwritten) from subtraction to addition.

Page 257: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 257

To overwrite the method, select Overwrite, Calculate in the context menu of the Methods folder of the DeriveAdd class.

The Calculator method is then added and is opened in the program code editor with a dou-ble click the program code editor then overwritten. In the method, the arithmetic operator need only be changed from – to + for addition.

Page 258: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Page 258 Version 5.0

Save and compile the program. When online, download the changes to the destination system and start the program. Enter the same value in both objects. The objSubtract object will execute a subtraction (10 – 5 = 5), while objDeriveAdd will perform an addition (10 + 5 = 15) with the help of the overwritten method.

Page 259: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CLASSES AND OBJECTS IN LASAL CLASS 2

Version 5.0 Page 259

5.4 Topical Exercises 5.4.1 Simple Signal Generator

(SignalGenerator Project) Requirements 1. In this example, a class is created that outputs a saw tooth wave to a client and a

server as well. The CyWork method is programmed as well as an additional method (VIRTUAL GLOBAL) to implement this instruction. The Signal method, which generates a saw tooth wave, should be created using the operating system variable ops.tAbsolute.

2. The generator should be triggered using a client (start). Two additional clients are

needed to set the amplitude and change the time base. 3. If these classes function, a new class should be derived from them. In the new class,

the Signal method is then overwritten and programmed to out put a triangle wave (see Oscilloscope).

Process As soon as the start button of an object is pushed, the signal method should be called. The time delay, which dependant on the time base setting, is produced with the help of the op-erating system variable ops.tAbsolute. The other client specifies the amplitude of the output signal. Tips for completing the task

Begin with creating the derived class when the class that produces the triangle wave functions. In the derived class only the signal method is programmed.

Page 260: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 260 Version 5.0

6 Additional Components of Structured Text Pro-gramming

6.1 Working with Pointers 6.1.1 What is a pointer? In programming a pointer is a variable, which contains the memory address of data instead of the data itself. The pointer refers to specific data; it always points to the first byte. 6.1.2 Definition of a Pointer The size of a memory area is assigned in bytes. The numbers of these areas are described as addresses. To easier address memory space names (variable) are used instead of num-bers. Variables also represent addresses in memory. Pointers are thus variables, which point to specific addresses in memory.

A pointer is a variable that contains the memory address of another vari-able.

Pointers are 4.byte variable, which are used for a specific memory area and are not as-signed a value. A pointer can be aligned with any data type, making it possible to define a pointer that point to an individual integer value or to complex structures and arrays.

Page 261: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 261

6.1.3 Important Instructions for Working with Pointers

The character ^ is used to declare a pointer (e.g.: ptr of Type -> ^DINT). The address of a variable is determined using the address operator #. Using the ^ character, the contents of pointer are addressed (e.g.: ptr^)

// The variable is assigned a value a := 123; // Here, the address of the variable // (16#40AF5) is stored in the pointer. ptr := #a; // The content of the pointer, ptr, is // written to variable b b := ptr^;

Page 262: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 262 Version 5.0

The function of a pointer is explained on the following pages using exam-ples. A class in a project has a server and 3 variables. The first variable has a specific value and address in memory. The second variable is de-fined as a pointer and assigned the address of the first variable. This variable points, with help from the pointer, to the first variable and trans-fers the value contained to the third variable. The server acts only as a switch to start the program.

Create a new project (here: Pointer) and add the components as shown in the Class View window below:

Remove the write protection from the server (Switch) and assign a CyclicTime. Also cre-ate a network (here: PointerNet). Place an object of the class (PointerClass) in the network.

Page 263: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 263

In the Properties window, assign the type DINT to all three variables.

Select the ptr variable and in the Properties window, set Pointer to true. As can be seen, the data type DINT is now written as => ^DINT. This means the variable, ptr, is now de-fined as a pointer.

Page 264: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 264 Version 5.0

Open the program code editor to program the Cywork method:

Read the commentary carefully to better understand the program code.

Save and compile the project. Go online, download the project to the destination system and start the program.

Page 265: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 265

In the network, enter the value 1 in the Switch server of the object, objPointerClass to run the program.

How the address of variable a is assigned to the variable ptr can now be observed in the debugger window. The ptr variable points to variable a with the help of the address and transfers the value within to variable b (here: 241).

Page 266: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 266 Version 5.0

6.1.4 Conversion and Casting of Type In a project, it is possible that global and local variables, clients and servers of various data types are assigned. If the value of a client of type DINT (double integer) is assigned to a variable of type INT (integer), the compiler would generates an error message in the output window:

To avoid the above situation, the client must be changed to the same type as the variable. The compiler will also not accept an assignment between to unlike types with the same data width (i.e. BINT to INT). For assigning small data types to larger types, the conversion is done by the compiler automatically. a : SINT; // Short Integer b : DINT; // Double Integer b := a; // assignment to larger data type The next example shows how variable b of type DINT is converted to the same data width of variable a of type SINT. a : SINT; b : DINT; a := TO_SINT(b); // convert variable b to SINT

The variable to be converted (here: Variable b) must always be in ( ). The following instructions are available for converting data types: TO_INT, TO_SINT, TO_DINT, TO_UINT, TO_USINT, TO_UDINT, TO_REAL

Page 267: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 267

The following graphic shows the difference between casting and conversion. Variable, a of Type USINT, is assigned to variable x of type UDINT.

With converting, the value of variable a is written to the first byte of variable x. With casting, the value of variable a is not only written to byte 1 of variable x, the contents of variables b, c and e are also written to bytes 2, 3 and 4 of the x variable.

At casting only variables with the same data rate should be used. Other-wise a part of the variable may not contain the desired values. Primarily pointer or self-defined types (all types that cannot be converted) should be casted.

Example: VAR v1 :INT; v2 :IINT; v3 :USINT; END_VAR v1 := 256; v2 := v1$UINT; // The variable v2 contains the value 256 because the same data rate is casted. v3 := v1$USINT; // The variable v3 contains the value 0! The reason for that is that the USINT data type ranges from 0 to 255. As v1 has the value 256, it is started from the beginning and the value 0 is called after 255.

Page 268: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 268 Version 5.0

In the following example, a class is created, which has 5 variables. The variables Val1, Val2, Val3 and Val4 are assigned as type HSINT. The variable, ValX, is defined as type HDINT. Variable Val1 is the assigned to variable Valx. Since both variables are different data types, they must be changed so that the data types match. To illustrate this, the assignment will be done once using conversion and again by casting.

Create a new project (ConvertCasting) and assign the components shown in the illustra-tion below:

Create a network (here: ConvertNet) and place an object of the class (ConvertClass). Assign a value to CyclicTime. Next, open the program code editor and insert the following code:

Page 269: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 269

Save and compile the project then download it to the destination system.

Set a break by the first variable using the button and start the program.

Next, press the button to process the first program line. Observe the debugger window. As can be seen, the value from Val1 is assigned to ValX through the conversion:

Press the F5 button to execute the next the program line and reset ValX to 0.

Page 270: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 270 Version 5.0

The program is now at the next program line:

Press the Step Into button once more to process this line. In the debugger window, the assignment of the values from the other variables through casting is shown:

With the F5 button jump to the next line in the program. ValX now contains the value 16#FFFF0F0F.

Page 271: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 271

The program is now at the last line of code:

Execute the last line in the program and in debugger window, observe how the value in Val1 is assigned to the first byte in ValX only. The remaining bytes are unchanged.

Byte

Page 272: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 272 Version 5.0

6.1.5 Transferring a pointer to a Method

To show how a pointer is transferred to a method, a class is assigned with the CyWork method and an additional private method is assigned in the next example. The transfer parameter of the private method is then defined as a pointer to hold the address of a variable. The variable will then be assigned values over the pointer of the private method.

Create a new project (here: PointerMethod) and define the components shown in the Class View window below:

Make sure that the write protection for the Switch server is removed.

First assign the type MYDATA and define it in the Properties window as data type STRUCT with 3 elements. Next, create the variable DataEle-ment and assign it to MYDATA.

Create a network (here: PointerMethodNet) and place an object of the class, Pointer-Class).

Page 273: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 273

In the next Step, a private method is required. This is created in the context menu of the folder, Methods under New Method.

Name the new method InitData then right click on this new method to open the context menu and select New Input Variable.

Page 274: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 274 Version 5.0

Select the new input variable (here: ptr) to display the properties in the Properties window. Assign the type, MYDATA.

Finally, set Pointer to true. The input variable ptr for the InitData method now acts as a pointer.

Page 275: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 275

Open the program code editor with a double click on a method.

Read the commentary carefully to better understand the program code.

Save and compile the project. Go online, download the project to the destination system and start the program.

Page 276: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 276 Version 5.0

Place the cursor on the first program line in the InitData method.

Set a breakpoint at this position by pressing the button or selecting Debug, Break-point(s) and Toggle Breakpoints in the menu bar.

Open the Watch tab in the debugger window and click on Click to add new. Insert ptr as show below by pressing Enter.

Page 277: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 277

It's easier to mark the ptr pointer in the program code editor and to pull it into a Watch window via Drag & Drop.

Switch to the network window and enter the value 1 in the Switch server to start the pro-gram.

Press the F5 button to process the program line where the breakpoint is set; element1 is then set to 1. Push F5 twice to process the rest of the program and assign the correspond-ing values.

Page 278: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 278 Version 5.0

As can now be see in the following illustration, the address of the DataElement variable is read with the help of the pointer.

Page 279: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 279

6.1.6 Using a Pointer as the Return Parameter of a Method

Since a method can have only one return parameter, a pointer will be used in this example as the return parameter of a method to access lar-ger amounts of data. Other classes will also be able to access this data.

Create a new project (here: ReturnData) and construct it to the point shown in the project trees of the windows shown below:

First, create a global type (here: TEXTINFO) of the type STRUCT and define 3 elements (xpos, ypos and alphanumeric). Define the alphanu-meric element as an array of type CHAR. Define both the transfer pa-rameter ptr for the InitData method and the return parameter ptr for the Outptr method as pointers of type TEXTINFO. For the Outptr method, global access must be enabled.

Page 280: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 280 Version 5.0

Open the program code editor with a double click on a method and insert the following program code:

The variable index of type USINT is assigned locally through Index : USINT; That means this variable can only be used for this function! Also see chapter Local Variables in LASAL CLASS 2.

Page 281: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 281

In the next Step, a new class (GetData) is required. In addition, define the components shown in the Class View window below:

Remove the write protection from the server, ClassSvr and define both variables (Address and TextParam) as type TEXTINFO. Assign the vari-able Address as a Pointer.

Next, select the client Connect in the Class View window and define it as an object chan-nel of the Handling class in the properties window.

Page 282: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 282 Version 5.0

To program the CyWork method, open the program code editor:

Create a network (PointerNet) and place an object of both classes. Connect both classes as show below:

Save and compile the project then download the program to the destination system.

Page 283: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 283

To start the program, enter a value unlike 0 in ClassSvr of the objGetData object.

Observe the address of the TextData variable in the object Handling and the value of the Address variable in the object objGetData. Using the Connect client in the GetData class, the Outptr method of the class Handling is called. Through the calling of this method, the address of the data is retrieved over the pointer.

As also can be seen, the elements xpos and ypos are assigned the values 4 and 1 respec-tively. In addition, the fields 0 to 9 in the alphanumeric element have been assigned a letter.

Page 284: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 284 Version 5.0

To observe how the address of the data is assigned to the pointer, set a breakpoint at the

Outptr method as shown in the following illustration using the button.

Enter the return parameter in the debugger window and press F5 to process the program line. As can be seen, the address of the data is now assigned to the ptr return parameter.

Page 285: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 285

6.1.7 Summary Through the use of pointers, data is processed more flexibly since it is easier for them to access structures. In certain cases, pointers can accelerate the program flow.

If several return parameters are required, they should be assigned as pointers! Pointers can also be defined as transfer parameters to which values can then be written!

6.2 Topical Exercises 6.2.1 Pointer Field

(Pointerfield Project) Requirements This example copies the data of an array to another array using a pointer. Both arrays should have the same field depth (20 array entries) and the maximum array depth should be copied.

Process Both arrays are pre-initialized, whereas one array (data source) is assigned arbitrary values and the other (data destination) is initialized with 0. To implement this project, create a method that will transfer the addresses of both arrays and the number of data (20) to be copied. Tips for completing this task

In the method, both pointers are MODIFIED to copy data until all data has been copied. A help pointer should be used to copy in this process.

Page 286: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 286 Version 5.0

6.2.2 Pointer-Copy

(Pointercopy Project) Requirements This example copies an array to another array over a pointer. Both arrays should have the same field depth (20 array entries) and should only copy this data. After the data is copied, however, the sequence should be inverted in the array to which it was copied.

Process Both arrays are pre-initialized, whereas one array (Data Source) is assigned arbitrary val-ues and the other is initialized with 0. The data should be copied by the triggering of an event (i.e. switch) and help variable. Tips for competing this task

In the Cywork method, both pointers are modified to copy data until all data is copied in inverted order. A help pointer should be used in this process.

Page 287: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 287

6.3 Operating System (OS) Functions 6.3.1 OS Classes in the Library The LASAL CLASS 2 operating system (OS) provides various methods for interfacing with the user program. These interfaces consist of graphic functions, operations for memory and file management, and functions for CAN communications as well as others. In this chapter, the library functions for memory and file operations are discussed. The _StdLib class provides methods with which memory areas can be reserved, expanded or cleared. In addition, functions are available for copying, shifting, comparing memory areas as well as assigning them specific values. The possibility exists with the _FileSys class to run file operations such as opening and closing files. It is also possible to read files and/or write to them through this class. Directories can also be created, deleted and renamed. 6.3.2 Linking and Applying OS Classes In order to use these functions, the category OS Interface.lcp in the Libraries window must be opened. The classes _FileSys and/or _StdLib can then be imported into the project.

Page 288: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 288 Version 5.0

So that the methods of the _StdLib or _FileSys class, a client defined as an object channel is required in the respective OS class. In the class pic-tured below, the client ConFile is an object channel of the _FileSys class and the client ConLib is an object of the _StdLib class.

The connection is made automatically when a client is defined as an ob-ject channel of an OS class. Therefore, it is not necessary to place an object of these classes (_FileSys or _StdLib) in a network and connect them to the user class.

Page 289: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 289

6.3.3 Using _StdLib Operations

In the following example, the methods of the class _StdLib are used to explain memory operations. Two arrays will be used, one of which has an area pre-initialized with various values. The other array is required to copy, shift and compare data to the first array.

MemMove This function is called to move memory blocks with a defined number of bytes from a source buffer to a destination buffer. If this function is inserted in the program code editor from the project tree using Drag & Drop, the line of code will appear as follows: MemMove(dest:=, source:=, size:=);

Transfer Parameter Return Parameter dest = Pointer for the destination buffer retval = Pointer to the destination buffer source = Pointer for the source buffer size = Size of the memory block to be copied MemSet This function fills a memory area with a specific number of bytes. The program code ap-pears as follows: MemSet(dest:=, value:=, size:=);

Transfer Parameter Return Parameter dest = Pointer for the destination buffer retval = Pointer to the destination buffer value = Fill value for the individual bytes size = Number of bytes to fill

Page 290: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 290 Version 5.0

MemCpy This function is called to copy memory blocks with a defined number of bytes from a source buffer to a destination buffer. The code appears as follows: MemCpy(dest:=, value:=, size:=);

Transfer Parameter Return Parameter dest = Pointer for the destination buffer retval = Pointer to the destination buffer source = Pointer for source buffer size = Number of bytes to fill MemCmp This function is used to compare memory blocks with a defined number of bytes. The pro-gram code appears as follows: MemCmp(dest:=, source:=, size:=);

Transfer Parameter Return Parameter dest = Pointer for the destination buffer source = Pointer for source buffer size = Number of bytes for comparison

retval = 0 means, the source and destination are equal <> 0 means, the source and destination are unequal

All available Loader functions can be found in the "Loader API.doc" document. The following functions are included: _memmove _memicmp _memcm _memcp _memcpyre _strcat _strcmp _strcpy _strlen ... These functions can be immediately used in LASAL Class. However the code is not added automatically.

Page 291: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 291

Create a new project (UseOs) and define the components shown in the Class View win-dow below:

Load the OS-Interface library in the Libraries window and import the _StdLib class. Define the variables, DataArray and SplitData, as Arrays of type USINT. The type, MEMSTEP is an ENUM type and contains the elements shown in Class View window above. Place an object of the class UserClass in the network (UseOSNet).

Page 292: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 292 Version 5.0

Open the program code editor and insert the following program code:

Save and compile the project. Go online and download the project to the destination sys-tem.

Page 293: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 293

Start the program and open the THIS tab in the debugger window to observe the process:

As can be seen, the DataArray variable is already initialized with a value, whereas the fields in the SplitData variable contain 0.

Using the Move up instruction in the context menu, shift the MemOp variable to the first position. This will also be displayed before the other variables in the debugger window.

Page 294: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 294 Version 5.0

Next, select the operation MemoryMove under the MemOp variable in the debugger win-dow.

10 values starting from the 3rd field (3, 4, 5, ...) of the variable DataArray are then shifted to every field in the SplitData variable:

Select the MemorySet operation to set all 15 fields in DataArray to 0:

Page 295: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 295

With the MemoryCopy operation, the values in SplitData are copied to 8 fields (starting with field 4) of DataArray.

Observe sever, Equal, in the MemoryCompare operation. Since the 8 values in DataArray starting from field 4 are the same as the values in SplitData, a value of 0 is entered in the server. If the fields in both arrays are not equal, a value unlike 0 is entered in the Equal server.

Page 296: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 296 Version 5.0

In the next example, additional functions of the OS class _StdLib are used. Using these functions, memory can be reserved for the application through programming.

Preliminary information on the OS functions Malloc and ReAlloc Free Malloc This function reserves a memory area in the CPU’s RAM. The size of the memory block is determined using a transfer parameter. Using this function, memory space in a program can be reserved as required in the exact size needed. The Malloc function provides a pointer which points to the reserved memory area. If no memory in the appropriate size is available, the return value of the function is NULL. The Malloc function also returns NULL if the transfer parameter contains the value 0. ReAlloc The ReAlloc function changes the size of a reserved memory block in the CPU’s RAM by changing the defined number of bytes in a previously reserved memory block. This function sometimes returns a new address for the memory block, which can deviate from the exist-ing address. If the size change is not possible, the return value is NULL

When using the ReAlloc function to change size, it’s possible that an-other application-reserved memory block is located behind previously reserved memory. In this case, the RAM will be searched sequentially and the next free memory space with the required size will be allocated. The data will be copied to the newly reserved memory block and the old one will be cleared.

Free The Free function clears a memory area previously reserved with Malloc or ReAlloc, mak-ing the memory area is available again. This function supplies no return value.

Page 297: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 297

The following example demonstrates how 2 Arrays (Alphabeth and Digits) can be copied after one another to a memory area that has been allo-cated before. A further array (MemResult) is filled afterwards with a filled memory area.

Create a new project (here: Alloc) like the one in the following Class View window:

Define the ConLib client as object channel of the _StdLib class. Define the pMallocaddress as pointer. The variables Alphabeth, Digits and MemResult are arrays of Char type. The STEPS type is an ENUM data type. Also create a network (here: StorageNet) and place an object of the Storage class in it.

Page 298: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 298 Version 5.0

Now open the program code editor and insert the following program code:

Page 299: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 299

FUNCTION VIRTUAL GLOBAL Storage::Init In the Init method both arrays were initialized. The Alphabeth variable now contains the ASCII values of all characters of the alphabet. The Digits variable contains the ASCII values of numbers from 0 to 9. FUNCTION VIRTUAL GLOBAL Storage::CyWork _MemALLOC: pMallocAddress := ConLib.Malloc(sizeof(Alphabeth));

Here via the ConLib client the ReAlloc method is called. The memory size (size of the Alphabeth variable) to be reserved is defined as transfer parameter. Therefore the method gets the required memory size. The pMallocAddress pointer is the return parameter of the method. Sizeof(Variable) returns a value in-cluding the required bytes for the variable. The Alphabeth variable, used here, is an array with 26 CHAR fields. As CHAR has 1 byte, sizeof(Alphabeth) will return the value 26. If pMallocAddress > 0 then

SSW := _NoOp; end_if;

Via this if instruction it can be controlled whether the pMallocAddress has been ini-tialized or not.

_COPY_Alphabeth:

ConLib.MemCpy(pMallocAddress,#Alphabeth[0],sizeof(Alphabeth)); Here via the ConLib client the MemCpy method is called. The content of the Al-phabeth array is written to the memory area, starting at the pMallocAddress. ConLib.MemCpy(#MemResult[0],pMallocAddress,sizeof(Alphabeth))

; Here the memory area content is copied to the MemResult array that can contain a maximum of 35 characters.

Page 300: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 300 Version 5.0

_MemREALLOC:

pMallocAddress := ConLib.ReAlloc(pMallocAddress, sizeof(Alphabeth) + sizeof(Digits));

As next step the Digits array should be written to the memory area according to the characters of the alphabet. For it the allocated memory area has to be increased by 10 bytes. Sizeof(Digits) then returns the value 10.

_ADD_Digits:

ConLib.MemCpy(pMallocAddress +sizeof(Alphabeth), #Dig-its[0], sizeof(Digits));

Here the content of the Digit array is copied to the memory area according to the alphabet values (target address is pMallocAdress +sizeof(Alphabeth)!).

ConLib.MemCpy(#MemResult[0] +sizeof(Alphabeth), pMallocAddress +sizeof(Alphabeth), sizeof(Digits));

Here the content of the memory area is written to the MemResult array, starting at field position 26 (=sizeof(Alphabeth)). Now the MemResult array contains all char-acters and numbers from 0 to 9.

_MemFREE:

Here the allocated memory area is deallocated again, so the operating system can use it for other applications.

Assign a Cyclic task to the Storage class and define a cyclic time of 100ms at the objStor-age object. Save your project, compile and start it in online mode.

Page 301: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 301

Open the Debugger tab in the THIS window.

Here you can see the pre-initializations of the arrays Alphabeth and Digits. The pointer variable still shows 0 (16#00000000). Thus no memory has been allocated. Now at the step control select _MemALLOC.

At the pMallocAddress pointer variable you can see now that an address has been as-signed.

Page 302: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 302 Version 5.0

Now select the step _COPY_Alphabeth at your step control.

Watch the content of the MemResult array that has been copied from the allocated mem-ory area. Select _MemREALLOC afterwards.

The pointer variable got a new address for the increased memory area! The content has been copied automatically from the "old" memory area (16#018E5A44) to the new one (16#018E5AAC).

Page 303: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 303

Select _ADD_Digits as the next step.

Now you can see the content of the Digit array (numbers from 0 to 9) at the end position of the MemResult array. It has been copied from the reallocated memory. If the requested memory is no longer required, it can be deallocated again by selecting _MemFREE

Page 304: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 304 Version 5.0

6.3.4 Using _FileSys Operations

In this example, _FileSys operations from the OS interface library are used. With help from these functions, a file is created in the destination system. In online operation, values will be written to and also read from this file. A Case instruction can be used to change between the opera-tions.

Preliminary information over the OS functions used in this example FileOpen This function is used to open or create a file. If this function is inserted into the program code editor using Drag & Drop, it will appear as follows: FileOpen(filename:=, attributes:=);

Transfer Parameter Return Parameter Filename = Name of the file Handle = Pointer to whether the file was

opened or the error code when an error occurs

Attributes = User specific attribute (In this example, the constant ATT_CREATE is used to create a file)

In the following table, the most frequently used attributes are listed. A full list is available in the operating system documentation. ATT_READ_WRITE File opened with read and write authorization ATT_READ_ONLY File opened with read only authorization ATT_CREATE File is created if it none exists ATT_CREATE_ALWAYS File is always created new whether or not it already exists

Page 305: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 305

FileWrite This function is called to write data to a file. The code is written as follows: FileWrite(handle:=, buffer:=, length:=);

Transfer Parameter Return Parameter Handle = Handle on the file written to Written = The number of bytes written or

the error code if an error occurs Buffer = Buffer that holds data to be written in the file

Length = the size of the data in bytes

File Read This function serves to read data from a file. The program code is written as follows: FileRead(handle:=, buffer:=, length:=);

Transfer Parameter Return Parameter Handle = Handle of file to be read Read = The number of bytes read or the

error code in the event of an error Buffer = Buffer to hold data from the file Length = Size of the data to be read in bytes FileClose This function is called to close a file. The program code appears as follows: FileClose(handle:=);

Transfer Parameter Return Parameter Handle = Handle for the closed file -

Page 306: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 306 Version 5.0

Several file functions send error codes to the return parameter when errors occur. The most frequently occurring error codes are listed below. A full list is available in the operating system documentation. Return value Error code Description 0 NO_ERROR No errors -3 INVALID_FILENAME An invalid file name is entered (containing

special characters, for example) -6 NO_MORE_FILES This error code is given when using Find-

First() and FindNext() and no more files can be found.

-9 FILE_NOT_FOUND The file name entered was not found. -16 ACCESS_DENIED Access to the file was denied. For example,

data was opened with read only access and an attempt was made to write to the file.

-19 PATH_NOT_FOUND The directory entered was not found. -22 DISK_FULL To little memory space on the medium used. -29 DRIVE_NOT_READY The selected drive or medium cannot be

accessed. (i.e. accessing an unavailable USB interface)

-36 FILE_EXISTS The file already exists. (Renaming a file to an existing file name)

Page 307: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 307

Create a new project and begin by importing the _FileSys class from the OS interface li-brary. Add the components shown in the Class View window below to the project.

Define the type FILEDATAS as type ARRAY OF CHAR and the type FILESTEPS as an ENUM type. Also create a network (here: FileOpNet).

Page 308: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 308 Version 5.0

Open the program code editor to program the Background method:

Page 309: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 309

Explanation of the program code Handle := ConFile.FileOpen("C:\MyFile.txt", ATT_CREATE); With the OS function FileOpen, MyFile is created using the constant ATT_CREATE. Handle := ConFile.FileOpen("C:\MyFile.txt", ATT_READ_WRITE); With the FileOpen function, MyFile is opened for reading and writing with the constant ATT_READ_WRITE. FileState := ConFile.FileWrite(Handle, #FileData[0], SIZEOF(FILEDATAS)); Using the FileWrite function, the values in the FileData variable are written to the file. ConFile.FileRead(Handle, #FileData[0], SIZEOF(FILEDATAS)); The OS function FileRead is called over the client ConFile and the values in the file are written to the FileData variable. ConFile.FileClose(Handle); With help from the ConFile, the FileClose function is called and the file is closed. Save the project and download it to the destination system.

Page 310: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 310 Version 5.0

In online mode, open the THIS tab in the debugger window and under FileStep, select Create File.

The MyFile.txt file is thereby created, opened and stored in the assigned directory (here: C:\). The file is then closed again. The Handle variable is assigned an identification number as the file is created. The operat-ing system now has a definitive identification for the opened file.

Page 311: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 311

In the next Step, select the operation Open4ReadWrite under the variable FileStep to open the file for read and write access.

Next, enter a value, respectively, letter (here: HELLO) in the individual array fields of the FileData variable, which are then written to MyFile.txt. Don't forget to write the letters be-tween two inverted commas.

Select the WriteFile operation to save the entered letters to the file. Close the file and Stop the program. This is not necessarily required, however, whether the values were actually stored in the file can be verified since the array fields are initialized with 0 when restarted. When the file is read, the stored values are re-entered into the array.

Page 312: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 312 Version 5.0

Select CloseFile under the variable FileStep and Stop the program using the button or the F8 key.

Restart the program by pressing the button or the F7 key. The array fields are again initialized with 0.

Open the file with read and write access (Operation Open4ReadWrite). To read the values, select the ReadFile operation. The values are then entered in the array fields.

Page 313: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 313

To save the file (MyFile.txt) from the destination system to the hard drive of the PC, select Debug, Extras, and Load File from PLC in the menu bar:

Before the file can be saved from the target system to your PC, you have to close the it. Select the CloseFile step under FileStep to close the file. Otherwise an error message is displayed in the Output window!

In the PLC Filetransfer window, enter the path of the file as well as the file name. Confirm with OK.

Page 314: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 314 Version 5.0

In the Save under window, select the directory in which the file should be saved and define the file name (here: MyFile.txt). Ensure that the .txt file ending is included and click on Save.

Afterwards open the text file with a text editor. The inserted letters are saved, as shown in the following illustration.

Page 315: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 315

If the FILEDATAS type is defined as ARRAY OF UDINT...

... and afterwards numbers are inserted to the Array fields,...

...then the entered numbers are stored as ASCII values in the MyFile.txt file.

Page 316: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 316 Version 5.0

6.4 Working with Tables 6.4.1 What are tables used for? Tables are used to define values or text in user programs. Tables can contain text, numbers and/or constants. The contents can be read from the table according to specified criteria and subsequently used in various applications. Applications using tables:

- Definition of machine dependant set values - Assignment of text for various messages, for example, to terminals - Interpolation of temperature - Providing parameters for various processes

6.4.2 Important Information over Tables Tables can only contain constant data, which cannot be changed during the run time of control program. Also, the values contained in a table are predefined.

The name of a table also serves as the pointer to the table. The first 4 bytes of every table contain the length of the table but are not included in the actual table length.

6.4.3 Syntax for Text and Numbers in Tables The input of elements in tables can be done the following ways: The Declaration of numbers with different number systems:

As decimal number 462 As binary number 2#01110101 As Hexadecimal number 16#B4A

The Declaration of character strings:

Input as Text “This is text“ The possibility also exists to use pre-processor commands in tables. With help from these commands, constants can be defined and symbolic names entered in a table. The definition of these constants can be made in a header file or in the table directly.

Page 317: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 317

The various methods for writing tables are as follows: Text in a table Here, MAX_TEMP and MIN_TEMP are defined directly in the Table. (Pre-Processor instruction) Decimal number Binary number Hex number START_VALUE and STOP_VALUE Would then be defined in a Header file. Line and block commentary can also be used in Tables.

Further information on linking header files and applications for pre-processor instructions is found in chapters 1.4 and 1.5.

Additional instructions allowed The LASAL CLASS 2 compiler always uses the smallest data type possible, which is 1 byte. For example, for 16#00A2, here this data type can also be converted or casted (I.e.: TO_UINT(16#00A2) or 16#00A2$UINT).

Page 318: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 318 Version 5.0

6.4.4 Creating Tables in a Class To create a table in a class, open the context menu and select New Table.

The table (Greeting) is then displayed in the Tables folder and can be opened with a dou-ble click.

Page 319: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 319

6.4.5 Tables Containing Text

The following example shows how the data length of a table is deter-mined. In addition a pointer is be created to access the first and/or the following character of a text string. This character will be displayed with the help of a variable.

Create a new project (GetText) as shown in the Class View window below:

Define the variable MyChar as type CHAR and the variable Len as type UDINT. Also create a network (here: TableNet).

Page 320: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 320 Version 5.0

Open the program code editor and insert the following program code:

In the program code editor, a table is identified through the designation, TAB! FUNCTION TAB Table::Greeting

Explanation of the program code Len := #Greeting()^; This line defines the data length of the table (here: 20 characters). As previously men-tioned, the table name (Greeting) is also the pointer to the table. The address of the table is assigned through the pointer (table name) and the contents are written to the variable using the ^ character.

Page 321: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 321

pchar := #Greeting() + SIZEOF(UDINT) + NextChar; The pointer should be set on the first letter of the table text with this program line. Through pchar := #Greeting() The pointer points to the table only. Because the pointer should point to the first letter in the table text, the instruction SIZEOF (UDINT) is used: pchar := #Greeting() + SIZEOF(UDINT) SIZEOF(UDINT) ensures that 4 bytes are added to the actual pointer position. This means the pointer is set to the first letter (H) of the table text.

4 bytes is the length of the table!

Create a variable (with the name Size for example) of type DINT. Type the following code in the CyWork method: Size := SIZEOF(UDINT) In online mode, how the value 4 is written to this variable can be seen in the debugger window.

pchar := #Greeting() + SIZEOF(UDINT) + NextChar; The client NextChar serves only to shift the pointer so that the next letter can also be shown. A value of 1 in this client will set the pointer on the letter e. MyChar := PChar^; With this line, the contents (the letter to which the pointer points) are written to the variable MyChar. Save and compile the project then go online and download the project to the destination system.

Page 322: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 322 Version 5.0

Set a breakpoint at the position shown in the following illustration and start the program.

Press the F5 button to process the program line. In the debugger window, the assignment of the text length (20 characters) to variable Len can be seen.

To observe the pointer, pchar, open the Watch window and enter pchar.

Page 323: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 323

When the F5 button is pushed again, the contents (H) on which the pointer is positioned is written to the variable MyChar.

Return to the breakpoint from the function using the button combination Alt + F5 or by

pressing the button. In the client NextChar, enter the value 1 to load the next letter with the next program scan.

With the next step using the F5 button, MyChar is assigned the next letter (e).

If the value of the client NextChar is incremented by 1 with each program scan, the pointer will continue to point to the following letter in the table text and assign it to the variable MyChar. The OS function MemCpy can be used so that the value of the client must not be incremented manually.

Page 324: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 324 Version 5.0

First import the OS Interface.Icp library and the _StdLib class there from. Next, create a new client (ConnLib) and define it as an object channel of the class _StdLib. A new vari-able (NewChar) of type ARRAY OF CHAR is now required. For this array, 25 fields should be defined.

Expand the program code with the following line:

Page 325: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 325

Go online and start the program. Click on the + next to the variable NewChar to show the array fields:

In the Array Range window, define the desired number of array fields to be displayed (here: all 25 fields). As can be seen in the debugger window, the text is entered in the array fields sequentially and the entire table text is displayed. The fields 20 to 24 remain empty since the text has only 20 characters.

Page 326: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 326 Version 5.0

6.4.6 Tables Containing Numbers or Constants

This example shows how numbers can be read from a table using point-ers and displayed in a server.

Create a new project (TableValue) and define the following components as shown in the Class View window below:

Define the variables NextVal and TabLen as type UDINT. The variable TabResult should be defined as USINT. Also create a network (here: TableNet).

Page 327: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 327

Open the program code editor and insert the following program code:

Page 328: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 328 Version 5.0

Explanation of the program code TabResult := TO_USINT((#MyTable() + SIZEOF(UDINT) + NextVal)^); With this line, the pointer should point to the first number in the table. Because the table only contains USINT values (0-255 without sign), the contents on which the pointer points is converted to USINT with TO_USINT

Since only USINT values are available in the table, it is enough to add (1 byte) an index (nextVal). With 2 or 4 byte values, the index must be mul-tiplied by 2 and/or 4 bytes (NextVal * sizeof(UINT) or NextVal * sizeof(UDINT)). If table values of different type sizes are available, the index increasing has to be adapted accordingly. Otherwise the result is incorrect!

SIZEOF(UDINT) This code ensures that 4 bytes are added to the actual position pointer. The pointer is then positioned on the first number (0) in the table. The variable NextVal guarantees that the pointer points to the values in the table sequentially. The number on which the pointer is currently positioned is assigned to the variable TabResult. This number is then assigned to the Result server via the Result := TabResult; instruction TabLen := #MyTable()^; Here, the number on which the pointer is positioned (length of the table) is written to the variable TabLen Save and compile the project then go online and download the project to the destination system. The values from the table, MyTable, can be observed in the Result of the objDiffValues server as they count up and down.

Page 329: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 329

6.4.7 STRING processing via the SIGMATEK classes String and

StringRAM

In this example Strings will be created in different ways and stored into a file afterwards.

Create a new project (here: StringHandling) according to the following screenshot:

Design a class (StringClass) and create a network (StringNet). Assign the class a cyclic task. Import the String class from the Memory library and create an object of it by moving it to the network. Call this object objString. Furthermore import the _FileSys class from the OSInterface library.

Page 330: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 330 Version 5.0

Insert the following program code:

Page 331: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 331

Program code explanation Here you can see 4 possibilities to initialize a string: Possibility 1: MyString[0] := 'H'; MyString[1] := 'e'; MyString[2] := 'l'; MyString[3] := 'l'; MyString[4] := 'o'; MyString[5] := 0; This string is designed manually. Each string has to be finished with a null, to be able to identify the string end (MyString[5] := 0; ) Possibility 2: for i := 0 to #MyTable()^ - 1 do TableString[i] := to_usint((#MyTable() + 4 +i)^); end_for; In this For loop the second string is initialized. Possibility 3: Connect.WriteDataOff(20 ,0, "User! "); In this line on the Data server of the objString string object the string "User!" is written. Connect.ReadDataOff( 0, #TextString[0]$USINT, 100); Via the ReadDataOff string method the content of the Data server is read out and written to the TextString variable. Possibility 4: Connect.Clear(); To be able to write on the Data server of the objString object again it is necessary to exe-cute the Clear() method.

Page 332: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 332 Version 5.0

Connect.InitFromTable(#TextTable()^, #TextTable()$^USINT + 4); The content of the TextTable is written to the Data server of the string object. Connect.ReadDataOff(0, #TextTableString[0]$USINT, #TextTable()^); Here the content of the Data server is copied to the TextTable string. Thus 4 strings have been created in different ways. Via the following program code these 4 strings are written into a file (StringFile.txt) and stored to the root directory: if ClassSvr <> 0 then Handle := ConFile.FileOpen("c:\StringFile.txt", ATT_CREATE); if Handle >= 0 then ConFile.FileWrite(Handle,#MyString[0],_strlen(#MyString[0]));

ConFile.FileWrite(Handle,#TableString[0],

_strlen(#TableString[0])); ConFile.FileWrite(Handle,#TextString[0],

_strlen(#TextString[0])); ConFile.FileWrite(Handle,#TextTableString[0],

_strlen(#TextTableString[0])); ConFile.FileClose(Handle); else TRACE("An error occurred at FileWrite!"); end_if; ClassSvr := 0; end_if; Now open the file created just now and check the correct functionality of the program.

The StringRAM class has the same functionality as the String class. The only difference is that the saved string is still available after program re-start.

Page 333: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 333

6.5 Pre-Processor Instructions 6.5.1 General Notes Pre-processor instructions are used to define constants or mark specific program lines which are treated as commentary (conditional compilation). With conditional compiling, the program lines are processed exactly the same as lines behind the \\ characters or in paren-thesis with stars (* *). With #pragma instructions, compiler warnings can be deactivated and the data type setting can be changed. A constant is used to define a value or condition in a program, which doesn’t change. Con-stants can be represented using either a fixed value (literal constant) or a constant name (symbolic constant). 6.5.2 Predefined Constants Trace Macro The Trace Macro can be used to output messages during the processing of program code. This message is defined with help from constants in the program code and displayed under the Debugger Trace tab in the output window.

Using Trace Macros, the program can be controlled to run specific pro-gram lines without having to use the debugger. In the desired program line, the user defines a message and starts program. If this message is output during the program run, the user knows that this program line was processed.

The Trace Macro is written as follows: TRACE(" ") Within this constant, the text is written between quotation marks. TRACE0(" {0} ", #Var0) Via the TRACE0 constant it is possible to display a variable within the text. {0} is the place-holder and displayed in brackets. After the comma in the constant the address of a CHAR variable (or ARRAY OF CHAR) is defined. This value can then be seen on the placehold-ers' position.

Page 334: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 334 Version 5.0

TRACE1(" {0} {1} ", #Var0, #Var1) The TRACE1 constant has the same functionality as the TRACE0 constant but with 2 vari-ables. TRACE2(" {0} {1} {2] ", #Var0, #Var1, #Var2) The TRACE1 constant has the same functionality as the TRACE0 constant but with 3 vari-ables. TRACE0 example:

Page 335: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 335

In the following example, a project is created in which the constant Trace Macro is used. With help from this constant, text will be defined that will then be displayed in the Debugger Trace window during the program run.

Create a project (Pre-Processor) and define the components shown in the window below:

Also create a network (here: PreProcessorNet). Next, open the program code editor and insert the following program code:

Page 336: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 336 Version 5.0

Save and compile the project then go online and push start. Enter a value in both clients, Value1 and Value2 and set the Switch1 server to 1 in order to start the program.

The following message is displayed in the Debugger Trace window according to the pro-gram code, after a successful arithmetic operation.

Page 337: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 337

Constant _PI The constant _PI supplies the value of Pi (3,141593) as a REAL number The constant _PI is written as follows: PiValue := _PI; That means the value 3,141593 is assigned to the variable PiValue.

In the following example, the constant _PI is implemented in the project Pre-Processor.

Assign the data type REAL to the Result server. Next, create a variable (PiValue) and define it also as the data type REAL.

Page 338: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 338 Version 5.0

Expand and/or change the program code as follows:

When online, enter a value in the client Value1, which should be multiplied with the Pi value (here: 4). Start the program by entering 1 in the Switch server.

In the debugger window observe how the number Pi is multiplied with the number in Value1 and the result (12,566371) written to the Result server as a Real number.

Page 339: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 339

6.5.3 Available Pre Processor Instructions The following pre processor instructions are available: #define #undef #ifdef #ifndef #elsif, #else, #endif #if #elif

#define With #define; symbolic constants can be created in a program or a header file. Constants defined with #define can be removed with the #undef instruction.

In the following example, 2 constants are defined. First the constant VALUE3, which contains a value of 2. The second constant, VALUE4 contains a value of 3. With the help of both constants, an arithmetic op-eration will be performed. The example will then be expanded and changed for pre processor instructions.

Change the program code from the previous example as follows:

Page 340: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 340 Version 5.0

Through the defined constants VALUE3 (with a value of 2) and VALUE4 (with a value of 3), the value 6 will be written to the Result server through the multiplication in the program code.

Constants can be defined with a value, but this is not required. ...either #define VALUE3 => here, only the constant VALUE3 is defined. ...of #define VALUE3 2 => Here, the constant VALUE3 is defined with the value 2

#undef Removes the constants defined with the #define instruction.

With the #undef instruction, the constants loose their availability only.

Page 341: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 341

If the constants that have been undefined with the #undef instruction are used in the pro-gram code, the following message appears in the output window:

#ifdef, #elif, #else, #endif With the #ifdef, #elif and #elsif instructions, several defined constants can be selected. The selection is then ended with #endif. Modify the program code as follows and note the commentary to better understand the individual program lines.

Page 342: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 342 Version 5.0

Note the difference between #elsif and #elif. While #elsif checks whether the assigned value (here: #elsif VALUE4 = 3) corresponds to the value defined in the constant (here: #define VALUE4 3), #elif checks whether the constant is actually defined (here: #elif VALUE4).

In the Online mode, the value 10 is now written to the Result server since the VALUE3 is defined as a constant.

If VALUE3 is not defined as a value, a value of 24 is written to the Result server through the #elsif instruction since the constant VALUE4 is assigned a value of 3. #ifndef This instruction can be used to define what should occur if a specific constant is now de-fined. Insert the following program code and start the program online. Because VALUE5 is not defined, the Result server outputs a value of 20

Page 343: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 343

#if When the #if instruction is used, the constant must be assigned a value. Start the program with the following code:

Since the assigned value in the constant VALUE3 is 4 rather than 7, the value in the con-stant (here: 8) VALUE4 is displayed in the Result server.

Page 344: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 344 Version 5.0

6.5.4 Pragma Instructions The pragma instruction uses C-programming to provide access to several instructions. The function of the pre processor is expanded through the use of pragma instructions. The us-able instructions are compiler and operating system specific. The instructions not recog-nized by the pre processor trigger a compiler message. The following pragma instructions are available: #pragma warning #pragma pack #pragma pack (push, n) #pragma pack (pop) #pragma pack (n) #pragma message #pragma once

#pragma warning If the pre processor doesn’t recognize an instruction, a warning message is displayed dur-ing compilation. With #pragma warning this warning message can be deactivated.

For the following example, a new class is required in the Pre-Processor project. A private method with an input variable will also be created. This input variable will not be used in the project and therefore trigger a com-piler warning that will subsequently be deactivated. Further Pragma In-structions will also be introduced through this project.

Create a new class (PragmaInstruction) and a private method (Warning) with an input variable (Input1)

Page 345: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 345

Open the private method in the program code editor:

Compile the project. The compiler warning Parameter 'Input1' is never used now appears in the output window because the input variable is not used in the program:

The indicator W 0073 at the beginning of the warning can now be deactivated using #pragma warning. Insert the following program lines to deactivate the warning:

Page 346: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 346 Version 5.0

The program line #pragma warning (disable:73); disables the compiler message so that it is no longer displayed. With #pragma warning (default:73); the compiler message is deactivated in the specified method only. If this warning occurs in other methods, it is displayed in the output window. #pragma pack (push, n), #pragma pack (pop) With help from these instructions, individual types, variables or function definitions can be changed in a complete project after the alignments (data alignment) have been made.

At project creation the alignment is set to 4 by default for the complete project (see project properties compiler), as this is the optimal setting for the CPU performance. Here EACH data type (also BOOL, SINT,…) works with the complete 4 bytes, whereby the bytes not used are left blank.

A change to a lower alignment is only reasonable in exceptional cases (at very low RAM memory)!

For example: a of Type DINT b of Type INT c of Type SINT

Page 347: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 347

To explain the function of the #pragma pack (push, n) and #pragma pack (pop) instruc-tions, the Pre-processor project is expanded. Create an additional method in the class PragmaInstruction (PragmaPack) and insert 3 input variables (here: a, b and c) as shown below.

Open the program code editor with a double click on the PragmaPack method and insert the following code: ensure that data types of the three input variable are different.

The #pragma pack (push, 2) instruction ensures that the variables a, b and c are aligned to 2 bytes. The instruction #pragma pack (pop) reestablishes the data alignment set with the project properties. The 2-byte alignment is valid only for the variables a, b and c.

Page 348: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 348 Version 5.0

The instruction #pragma pack (pop) must always follow the #pragma pack (push, n) instruction.

In the illustration below, the possible alignments for the 3 variables are show graphically: Variable a => DINT (requires 4 Bytes of memory) Variable b => INT (requires 2 Bytes of memory) Variable c => SINT (requires 1 Bytes of memory)

Page 349: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 349

The following Graphic shows how alignment 4 is changed to alignment 2 using the pragma pack (push, 2) instruction and subsequently limited to the variables a, b and c with #pragma pack (pop).

Page 350: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 350 Version 5.0

#pragma message Using the #pragma message instruction, a message can be displayed in the Output tab of the output window. First define a constant (Temperature) and assign it a value (here: 45°). Next, define a message using the #pragma message instruction:

The message will then be displayed in the output window during compilation:

Page 351: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 351

#pragma once Via this instruction the compiler is told to only compile this file (header file) once. If a further #include file is available, this will not be opened and compiled by the compiler. Therefore the compilation time can be optimized and no warnings concerning "identical redefinition" are output. The #pragma once instruction is written in the Header file as follows:

The header file will then be compiled with the two defined constants only once. Information on creating and linking header files is found in chapter 6.6.

Page 352: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 352 Version 5.0

Compiler In this branch, all settings required for compilation are made and are all set to true.

Page 353: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 353

VariableNeverUsed Gives a warning message (WARN) in the compiler window if a variable is not used in the program code. E.g. 'i' declared but never used ValueNeverUsed Occurs when a variable is assigned a value that is never used. E.g. 'i' assigned a value that is never used LabelNeverUsed Triggers the message that a label is defined, which is not used. E.g. Label 'step20' is declared but never used ParameterNeverUsed Triggers a message (WARN) in the compiler window that a transfer parameter in the pro-gram is never used. E.g. Parameter 'Param' is never used VariableUnitialized This message appears when a variable is used that has not been initialized. E.g. Possible use of 'a' before definition RetValueUnitialized Indicates that the return value of a method has not been initialized. E.g. return value 'OutParam' is not defined PrivateDataAccess Triggers a message if the private variables of another object are accessed. SemicolonMissing This message appears when the semicolon at the end of an instruction is missing.

Page 354: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 354 Version 5.0

ConditionConstant If an operation is always true or false, a message is triggered (i.e. infinite loop). E.g. Condition is always TRUE ExactTypeChecking Gives an ERROR message when variables of different data types are used. E.g. Different types: using 'DINT' instead of 'UDINT' CheckConnectionType Checks the connection between a client and server as to whether they have the same data type.

Page 355: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 355

Alignment The alignment serves to align the data in an entire project. Complete projects and/or librar-ies whose classes are linked must be compiled with the same alignment. This is also true for the loader. Basically, the alignment for a project can be set with the properties of a project in the Prop-erties window. Here, the user can align data in 1,2 or 4 bytes.

Page 356: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 356 Version 5.0

ReducedClientDependency Reduced Client Dependencies (RCD) comes with projects carrying linked classes. There-fore classes in the second (linking) plane are not normally imported. Whether the setting should be made or not depends on each project. When loading projects in LASAL CLASS 2, synchronization between the project and library is established automatically by which new class information is assumed by the project. After determining whether RCD is being used with the project, the automatic importing of unnec-essary classes in prohibited (a simple synchronization is executed however). If the RCD setting is deactivated during the working with LASAL CLASS 2, the project must be re-loaded to include the missing classes. MaxModuleErrorCounter With this value, the maximum number of compilation errors can be output. If more errors occur in a module during compilation of a project than the MaxModuleErrorCounter value, only the specified number of errors is shown in the Compiler window. The errors from the next module are then shown in the Compiler window.

Page 357: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 357

6.5.5 Include Instruction With help from the Include instruction, the location of a specific header file on the hard drive can be searched and inserted. There are two ways to implement this instruction: #include "File.h" #inlcude <File.h>

#include “File.h“ If the name of the header file is written between two apostrophes, the compiler searches the actual project directory (E.g.: C:\Sample\PreProcessor) for the Include file.

In this header file, 3 constants are defined. In addition, the header file, MyHeader-File.h is included so that constants can be defined in this file as well.

With the addition of “..\“ in the assignment of header files, a directory can be limited.

Page 358: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 358 Version 5.0

#include <File.h> If the name of the included file is written between <> characters, the compiler searches for the Include file starting from the path in the Options menu under Tools where the Include Paths parameter is assigned.

Page 359: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 359

6.6 Linking Header Files 6.6.1 When and Why Header Files are Used As soon as a project constant is used, it can be defined in a header file. This is not abso-lutely necessary but it can significantly improve the clarity of a project with a large number of constants. The use of header files is at the discretion of the programmer. The possibility exists in LASAL 2 to assign header files for a global or class linked project. 6.6.2 The Difference Between Class-Oriented and Global Header

Files A class-oriented header file is created with the class of a project and can only be used by the class for which it was created. Global header files are created in the File Explorer and can be used by every class in a project. The disadvantage of global header files in a project is that constants defined within are not transferred if a class is imported to another project.

Page 360: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 360 Version 5.0

6.6.3 Class-Oriented Header Files

In this example, a project is created in which a class oriented header file is created. Constants, which will later be used in the CyWork method of a class, will be defined in this header file.

Create a new project (UseHeaderFile) and define the components shown in the following illustration:

Also create a network (here: UseHeaderNet). In the context menu of Temperature, select Add File....

Page 361: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 361

Next, select the folder in which the header file should be saved and assign a name (My-Header.h). Be sure not to forget the .h file ending and click on Open.

When selecting the destination folder, it is important that the header file is located in either in the Source Folder of the project or in the folder of the class that uses the file. It is also important not to forget the *.h file ending in the file name!

In the Class View window of the project tree, the Files folder is assigned automatically in which the header file is located.

Page 362: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 362 Version 5.0

Open the header file with a double click and define the following constants:

In the program code editor, the Cywork method is programmed as follows:

Page 363: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 363

The defined constants are now used as follows in the Temperature class: With MaxTemp := MAX_TEMPERATURE; MinTemp := MIN_TEMPERATURE; The defined temperatures (50° and –15°) are written to the respective servers. In the if-instruction if ActualTemperature > MAX_TEMPERATURE then elsif ActualTemperature < MIN_TEMPERATURE then the constants are compared with the value in the client, ActualTemperature.

In Online mode, enter the value 60 in the ActualTemperature client. Since a temperature of 60° exceeds the maximum temperature of 50°, the difference (10°) is written to the DiffTemp server. In the Debugger Trace register, the following message is also displayed in the output win-dow:

Test the program by entering different values in the client, ActualTemperature and ob-serve the messages in Debugger Trace register in the output window.

Page 364: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 364 Version 5.0

6.6.4 Global Header Files

In this example, a header file is created and defined as global so that its not linked to a specific class. This example will be implemented in the UseHeader-Files project. To show how a global header file can be used, a new class is created in the project with the previously defined constants MAX_TEMPERATURE and MIN_TEMPERATURE.

Create a new class (NewTemperature) and define the components defined in the following Class View window:

Next, in the Properties window of the Temperature class, set Global to true for the My-Header.h file.

Page 365: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 365

The header file, MyHeader.h can now be used by all classes in the project. Note: Change to the project tree and select the tab File and open the Header Files folder. As can be seen, the MyHeader.h is located in this folder. The other header files are already avail-able by default and contain predefined constants.

That means a header file can be created in this window. A header file created here does not belong to a specific C-File; therefore it is advantageous to always create a header file directly in the class.

Page 366: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Page 366 Version 5.0

Connect both objects placed in the network as follows:

Open the program code editor to program the CyWork method of the NewTemperature class as follows:

The constant, MAX_TEMPERATURE, in the header file of the Temperature class can now be used since the setting for this file was made global.

Page 367: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ADDITIONAL COMPONENTS OF STRUCTURED TEXT PROG.

Version 5.0 Page 367

In Online mode, enter the value 60 in the client ActualTemperature to create a tempera-ture difference of 10°. So that the message defined in the program code is displayed, a value greater than 40 (here: 45) must entered to exceed the maximum temperature.

The message is then displayed in the Debugger Trace register of the output window:

If constants in a header file are required by several classes, the #pragma once instruction is defined in the header file so that it is compiled only once and not per class.

Page 368: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 368 Version 5.0

7 Instruction List Programming 7.1 Advantages of an Instruction List Program In LASAL CLASS 2, the possibility exits to create programs, program sections or functions in IL code. The programming language, IL (Instruction List) is a type of Machine language. The advantage of programs written with IL is that they are processed faster than structured text due to its similarity with machine code. Because IL programs are processed faster, they are mostly used to access hardware. 7.2 Principle Construction of Memory The following illustration shows the schematic construction of a LASAL CPU. The memory area is shown with its individual components.

Page 369: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 369

In LASAL CLASS 2 in the Project menu under Info, the project information can be viewed. In this window, the addresses for the code and the data in memory are visible. Here, infor-mation over their length can be found.

Page 370: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 370 Version 5.0

7.3 The Most Important Information Concerning a CPU During a program run, the intermediate memory is available for data in the process memory units. These memory units are described as registers in which individual data words can be stored. Because these registers are found inside the CPU, intermediate results can be saved and/or recalled faster. Basically, registers are divided according to the following scheme: the so-called universal registers (AX, BX, CX, DX) are fully available. These can be assigned values freely. The universal registers can be sectioned further. The resulting half registers have their own name and are only one byte in size.

Register Half register Half register AX changed to AH AL BX changed to BH BL CX changed to CH CL DX changed to DH DL

The AX register is divided into AH and AL. H stands for high and is the upper section of the main register. L stands for low and is the lower section of the main register. In the illustration below, the expanded 32-bit AX register is shown. That means the ex-panded 32-bit register becomes the EAX register.

Inside the CPU, there is a special register that can be used to test specifies conditions after the execution of instructions. In these flags or status registers, each bit represents a switch that can be activated or deactivated. The so-called special registers such as IP and SP, for example, are designated for specifies tasks inside the CPU. Registers used for addressing are the most important in this case.

Page 371: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 371

7.3.1 Universal Registers Accumulator: EAX, AX (AH, AL) Several arithmetic operations (multiplication and division) can be done through the accumu-lator. In addition, all I/O data is passed over the Accumulator. Base Register: EBX, BX (BH, BL) Used as the base register for indirect addressing. (Addition and Subtraction) Count Register: ECX, CX (CH, CL) Counter register for loops and repetitive operations such as shift operations to several bit positions. Data Register: EDX, DX (DH, DL) Used mostly for multiplication and division. For indirect I/O instructions, DX contains the channel number (access to port addresses). Moreover, each of these registers can be used as a buffer. 7.3.2 2 Index Registers and 2 Pointer Registers The source index and the destination index are used for indirect addressing of memory space in which general data or special string elements are stored. Source Index: ESI Places the pointer on data source for block transfer instructions.

ESI is always the this-pointer and must always be reset (using PUSH and POP)! In each object a pointer called this is available, which points to the object itself. The this pointer contains the address of the object.

Page 372: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 372 Version 5.0

Destination Index: EDI Places the pointer on the data destination for block transfer instructions. The stack pointer and base pointer are used for indirect addressing of memory areas.

These registers are not for use by the operator!

Base Pointer: EBP In the EBP, data in the stack memory can be accessed. Stack pointer: ESP The ESP manages the stack and contains the address of the last place filled on the stack. 7.3.3 Segment Register When addressing memory space, the base address is assigned through a segment register. Each of the 4 segments (DS, CS, ES, SS) are used for a specific purpose as described below: The user does not require these registers. Data Segment Register: DS In the data segment, general data is stored. Code Segment Register: CS The instructions in the running program are stored in the code segment. Extra Segment Register: ES The extra segment serves as an additional data segment. During string operations, it con-tains target operands.

Page 373: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 373

Stack Segment Register: SS In the stack segment, data is stored during stack operations. 7.3.4 Special Register Instruction Pointer: EIP The instruction pointer always contains the address of the next instructions to be executed. The corresponding address is supplied by the code segment register, CS. Flag Register: EFL This register contains status bits, which show the status of the last executed instruction and triggers conditional jumps in the program.

Carry-Flag Parity-Flag Auxiliary-Flag Zero-Flag Sign-Flag Direction-Flag Overflow-Flag

Page 374: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 374 Version 5.0

7.4 Instruction List Programming in LASAL CLASS 2 SIGMATEK CPUs are equipped with an INTEL 80386 and IPCs have an INTEL CELERON processor. The C-DIAS industrial PCs are equipped with an INTEL Pentium compatible processor. Because the original instruction syntax for IL programming is not ideal for PLC applications, a few minor changes were made to make programming easier. The logic instructions that occur predominantly in programming have been shortened to a letter. In the original instruction syntax, there are no “load” or “save” instructions. Instead, “MOV” is used. The destination is to the left of the data source. SIGMATEK uses the following abbreviations: L (load): For everything that enters the processor, except for loading a memory area di-rectly. S (save): For everything that comes out of the processor.

SIGMATEK INTEL L Number MOV AL, Number S Result MOV Result, AL

For byte, word and double word operations without the use of a processor register, the width must be designated as 8, 16 or 32-bits. In the original syntax, the addition of “BYTE PTR“ for 8-Bit, “WORD PTR“ for 16-Bit and „DWORD PTR“ for 32-Bit are place before the address. SIGMATEK uses the abbreviations: B → Byte = 8-Bit W → Word = 16-Bit D → Double word= 32-Bit

SIGMATEK INTEL CMP.B Hand, 001 CMP BYTE PTR Hand, 1

Page 375: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 375

7.5 Important Information Over the Stack A section of the RAM is reserved for special memory; the so-called stack. Through the stack, subroutines are called and returned to the main program more easily. The instruction address of the interrupted program, which will later be restored, is stored automatically in the stack. The stack is loaded and unloaded whereas new data is placed on top of previously stored data and is recalled from last to first. This is called the LIFO method: Last in – First out. Local variables are also placed in the stack. A special register called the stack pointer, always points to the element at the top of the stack.

Page 376: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 376 Version 5.0

7.6 Instruction Groups for Programming with IL The instructions for creating a program and/or function in IL are classified in the following instruction groups. These groups contain all necessary instructions for creating programs in IL: Data transfer instructions Logic instructions Comparison instructions Shift instructions Jump instructions Arithmetic instructions Status register manipulation Special instructions

On the following pages, only the most important commands are listed. Further commands can be found in the LASAL 2 help support under Help, Help Topics. The entry for Instruction Groups for Programming with IL is listed in the Index tab.

7.6.1 Data Transfer Instructions L - LOAD Load

The assigned register or memory location is loaded with a value. The load instruction must always be at the beginning of a link

L.Destination Source L.EAX Variable //The EAX Register is loaded with

//the value of the variable L.BX AX //The contents of AX are loaded to

//BX

Page 377: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 377

S – SAVE Save

The contents of a register are copied to the assigned memory location.

S.Source Destination S.EAX Variable //The value of the EAX Registers

//is saved in the Variable S.AX BX //The contents of the AX

//are stored ins BX

XCH Exchange

The contents of a register are exchanged with the contents of another register (or memory space).

XCH.AX BX //the contents of AX are exchanged //with the contents of BX

7.6.2 Logic Instructions O – OR Bit wise OR connection

Creates a bit wise OR connections and serves to set bits

OR.AX 2#00001111 //the lower 4 Bits in the AX //register are set to 1

Truth table:

E1 E2 A 0 0 0 0 1 1 1 0 1 1 1 1

Page 378: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 378 Version 5.0

A - AND Bit wise AND Connection

Creates a Bit wise AND connection and deletes bits.

AND.BL 2#00001111 //The upper 4 Bits in the //BL-Register are set to 0

Truth table:

E1 E2 A 0 0 0 0 1 0 1 0 0 1 1 1

X – XOR Exclusive OR connection

Creates a bit wise XOR connection and serves to invert individual bits.

X.AL 2#00001000 //The assigned Bits are linked //with the XOR connection to the AL //register

Truth table:

E1 E2 A 0 0 0 0 1 1 1 0 1 1 1 0

Page 379: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 379

NOT Negation through ones complement

Inverts and/or negates all bits.

NOT AL //All Bits are inverted

Truth table:

E1 A 0 1 1 0

7.6.3 Comparison Instructions CMP Compare two operands

Compares the left operand with the right. The right operand is subtracted from the left for this purpose, however no result is saved. This instruction is used to prepare for a condi-tional jump. The CMP instruction sets the following bits in the EFL registers: AF, CF, OF, PF, SF and ZF.

CMP.AX BX JBE MAXI //jumps to MAXI, when AX < BX

TEST Test bits

Executes a logic AND connection between both operands. No result is given; the status bits in the EFL register (flag register) are changed. This instruction is used in preparation for a conditional jump in the program when specific bits in the operands are equal (or unequal).

TEST.EAX (EBX) //goes to jump marker JE SWITCHON //SWITCHON //If at least 1 bit in both //operands is set, a jump to //SWITCHON occurs

Page 380: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 380 Version 5.0

7.6.4 Shift Instructions SHL Logic shift left

The operand is shifted to the left by the desired number of bits. With each shift instruction, the bits to the right are filled with 0.

SHL.EAX 002 //EAX is shifted to the left 2 //times

ROR Rotate right

The operand is shifted to the right by the specified number of bits. With each rotate process the bits to the left are filled with the bits shifted to the right.

ROR.EAX 002 //EAX is rotated to the right //2 times

Page 381: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 381

7.6.5 Jump Instructions JE Jump if 0

The jump is executed when ZF (Zero Flag in the flag register) is set. This occurs when the result of a logic, arithmetic or write instruction is 0. Also, when the operands in a CMP in-struction are equal.

CMP.AX BX //Jump to LAB1, if AX = BX JE LAB1

JAE Jump if greater or equal

This jump is executed if CF (Carry Flag in the flag register) is not set. This occurs when no carry over exists after an arithmetic instruction or the CF contains a 0 after a write instruc-tion is processed.

CMP.AX BX JAE LAB1 //Jump to LAB1, when AX >= BX

JNZ Jump when not 0

The jump is executed when ZF (Zero Flag in the flag register) in not set. This occurs when the result of a logic, arithmetic or write instruction is not equal to 0.

CMP.AX BX JNZ LAB1 //Jump to LAB1, if AX <> BX

Page 382: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 382 Version 5.0

JNE Jump when not equal

The jump is executed when ZF (Zero Flag in the flag register) in not set. This occurs when the result of a logic, arithmetic or write instruction is not equal to 0.

CMP.AX BX JNE LAB1 //Jump to LAB1, if AX <> BX

CALL Call a subroutine

This instruction is used to call a routine, which is needed several times within a program. The program is therefore divided into a main program and subroutines. In the main pro-gram, only the calls for the subroutines and the criteria for which subroutine should be processes are set. Using the CALL instruction, a structured, easy to read program can be created.

FUNCTION AWL MAIN CMP.B MAN, 001 //Query whether the machine is in JE MANUAL //Manual operation mode. CALL AUTO //No: Call automatic subroutine JMP NEXT //--> See what happens next MANUAL CALL MANFCT //Call manual subroutine NEXT CALL SECURE //Call higher //secure function END_FUNCTION //---- END MAIN PROGRAM ---- FUNCTION AWL AUTO //*** Subroutine: Automatic *** .... END_FUNCTION FUNCTION AWL MANFCT //*** Subroutine: Manual **** .... END_FUNCTION

Page 383: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 383

7.6.6 Arithmetic Instructions ADD Add

The right operand is added to the left; the difference is also stored in the left operand. In this case, a carry over from a previous addition is not considered. A carry results when CF (Carry Flag in the flag register) is set.

ADD.AX 00020 //the number 20 is added to AX

SUB Subtract

The right operand is subtracted from the left; the difference is also stored in the left oper-and. A carry over form a previous subtraction is not considered in this case; a carry over results when the CF (Carry Flag in the flag register) is set.

SUB.AX 00020 //AX is reduced by 20

7.6.7 Status Register Manipulation STC Set Carry

Sets the CF (Carry Flag) in the flag register. This instruction is used in transfer of yes/no information and influencing the shifting of bits with shift instructions used with carry.

STC RCL.AX 1 //afterwards AX is shifted to the left //and Bit 0 = 1

Page 384: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 384 Version 5.0

7.6.8 Special Instructions NOP No operation

NOP is a single byte instruction, which executes no operation and has no influence on the function of the program. This instruction changes the EIP register only. CBW Conversion from Byte to Word

CBW converts a byte in the AL register while retaining the sign to a signed word in the AX register to transfer the most significant bit from AL to all bits in the AH register.

Page 385: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 385

7.7 Example Applications in SL 7.7.1 Creating an IL Method

In the following example, 2 values will be multiplied through IL program-ming and the result subsequently written to a server.

Create a project as shown in the Class View window below:

Also create a network (here: AWLMultiNet) and remember to remove the write protection from all three servers! Next, open the program code editor:

Page 386: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 386 Version 5.0

To program the CyWork method in IL code, select CyWork in the Class View window to display the Properties window. Set the property AWL implementation to true.

Through this setting, the first line (marked in yellow) of the CyWork method includes the designation AWL:

An IL function is always identified by the designation AWL in the first line of the program: FUNCTION AWL VIRTUAL GLOBAL Multiply::CyWork

Page 387: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 387

The following error message appears in the output window when the project is compiled:

The reason for this is because the line, state:= READY; is not recognized in IL programming. Delete this line or define it as commentary so that the compiler will not read it. In IL pro-gramming the following lines are required instead:

L.EAX READY Loads READY to the return parameter state. S. EAX state Saves READY to state. The EAX register is used since state is of type UDINT.

Page 388: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 388 Version 5.0

Take caution to ensure that, in IL programming, not to begin at the far left margin of the program code editor; rather start with an indent. Program lines started from the left margin are recognized as jump points. A jump point is a reference that tells the program where to begin after a specific instruction (i.e.: loop).

Expand the CyWork method with the following program code:

Compile the project then go online. Set a breakpoint as shown below and start the program.

Page 389: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 389

Enter the values in servers Value1 (here: 5) and value2 (here: 4) to be multiplied.

Open the Register window of the debugger window to observe the individual steps of the program process.

Execute the first line of the program by pressing the F5 button. In the Register window, the number in Value1 is entered in the EAX register:

Page 390: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 390 Version 5.0

When the next line is processed the value in the server, Value2, is loaded to the EBX regis-ter.

In the next program Step, the result of the multiplication is written the EAX register.

Continue to Step through the program and the result will be written to the Result server as can be seen in the THIS window.

Page 391: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 391

7.8 Topical Exercises 7.8.1 Arithmetic Operation (Project Arithmetic1_AWL) Requirements In this example, a class with 3 clients should be created. The first two clients Op1 and Op2 are added and the sum is multiplied with Op3. The end result of this arithmetic operation should be written to the Result server.

Process Create the required IL program code for this operation in the CyWork method. Tips for completing this task

Look in the LASAL CLASS 2 Help for the required IL instructions for addition (ADD). Simply enter ADD in the help index to find the descrip-tion.

Page 392: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 392 Version 5.0

7.8.2 Arithmetic Operation (Project Arithmetic2_AWL) Requirements In this example, class is created which has 2 clients used as inputs for an arithmetic opera-tion (division). 2 servers are used to store the result and the remainder of the operation.

Process Create the required IL program code for this operation in the CyWork method. Tips for completing this task

Look in the LASAL CLASS 2 Help for the required IL instructions for division (DIV). The IL instruction CLR is also needed to clear the EDX register before the operation. This is necessary since the remainder of the division is stored in this register.

Define initialization values for the clients and pay attention to not make a division over 0!

Page 393: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 393

7.8.3 Jump Points and Loops in AWL

In the next example, the value 3 will be added to a register 7 times (3 + 3 + 3 ...) using the IL function LOOP with a defined loop index.

Create a new project as shown in the Class View window below:

In the private method called LoopMethod, open the Properties window and set AWL im-plementation to true in order use the IL programming language.

Page 394: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 394 Version 5.0

Also create a network (here: LoopAWLNet).

Page 395: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 395

Open the program code editor and insert the following code:

Result := LoopMethod(7,3); The LoopMethod with transfer and return parameters is called. The transfer parameter Input1 is loaded with the value 7 while Input2 has the value 3. The value of the return parameter is written to the Result server. CLR EBX The EBX register is cleared. L.ECX input1 The ECX register is loaded with the value of the transfer parameter, Input1

Page 396: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 396 Version 5.0

COUNT Jump point at which the start position of the loop is defined. This code must be written on the far left margin in the program code editor. ADD.EBX input2 Adds the value of the transfer parameter, input2, to the value stored in the EBX register LOOP COUNT Starts the loop at the jump point, COUNT. The loop will run as long as the value in the ECX register is 0. The value of the transfer parameter, input1, is loaded to the ECX register through L.ECX input1. The value in the ECX register is reduced in increments of 1 from 7 to 0 via the loop. When 0 is reached, the loop is exited. The loop is therefore executed 7 times; each time the EBX register is raised by 3 (7 x 3 = 21). S.EBX retcode The value of the EBX register (21) is now stored in the return parameter, retcode. Save and compile the project then go online.

Page 397: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 397

Set a breakpoint as shown below and the start the program.

Next, Step through the program until the program line that clears the EBX register is reached. Process this program line and in the Register window, observe how the EBX register is set to 0.

Page 398: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 398 Version 5.0

Press F5 and observe how the value 7 is loaded to the transfer parameter input1 from the ECX register

With the next program Step, the value (3) of the transfer parameter input2 is added to 0 in the EBX register.

Because of the LOOP, the value in the EXC register is reduced by 1 (from 7 to 6).

Page 399: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 399

In the next Step, the value 3 is again added to the EBX register (from 3 to 6).

Continue to Step through the program until the EBX register contains the value 21 and the ECX register is 0. This means the loop was executed 7 times. The ECX register was re-duced from 7 to 0 with each program scan and the EBX register raised by (7 x 3 = 21).

When F5 is pushed again, the program exits the loop. In the next Step, the value (21) of the EAX register is saved to the return parameter ret-code.

Page 400: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 400 Version 5.0

In the CyWork method, the value in the return parameter retcode is written in the Result server of the LoopMethod.

Page 401: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 401

7.8.4 Method Calls and Shift Instructions in IL

In this example a running light is created with the help of IL programming. Here, methods will be called and shift instructions as well as jump points will be used. The running light should start with the first bit, move to the highest bit and when the 16th bit is reached, reverse direction.

Use the following Class View window as a start point for this project:

Set the AWL implementation property to true for all 4 methods. The variable, MoveBit, should be defined as type BINT and the variable Dir as type USINT. Also create a network (here: LightNet).

Page 402: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 402 Version 5.0

Open the program code editor and insert the following program code:

Read the commentary carefully to better understand the program code.

Page 403: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 403

FUNCTION AWL VIRTUAL GLOBAL LightAWL::Init CMP.B _firstscan,1 The operating system variable _firstscan is compared with the value 1. With the 11th pro-gram scan, this variable is set to 1. The .B (CMP.B) ending is use since _firstscan is of type USINT. JNE END_INIT The jump to END_INIT (end of the Init method) is executed when the ZF (Zero Flag) in the EFL register is not set. L.W MoveBit,1 With this line, the MoveBit variable is set. END_INIT After this jump point, the Init method is ended. FUNCTION AWL VIRTUAL GLOBAL LightAWL::CyWork CMP.B Dir,1 Here, the value of the variable DIR is compared with the value 1. The .B (CMP.B) ending is use since the variable is of type USINT. JE RIGHT When the above comparison is applied, the program jumps to RIGHT. LEFT The jump point for the shift left command. CMP.W MoveBit, 2#1000000000000000 Compares to see if MoveBit is set. If so, the direction must be changed. The .W ending (CMP.W) is used since MoveBit is of type BINT (2 bytes).

Page 404: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 404 Version 5.0

JE RIGHT When the comparison is true then a jump to Right is made. CALL ShiftLeft Here, the ShiftLeft method is called. L.B Dir,0 The Dir variable is set to 0. JMP ENDOF Jumps to ENDOF. The instructions within the jump point RIGHT, function the same as ShiftLeft except the shift direction is to the right (see the commentary in the program code). FUNCTION AWL LightAWL::ShiftLeft L.AX MoveBit Loads the value in the variable MoveBit to the AX register. SHL.AX 1 In the AX register, 1 bit is shifted to the left. S.AX MoveBit The value of the AX register is saved to the variable MoveBit. FUNCTION AWL LightAWL::ShiftRight The ShiftRight method functions the same as the ShiftLeft function, except the SHR in-struction is used to shift a bit to the right. Save and compile the project then go online and transfer the project to the destination sys-tem.

Page 405: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 405

Set a breakpoint as the position shown below and start the program:

Let the program run Step-by-Step using the debugger and observe the changes of the registers in the Register window:

Page 406: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 406 Version 5.0

Stop the program and clear the breakpoint. Restart the program and observe the shifting of the bits in the MoveBit variable using the THIS window:

Page 407: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 407

7.9 Topical Exercises 7.9.1 Pump Work (Project PumpControl_AWL) Requirements In this example the pump work project is reused. Entering the values using the Read method and/or setting the pump and alarms should be programmed in the CyWork method. Only the method to control the pump is programmed in IL and called in the Cyclic Work method.

Process If the maximum level is reached, the pump is activated and the water level in the tank sinks. When the lower sensor is reached (minimum level), the pump is deactivated and the tank fills again. If the value for the minimum level is larger than the value for the maximum level, an alarm is triggered. Tips for completing this task

The IL instructions JGE, JL and JA are used to implement this task. The description for these instructions is found in the LASAL CLASS 2 Help.

Page 408: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 408 Version 5.0

7.9.2 Read and Write Methods for Clients in IL

In the following example, the Read method is first called to read a speci-fied value from a server through a client. Over a second client, an addi-tional value is written to a server using the write method.

Create a project with the components in the Class View window below:

Don’t forget to activate the CyWork method for the IL programming and to create a network (here: ReadWriteNet). Next, place a Ram class object in the network and connect it to the UseReadWrite class.

Page 409: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 409

Open the program code editor and insert the following program code:

L.EBX UseReadWrite.cRead Using the input from the cRead client, the ReadWrite class loads the Offset of the cRead client to the EBX register. CALL ASM_RD_CHNL The ASM_RD-CHNL function (read channel) is called. With help from this function, the input value in the cRead client is loaded in the EAX register. ASM_RD-CHNL Calls the read method from other objects and supplies the actual value from the server. If no connec-tion to another object exits, the value of the client is supplied. S.EAX GetResult The value of the EAX register is saved to the GetResult server. Save and compile the project then go online and transfer the project to the destination sys-tem.

Page 410: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 410 Version 5.0

In the Data server of the objRam object, enter a value (here: 4). This value is then read from the Read client using the cRead method and written to the GetResult server:

To write a value to the server of another class over a client, the Write method is used. Cre-ate an additional client (here: cWrite) in the UseReadWrite class.

Over this client, a specific value is written to the Ram class server.

Page 411: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 411

Place an additional Ram class object in the network and connect it to the objUseRead-Write object as shown below:

Expand the program code with the following program lines:

Page 412: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 412 Version 5.0

L.EBX UseReadWrite.cRead Through the input of the cRead client, the UseReadWrite class loads the Offset of the cRead clients to the EBX register L.EAX cWrite The value of the cWrite clients is loaded to the EAX register. CALL ASM_WR_CHNL The ASM_WR_CHNL (write channel) function is called. Using this function, the value of the cWrite client is written to the Data server of the Ram class. ASM_WR_CHNL calls the write method from other objects and writes the actual value of the server. Save and compile the project then go online and transfer the project to the destination sys-tem. Enter a value in the cWrite client (here: 7). This is then written to the Data server using the write method.

Page 413: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 413

7.9.3 Calling and Reading Tables in IL

The next example shows how text is read from a table using IL program-ming. In the following project, a different type from data type ARRAY OF CHAR is created. A variable is then defined from this type. The individual letters of the text in the table are then written in the array fields of this variable.

Create a project with the components show in the Class View window below:

Don’t forget to set AWL implementation to true and to create a network (here: TableNet).

Page 414: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 414 Version 5.0

Open the program code editor and insert the following program code:

FUNCTION AWL VIRTUAL GLOBAL AWLTable::CyWork L.EDI #MyAWLTable() The address of the table, MyAWLTable, is read and the loaded in the EDI register L.EBX #InsertText[0] The address of the first array field (field 0) of the InsertText variable is read and loaded in the EBX register L.ECX (EDI) The EDI register is in parenthesis so that the contents can be loaded in the ECX register

Page 415: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 415

ADD.EDI 4 4 bytes are added to the EDI register for the table length. L.AL (EDI) The contents of the EDI register is loaded to the AL register S.AL (EBX) The contents of the AL register are saved to the address of the EBX. INC EDI The INC instruction ensures that the EDI register is incremented. INC EBX Increments the EBX register. LOOP START This line starts the loop at the jump point; Start. L.B (EBX),0 Here, the value 0 is the loaded in the EBX register.

Page 416: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Page 416 Version 5.0

When the project is started in online mode, the table text can be seen in the THIS tab of the debugger window as it’s loaded in the array fields.

To better follow the individual program Steps, set a breakpoint and debug the program line by line.

Page 417: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

INSTRUCTION LIST PROGRAMMING

Version 5.0 Page 417

In the THIS window, the process can be observed as each letter of the table text is written in the array fields.

In the Register window, the register content change can be observed with each run.

Page 418: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 418 Version 5.0

8 Trouble Shooting In this chapter, how errors arise and/or approaches and remedies for correcting frequently occurring errors are discussed. 8.1 Debugging Programs 8.1.1 What is Debugging Programming is a complex matter; therefore it is not often that a program is built without errors. For this reason programs sometimes require a lot of time to find and correct them. To find errors faster and easier, the program can be processed line by line using the de-bugger.

Because debugging is an essential part of programming, the user should have a good command of debugging techniques.

8.1.2 General Information on Debugging In order to debug a program, it must be online with the control. Moreover, the project must be downloaded to the control. If the following message appears in the status display

that means the project in the PC does not correspond to that in the destination system. In this case there is no sense in debugging the program. Only when

appears in the status display, the project in the PC matches that in the destination system and the program can be debugged.

Page 419: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 419

8.1.3 Debugging of a Program Debugging a Program can best be explained using the previously created Arithmetic exam-ple. Load this example or create it new.

The Debug symbol bar is of great importance for debugging since it contains all required instructions.

Local variables as well as transfer parameters and return parameters of a function can only be displayed in the Watch windows 1 to 3 during de-bugging! See also chapter Local Variables in LASAL CLASS 2.

Page 420: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 420 Version 5.0

Create an online connection and download the project to the destination system. In the objCallMethode object, enter a value in the clients Value1 and Value2 (here: 7 and 8).

Set a breakpoint in the program code of the CallMethode as shown in the following illustra-

tion using the symbol or with the F4 button. The breakpoint is set in the program code where the cursor is located.

The breakpoint on the Multiply operation to see how the multiplication is executed step for step. A breakpoint can naturally be set at any line in the program to follow its process.

Page 421: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 421

Select the objCallMethode in the network and in the debugger window, set the Selec-tArithm to Multiply

Through these settings, the program jumps to the Multiply step in the program code editor and stops at the breakpoint.

Page 422: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 422 Version 5.0

Through the program line Multiply: Result := Connect.Multiply(Value1, Value2); The Multiply method is called by the class, Calculator over the Connect client.

To process this program line, press the symbol or the F5 button.

The program code window of the Calculator class is then opened and the program jumps to the Multiply method where the arithmetic operation was defined.

The symbol indicates the line on which the program is currently lo-cated. The user can spring to the actual program position by pressing the above symbol.

Click on the Watch1 tab to open the debugger window and enter all three variables (op1, op2 and retcode) of the Multiply method.

Page 423: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 423

Since the program is still at the beginning of the method, the transfer pa-rameters don’t have values.

With another push of F5, the program jumps to the next line.

In the Watch window, how the values (7 and 8) are entered in the defined clients can be seen. The retcode variable still contains an undefined value since the program line has not yet been processed. To process this line and execute the multiplication, press F5 again.

The result, 56, is then assigned to the retcode variable and the program jumps to the end of the method.

Page 424: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 424 Version 5.0

Change to the THIS window in the debugger and press the F5 button again.

The result of the multiplication is then written to the Result server and the program jumps to the next line.

Page 425: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 425

The possibility also exists in the debugger, to exit a function and/or program line. To dem-onstrate this, clear the existing breakpoint and set a new one at the following position:

Page 426: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 426 Version 5.0

Push F5 to process this line (Read method).

The program is now on the next line. With F5, the program code of the Read method is

processed. To jump over this program line, Alt + F5 or the symbol can be used again.

The program line is then skipped but it is still processed, which means the value in the Value2 is read.

Page 427: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 427

It is also possible to set more than one breakpoint at a time. Set a second breakpoint in the program code as shown below:

All breakpoints set in the program code are also displayed under Breakpoints in the de-bugger window. If the control box before the class name is checked, the breakpoint is ac-tive.

Page 428: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 428 Version 5.0

When a third breakpoint is set, the first breakpoint is deactivated (the one at line 10). That means there can only be a maximum of two active breakpoints at a time.

The first breakpoint is also deactivated in the Breakpoints window.

Page 429: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 429

A further possibility to locate errors is offered by debugging in compiled code. First clear all breakpoints.

Set a breakpoint by the Step Multiply and start the program.

Press F5 to process this line and open the Multiply method in the program code editor win-dow.

Page 430: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 430 Version 5.0

Use the button combination Ctrl + Shift + D to display the compiled code. With Ctrl + Shift + D, it is possible to switch between ST code and compiled code.

FUNCTION GLOBAL Calculator::Multiply retcode := op1 * op2; 00678 L.EAX (EBP+008) 8B 45 08 Here, the first transfer parameter is loaded in the EAX register. 00681 IMUL.D (EBP+012) F7 6D 0C The multiplication is executed with the second parameter and the result is stored in the EAX register. 00684 S.EAX (EBP+016) 89 45 10 The result in the EAX register is written to the return parameter.

The numbers at the beginning of each line of compiled code represents the byte offset relative to the corresponding module.

Page 431: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 431

8.1.4 AWL-Trigger A further possibility to control whether a specific program line is processed is provided by AWL-Trigger. With this variation, it is no longer necessary to set breakpoints. First, activate this function by selecting AWL Trigger in the menu bar under Debug and Settings.

Set the cursor on the desired line in the program code. When the program reads this line, a number in the status bar is incremented.

Page 432: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 432 Version 5.0

8.1.5 Debugging with Conditional Breakpoints Conditional breakpoints are used in debugging when several objects of a class are avail-able and are queried for specific conditions or processed for a pre-assigned number of executions.

In the next example, how to set a breakpoint with a defined condition and how they can be inserted is shown. To accomplish this, two objects from a class are placed in the network. Next, a conditional breakpoint is set and assigned to one of the objects.

Create a project according to the following Class View window:

Define the variable Timemark as data type UDINT and the Counter vari-able as data type DINT.

Page 433: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 433

Open the program code editor and insert the following program code:

Compile the program and go online to download the program to the destination system. Next, enter a value in the client DelayTime for both objects as shown below:

Page 434: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 434 Version 5.0

Set the cursor on the position shown in the program code editor below:

Next, click on the symbol to set a conditional breakpoint and open the Breakpoint Condition window. Under Stop when code is executed for object, select the object ob-jTimeDelay1. The breakpoint is now valid for the selected object. Click on OK to exit the window.

Page 435: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 435

Under Condition, an additional condition can be defined. If the condition stated for example, ClassSvr = 10, the program would only stop when the ClassSvr server contained a value of 10. In the field, Continue so many times before stopping, the number of program scans is defined before it is stopped by the breakpoint.

To start the program, first enter 1 in the Start client of the objTimeDelay object.

The program is now started and the ClassSvr of the objTimeDelay object increments con-tinuously. The program however, will not stop at the breakpoint since it is defined for the other object (objTimeDelay1) only. In the next Step, 1 is entered in the Start client of the object, objTimeDelay1.

Page 436: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 436 Version 5.0

Since the breakpoint was defined for this object in the breakpoints window, the program stops at the position where it was set.

Now, the program stepped through using the debug symbol bar.

Page 437: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 437

If the program doesn’t stop at the breakpoint with the first scan, the number of scans at which the program should stop can be specified. Stop the program and set a conditional breakpoint in the program code editor as shown below. In the Breakpoint Condition window, enter the value 100 under Continue so many times before stopping. The program will then stop at 100th scan. Click OK and start the program.

In the THIS register of debugger window, the Counter variable can be observed as it counts to 100 then stops.

Page 438: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 438 Version 5.0

8.1.6 Debugging with Data Breakpoints Clients, servers and data elements from objects of a class have definite addresses. To limit a breakpoint so that it only stops on the memory address of a specific client, server or data element, a data breakpoint is used. With a data breakpoint, the address of the client, server or data element can be assigned.

In this example, the project control is used in order to explain the function of a data breakpoint. For this purpose, the address the ClassSvr of the objTimeDelay1 is given to the data breakpoint so that it stops only if the server is accessed for the first time.

Before a data breakpoint can be set, the address of the ClassSvr must first be established. This is required because the data breakpoint only stops the program when the server with the specified address is accessed. Go online and select the objTimeDelay1 object in the network. Read the address of the ClassSvr in the Debugger window and select it

Page 439: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 439

Because the breakpoint is now dependant on an address, the position of the cursor (Breakpoints) no longer plays a roll.

To set a data breakpoint, select Debug, Breakpoint(s) then Data Breakpoint from the menu bar.

Page 440: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 440 Version 5.0

In the Data Breakpoint window, enter the address of ClassSvr. Under Length, the data length is entered depending on the address (here: 4 bytes). Next, click OK.

The assigned address must always be divisible by the length. Every ad-dress is divisible by 1 (1 byte) so 1 byte can always be used. Here, the last number is 20. This number is divisible by 2 (2 Bytes) as well as 4 (4 Bytes). If the last number was 10, 4 bytes could not be selected and the OK button would be inactive.

If the field next to Halt on read also has a check mark, the program will also stop with a read access of the server.

Enter a value of 1 in the Start client of the objTimeDelay object in order to start the pro-gram.

Page 441: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 441

As can be seen, the server, ClassSvr, of objTimeDelay increments continuously and the program does not stop. The reason for this is that the data breakpoint is defined for ClassSvr of the objTimeDelay1 only.

Next, enter a value of 1 in the Start client of the objTimeDelay1 object.

Page 442: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 442 Version 5.0

The program now Stops after the ClassSvr was raised by 1.

The program can now be stepped through as before with help from the debug symbol bar.

Page 443: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 443

8.2 Compiler Errors Compiler errors and/or warnings occur during the compiler process. These messages are displayed in the Output and/or Logging window of LASAL CLASS 2. The Logging window logs all actions, instructions or compiler messages. This window is not recommended for troubleshooting. For troubleshooting or error correcting, the Output window should be used. If an error mes-sage or compiler warning occurs in the Output window, the line in the program code can be located with a double click on the message. The cursor then shows the line in which the error is located.

If several errors occur after the compiling process, it is recommended to correct the error that occurred first since a single error can generate sev-eral others.

The following program code shows typical errors, which trigger two errors in the Output window. With a double click on the error messages, cursor jumps to the same line twice. Error – Wrong Syntax! Syntax

In an If-instruction, only comparison operators can be used. Assignment operators cannot be used in if-instructions.

Page 444: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 444 Version 5.0

If several errors or warnings occur after the compiling process, the error messages can be selected sequentially with the F12 button. The cursor the jumps to the line in the program code containing the error marked in the Output window. If the user is currently in a different window (i.e. the network window), the program code editor is opened automatically with F12 and the cursor is positioned at the assigned line.

8.2.1 Error Message: Different types The following error message occurs when variables, clients or servers of different types are assigned.

Error – Different data types!

For assignments or server, client and data element queries, always select the correct data type. Create the correct data type using conversion or casting.

i.e.: Variable := TO_USINT(ClassSvr); More information can be found in the chapter Conversion and Cast-

ing of Type.

Page 445: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 445

8.2.2 Error Message: Undefined function If a method is called whose name is not recognized by the class or the wrong name was written, the compiler supplies the following error message.

Error – Wrong spelling! Method name Arithmetic

Insert the method name in the program code editor using Drag and Drop to avoid a typing error.

If a method is called from another class and it is not recognized, the client in use should be checked for the correct spelling as well as the link to the class.

Page 446: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 446 Version 5.0

8.2.3 Error Message: Value ’. . .’ out of range When creating a Step control, the following message is supplied by the compiler. The vari-able for the step control was not defined as an ENUM type. Work is a Variable of type USINT!

Change the type of the variable or select a different type for the step that is outside the value range.

Page 447: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 447

8.2.4 Error Message: Missing ’END_IF’ instead of ’END_FUNCTION’ When for an If-instruction, END_IF is forgotten, the above error message appears. With a double click on this message, the cursor jumps to END_FUNCTION. That means in this function the End_IF instruction is missing.

end_if; instruction in missing

The cursor buttons ↑ and ↓can be used to move the cursor from the be-ginning of an if-instruction to the end_if. With this method a missing end_if can be easily found.

Page 448: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 448 Version 5.0

8.3 General Information Over the Status Display Messages regarding the CPU status are displayed in the status bar of LASAL Class2. How-ever, this can only be displayed when an online connection to the control exists. If a project is downloaded to the control and not started, Reset is displayed in the status bar.

If the program in the control is started, Run RAM and/or Run ROM should then appear. The time required for this text to appear depends on the program size.

In the field in which Reset, Run RAM or Run ROM is displayed, all other messaged regard-ing the status of the CPU are also shown. If other text is displayed in this field, it means that there is an error.

Page 449: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 449

8.4 Examples of Error Diagnosis Program errors don’t always occur immediately after the program start. Because of queries, conditions or value changes, an error can occur due to specific actions. 8.4.1 The Access Exception Error Message

In this example, an access exception in deliberately triggered in the con-trol. This example should show how to locate such an error.

Create a class with the name Access as shown in the following Class View window and place it in an object network (here: One).

Page 450: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 450 Version 5.0

The variable bInitVar is defined as type BOOL. Dataptr is of type DATA and defined as a pointer. The type DATA is assigned as STRUCT with 2 elements of type DINT.

Insert the following program code in the program code editor and download the project to the control.

Next, enter a number unlike 0 in the ClassSvr to trigger the access exception.

Page 451: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 451

The following message appears in the status bar: The program code editor is opened at the same time (if another window or object network is displayed) and a yellow arrow points to the location in the program where the access exception occurred.

The program can no longer be run when an access exception occurs and freezes with an error.

Observe the values in the THIS and/or Watch window. Accessing a pointer that is not initialized interrupts the control (yellow arrow in the pro-gram code).

Page 452: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 452 Version 5.0

Correct by testing the NIL Pointer: This is only a safety check (it should also correct the error). DataPtr^.Element2 := 13; else if DataPtr <> NIL then DataPtr^.Element1 := 34; DataPtr^.Element2 := 13; end_if; end_if; Correcting the program error: The bInitVar was set to TRUE in the Init method and not to False, as it should have been.

It is also possible to locate this window in the Callstack window. Click on the Call Stack tab in the Debugger Window. In the Callstack window, the most recently processed program line is displayed. The Function column lists the functions that were called before the access exception oc-curred. In the Line column, the line number of the call can be seen. impl. Line shows the concerned line in the program code editor. The LOB Filename column shows the Lob data, which contains the code and debugger information.

Double click on both lines with the mouse. Here, the lines are then identified with a green arrow where the program code was last called.

Page 453: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 453

The yellow arrow still points to the line where the access exception occurred.

For further troubleshooting, the EVENT00.LOG file can be consulted. This file is created by the operating system and contains messages and information over various events. This file is located in the destination system under C:\SYSMSG\EVENT00.LOG.

The last entry called in the EVENT00.LOG file is the actual log event.

Page 454: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 454 Version 5.0

In the menu bar, select Debug, Extras and Load File from PLC to load this file to the control. In the PLC-Filetransfer window, enter the path of the file to be loaded and confirm with OK.

Select the path and name for the file to be saved in the following window.

Page 455: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 455

The log file can be opened with a text editor to view the contents.

To better explain the Event00.log file, the contents are divided into sev-eral blocks.

The first line contains the time the log file was created including header (operating system version). The second line contains the time the CPU was turned on and the operating system with which it was started.

In the first line, the register status at the time of the access exception is logged (Register EIP). The second line gives the data and time the access exception occurred. The CPU status is also logged.

Here, the register contents at the time of the interrupt are stored

Page 456: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 456 Version 5.0

The file, method and class in which the error occurred are logged (see file path). The af-fected function is also listed in this line.

Here the stack area, which lists the size of the stack and the lowest stack pointer, is logged. In addition, information over the heap (free memory space) such as the start address, size, plus used and free memory is stored. The last two lines contain information over the start and size of the program and/or data.

Here, the last 256 bytes of the stack at the time of the interruption are shown.

Page 457: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 457

This section of the log file shows an overview of all active tasks with their stack area and memory available at the time of the disruption.

This is area the same as the output in the CallStack window when the user is online with the control. Here the file and function names as well as the classes, which were last called during the interruption, are logged. The numbers on the end of these lines give the byte offset relative to the beginning of the module. These byte offsets can be viewed LASAL CLASS 2 using the combination, Ctrl + Shift + D In the CallStack, the information in the EIP register refers to the internal operating system functions.

Page 458: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 458 Version 5.0

Open the program code window and press the Shift + Ctrl buttons simul-taneously. Then press the D button. With the same keystroke combina-tion, change back to the structured text code. The assembler code can only be shown when the program was previ-ously compiled.

With a double click on the output listed in the Call Stack window, the green arrow jumps to the most recent program call.

Here the byte offset of the module can be compared with the entry in the Event00.log file.

Page 459: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 459

8.4.2 The Division Error Message Numbers, regardless of type, cannot be divided by null (0). If an instruction tries to divide by 0, the program can no longer be run. The same is true for modulo operations, whose value is the remainder of a division.

If a division error occurs, a yellow arrow points to the position in the program where the error is located.

Using a comparison instruction, the divisor can be tested as to whether it is 0 or not. if Value2 <> 0 then Result := Value1 / Value2; end_if;

Page 460: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 460 Version 5.0

Using this example, a Division Error is generated without a division by null (0). This error occurs when the result of a division is larger than 32 bits.

To reproduce this example, create a class with the name ErrorSearch as shown in the Class View window below and place an object of this class in the object network.

The variables required in this example are all assigned as type HDINT.

Page 461: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 461

Insert the following program code in the program editor and down load the project to the control.

If the program is started, a division error occurs. The yellow arrow points to the affected line in the program code.

Page 462: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 462 Version 5.0

With the button combination, Shift + Ctrl + D, the assemble code is shown.

This division error occurs when the result of a 64-bit multiplication and a subsequent division is larger than 32 bits.

Set a breakpoint by the line ValA := 16#FFFFFF; and debug the pro-gram until the division error is reached and observe the register.

If the 32-bit EAX register is not sufficient for the multiplication of ValA and ValB, a carry over is written to the EDX register. If the value is still larger than 32 bits, a division error is generated (see EAX- and EDX- registers in the register output window).

Page 463: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 463

A division error doesn’t necessarily have to be caused by a division through 0. For this reason the Event00.log file can be checked to later gather information on the possible error.

Under Debug, Extras, Load File from PLC, load the Event00.log in the PC file to com-pare the values in Register of the Debugger window.

The cause of the error can be located in the Event00.log file. The reason for the error is shown in the message CpState=24. In this case, the number 24 is the error code. This is also shown on most CPUs with a 7-segment display. In addition, these CPU status codes can be found in the LASAL CLASS 2 help (Online Status Message).

Page 464: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 464 Version 5.0

8.4.3 The Run Time Error Message

In the following example, an infinite loop is programmed to illustrate the effect on the destination system.

Start a new project with two classes and place an object of each in the object network. The program code for the anything class is not of any real significance in this example, it is only used to increment the class server in the RtWork method. The program code in the class EndlessLoop, is programmed in the CyWork method and should trigger a Runtime error in the control with an infinite loop.

Page 465: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 465

Create the EndlessLoop class using the Class View window below:

Down load the program to the control and start

Page 466: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 466 Version 5.0

Operating system variables are available so that the principle runtimes of the three main tasks can be seen. These variables give information over the maximum and average run-times of the three main tasks (RtWork, CyWork and Background).

_CyclicMaximumTime _CyclicAverageTime

_RealMaximumTime _RealAverageTime

_BackgroundMaximumTime _BackgroundAverageTime

Enter these variables in the Debugger window under Watch and observe the cycle time of the individual tasks. The cycle times are listed in the Value column and show the program runtime in µs.

FUNCTION VIRTUAL GLOBAL EndlessLoop::CyWork for cnt := 10 to limit by –1 do CountValue += 1; end_for; With this for-loop, the value of the cnt variable (10) is reduced by 1 with each program scan until the value of the variable limit (0) is reached. Since the variable cnt is decremented with end_for;, the loop will still be executed if the value in limit is already 0. This scan will result in a value of –1. Because both variables are defined as type USINT, which doesn’t recognize signed values, the value 255 follows 0 and an infinite loop is generated!

Page 467: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 467

To monitor the CyWork tasks, a runtime monitor must be set in the AUTOEXEC.LSL file located in the destination system.

In a monitor is set in the AUTOEXEC.LSL, all cyclic tasks processed after this time has elapsed otherwise the control remains frozen with a Run-time error.

If the control is halted with a runtime error, the following text is shown in the status display:

For safety reasons, it is recommended that the runtime monitor always be activated in the AUTOEXEC.LSL. The default setting for the cyclic tasks monitor is 300ms!

If the AUTOEXEC.LSL file must be changed, it can be loaded to the PC from the destina-tion system with help from LASAL CLASS 2, changed and then saved to the destination system again. In the menu bar select Debug, Extras then Load File from PLC to make changes in the file.

Page 468: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 468 Version 5.0

Enter the name of the file to be transferred (AUTOEXEC.LSL) and press OK.

Select the desired path and file name in the window below:

This file can then be opened in a text editor to make the changes.

Page 469: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 469

To set the runtime monitor, change the following line: SET RUNTIME 0 to SET RUNTIME 10. If a 0 is written next to SET RUNTIME or no value is present, the runtime monitor is inac-tive. A value between 1 and 255 must be entered. If a value is entered, that means: Runtime monitor = value * 10ms All cyclic tasks must be processed within this time!

Page 470: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 470 Version 5.0

Runtime control is set by • SET RUNTIME x for the Cyclic task • SET BTRUNTIME x for the Background task • SET RTRUNTIME x for the Realtime task

Default settings of the single tasks: • Background task: OFF • Cyclic task: 255 • Realtime task: 1

The Realtime task should be left as default and only deactivated in excep-tional cases.

Once the changes in the AUTOEXEC.LSL file are made, it can be down loaded back to the control as follows. Select Debug, Extras, Save File to PLC in the menu bar to save files in the destination system.

Page 471: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Version 5.0 Page 471

In the window shown below, select the path and corresponding file that should be saved to the destination system (AUTOEXEC.LSL).

After confirming with Open, a window appears in which the name of the file is entered and then saved to the destination system when OK is pressed.

When changes are made in the AUTOEXEC.LSL, it is necessary to re-start the control to reset the CPU with the new settings.

Restart the CPU to assume the changes in the AUTOEXEC.LSL file.

Page 472: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

TROUBLE SHOOTING

Page 472 Version 5.0

After the CPU has reset, start the application and enter a value in the server of the End-lessLoop object.

The control stops and a runtime error is displayed in the status bar:

The infinite loop has hindered all three tasks from being executed within the specified time, causing the control to stop.

The current Runtime settings can be requested in the Command Line Interface by defining no value after the SET RUNTIME command. The same process for SET BTRUNTIME and SET RTRUNTIME.

Page 473: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 473

9 Contact Plan (COP) in LASAL CLASS 2 9.1 What is a contact plan? A contact plan (COP), also called a Ladder diagram (LD), is a method for programming for Programmable Logic Controls. It is a standardized graphic programming type similar to a Circuit diagram. The creation of the program with COP is used especially for creating logic controls. 9.2 Fundamentals for creating a contact plan

In the next pages, the Steps necessary for creating a contact plan are explained using an example. In the contact plan, 2 inputs and 1 output are place. An OR gate is then placed between the two inputs so that ei-ther input 1 OR input 2 must be set in order to set the output.

To begin create a new project (here: LadderExample) and in the context menu, select Create Ladder Diagram Class to create a ladder diagram class (here: ORFunction).

Page 474: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 474 Version 5.0

Next select the class and in the Properties window, set CyclicTask to true.

By activating the CyclicTasks, the other two tasks (Realtime and Back-ground) are deactivated automatically and can no longer be selected. Only one task can be selected for a ladder diagram class.

Page 475: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 475

Create a new network (here: LadderNet) and place the ORFunction class within. Remem-ber to set the cyclic time.

When creating a class, a network (here: LadderNet) is created automatically. Place the mouse on the object to open the network as shown below.

Page 476: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 476 Version 5.0

Open the network with a double click. Open the context menu with a right click in the net-work. Next, select Contact, Contact to create a new connection (input).

Place a second input in the lower field of the network.

Page 477: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 477

Select Coil, Coil from the context menu to place an output.

Next connect the elements as shown in the following 4 illustrations.

Page 478: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 478 Version 5.0

Close the ORFunction network. In the LadderNet network, the inputs (Clients Input1 and Input2) and output (Output Server) are automatically assigned to the objORFunction object. For the output, a client with the called Clt_Output is also created. This client serves to connect the output to the hardware.

Next, create an online connection and download the project to the target system then open the objORFunction network with a double click on the arrow in the object (see below).

Page 479: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 479

Because of the OR gate, a decision must be made as to which input (Input1 or Input2) to set in order to activate the output. Open the context menu with a right click on one of the inputs (here: Input1) and select Set Contact to create the contact with the output.

Once contact is made, the color of both the input and output changes to green.

Page 480: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 480 Version 5.0

In the LadderNet network, the clients Input1, Clt_Output and the output server of the objORFunction object are set to 1.

To reopen the contact, select Reset Contact in the context menu of Input1.

Page 481: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 481

To connect Input2 with the Output, the corresponding input is set to 1 in the objORFunc-tion object.

Page 482: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 482 Version 5.0

9.3 Contact Plan Tools 9.3.1 Contact Types

Normally Open (Open Contact) The normally open contact switches the left current path to the right current path as long as it’s activated (TRUE, On or 1). When the contact is deactivated, the status of the right cur-rent path is 0.

Page 483: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 483

Normally Closed contact (Closed Contact) The closed contact switches the left current path to the right current path as long as it is deactivated (FALSE, off or 0). When the contact is activated the no current flows and the right current path is 0. Positive Flank Contact

The contact used to recognize a positive flank is 1 if, with the last evaluation of the contact, a signal change from 0 to 1 has occurred. The status of this contact remains the same as long as the object is set for which the contact plan network is used.

Page 484: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 484 Version 5.0

Negative Flank Contact The contact used to recognize a negative flank is 1 if, with the last evaluation of the contact, a signal change from 1 to 0 has occurred. The status of this contact remains the same as long as the object is set for which the contact plan network is used.

Page 485: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 485

9.4 Coil Types

Preliminary Information: When using the contact plan tools Memory Coil, Set Memory Coil and Reset Memory Coil, the RAM class must be imported from the library. Otherwise the following error message appears in the output window when one of these coils is placed.

Coil The coil shows a normal output.

Page 486: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 486 Version 5.0

Negate Coil The Negate Coil represents an inverted output.

Set Coil This coil is set to 1 when the status of the left current path is 1. When the left current path changes to 0, the value of this coil remains 1.

Reset Coil A coil that has been set is reset to 0 following a reset instruction. With the Reset coil, a coil set using the Set coil can be reset to 0.

Page 487: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 487

Memory Coil The Memory coil saves the status of the left current path. After the CPU is restarted, the value is retained in the memory coil. This value is stored, however, only for the duration of the cycle time for the object on the memory module.

Example application: In the following screen shots, the signal flow can be seen when the con-trol is restarted after the input have been set. The signals are delayed according to the cycle time of the object. Program restart

Set Memory Coil This coil is the same as the Set Coil, except this coil retains the status even after the CPU is restarted.

Page 488: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 488 Version 5.0

Reset Memory Coil This coil is the same as the Reset Coil, however it also retains the status after a restart.

Positive Transition This coil recognizes a positive flank on the left current path and sets the right path to one for a cycle (Note: cycle time of object). Negative Transition This coil recognizes a negative flank on the left current path and d sets the right path to one for a cycle (Note: cycle time of object).

Page 489: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 489

9.4.1 Additional Contact Plan Tools

Jump With the Jump instruction, a conditional jump to a section of the circuit identified by a label. The jump instruction is always drawn toward the right frame.

Label If a part of a circuit called from different program location with a jump instruction, it must be identified with a label. The label is always placed in the left frame.

Page 490: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 490 Version 5.0

Return Here, the processing of the contact plan is interrupted.

Insert New Row With this option, a new line can be added to the contact plan. Delete Empty Row This option is used to delete an empty line in the contact plan

Page 491: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 491

9.5 Important Display Modes and/or Settings 9.5.1 Switch Status Display in the Contact Plan In both inputs (Input1 u. Input2) are set as shown in the following screen, the output is also displayed with a green field.

Input and/or output with green background! The following screen shows input 2 when input 1 is reset to 0. Input2 is shown with a blue background. This means that the input (input2) is still set but, according to the circuit dia-gram, is no longer supplied with power.

Input with blue background!

This display helps to identify the status of the switches in the contact plan.

Page 492: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 492 Version 5.0

9.5.2 Class Properties with a Contact Plan If a class is created with the following contact plan, it will have 5 clients and 2 servers ex-tending outward. To make classes as small as possible (meaning as few clients as possi-ble), they can be hidden.

Open the contact plan network and click on the desired inputs (here: Input1, Input2 and Input3). In the properties window set DataElement to true. The class with the hidden cli-ents is shown below to the right.

Hiding clients and servers have no effect on the function of the class.

Page 493: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 493

9.5.3 Inputs and/or Outputs as Alarm displays

If an input or output should be prominent in the contact plan when active, the settings can be changed. The in- or output is then displayed with a red background (in online operation).

Click on an output and in the properties window set the AlarmObject to true. If the output should also be inverted, Alarm inverted can be set to true in the properties window.

In online operation, once both input1 and input2 are set, the output should now appear with a red background.

Output with red background!

Page 494: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 494 Version 5.0

9.5.4 Application of User-Created Objects in a Contact Plan

For User-defined objects of a class applied in a contact plan, no cyclic time can be set. These objects are called in the time period of the object containing the contact plan.

To link classes programmed in structured text or IL, a server from the class must have a Read method. The read method is called by the con-tact plan automatically.

In the next example, a class should provide a time delay. An object of this class is then placed in a ladder diagram of a contact plan network. In the network, an input is used to set one output immediately and an additional output after a time delay.

Create a new project (here: LadderExample2) and construct it as shown in the Class View window below.

The TimeMark is of type UDINT. In the Network View window, create a network as well (here: LadderNet).

Page 495: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 495

As previously mentioned, remember to define the Read method for the OnOff server. Pro-gram this function as shown below to create a time delay:

Next, Create a ladder Diagram (here: SetInOut) and in the Properties window, set Cyclic-Task to true.

Page 496: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 496 Version 5.0

Place an object (here: SetInOut) of the ladder diagram class in the network and set a cyclic time (here: 100 ms).

Double click on the arrow in the object (see below) to open the network for the ladder dia-gram class SetInOut.

Page 497: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Version 5.0 Page 497

In the SetInOut network, first create an input (Input1). Next, insert the TimeDelay class into the network via Drag & Drop from the Class View window and enter a time in the De-layTime client (here: 3000 ms). Define the two outputs (here: Output1 und Output2) and connect them to the input as shown below.

Go online and open the context menu for Input1 and select Set Contact to set the contact between Input1 and Output1.

Page 498: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

CONTACT PLAN (COP) IN LASAL CLASS 2

Page 498 Version 5.0

Output1 is then active and appears with a green background as with Input1.

Output2 is then activated after a time delay of 2 seconds (3000ms).

Page 499: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Version 5.0 Page 499

10 Using C-Files 10.1 Application In LASAL CLASS 2, the possibility exists to link existing or newly created C-Files. The ad-vantage of linking C-Files is that available program code doesn’t have to be written again in structured text, which significantly shortens the project development time. 10.2 Important details when using C-Files To load a project in the control, the project must be compiled with the C-files. In the menu bar under Tools, Options the Applications Options window is opened and under CPPKompilerPath, the path of the C-compiler is entered:

The GNU compiler (GNU GCC GPP 3.1) is available from SIGMATEK. The MS-VC 6.0 compiler can also be used. However, the MS-VC 6.0 compiler is not supplied by SIG-MATEK.

Every LASAL project linked to C-files must be compiled with the C-files at least once.

Page 500: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Page 500 Version 5.0

A further setting concerning C-Files can be made in the Properties window of the project. For that purpose select the project name (here: C_File) and open the Drop-Down field of the CompileCFiles entry in the Properties window.

If false is selected here, then C-Files will not be compiled by the compiler. With true the compiler compiles them. The detail debuginfo setting allows to use the Debug functionality of LASAL CLASS 2 also for C-Files.

Page 501: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Version 5.0 Page 501

10.3 Creating and Linking a C-File in LASAL CLASS 2

The next example explains how a C-File is created, linked and/or used in LASAL CLASS 2. In this example, a class with two clients and a server is created in a project. Using the Read method, the value of both clients is read and then transferred to a C-File. The result of a multiplication using these values is then returned. The C-File containing this function must be linked to the class.

Create a project with the components shown in the following Class View window:

Assign a corresponding CyclicTime (here: 10ms). Also create a network (here: CNet).

Page 502: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Page 502 Version 5.0

To create a C-File, select File, New File... in the menu bar

In the window that opens, type the following program code:

To save the C-File, select File, Save File As... in the menu bar.

Page 503: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Version 5.0 Page 503

There are two possibilities to save a C-File. Either with the file extension *.c or with *.cpp! If the C-File is saved with the file extension *.cpp (as in this example), then the first program line ALWAYS starts with extern "C" … The "C" after the extern is NOT required, when the C-File is saved with the file extension *.c. extern …

In the Save File As window, enter the name (MyCFile.cpp) of the C-File. Make sure that the target folder is either the source or respective class folder of the project.

Page 504: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Page 504 Version 5.0

Explanation of the program code extern "C" => Required for calling the following function from LASAL CLASS 2. int => Data type for the return parameter of the C-Function MyCFunc => Name of the C-File. (int value1, int value2) => Data type and name of both transfer parameters { => Start of the function int result; => Data type and name of the local Variables in the C-function result = value1 * value2; => Multiplication and assignment to the return

parameter, result return(result); => Assignment to the return parameter (always return) } => End of the function

In the project folder under "Compiler" set the property "CompileCFiles" to TRUE!

Page 505: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Version 5.0 Page 505

Activate the context menu in the Class View window with a right click on the class name (IncludeC) and select add Add File....

In the Open window, select the C-File (MyCFile.cpp) and click on open.

Page 506: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Page 506 Version 5.0

In the Class View window the newly linked C-File is found in the Files folder.

So that the C-file function can be used, a private header file from the class must be created. Select Add File... from the context menu of the class and assign a name to the header file (MyHeader.h).

Page 507: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Version 5.0 Page 507

The header file is now located in the Files folder:

Double click on the header file (MyHeader.h) in the File Explorer window to open the pro-gram code editor. Insert the following program code:

__cdecl => Means the transfer and return parameters of the function are written in C-

notation. This keyword is always required when a C-function is called.

To call a C-function, the compiler must be told how the function looks. This is done with an external declaration, which describes the appear-ance of the function (MyHeader.h-file).

Page 508: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

USING C-FILES

Page 508 Version 5.0

Insert the following program code in the CyWork method to call the C-function.

After placing an object of this class, download the project to the control and test the function by entering values in the clients.

Page 509: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 509

11 Scripting (Batchfile – Python) 11.1 What is Scripting Scripting is the creation of processes. With the instructions available in the script language, existing projects can be expanded or new projects generated. LASAL CLASS 2 uses Py-thon for this purpose. 11.2 Introduction to Python Python is a relatively easy to learn yet impressively strong script language and is also suit-able for beginner programmers. For Python, no explicit interpreter process is required. More information regarding programming with Python can be found at the following ad-dress: www.python.org

Page 510: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 510 Version 5.0

11.3 LASAL CLASS 2 Commands To use the Python interpreter language with LASAL CLASS 2, an additional SIGMATEK module was created which provide Python instructions especially for LASAL CLASS 2. The following instruction must be implemented it the script file: “import sigmatek.lasal.batch as batch” The addition of “as batch” is assigned so that the complete module name doesn’t have to be used.

The pump work example should be generated automatically with help from a script file. The complete description of the Pump Work example is found in chapter 4.5.1.

To create a script file, select File, New File... in the menu bar. Open the Save File As win-dow with File, Save File As in the menu and assign a file name (PumpControl.py) and click on save.

Be sure the file name contains the ending .py!

Page 511: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 511

The following window then appears in LASAL CLASS 2:

To use the SIGMATEK script instructions, the previously mentioned script module must be linked.

It is not possible to create new classes or change existing ones using script since additional source code cannot be inserted into the class.

Page 512: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 512 Version 5.0

To create the pump work, existing classed must be accessed. The classes required for this example are available in the DiasMaster.lcp library and the PumpControl project created earlier. Both projects will now be linked in the script file under the LoadProject instruction:

Because the LoadProject instruction comes from the SIGMATEK module, batch is added before the instruction. Both projects are assigned to the variables prjDiasMaster and prjHysterese. From now on only these variables are used. The # symbol identifies the line of text following it as com-mentary. To create a new project, the CreateProject project instruction must be used. All required classes are then copied with the CopyClass instruction.

Page 513: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 513

After the required classes have been successfully imported, the objects for the classes must be created with the CreateObject instruction. Since objects have to be placed in an object network, a new network must be generated using the CreateNetwork instruction.

The number pairs at the end of the last 4 lines of the screenshot are the starting coordi-nates (upper left corner) of the graphical objects as they are placed in the LASAL network. Because the DiasMasterC has a Realtime task and the Hysterese has a Cyclic task, it is necessary to set a time for both objects. This is done using the instruction SetTaskTime. The objects also need initial values, which are set with the SetInitValue instruction.

Several clients of the objCAM123_IM object require the same initial value. A for-loop is used to accomplish this.

Page 514: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 514 Version 5.0

In the next Step, the connection between the objects is made (CreateConnection). The project is then compiled (Compile) and saved (Save). The libraries are then closed, as they are no longer necessary (CloseProject).

In the menu bar select Tools, Scripts, Run Current Script to execute the script file.

Page 515: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 515

The processing of the script instructions can be seen in the Output window.

It is also possible to execute the script file in LASAL CLASS 2 externally. The following instruction must be processed in the command line of the LASAL CLASS 2 directory: Lasal2 /script:C:\sample\PumpControl.py

The following screen should appear when the project is loaded and the object network, PumpControl, is opened:

Page 516: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 516 Version 5.0

When running a script file, the possibility exists to simultaneously write a log file in which the execution of the instructions and possible errors are logged. In the next example, a log file is created in the script file.

The OpenLogfile is used in order to create a log file. So that the script file is interrupted immediately when an error occurs, the bExceptionOnError must be set to true. At the end of the script file, the CloseLogfile is used to close the file.

Page 517: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 517

To generate an error in this script file, the last letter was removed when loading the Pump-Control (see program code). By executing the erroneous script file, the processing of the LoadProject instruction is aborted. When the Logfile.txt file is opened, the line containing the error is shown:

The entry, project .. not found and the line number of the script file where the error oc-curred, appears in the log file. The interruption of the script file is also shown in the Python Script window and the corre-sponding line number is referenced.

Page 518: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 518 Version 5.0

In the following section, the messages that can occur when downloading a project are shown.

When processing script files, events can occur that the user must be made aware of. The existing script file will now be expanded with the Download instruction, which loads the project to the destination system. But first, the bExceptionOnError must be set to false so that the script file is not interrupted when an error occurs. The message, Download fin-ished, appears after the project has been successfully downloaded. When a transfer error occurs, Download on address...failed appears. Next the bExceptionOnError is reacti-vated.

Page 519: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 519

Run the modified script file. If the connection, which was assigned with a symbolic name, is correct then the following message appears:

If the connection was constructed incorrectly, the message below is displayed:

Page 520: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 520 Version 5.0

11.3.1 Description of Script Instructions In the following list, all commands are explained. A complete overview of commands can be found in the LASAL CLASS 2 Help. LoadProject(strFilename) Loads an existing project. Transfer parameters: strFilename The project file name. CreateProject(strFilename) Creates a new project. Transfer parameters: strFilename The project file name. CopyClass(prjDst, prjSrc, keyClass, boverwrite) Copies a class to a project. Transfer parameters: prjDst The destination project to which the class should be added. prjSrc The source project from which the class comes. keyClass The name of the class to be copied. boverwrite true = overwrites an existing class with the same name in the des-

tination project (Default=False). CreateNetwork(prjDst, keyNetwork) Create a new network. Transfer parameters: prjDst The project in which the network should be placed. keyNetwork The name of the new network.

Page 521: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 521

CreateObject(prjDst, keyNetwork, keyClass, keyObject, xPos, yPos) Creates a new object with the assigned coordinates. Transfer parameters: prjDst The project, which contains the network. keyNetwork The name of the network. keyClass The name of the class on which the object is based. keyObject The name of the object created. xPos The x position of the object in the graphic view. yPos The y position of the object in the graphic view. SetInitValue(prjDst, strNetworkName, strObjectName, strChannelName, strValue) Sets the start value of channel. Transfer Parameters: prjDst The destination project. strNetworkNam The name of the network, which contains the object whose chan-

nel should be changed. strObjectName The name of the objects. strChannelName The name of the channel whose start value should be changed. strValue The new start value of the channel.

Page 522: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 522 Version 5.0

CreateConnection(prjDst, strSourceNetworkName, strSourceObject Name, strSour-ceClientName, strTargetNetworkName, strTargetObjectName, strTargetServerName) Creates a new connection between a client and a server channel. Transfer parameters: prjDst The destination project. strSourceNetworkName The name of the network from which the connection starts. strSourceObjectName The name of the object, which contains the start of the client chan-

nel. strSourceClientName The name of the client channel from which the connection starts. strTargetNetworkName The name of the network in which the connection ends. strTargetObjectName The name of the object, which contains the server channel. strTargetServerName The name of the server where the connection ends. SetTaskTime(prjDst, strNetworkName, strObjectName, strTask, strTime) Sets a new process time for an object. Transfer parameters: prjDst The destination project. strNetworkName The name of the network, which contains the object. strObjectName The name of the object whose process time should be changed. strTask The name of the application [realtime | cyclicwork | background]. strTime The new cyclic time. Save(prjDst) Saves a project. Transfer parameters: prjDst The destination project.

Page 523: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Version 5.0 Page 523

Compile(prjDst) Compiles a project. Transfer parameters: prjDst The destination project. Download(prjDst) Loads the project to the PLC. Transfer parameters: prjDst The destination project. CloseProject(prjDest) Closes the project. Transfer parameters: prjDst The destination project. OpenLogfile(strFilename, strLayout="[%d{%H:%M:%S} (%p) %c] %m%n", bAp-pend=False) Opens a log file. Transfer parameters: strFilename The name of the log file. strLayout Optional parameter for formatting the layout of the error messages. bAppend true = Reports attached to an existing log file.

False = A new log file is created. CloseLogfile() Closes the log file

Page 524: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

SCRIPTING (BATCHFILE – PYTHON)

Page 524 Version 5.0

SetExceptionOnError Whether a message is supplied in the event of an error (all commands up to LoadProject and CreateProject supply boolean return values) can be set over this parameter (Default = False). _internal.msgbox(strText) Shows a modal message box on the screen (OK button only). Transfer parameter: strText The text shown in the message box.

Page 525: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 525

12 Online with the Control 12.1 Introduction On the following pages, the variations with which an online connection is made to the desti-nation system are discussed. In LASAL CLASS 2, a connection can be made to all SIG-MATEK CPUs or IPCs with each of these variations.

In addition, it is important to ensure that all configurations are written for the Microsoft Windows XP operating system. However, the settings for other versions of Microsoft Windows differ just slightly.

12.2 Contents The following 4 Online connection methods for LASAL 2 are: Serial Interface CANBUS TCP/IP Modem

How the connection type and their configurations are created, can be found in their respec-tive product manuals. The settings required for communicating with the LARS simulation program are explained.

Page 526: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 526 Version 5.0

12.3 Basics Before an online connection to the destination system is can be made, a decision must be made in LASAL CLASS 2 as to which of the 4 connection types will be used. In the project tree, select the project name to open the Properties window. Click on Online connection in the Properties window and press the button.

Page 527: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 527

The LASAL Online configurations window opens.

Independent if a project is loaded or not the LASAL Online configurations window can be opened with the Ctrl key + the online symbol . There-fore every time online settings can be made, respectively, changed.

This window is divided into two sections. The left section is the Global configurations window in which the various connection types are displayed and selected. In the right sec-tion, the settings are made according to the type of connection selected.

Each connection type is standard once it has been assigned. Using the

button, a new connection can be made. With the button an existing con-nection is deleted.

Page 528: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 528 Version 5.0

Once a new connection has been created in the Global configurations window, it is called noname by default.

To change the name of a connection, click on it with the right mouse button and select Rename in the context menu. A new name can then be assigned.

Page 529: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 529

12.4 Connection Types In this chapter, the configurations that must be made for the connection types RS232 (serial interface) CANBUS TCP/IP Modem

are discussed. In addition, the difference between the individual connection types in speed and configura-tions are illustrated and explained.

Page 530: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 530 Version 5.0

12.4.1 Connection Over the Serial Interface This communication interface is extremely important since a valid connection can always be made with a serial connection. If a serial connection is made, the autoexec.lsl with the re-quired online settings can be downloaded from the destination system. These online set-tings can be used to establish a faster connection (i.e. TCP/IP). Settings in the LASAL online configurations window In this window a new connection can be created and assigned a name according to connection type (e.g. Serial connection or RS232-connection, here: RS232 new). Under Connect Type:, select RS232. Under Interface:, select the corresponding COM number depending on the port to which the serial cable is connected. If only one serial connector is available, COM1 must be selected as the interface. Set the Baud rate for each interface defined In the CPU. If the baud rate is not known, simply try all the available baud rates until a connection is established. Interface: COM1 and baud rate: 57.600 (3) are set by default.

Page 531: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 531

12.4.2 Connecting Over the CAN Bus The CAN bus is faster than the serial connection. Connection via USB interface: Settings in the LASAL Online configurations window Establish a new connection (here: CAN neu) or select an already existing CAN connection. Afterwards select CAN-BUS under Connect Type:. Then choose the USB adapter (USB-CAN Adapter Lawicel) under Interface:. Insert the values of the target system under Baudrate and PLC station or press the CAN-Finder button. At PC station please be care-ful to use different numbers for LASAL Class 2 and your LSE project.

It is recommended to activate the Hardmode checkbox in order to make the connection faster.

In the CAN-Finder window you can search for a CAN connection on the desired interface (here: USB-CAN Adapter Lawicel).

The BU106 Adapter is simply connectedto the USB interface of the PC. Beforethe required drivers have to be installedon the PC. Further details under www.canusb.com.

Page 532: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 532 Version 5.0

Connection via LPT interface: The DIAS adapter (pictured right) is connected to the LPT printer port of the PC. Therefore, the operating system configuration must be changed. Settings in the Operating System Under System Control in the System folder, the Hardware manager is found under the Hardware tab. In the menu item connections, the desired printer port can be selected. In most cases a computer has only one printer port so only LPT1 can be used. Next, open the properties window with a double click on the printer port (LPT1) then open the connection settings tab and activate the Use interrupts for every connection option field as shown in the following illustration.

Page 533: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 533

The PC must be restarted in order for the modifications to take effect.

Page 534: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 534 Version 5.0

Settings in the LASAL Online Configurations Window Create a new connection (CAN new) or select the existing CAN connection. Under Con-nect Type: select CAN BUS. Afterward, select the printer port (LPT1) in the Hardware manager under Interface:. The baud rate and PLC station must have the same setting as the destination control. For the PC station setting, different numbers are set in LASAL CLASS 2 and the LSE pro-ject.

It is recommended to activate the Hardmode selection, as the connection is faster.

Page 535: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 535

12.4.3 Connecting Over TCP/IP The TCP/IP connection type has the fastest data transfer rate. This connection is a must for acceptable download time for large projects. A further advantage is that with a TCP/IP connection, several controls in the same network can be handled simultaneously. Settings in the operating system

If in a company network, the network administrator should be consulted before making any changes in the operating system. In such a case, one or more IP addresses should be requested and not assigned arbitrarily.

If only one connection between the PC and the control is to be made, the following instruc-tions must be followed: First, a functioning network card and a crossed network cable are needed. Once these requirements are met, open the Network Connection window in the operating system. Under Windows XP, open the explorer, click on network environment and select proper-ties in the context menu.

Page 536: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 536 Version 5.0

In the following window, LAN connection must be clicked with the right mouse button and Properties selected in the context menu. The Properties of the LAN Connection window opens as shown below:

In this window, select the Internet Protocol (TCP/IP) and under This connection uses the following elements:, select Properties.

Page 537: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 537

The Properties of Internet protocol (TCP/IP) window now appears on the screen. In this window, a valid IP address and subnet mask are assigned.

The destination system must then be assigned the same subnet mask and a valid internet address. In a network two machines can never have the same IP address!

Page 538: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 538 Version 5.0

Settings in the LASAL Online Configurations Window Create a new connection (TCP/IP Connection new) or select the existing TCP/IP connec-tion. Next, select TCP/IP under Connection Type:. Under IP Address: assign an IP ad-dress that corresponds to the one assigned in the operating system (only the last value must be changed and can be between 1 and 254, here the last number is 14 instead of 13).

The IP address in LASAL CLASS 2 must correspond to each address in the destination system.

To set the IP address and subnet mask, the autoexec.lsl is used.

Page 539: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 539

12.4.4 AUTOEXEC.LSL This file contains the instructions, which the CPU executes at startup and is located in the C:\ directory on the hard drive of the destination system. In the autoexec.lsl, the connection types are configured. This file is found in all IPC types. In the following illustration, the connection to a C-IPC is made and the commands for the connection settings are clearly explained. An overview of all available commands is found in the documentation for the operating system.

Page 540: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 540 Version 5.0

SET CAN 1 STATION 0 BAUD 0 In this line, the CAN bus parameters are displayed and changed. Syntax SET CAN [ifnum [STATION addr] [BAUD baudind]]

Ifnum – Number of the CAN Interface (1 = CAN1, 2 = CAN2, …) addr – Number the CAN station (0..31) baudind – Index for the baud rate table: 0.. 615 Kb 1.. 500 Kb 2.. 250 Kb 3.. 125 Kb 4.. 100 Kb 5.. 50 Kb 6.. 20 Kb 7.. 1 Mb

SET CAN - shows the settings for all CAN connections SET CAN ifnum BAUD baudind - Sets the CAN baud rate SET CAN ifnum STATION addr - Sets the CAN station number

The following instruction defines a baud rate of 615kb and the station number 24 for the CAN 1 interface: SET CAN 1 STATION 24 BAUD 0

SET LASALCOM COM1 BAUD 56000 With this instruction, the COM connection (RS232) is selected as the online connection and the parameters are defined. Syntax SET LASALCOM [[port] [BAUD] [baudrate]] port - COM-Interface: COM1 | COM2 baudrate - 9600 14400 19200 38400 56000 115200

Page 541: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 541

SET IP HOSTADDR 192 168 0 1 Here, the IP address of the host computer is defined. SET IP GATEWAY 255 255 255 255 With this instruction, the Gateway IP address is set. SET IP SUBNET 255 255 255 0 The subnet mask IP address is defined with this instruction. In order to change the autoexec.lsl, must first be downloaded from the destination system to the PC. An existing online connection is required to accomplish this. Change to Online mode in LASAL CLASS 2 and select Debug in the menu bar. In the context menu that opens select Extras Load File from PLC... (as shown below).

Page 542: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 542 Version 5.0

In Load File from PLC window, enter C:\autoexec.lsl.

Click OK and save the file to the PC hard drive.

Page 543: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 543

A backup copy should also be stored on the PC before the file is changed so that the origi-nal settings can be reinstated. The autoexec.lsl can now be opened and changed with a normal text editor.

To download the modified autoexec.lsl to the destination system, select Debug, Extras, Save File to PLC... in the menu bar. In the Open window select autoexec.lsl and click on Open. Enter C:\autoexec.lsl under Filename PLC: and press OK.

When the CPU is restarted, the settings in the autoexec.lsl are put into effect.

When changes are made in the AUTOEXEC.LSL it is necessary to re-start the CPU to that the changes are assumed!

Page 544: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 544 Version 5.0

12.4.5 Connecting via Modem Basically, both Modems must control the DIREKT-Modus (AT\N1) and the Modem on the destination system must be able to establish a connection without a hardware handshake. For this reason, it is recommended that the PLC side be equipped with a WESTERMO TD-32 DC and the LASAL CLASS 2 side, an ELSA-Modem. Block diagram of the connection

Destination system settings

• The Modem cannot send any messages to the PLC. • The Modem itself must take an incoming call. • A baud rate of 9600 and an 8N1 data format must be fixed • The Modem must operate in direct mode. Neither buffer operation or error correc-

tion is allowed. • No data flow controls can be activated (RTS-CTS or XON-XOFF).

Page 545: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 545

Example of WESTERMO TD-32 DC The Modem operating instructions should also be read. Standard dial connection

DTR/DSR switched off

Two wire connection

9600 Baud, 8N1

Automatic recording of speed

Page 546: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 546 Version 5.0

Online Configuration The setting must be made in a terminal program (i.e.: Windows HyperTerminal). If setting the modem is unclear, the standard settings can be called as follows: AT&F&W0 ……………. Reset to standard The configurations string for the Westermo Modem written as: ATQ1E0&K0\N1S0=2&W0 ATQ1 Quiet mode, no return messages ATE0 No echo from commands (not required) AT&K0 No data flow control AT\N1 „Direct mode“ ATS0=2 Automatic pick up after to call signals AT&W0 Save as actual configuration With the AT\S command, the actual configuration can be tested and should correspond to the list shown below:

Page 547: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 547

Operating System Settings To start, the Modem must first be installed. In Windows SP, open the system controls and then the Telephone and Modem options window:

Select the Modems tab in the above window and click on the ADD….

Page 548: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 548 Version 5.0

In the Hardware Assistant window, the decision can now be made as to whether the Mo-dem is selected automatically or manually.

When automatically selected, make sure that a Modem is connected and turned on. Click on Continue > to start the automatic search.

To select the modem from a list manually, activate the Modem select function (no automatic recognition).

Page 549: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 549

Select the corresponding modem from the list. If a data carrier with the driver information is available, push the Data carrier… button to install the Modem then click on Continue >.

Next, select the PC connection (here: COM1) for which the Modem should be installed the click Continue >.

Page 550: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 550 Version 5.0

A window then appears in which the Modem configuration is confirmed. Click on Finish.

As can be seen, the newly installed Modem is shown in the list.

Page 551: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 551

Select the Modem and press the Properties button. In the window that opens, select the Modem tab.

In this window, define the maximum transfer rate of 9600 as shown above and click OK to confirm the selection.

Page 552: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 552 Version 5.0

Settings in the LASAL Online Configurations Window Create a new connection (here: Modem new) or select the existing Modem connection. Under Connect Type:, select Modem. Under Modem:, select the newly installed Modem (Standard 56000 bps Modem). Here the decision is also made whether Dial type Tone, Pulse, Mode direct or Modem processor is used. Finally, under Phone number: enter a phone number by which the modem is dialed.

Page 553: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 553

12.5 LARS LARS is the abbreviation for LAsal Runtime System. It runs the LASAL operating system on a Windows platform. LARS calls LASAL applications with limited realtime and hardware access requirements. The connection is made in the same way as to a CPU. LARS can also be run on a PC, which has the LASAL CLASS 2 software design tool. In this case, the communication must be constructed manually.

Because only limited realtime (windows dependant) and hardware access is available under LARS, it is recommended that only visualization or simulations be run.

Page 554: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Page 554 Version 5.0

A connection to the user computer can be made two ways: 1. Loopback Address This is the IP address of the PC, which should always be provided when TCP/IP is used. As soon as an inquiry is made in the network for the Loopback address, the connection to its own interface is returned. The Loopback address is normally used for troubleshooting but in this case, it’s the best solution for accessing LARS. A Loopback address is an IP address, whose first number must be 127 and appears as follows: Loopback Address: 127.x.x.x The x can be any value between 1 and 245.

To use the Loopback address, you cannot be in a network. A network card need only be installed.

Page 555: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

ONLINE WITH THE CONTROL

Version 5.0 Page 555

2. Own IP Address If connected to a network, this type can be used to establish a connection to LARS. The IP address from the user’s own must be assigned.

Page 556: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Page 556 Version 5.0

13 FAQ’s 13.1 Overview

What does syntax and syntax highlighting mean? What are tasks? What does the IEC 61131 standard mean? What are methods used for? What is a variable and for what are they required? What does variable declaration mean? What is a compiler? What is the debugger used for? What is an array? What does the data type ASCII mean and what is it used for? What do OS variables mean? What is Ops.tAbsolute? What does the Handle in file operations mean? What is an instruction pointer? In the script file, why is a slash used for the directory assignment instead of the usual backslash?

Page 557: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Version 5.0 Page 557

What does syntax and syntax highlighting mean?

Syntax refers to the patterns and rules in which words are compiled into larger functioning units such as sentences and phrases as well as relationships formulated between whole and parts as well as dependency etc. In information technology a formal grammar is defined to establish allowable and non-allowable constructions in a formal language (Programming language). Syntax highlighting describes the ability in some text editors to display specific words and character combinations in different colors, styles (bold, cursive, etc.) and writing types. Syntax highlighting is used mostly in the processing of program source text, where key-words and other program language elements are highlighted. Syntax highlighting improves the readability of text: structures in the text are easier to rec-ognize, proof reading is simplified, commentary is distinguished form the actual code and typing errors are found quicker. In many cases a typing error changes the appearance of the text.

Page 558: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Page 558 Version 5.0

What are tasks?

A task is a process, which runs at the lowest system level. Multitasking is the when several processes are run simultaneously. Because a processor can only process one task in a given unit of time, the system switches between the various tasks and appears to process them at the same time. Because this occurs in split second intervals, the user doesn’t notice it. There are three types of multitasking:

Real Multitasking

Cooperative Multitasking Cooperative (non-preemptive) multitasking works without time slices. The CPU blocks a process until it stops automatically.

Preemptive Multitasking

With preemptive multitasking, the time frame is divided into bit slices of a defined length. The individual processes are assigned time slices through a scheduler (a part of the operating system). Once the time slice has elapsed, the process is in-terrupted and another process is run for a time slice.

In LASAL CLASS 2, preemptive multitasking is used.

What does the IEC 61131 standard mean?

IEC is the abbreviation for International Electro technical Commission, which is the interna-tional standardization committee for standards in the area of electro technology and elec-tronics with headquarters in Genf. The IEC 61131 standard was designed to standardize the various languages, instruction sentences and concepts in the field of automation. Under IEC 61131, program languages, interfacing between PLCs and programming systems, the various instructions as well as the processing and structuring of projects are standardized.

Page 559: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Version 5.0 Page 559

What are methods used for?

The algorithms assigned to a class of objects are called methods. Methods are used to provide complete functions. Methods can have transfer parameters that send data for the function and return parameters that supply results. The term Method is frequently used synonymously with function or procedure, although the function or procedure is actually the implementation of a method. In daily use, one also says “object A calls method m from object B”.

What is a variable and for what are they required?

The data processed in a program must be stored during processing. In general, this occurs in the main memory of the CPU. Because explicit address assignments aren’t practical with lager programs, variables are used in high level programming languages. A variable is a placeholder for a memory area. The size of the memory area depends on the variable type. The value of the variable has a specific meaning according to the type assigned. The memory area assigned to a variable can either contain the value of the variable directly or the address to the place in memory where the actual data is stored. In this case, the variable is called a pointer

Page 560: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Page 560 Version 5.0

What does variable declaration mean?

In most program languages, a variable must be declared, which means the variable name and in most cases, the type also, are defined. Under the scope of a variable, the program section for which the declaration is valid is cov-ered. If the variable is declared within a routine, it cannot be accessed by program text outside of the routine. In this case the variable is referred to as a local variable. If a variable is declared outside of a routine it is called a global variable. Local variable names can be used in other routines without conflict. Global variables however, must have a unique name. The life span of a variable refers to the time span for which a variable is assigned in mem-ory. For global variables, this time frame is generally from the program start to program end. With local variables this generally starts from the time the respective routine is called to the time it is exited by the program. Variables should be initialized before being used. This can be done through the runtime system of the program language or through an explicit assignment of a value to the vari-able. Un-initialized variables are a source for hard to find errors; without initialization, the variable contains a value arbitrarily stored in the assigned memory area. A program is often disrupted by arbitrary value functions or it simply returns false results, which may not be found though testing.

What is a compiler?

A Compiler (also called a translator) is a computer program, which converts a program from its original language to an identical program in the target language. Normally it concerns translating the program source code from the program’s language to assembly language, byte code or machine language. The application of a compiler is described as compiling. The interpreter is similar to a compiler except that it doesn’t translate a program to the tar-get language rather executes it directly step by step.

Page 561: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Version 5.0 Page 561

What is the debugger used for?

Debugging is the process by which the user searches, diagnoses and eliminates errors in the hardware and programming errors in the software. The tool used to debug software is called a debugger. The debugger enables the user to follow the process of a program in single steps. A debugger is often a standard part of a program design environment.

What is an array?

An array (or field) refers, in information technology, to a data structure and is used to store elements of the same type in a row of data fields. With help from an array, data of a single data type can be assigned in the memory of a CPU so it can be accessed over an index.

What does the data type ASCII mean and what is it used for?

ASCII stands for "American Standard Code for Information Interchange". ASCII de-scribes a character set based on the Latin alphabet used in modern English and computers as well as other representations of text used in communications. ASCII describes the assignment of whole numbers as code that represents characters in normal written language. With this code, text is interpreted as number sequences.

Page 562: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Page 562 Version 5.0

What do OS variables mean?

OS Variables are Operating system variables, which are available to the user globally. The user can change the values of these variables under certain conditions (depends on the respective variable). These variables include for example, _CyclicMaximumTime and Ops.tAbsolute.

What is Ops.tAbsolute?

The global variable, Ops, contains a structure that provides various information. The entry tAbsolute provides the CPU time in ms. This time is initialized with 0 at the start of the project in the destination system and is incremented in milliseconds.

What does the Handle in file operations mean?

The Handle is a 4-byte identification for an opened file. Using this identification, it is pos-sible to distinguish files opened at the same time.

What is an instruction pointer?

The Extended Instruction Pointer (EIP) is a register, that tells the processor which in-struction should be processes next.

Page 563: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Version 5.0 Page 563

In the script file, why is a slash used for the directory assignment instead of the usual backslash?

The backslash „\“ triggers a so-called escape sequence, which is used to write various special characters in a text (i.e. „\t“ for Tabulator, „\n“ for new line). In order to get the „\“ character, an additional backslash must be included (i.e. „C:\\Lasal2\\...“). Therefore, the UNIX syntax for paths is used. The possibility exists to deactivate the escape sequence function. To accomplish this, type „r“ before the text (i.e. r“C:\Lasal2\...“).

Page 564: Training Manual Lasal Class 2 - gongkongfs.gongkong.com/files/technicalData/200910/2009102111302200002.pdf · Training Manual LASAL CLASS 2 Contents ... 15 2.2.3 Menu Bar ... 3.2

FAQ's

Page 564 Version 5.0