Training Manual Lasal Class 2
Training Manual Lasal Class 2
Training Manual Lasal Class 2
Version 7.0
Page 1
CONTENTS
2.3 LASAL CLASS 2 File Types .................................................................... 43 2.3.1 Project Files .................................................................................... 43 2.3.2 Source Code Files .......................................................................... 43 2.3.3 Project Administration File.............................................................. 44 2.3.4 Temporary Files.............................................................................. 45 2.3.5 Text File .......................................................................................... 45
Page 2
Version 7.0
CONTENTS
4.4 Operators .................................................................................................. 91 4.4.1 Comparison Operators ................................................................... 91 4.4.2 Arithmetic Operators....................................................................... 91 4.4.3 Assignment Operators .................................................................... 92 4.4.4 Bitwise Operators ........................................................................... 92 4.4.5 Logic Operators .............................................................................. 93 4.5 Introductory Example: Incrementing a Server ...................................... 94 4.5.1 Online Settings with TCP/IP ........................................................... 97 4.5.2 Downloading the Project to the CPU .............................................. 99 4.5.3 An Example with Floating Comma Numbers................................ 102 4.5.4 Read and Write Methods of Servers ............................................ 105 4.5.5 Connecting Clients and Servers ................................................... 117 4.6 Instructions............................................................................................. 119 4.6.1 The if-instruction ........................................................................... 119 4.6.2 Example: Pump station................................................................. 120 4.6.3 Automatically placing Read and Write methods........................... 135 4.7 LASAL CLASS 2 Library........................................................................ 139 4.7.1 LASAL CLASS 2 Library Overview............................................... 139 4.7.2 Importing Classes ......................................................................... 143 4.7.3 Introduction to Hardware Class Principles.................................... 145 4.7.4 The Hardware Editor..................................................................... 154 4.7.5 Connection Manager .................................................................... 170 4.7.6 Online with the Hardware Editor................................................... 177 4.7.7 Null Voltage Protected Servers and Clients ................................. 178 4.7.8 Bit Operator Applications.............................................................. 180 4.7.9 Using Bit Connections ("Masking" Bits)........................................ 185 4.7.10 The Case Instruction ("Schrittkette") ............................................ 189 4.7.11 Network Overlapping Object Connections.................................... 201 4.8 Topical Exercises................................................................................... 208 4.8.1 Conveyor Belt Project ................................................................... 208 4.8.2 Traffic Light Poject ........................................................................ 210 4.8.3 Run light........................................................................................ 211 4.9 Program Loops....................................................................................... 212 4.9.1 The For-Loop ................................................................................ 212 4.9.2 The while-Loop ............................................................................. 212 4.9.3 The Repeat-Loop.......................................................................... 213 4.9.4 Interrupt instructions for Loops ..................................................... 213
Version 7.0
Page 3
CONTENTS
4.10 Data Fields .............................................................................................. 215 4.10.1 Declaration of an Array ................................................................. 215 4.10.2 Accessing Array Elements............................................................ 216 4.10.3 Initialization of an Array ................................................................ 217 4.10.4 Memory Map of an Array .............................................................. 217 4.11 Topical Exercises................................................................................... 223 4.11.1 Search .......................................................................................... 223 4.11.2 Multidimensional Array ................................................................. 224 4.12 Additional Exercise Examples.............................................................. 229 4.12.1 Lotto Generator............................................................................. 229 4.13 LASAL CLASS 2 Operating System Variables.................................... 230 4.13.1 The Operating System Variable _Firstscan and ops.tAbsolute.... 230 4.13.2 _Firstscan and Ops.tAbsolute Application.................................... 232 4.14 Topical Exercises................................................................................... 239 4.14.1 Delay Off Switch ........................................................................... 239 4.14.2 On/Off Delay Switch ..................................................................... 240 4.14.3 Filter .............................................................................................. 241
Page 4
Version 7.0
CONTENTS
Version 7.0
Page 5
CONTENTS
6.7.3 Class-Oriented Header Files ........................................................ 395 6.7.4 Global Header Files ...................................................................... 399
CONTENTS
Version 7.0
Page 7
CONTENTS
13 FAQs...................................................................................... 589
13.1 Overview ................................................................................................. 589
Page 8
Version 7.0
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
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 introduce 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 symbol indicates a helpful tip for how something can be done faster or better.
Version 7.0
Page 9
1.1.3
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 into the target system) 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 processes. Using the LASAL software tools, the development time can be significantly reduced and machine concepts can be realized quickly 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 axes Visualization tool for graphic terminals Visualization tool for text terminals With LASAL class 2, all programs for machine process control are created. Therefore the complete SIGMATEK product palette such as CPUs, terminals and industrial PCs are supported. A change of the target platform (within the SIGMATEK product line) is possible at any time with little or no changes required in the LASAL CLASS 2 project.
Page 10
Version 7.0
1.3
1.3.1
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. Furthermore, the software in LASAL CLASS 2 is easier and more efficiently tested. Defined interfaces (connections) that can send and receive data 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
The advantage of creating programs with LASAL CLASS 2 is that programming is significantly 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
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.
Version 7.0
Page 11
1.3.4
With scripting, projects can be generated automatically. Here, pre-assembled classes from a library and/or entire object networks from several projects can be combined into a new project. With the automatic generation in the background, the user is free to perform other tasks.
1.3.5
LASAL CLASS 2 has a library collection of components, which is expanded regularly. Components imported from the library can be linked in the project and used to implement applications. 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 allow it to be updated automatically.
1.3.6
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 in a way that appears simultaneous. Thereby 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 especially optimzed 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 12
Version 7.0
Version 7.0
Page 13
2.2
2.2.1
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 14
Version 7.0
2.2.2
Layout
In LASAL CLASS 2, it is possible to store different layouts of the program interface and recall them later via a list menu. That means, in 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:
to define a new layout. By selecting Capture Layout the current layout of the Click on 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 respective layout can be inserted.
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.
Version 7.0
Page 15
2.2.3
Menu Bar
The menu bar in LASAL CLASS 2 contains 9 menus with various LASAL CLASS 2 instructions 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
Page 16
Version 7.0
View, Toolbars
View, Layout
Version 7.0
Page 17
THE DESIGN ENVIRONMENT View, Graphical User Interface View, Graphical User Interface, Theme
Project
Build
Page 18
Version 7.0
Debug, Breakpoint(s)
Debug, Settings
Version 7.0
Page 19
Tools
Page 20
Version 7.0
Extras
Help
Window
Version 7.0
Page 21
2.2.4
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
Saves a file Open a project Save a project Close the actual project
Page 22
Version 7.0
Build Toolbar
Strg+ F9 Compile project changes Scroll+ Caps lock Abort compilation process
Strg + F9
Toolbox
Opens the Data Analyzer Opens the Interpreter environment Opens the Hardware Editor
Opens the DiasDrive environment Opens the advanced debug tools Opens the Connection Manager
Version 7.0
Page 23
Shows a list including all stored layouts. Select View, Layout, Layout Manager from the menu list to save a layout. Debug Toolbar
Alt + F6 F6 F7 F8 F4
Online / Offline Download Project Start/ Reset Reset Toggle Breakpoint Set conditional breakpoint Clear all Breakpoints Several functions at once: F5 Alt + F5 Shift+ F5
AWL Trigger on/off Display all current instructions (Goto instruction pointer) Step Into Step Over Step Out Set actual instruction (set instruction pointer) Change online settings
Ctrl + Alt + F6
Compiles the project changes and goes online with the control, downloads and starts the project: + + +
Page 24
Version 7.0
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 illustration below, each of these areas can be selected using tabs to open the respective window.
Tabs
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 desired position.
The following pages give an overview of how the individual components in the various project 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.
Version 7.0
Page 25
THE DESIGN ENVIRONMENT 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 menu the individual components can be created.
The illustration above serves primarily to re-introduce several important concepts in LASAL CLASS 2, which were mentioned previously.
Page 26
Version 7.0
THE DESIGN ENVIRONMENT Libraries When the Lib register tab is selected, the Libraries window is opened. Here various libraries 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.
Version 7.0
Page 27
THE DESIGN ENVIRONMENT 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
Version 7.0
THE DESIGN ENVIRONMENT Net Selecting the Net tab opens the Networks View window. In this window, a network is created 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.
Version 7.0
Page 29
THE DESIGN ENVIRONMENT 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 a 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
Version 7.0
THE DESIGN ENVIRONMENT 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 identifies the libraries used in LASAL 2 projects and are linked to the actual project. Changes cannot be made in these files.
Version 7.0
Page 31
THE DESIGN ENVIRONMENT 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 information on the actual process status and displays keyboard instructions.
Page 32
Version 7.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 debugging window. The debugging window contains the following output windows: THIS Watch Register Breakpoints Call Stack
Tabs
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.
Version 7.0
Page 33
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 window. Watch
To track values from different objects, variables can be placed 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
Version 7.0
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.
Version 7.0
Page 35
2.2.8
Output Window
The Output Window is located in 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
Tabs
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.
Page 36
Version 7.0
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. Version 7.0 Page 37
2.2.9
This represents the python interpreter input window. Here, the Python Instructions can be entered and executed.
Page 38
Version 7.0
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.
Version 7.0
Page 39
Page 40
Version 7.0
THE DESIGN ENVIRONMENT In addition, the user can create a help document for a user-defined class. In such a case, the type of document does not matter (.doc, .pdf., .xls). The document name, however, must start with the name of the respective class for which the document is created. If a dot or space is then inserted, more characters can be added to the document name. Example: The class is called TestAppli. The document names can be written as follows: Testappli.doc TestAppli Info.txt TestAppli.Info.pdf Next: the path for this document must be defined under Tools/Options.
Version 7.0
Page 41
Here, 2 types of protection can be selected: Write Protection If this function is activated, the entire program code for this class is write protected. This protection can only be lifted with the correct password. The program code is shown in gray. Encryption This function encrypts the class file and prevents access to the program code over Lasal Class. The encryption can only be removed by entering the correct password.
Page 42
Version 7.0
2.3
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
*.lcp
Project Files
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 settings, etc..). The project files format is XML.
2.3.2
*.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 elements 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
Version 7.0
Page 43
THE DESIGN ENVIRONMENT *.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 its 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
*.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 44
Version 7.0
2.3.4
*.lcb
Temporary Files
LCB files contain binary information so the user doesnt 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
*.txt
Text File
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).
Version 7.0
Page 45
Each of these objects (sports car, truck, bus) has certain characteristics. The user, however, doesnt 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 functions. 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 function It is only necessary to understand the total function of an object last. How an object performs its tasks is an internal issue.
Page 46
Version 7.0
3.1.1
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 exhibit? 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 possesses attributes and methods. In order to work with an object in a 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.
Version 7.0
Page 47
INTRODUCTION TO OBJECT ORIENTATION Attributes Each object of a class has the same attributes, but can work with different data for these attributes.
Objects
Sports car Attributes: Max. Speed Color Wheels Length 280 km/h Red 4 3,5 m Truck 140 km/h Grey 8 8,4 m Bus 120 km/h Orange 6 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 external access of an object is only possible using public methods (global methods). A class therefore, insulates data from direct access.
Page 48
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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 project. 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 characteristics. 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 properties of a base class is identified as a Derived Classes. Derived classes take on the properties 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 implemented only 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.
Version 7.0
Page 49
3.1.2
Advantages of OOP
The reusability of classes through importation from the library into a new project. Defined interfaces of a class determine which data an object should process. Simple expandability of classes through reusability => derivation => inheritance. Simplified programming. It is easier to imagine an object with properties, functions and interfaces than working with a long continuous chain of instructions.
Page 50
Version 7.0
3.2
3.2.1
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.
Version 7.0
Page 51
INTRODUCTION TO OBJECT ORIENTATION 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 52
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION In the Class View window of the project tree, the newly 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.
Version 7.0
Page 53
INTRODUCTION TO OBJECT ORIENTATION 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 Network to create a new object network.
Also in the Network View window folders can be created by selecting Add Folder in the context menu of the project.
Page 54
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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 simply double clicking on the network name or marking it and pressing the Enter button.
Version 7.0
Page 55
INTRODUCTION TO OBJECT ORIENTATION 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 56
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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.
Class name
Class name
Object name
Object name
Next, select the object name (here: CountObj) in the network to open the Properties window. Under comment, the user can include a comment (here: with Object of my class) the object.
Version 7.0
Page 57
INTRODUCTION TO OBJECT ORIENTATION 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 58
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION Youre sure to have noticed the star next to the network name.
Now is the time to save the project. For this, press the bar. button or select File, Save Project in the menu
When the star is no longer present next to the network name, the project has been saved.
Version 7.0
Page 59
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 network. 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.
Page 60
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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 deliver. Server => Provides and receives information. Client => Collects and transfers Information.
Version 7.0
Page 61
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 62
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION The next graphic shows when a process, in the event of 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.
Version 7.0
Page 63
3.2.4
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 already 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 64
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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.
Version 7.0
Page 65
3.2.5
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 its defined. That means, private methods are valid only in 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 within 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 66
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION Virtual Global Method Virtual global methods of a class are valid within 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 classes. With virtual methods, the methods of the base or derived class are called using a table of methods, but only if they were overwritten.
Version 7.0
Page 67
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 activated 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 68
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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.
Version 7.0
Page 69
INTRODUCTION TO OBJECT ORIENTATION 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 70
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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:
Version 7.0
Page 71
INTRODUCTION TO OBJECT ORIENTATION 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 lowest 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 72
Version 7.0
INTRODUCTION TO OBJECT ORIENTATION 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.
Version 7.0
Page 73
Programs consist of a number of instructions, which are executed sequencially. 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, a compiler warning is triggered. 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 problem. Because the program code would be difficult to read, the following writing technique should be avoided: MaximalTemperature := 65; MinimalTemperature := 10;
Page 74
Version 7.0
4.1.2
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.
Version 7.0
Page 75
4.1.3
The program structure in LASAL CLASS 2 is class oriented, whereas the classes are further 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 input parameters. FUNCTION ClassName::NewMethode Program code END_FUNCTION If a method has input 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 76
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The program code in a method should be designed in a structured and continuous manner to create a clear and easy to 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
Version 7.0
Page 77
4.1.4
Commentary
One cannot 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 programmer, 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 function of the program.
With the short cut SHIFT+CTRL+C, previously marked code can be either quickly set under commentary or commented out.
Page 78
Version 7.0
4.1.5
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.
Version 7.0
Page 79
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, however, 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: Base: Highest denomination: Place values: 103 1 102 2 0 10 9 100 = 1, 101 = 10, 102 = 100, etc. 101 3 100 7 1 2 3 4 5 6 7 8 9
Dec
Dec 1237
Page 80
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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).
0 und 1 2 1 20 = 1, 21 = 2, 22 = 4, etc. 27
128
29
512 1024
28
256
26
64
25
32
24
16
23
8
22
4
21
2
20
1
Bin 1
0
+
0
+
1
16
0
+
1
4
0
+
1
1
= Dec 1237
= 1237
128 + 64
Version 7.0
Page 81
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 numbers 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 character. 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: Base: Largest denomination: Place value: 162 4 161 D 0 16 F 160 = 1, 161 = 16, 162 = 256, etc. 160 5 1 2 3 4 5 6 7 8 9 A B C D E F
Hex
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:
Bin
4 0100
D 1101
5 0101
Dec 1237
Page 82
Version 7.0
4.3
4.3.1
In a program, there are many changeable number values that can contain specific machine or equipment information (position, temperature, etc.) or intermediate results. These number 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 is 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, serves 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 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 between the variable name and the variable type have to be entered (e.g. index : USINT;). Naturally, several variables can be defined 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!
Version 7.0
Page 83
4.3.3
Contrary to local variables, private variables are valid for the entire class. This means a private variable can be used in each function of a class.
A private variable is initialized with 0 at the start of the program. With a private variable (member variable), it is possible to work in every function of a 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 keyword, 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 84
Version 7.0
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 0 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 individual variable types are shown. Data Type SINT INT DINT USINT UINT UDINT REAL BOOL CHAR BSINT BINT BDINT HSINT HINT HDINT ARRAY STRUCT ENUM Lower Limit -128 -32768 -2147483647 0 0 0 -3,4 E+38 0 (FALSE) 0 0 0 0 0 0 0 Upper Limit 127 32767 2147483647 255 65535 4294967295 +3,4 E+38 1 (TRUE) 255 255 65535 4294967295 255 65535 4294967295 Description Short Integer Integer Double Integer Unsigned Short Integer Unsigned Integer Unsigned Double Integer Real number, floating point number Bool Character (ASCII characters) 8 Bit Short Integer 16 Bit Integer 32 Bit Double Integer Hex Short Integer Hex Integer Hex Double Integer Data field Data structure Enumeration type
Version 7.0
Page 85
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 SINT Memory 1 Byte Explanation 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. The data type, Integer, consists of both a positive and negative value range from 32768 to +32767 and is used with whole number values. 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. The data type, Unsigned Short, Integer consists of a positive value range from 0 to 255 and is used with whole number values. The data type, Unsigned Integer, consists of a positive value range from 0 to 65535 and is used with whole number values. The data type, Unsigned Double, Integer consists of a positive value range from 0 to 4294967295 and is used with whole number values. 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. With this data type, only the condition 1 (TRUE) and 0 (FASLSE) are possible. This data type is used for logic conditions and can be linked to logic operations. This data type can be written to with ASCII characters or numbers between 0 and 255. This data type displays ASCII characters only. 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.
INT
2 Byte
DINT
4 Byte
USINT
1 Byte
UINT
2 Byte
UDINT
4 Byte
REAL
4 Byte
BOOL
1 Byte
CHAR
1 Byte
BSINT
1 Byte
Page 86
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 is always displayed in the binary number system. 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 is always displayed in the binary number system. 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. 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. 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. This data type consists of a one or more dimensional fields of a different data types. This data type enables the creation of a data structure of different data types. These data types a named allocation of numbers (0 to.).
BDINT
4 Byte
HSINT
1 Byte
HINT
2 Byte
HDINT
4 Byte
Version 7.0
Page 87
4.3.6
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. Variables of this data type are mostly used in a step switch, also known as sequences, in a CASE instruction. With this type a clear step name can be assigned.
Page 88
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 (American Standard Code of Information Interchange) is a standardized code for writing and control characters. The American standard coding for information exchange determines which number value corresponds which character. 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 0 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 components. The expanded ASCII code, which consists of the ASCII values between 128 and 255, can contain various characters and depends on written or graphic character sets.
Version 7.0
Page 89
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Datentyp BSINT, BINT or BDINT If a variable of this data type is placed in the system, the individual bits can then be assigned names and activated. Example:
New
Data type HSINT, HINT or HDINT If a variable of this type is placed in the system, the content is displayed in the hexadecimal number system. Example: The number 1,000,000 written as a hexadecimal value: 16#00 0F 42 40
Page 90
Version 7.0
4.4
Operators
Operators are used in programming to execute logic, bitwise 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. + * / ** Mod Addition Subtraction Multiplication Division Exponentiation 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
Version 7.0
Page 91
4.4.3
Assignment Operators
The following operators are available in structured text for simple and/or combined assignments: := += -= *= /= Simple allocation Increment variable Decrement variable Multiply variable Divide variable
:= ..... Simple allocation += .... Combined allocation -= ..... Combined allocation *= ..... Combined allocation /= ..... Combined allocation
x := 44; x += 1; x -= 3; x *= 5; x /= 2;
x := x + 1; x := x 3; x := x * 5; x := x / 2;
4.4.4
Bitwise Operators
NOT or ! AND OR XOR SHL SHR SAR ROL ROR Negation (Two-complement) Bitwise Negation (one-complement) Bitwise AND Operation Bitwise OR Operation Bitwise XOR Operation Bitwise shift to the left Bitwise shift to the right Arithmetic shift to the right Bitwise left rotation Bitwise right rotation
corresponds to Var := ! x
Page 92
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 In this shift operation, the newly freed bits are filled with 0: Var := x SHL y; Var := x SHR y; Example: with SHL 0 0 0 0 0 0 0 1
Before After
1 1
1 0
1 1
1 0
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 0 0 0 0 0 0 0 1
Before After
1 1
1 0
1 1
1 1
4.4.5
Logic Operators
!! & | Logic Negation, tested with <> 0 Logic AND Operator Logic OR Operator
Version 7.0
Page 93
4.5
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 94
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 To increment a server, the assignment operator += is used. Position the cursor in the program code after ClassSvr and type:
+= 1;
That means the value in ClassSvr will be raised by 1 with each cycle.
Version 7.0
Page 95
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 simply press the in the symbol strip.
In the Output Window, the compiler process is displayed. The process should be completed 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 program code or seek help under Troubleshooting.
(or Build, Build from the menu bar), only the changes When using the Build button made since the last Rebuild All will be compiled. If a project has not been compiled before and you only use the build function, the project will still be compiled correctly.
Page 96
Version 7.0
4.5.1
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.
Version 7.0
Page 97
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 connection (here: TPC/IP 10.10.57.65) and under Connect Type and select TCP/IP as the connection 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. The search result consists of a list that includes all located controls is displayed in the Network IP Scanner window. Select the desired 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 98
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 In the status bar, the following message appears in red:
PLC != PC means that the project in the destination system doesnt 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.
4.5.2
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:
Version 7.0
Page 99
By selecting Download Module on the Fly in the Debug menu changes can be transferred to the control during runtime, without stopping the program. More information about this function can be found in the LASAL CLASS 2 documentation or LASAL CLASS 2 help respectively.
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 100
Version 7.0
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 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 destination system.
Version 7.0
Page 101
4.5.3
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.
Next create a CyWork method in the class and define a cyclic time of 100ms.
Page 102
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 103
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
In the project properties under Target you can find Use FPU. If this entry is set to TRUE, the floating-point calculation is performed by the existing Co processor in the hardware, which provides an advantage of speed. Otherwise the calculation is performed by LASAL Class.
Page 104
Version 7.0
4.5.4
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.
Version 7.0
Page 105
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 create a second client (here: Set).
Page 106
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 Double 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 for a mandatory connection. If Required is 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 exists over which a value can be read through the Read Method, the actual value written in the client is used.
Version 7.0
Page 107
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Because the CyWork Method of the CounterClass is no longer necessary for this example, 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 CounterClass again, double click on the method under CounterClass in the project tree.
Page 108
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 A CyWork Method for the class is now needed. Open the context menu of ReadWriteClass and select New Std. Methods, CyWork.
To activate the CyWork method, open the properties window of ReadWriteClass and set the CyclicTask to true.
Version 7.0
Page 109
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 program code editor from the project tree, using the Drag & Drop method. Dont forget to include commentary.
Page 110
Version 7.0
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 parameter be transferred with it. This parameter is set in the parentheses and can appear as follows: 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.
Version 7.0
Page 111
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 112
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 ReadWriteClass) 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).
Version 7.0
Page 113
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 To define a cyclic time for the object, ReadWriteObj, select it either from the network directly or from the project tree to open the Properties window.
As can be seen in the network, the object ReadWriteObj is now also blue.
Page 114
Version 7.0
This is a good point to save the project. Press the File, Save in the menu bar.
button or select
To load the project in the destination system, it must first be compiled. Select Build, Rebuild 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.
Version 7.0
Page 115
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The Network Window should now appear as shown in the following illustration:
Because CounterClass and its object, CountObj, were not changed during the course of this exercise, the server ClassSvr continues to increment.
Open the input field with a double click on 0 under the client, Get and a enter number (here: 9). Confirm the input with enter.
As can be see in the illustration above, the value (here: 9) entered in the Get client is assigned to the Set client through the program code.
Page 116
Version 7.0
4.5.5
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.
Version 7.0
Page 117
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Recompile the project using the destination system with the button and re-establish an online connection 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 118
Version 7.0
4.6
4.6.1
Instructions
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 comparison 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;
Version 7.0
Page 119
4.6.2
Page 120
Version 7.0
For this example, create a new project. Select File, New Project in the menu bar.
Here, assign the project name (in this example: PumpControl). Save the project in the folder C:\Sample and confirm with Enter.
Version 7.0
Page 121
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Your screen should appear as follows:
Page 122
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 In the Class-View window of the project tree, the newly created project is displayed. Activate 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 Properties window, set CyclicTask to true as shown below.
Version 7.0
Page 123
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 124
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 125
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Next, open the folder, Methods, with a left click on the + symbol then double click on CyWork to open the program code editor.
Page 126
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The following code is entered between the lines END_VAR and state:=READY; of the CyWork method in the program code editor (see illustration).
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.
symbol It is recommended, at this point, to save the project. Click on the to save the project. After compiling, the project is also saved automatically each time.
Version 7.0
Page 127
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Double click on the object network (here: PumpControlNet) to display the network.
Page 128
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Switch back to the Class View window and insert the class (here: Hysterese) into the object network using the Drag & Drop method. An object of the class Hysterese is also placed through this process.
Version 7.0
Page 129
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 operating system every 100ms.
As can be seen in the illustration below, the number 0 in the clients MaxValue and MinValue are red but in the other clients, theyre 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 130
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 131
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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, Settings, Detail Modus.
Page 132
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 To see whats 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).
Version 7.0
Page 133
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 counting upwards. The reason for this is because the value that has been entered in the object, objHysterese, did not trigger an alarm.
Page 134
Version 7.0
4.6.3
To implement the Read and Write methods of servers in the program code more easily, they can be placed automatically . This function has not been mentioned earlier in this manual, so that come familiarity with the syntax could be gained!
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:
Version 7.0
Page 135
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Afterwards open the context menu with a right-click and select Insert Client-Update Source Code....
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 136
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 After confirmation with OK the methods are automatically placed in the program code editor:
Now place the Write method of the remaining clients in the same way in the program code editor and confirm with OK again.
Version 7.0
Page 137
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 138
Version 7.0
4.7
4.7.1
In order to use a class from the library, change to the Libraries window, open the context menu and select the desired category.
Version 7.0
Page 139
Contains all hardware classes used to control the SIGMATEK product palette for Dias- CDias and Varan hardware modules and drives.
Loader.lcp
The loader is loaded into the target system with each LASAL CLASS 2 project and is responsible for placement of objects, processing the interpreter and the exchange of data and instructions between 2 controls, etc.
Motion
Da diese Library kostenpflichtig ist, ist diese nicht standardmig implementiert. Diese enthlt alle Klassen, die zum Betrieb von Achsen (z.B.: Dias-Drives,...) ntig sind.
OS Interface.lcp
In this category, all operating system interfaces such as CAN, file, graphic operations as well as functions for memory operations are provided.
Page 140
Version 7.0
This library contains, among other things, classes for visualization, communication, KOP, remote maintenance, memory functions, etc.).
Beispiele:
E.g.: LslRemote : interface class for the LASAL Remote Manager. Version 7.0 Page 141
E.g.: Ram: class that a client stores in null voltage safe Sram.
LasalTextKernel
This folder contains the visualization components for monochrome graphic displays.
lseRtk
This category contains the visualization controls and classes for the visualization of scrolls, alarm management, oscilloscope and language conversion E.g.: _Lse: Kernel-Klasse
Page 142
Version 7.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. Since the import type has already been selected, confirm with OK.
Version 7.0
Page 143
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 automatically 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 144
Version 7.0
4.7.3
In the DiasMaster category, all hardware classes for the component series Dias and CDias are found. In a project, if DIAS/C-DIAS 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 processor module with a 386 core. 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.
Version 7.0
Page 145
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The following illustration shows the hardware construction with a CPU and various hardware modules distributed over several module carriers. The CIC module serves as a voltage supply and to connect the decentralized C-DIAS module 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 depending 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 146 Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 DiasMasterC object. In addition, all MasterConnect clients of the hardware classes are connected to the Control server of the CIC module
Version 7.0
Page 147
VARAN network
All hardware classes of the VARAN type series can be found in the VaranLib library. If hardware 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 a DiasMasterC object (Server DiasMaster) can also be connected. If a connection to the DiasMasterC is established, the HwControl also controls the DIAS bus time management in order to be synchronized with the VARAN bus. VaranManager_1 or VaranManager_2 of VaranManager_3 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 148
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Connecting C-Dias modules to a VARAN bus structure:
To connect C-Dias modules to a VARAN bus, a coupling module is needed (here the CIV 512 for example). C-Dias modules are then connected to the CDIAS server. Further information on the modules can be found in the respective module documentation.
Implementing the pump station example with hardware modules
Import the required hardware modules from the DiasMaster.lcp library. In this example, the following modules are used:
CTO 163 CAM 123
Next place an object of each hardware module in the object network. In addition, an object of the DiasMasterC is needed. This must also be placed in the object network.
Version 7.0
Page 149
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Connect the objects as shown below:
In each of the clients identified with an arrow, enter the initialization values shown in the screen shot above. With a double click on the respective client value, a white field appears in which the initialization value must be entered. Confirm with Enter to close the field and assume the value. For the analog inputs of the hardware modules (CAM 123) an initialization value must be entered in the clients Al1_Scale (1000) to Al8_Scale (1000) for scaling.
Page 150
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The client-server connection is created by clicking the left mouse button on the client or server. If nodes should be created in the connection, use the grid (points) in the object network to set nodes with a left mouse click. Next, complete the connection with a left mouse click on the client or server. To change the connection, mark them in order to show the nodes. Next place the mouse pointer on a node then press and hold the mouse button to move the connection. Click on a node and hold the mouse button while pressing the ctrl button to delete this point. Set a new node by pressing the Ctrl button and the left mouse button at the desired location on the connection.
Add node
Delete node
Move node
Version 7.0
Page 151
To identify clients that are connected to a server by color, set the property Show connected Servers in the Application Options window (found in Menu Tools/Options).
Page 152
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 With the hardware class objects (CTO163_IM and CAM123_IM), an initialization value must be entered in the Place clients. This defines the position of the hardware module on the module carrier. In this case, the CTO163 is on Place 1 and the CAM123 is on Place 2 of the module carrier.
Next, save and compile the project with Rebuild All. Go online and load the project into the target system.
If the values are now changed over an analog input (here: CAM123; see AI1 in the above screen shot), the pump station should function the same as the project without hardware. Version 7.0 Page 153
4.7.4
The Hardware Editor provides the possibility to display available hardware with defined hardware classes in LASAL using just a few mouse clicks. The Connection Manager is discussed in the same connection, as it belongs to the hardware editor and works very closely with it. The hardware editor is started by pushing the corresponding button the menu item Tools / Hardware Editor. in the toolbar or in
Page 154
Version 7.0
On the left, the actual status is shown (Current Configuration), on the right the desired status (New Configuration) can be seen. On the bottom left, the Network for new Objects field is located. From now on, all HW objects are placed in this network (sections of the PLC such as the DIASMaster as well as all modules that can be connected). By default, HW_Network is entered; the name can be changed however. The buttions Apply und Close are located to the right. Apply can only be clicked when something in the status has changed, with Close the window is exited without changes.
Version 7.0
Page 155
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The maximum configuration appears as follows:
The Apply button is now clickable. When clicked, the following appears
on the screen. After which, the Import Class dialog fro the Library tab appears.
Here, individual classes can be selected or deselected and the option to link, copy or reference them can be chosen.
Page 156
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Once confirmed with OK, the hardware window appears as below (here in the maximum configuration with OnBoardIO, DIAS/CDIAS and 3 Varan ports):
Version 7.0
Page 157
Add Modules
Right click on one of the empty interfaces. The context menu appears, which contains the items Add Device and Device Searcher:
If Add Device is selected, the search for the desired module can be limited by categories:
Page 158
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The other option is to select Device Searcher. This menu item should be selected when the module name is at least partially known.
With the mouse, it is possible to scroll through the modules available at this interface alphabetically or by pressing the S button, the cursor springs to the input field where the user can search by module name.
Version 7.0
Page 159
If the module is now selected, an import Class dialog is opened for only those classes required for the module. Confirm with OK to add the module to the interface.
Page 160
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 To add another module to the VARAN interface, the context menu expands to the "Recent placed Device(s)" section. In the lower section of the menu, all modules that have been placed to that point are listed (as well as those that may have been deleted!). These can be added directly with a mouse click, without have to search.
Once the module has been placed, it can be moved over the same interfaces with the Drag & Drop method (here, a DIAS module is moved to a DIAS interface.
Version 7.0
Page 161
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The result of only a few mouse clicks can now be seen. Change to the network view from the HW network.
If the PLC is later reconfigured, so that suddenly modules have no interface (here: No DIAS/CDIAS, the DAM123 module no longer has an interface), the "floating" modules are placed in the "Unplaced Module(s)" folder.
Page 162
Version 7.0
With Move Device/Object To Network, a module can be moved to another network (here: NewNetwork) with only a mouse click. The required changes for existing connections are included automatically.
Show Network/Objects changes to the network view, in which the selected module is located. The module can now be seen in the new network:
As can be seen, the connection to DiasMasterC1 is included in the new network. With Delete Module, the selected module is then deleted.
Version 7.0
Page 163
Page 164
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 As can be seen, the hardware editor has a PLC in the maximum configuration consisting of a HWControl, a DiasMaster and a VaranManager. Therefore, three Object of Class... fields are displayed, which show the respective object names that can be changed.
Comment: Here, a comment regarding the PLC can be written. Place(s) for CDIAS (def.4) indicates how many CDIAS interfaces the PLC has. If no number is entered here, the default value is shown in the hardware tree (here: 4). If the value is 0, no CDIAS interfaces are shown. Modules that have already been added to interfaces are now moved to the "DIAS, Error WrongPlace" folder, which instead of the CDIAS interfaces, is now shown in the hardware tree.
If the 0 is deleted from the field in the properties, the module is removed from the Error Wrong Place placed back in the correct position. The Error Wrong Place folder then disappears.
Version 7.0
Page 165
Analog to the previous field, for DIAS interfaces only. The default value here is 8 interfaces (DIAS 0 to DIAS 7).
Varan Manager Time:
The time entered here is the cycle time of the isochronous Varan task. For more, see the class documentation.
Prevent Manager Error:
Here, whether the system should stop with a Varan Manager error can be set.
Iso Start Point:
Start of Processing the Varan task within the isochronous cycle time.This value is given as a percent of the VARAN Manager Time (10% to 90%).
IRQ TaskTime:
Indicates whether the manager is also a client (VMC, also a Varan Manager client)
Superior System Time:
Cycle time of the primary Varan mode. This must a multiple of the Varan Manager Time. This is assigned for a VMC only; when Is Also Client is true.
Settings:
Page 166
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Here, the individual object properties can be found. The individual fields were already addressed with the object properties. If "Sigmatek Inputs" or "Sigmatek Outputs" are entered in the RealIndex field of the DiasMasterC or HWControl object, it cannot be changed. Otherwise, the input options are as discussed in the Pre[index], Default, Post[index], or Last object tree.
PLC Configuration:
Shows all types of modules, which can be added to the PLC in the current configuration. Here they are: DIAS, CDIAS and VARAN modules, the PLC also has an OnBoard-IO module).
Shows the PLC interface to which the module is connected. If the module is moved in the hardware tree, this number changes. If the number is changed, the module moves in the hardware tree accordingly.
Version 7.0
Page 167
Here, whether the module is required for starting the system can be set.
Settings:
Here, the individual object properties can be found. In the hardware classes only Visualized (true or false the visualization of the object) and Comment (object-specific commentary) are processed.
With a right click, the following items are given in the context menu:
Goto Server:
The program jumps to the client connection in the network view. Page 168 Version 7.0
The program jumps directly to the connection entered in the Connection Manager. If the connection manager is closed, it now opens automatically. (for more informataion, see the chapter Connection Manager).
Here, the IO names can be entered or changed. Simply click and hold the mouse button on the connection.
Version 7.0
Page 169
4.7.5
Connection Manager
The Connection Manager is an organic component of the Hardware Editor and offers an additional view of the LASAL object relationships, which is especially suited for hardware connections. It also provides the option to create so-called temporary or IO objects and place them in the network. The interaction with the network view and the clarity are increased. The Connection Manager is started using the item Tools / IO Connection Manager,... icon in the tool bar through the menu
...or as previously mentioned, from the Hardware Editor with the context menu. The IO Connection Manager now opens.
If displayable connections are already available for the Connection Manager, they are automatically assumed and displayed.
Page 170
Version 7.0
The following functions are available in the toolbar of the Connection Manager:
Save sorting Show Sort column Delete connection Create new connection
A new, empty field is created in the table area. All columns, except the Online column, can be edited.
Delete Connection:
An additional column with numbers is displayed. The numbers are unique and cannot be edited.
Version 7.0
Page 171
Save Sorting:
The current sequence of the entries is saved, but the sort column numbers are reassigned (starting from 0). A unique sorting sequence is therefore saved, which can be called according to the sort column.
The Column buttons are sortable and can be easily moved. With a click on a column heading, the respective column can be sorted individually; clicking on the same column heading again reverses the sorting direction. To shift a column, click on the column header and hold the left mouse button while moving the mouse. The target location is indicated by a red arrow above and below the column heading.
Page 172
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The yellow filter line is especially suited for filtering the correct entries out of a large number of connections with just a few clicks. Combined filtering over several columns is also possible, as well as searching by letter groups within the word.
Filtering
Here, a dialog opens in which the end of the connection can be selected (here: the server).
Version 7.0
Page 173
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Repeat this process with the client. Alternatively, the server / client can also be entered manually. If a valid connection has been entered (server and client are legal), the "Connected" icon appears in front of the client:
If an invalid connection is entered e.g. illegal / not existent client -, an icon appears that is crossed out with a red line to indicate the defective connection.
If the IO Name column is filled out, an Icon with a red x is shown before the IO names, that don't yet correspond to a temporary network. The names can now be placed in the network. An IO or temporary object is thereby created. This view increases the readability of large networks, since the (remote) servers can be placed near the client as a temporary object. The icon before the IO name is no longer crossed out:
Page 174
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 With a right click on a connection in the connection manager, the following context menu is opened:
Version 7.0
Page 175
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 It is also possible to jump to the connection manager from the Network View, by clicking on a temporary object and selecting the menu item Goto IO-Connection Manager.
If an object name, server name, client name or the object itself is changed, the change is immediately assumed is all other relevant views of LASAL. When, in our example, the server is changed in the connection with the IO name "Cascade", the change is immediately visible in the hardware editor as well as in the network. If the name of a client user-defined class is changed that is part of a connection, the change is made immediately in the Connection Manager, network view, class view, properties window and in the hardware editor.
Page 176
Version 7.0
4.7.6
If online and the PLC is not yet configured, the existing hardware configuration in the control can be loaded. If the Import Class dialog is confirmed, the complete hardware tree in the control is imported with all networks. If the PLC is already configured and goes online, a comparison of the hardware configuration in the control and the one in hardware editor can be made. If differenced are detected, they are output to the Find Results 2 window. The hardware tree comparison is started with the toolbar button In the following image, an example of the differences is shown. .
In the hardware tree, the modules that are available in the control but not in the hardware tree are displayed with a red background.
Version 7.0
Page 177
4.7.7
The value of a client is stored with null voltage protection using the Sigmatek Ram class. The RAM class is found in the category Memory. This class is used to store remnant values, 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. If several data must be saved with null voltage protection (E.g.: an array or a structure), the RamEx class is used! For strings the StringRAM class is available.
Page 178
Version 7.0
It is possible to save a server value with null voltage protection. For this, the server property RETENTIVE must 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, whether the current server value is different from the value that should be written via the write method is compared. This means that when the server value has been changed before it has been written, no change has been detected and the server value is not stored! Example: MyServer := MyServer +1; MyServer.Write(MyServer); The correct programming is as follows: myValue := MyServer + 1; MyServer.Write(myValue); In this case, the change has been detected and the server value is stored.
Version 7.0
Page 179
4.7.8
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 180
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 181
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 182
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 As can be seen in the program code editor, the Cywork method is before the Init method. This, however, doesnt play a role for the program sequence because the operating system always calls the Init method first and then the Cywork method. To maintain clarity, the Init method can be placed 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:
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 :=.
Version 7.0
Page 183
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 destination system.
Open the THIS tab in the Debugger Window. There the shifting of bits in the Led variable can now be observed. If in the object (objMoveBits), the value of the SetDir client is set to 1 during online operation, the bits will be shifted to the right.
Page 184
Version 7.0
4.7.9
In a variable sometimes more the one piece of information is stored. As in the Sigmatek class _SysDateTime.
Bit 16-31 (Y) contains the entire year value (e.g. 2003) Bit 12-15 (M) contains the actual month from 1 to 12. Bit 4-11 (D) contains the day information starting from one to a maximum of 31. Bit 0-3 (W) contains the weekday whereby 0 is Sunday, 1 is Monday, etc. The SysTime server represents the system time.
Format: HHHHHHHHNNNNNNNNSSSSSSSSxxxxxxxx
(x) currently undefined and initialized with 0. (S) contains the seconds; from 0 to 59. (S) contains the progressing minutes; from 0 to 59. (H) contains the Hours; from 0 to 23.
In the following example, the SysTime server is imported into a new class (here: Clocktime). Next, the value is manipulated so that the hours, minutes and seconds are kept separated; these are shows as servers.
Create a project. This project contains a class with a background method, a network and an object of the class placed in the network window. In addition, a client is needed to read the value of the Systime server. In the object of this class, set a cycle time of ALWAYS instead of a concrete number. Thereby, the call is left to the operating system. This means that the object is called as soon as the time for it as arrived.
Version 7.0
Page 185
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Next, create a new project and prepare it to the point where the components shown in the following Class View window are created and named.
Create a network (here: TimeNet). Place an object of the SystemTime class. Import the _SysDateTime from the library, then place and connect the two objects in the network as follows:
Page 186
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 In the next step, open the program code of the CyWork method with a double click on Background or on the class name in the Class View window:
Next, copy the program code as shown in the following image. Be sure to avoid typing errors and maintain the clarity.
In the cReadTime client, the actual time is stored. For example: 16#0E333B00 This client is of data type HDINT and is 4 bytes in size. The first byte (on the right) is not used and is initialized with 00. The next byte (2nd byte) represents the seconds. This contains the value 3B. This value must now be separated from the cReadTime client with "Mask". The value 3B is shown in binary format 2#00111011. The value of cReadtime appears as follows: 2#00001110 00110011 00111011 00000000 Version 7.0 Page 187
If the value is shifted 8 bits to the right, the following results: 2#00000000 00001110 00110011 00111011.
and 255 ;
Now link this value with 255 (2#00000000 00000000 00000000 11111111), which then results in the desired seconds: 2#00000000 00001110 00110011 00111011 2#00000000 00000000 00000000 11111111 2#00000000 00000000 00000000 00111011 = 59 seconds Write this value to the seconds server. To obtain the minutes and hours, repeat the same process as with the seconds. Next, save and compile the project with Rebuild All. Go online and load the project into the target system. Next, start the program and check the result.
Page 188
Version 7.0
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.
Version 7.0
Page 189
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 button until a four arrow cross appears (see picture) hold the mouse button and move the object to the desired position.
Page 190
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 Tools.lcp.
Click on the + before Tools, find the Ram class in the Memory folder and import it by selecting Copy from the context menu.
Version 7.0
Page 191
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Page 192
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 193
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Insert two new entries in the type, MYSTEP, by selecting New Item in the context menu.
Page 194
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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).
Version 7.0
Page 195
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 196
Version 7.0
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 evaluated 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 Instruction is reset to the Start position.
Version 7.0
Page 197
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Save and compile the project with Rebuild All. Go online and load the project into the destination system. Afterwards start the program and insert a value (here: 40) in the Data server of the CountTime object as the 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 198
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 199
If the data type of the Fsm variable was assigned or changed to a USINT, the Case instruction 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 200
Version 7.0
Select both objects of the hardware class with the left mouse button and pres the Del button.
Version 7.0
Page 201
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 202
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 To connect the server Input1 in the objCDI16X object and the Client Switch1 of objCaseClass, 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.
Version 7.0
Page 203
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 204
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The HardwareNet network appears and is marked with the Input1 server, which is connected to the client Switch1.
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).
Version 7.0
Page 205
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 To show what would happen when several clients are connected to a server, place an additional 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 206
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 With continuous project expansion, objects can be placed in different networks and thereby several Client/Server connections created. Through 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 an object.
Version 7.0
Page 207
4.8
4.8.1
Topical Exercises
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 208
Version 7.0
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 conveyors 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 triggered 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.
Version 7.0
Page 209
4.8.2
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, the 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
Page 210
Version 7.0
4.8.3
Task
Run light
(Project MoveLight)
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 impression 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).
Version 7.0
Page 211
4.9
4.9.1
Program Loops
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; This loop counts backwards: FOR i := 4 TO 0 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 repeated. The value of the expression is tested before the execution of the instruction; therefore 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 212
Version 7.0
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
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;
Version 7.0
Page 213
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 doesnt necessarily help the programmer. Functions should be programmed without this instruction whenever possible.
Page 214
Version 7.0
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).
Version 7.0
Page 215
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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, its best to let the index of the array start with 0. That means 0 will be the first field of the array.
Page 216
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Through the assignment of the index, the element contents are evaluated. Here, the contents of the third element are written to a possible variable; MeasureValue:
MeasureValue := Measure[2];
Version 7.0
Page 217
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 In the following example, a project is created in which a variable is defined 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: PrtNew) 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 218
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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:
Version 7.0
Page 219
The number entered by the client GetNumber is assigned to the variable Number. Because this variable is defined as an array, a value is assigned to each field defined by the array variable. Since the variable, index, is automatically set to 0 when the target system is started, 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 and compile the project. Go online and load the project to the destination system and start the program. Enter a number in the Client, GetNumber (here: 78).
Page 220
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 In the THIS register of the Debugger Window, observe 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:
Version 7.0
Page 221
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 222
Version 7.0
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 additional server will display the search result. The search for the numbers should be implemented 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 whileloop 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 whileloop, 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 instruction.
Version 7.0
Page 223
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 224
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
Version 7.0
Page 225
Now insert the following program code into the program code editor:
Page 226
Version 7.0
Via this IF instruction, whether or not the values of the clients are within the matrix borders (5x5) is checked. Here, depending on the coordinates, the ASCII value of the located character is displayed in the ascii server. Otherwise 0 is displayed in 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. Now save and compile the project. Transfer the project to the target system and start the program.
Version 7.0
Page 227
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 228
Version 7.0
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 possible 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.
Lotto generator
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 numbers 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 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.
Version 7.0
Page 229
The LASAL CLASS 2 operating system provides variables, which can be employed by the user. These variables can be processed or evaluated in the user program.
The _Firstscan variable is set to 1 by the operating system after the program start for the duration of the last Init method execution only. 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 milliseconds. 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 The user does not have to worry about an overflow of this 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 230
Version 7.0
Timemark = 4294967292 Time = 1000 Current ops.tAbsolute = 4, because overflow took place! The value range of a UDINT number is from 0 to 4294967295 (= 2^32-1)! The following expression would therefore result in: If ( 4 4294967292) > 1000 then ... This corresponds to the following expression: If ( 0 4294967288) > 1000 then ... Since 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 therfore false and the IF loop is not yet executed.
Version 7.0
Page 231
t = time dt = delay time from the activation the switch to when the lamp lights.
Page 232
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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:
Version 7.0
Page 233
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Dont 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 because the data type of the variable, ops.tAbsolute is UDINT.
Page 234
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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.
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. The if-instruction is then valid and the code within is processed only 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.
Version 7.0
Page 235
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 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 is tested. If this is true, the lighting of the lamp is delayed 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 236
Version 7.0
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 The full program code should appear as follows:
Version 7.0
Page 237
STRUCTURED TEXT LANGUAGE BASICS WITH LASAL 2 Save and compile the project. 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 value difference 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 238
Version 7.0
In this example, a class should be created that delays the setting of a digital output to 0 using a switch. The delay time (dt) is entered over a potentiometer or ram object. All further information needed to implement this task can be taken from the time diagram below.
Process
This task should be implemented with the operating system variable ops.tAbsolute.
Version 7.0
Page 239
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
For an on/off delay switch, only one time setting should be used.
Page 240
Version 7.0
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 calculated. 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 values read from the client can again be written to the array fields.
Version 7.0
Page 241
5.1.1
The Standard Methods of a Class are always the Constructor-, Init-, CyWork-, RtWorkand Background Methods. This chapter contains additional important information and simultaneously reviews the standard methods already introduced.
5.1.2
The constructor, as previously mentioned, executes the initialization of class data. It is used exclusively for the initialization of the class in which its 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 242
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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 exchange data with other objects.
Clientname := Clientname.Read(); Clientname.Write(Clientname); // not allowed // 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.
Version 7.0
Page 243
5.1.4
These methods are task dependant, which means they are processed by the operating system within the time setting in the object of the class.
Here, the method priorities are reviewed. Highest Priority: Middle Priority: Lowest Priority: RtWork (Realtime Work ) CyWork (Cyclic Work) 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 244
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 The input 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
Version 7.0
Page 245
5.1.5
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 246
Version 7.0
5.1.6
Start with a new project and construct it so that it appears as shown in the Class View window below:
To deactivate the write protection of the server SelectArithm, set WriteProtected to False in the Properties window.
Version 7.0
Page 247
CLASSES AND OBJECTS IN LASAL CLASS 2 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 248
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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.
Version 7.0
Page 249
CLASSES AND OBJECTS IN LASAL CLASS 2 As in the CyWork method, the Background Method must also be activated. Select the class name in the Class View window and in the Properties window, set BackgroundTask to true. In the next Step, private methods are created. In the context menu of the Private folder, select New Method and create the private methods illustrated in the Class View window below:
Page 250
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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:
Version 7.0
Page 251
CLASSES AND OBJECTS IN LASAL CLASS 2 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 252
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 The setting always means that the Background method is called by the operating system as often as possible, however the maximum is every 2ms. The Always setting means that operating system calls the Background method as often as possible, but not more often than 2 ms. Open the program editor. As can be seen in the following illustration, the private method is shown next to the background method.
Version 7.0
Page 253
CLASSES AND OBJECTS IN LASAL CLASS 2 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 254
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 The Background method is now programmed as follows:
A CASE-instruction is created for the SelectArithm server. Within the Case-instruction, the type of operation executed by the SelectArithm server is determined. The SelectArithm server, of type ARITHM, allows the selection of the arithmetic operation (_Nothing, _Multiply, _Divide, _Addition, _Subtract or _Modulo). 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.
Version 7.0
Page 255
CLASSES AND OBJECTS IN LASAL CLASS 2 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 256
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 Save and compile the project. Create an online connection and load the project to the destination 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.
Version 7.0
Page 257
5.1.7
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 methods of the Calculator class. So that these methods dont have to be written separately in the new class, they will be simply called over a client. 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 accessed 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 corresponding methods are shifted to the Global folder!
Page 258
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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
Private Method
Global Method
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 create a connection between the Result server of the class, Calculator and the client, connect of the CallMethode class. Set a cyclic time of 10ms.
Version 7.0
Page 259
CLASSES AND OBJECTS IN LASAL CLASS 2 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 multipurpose usability. The advantage of a command channel is the multifaceted usability, since no reference to another class is required. (See also chapter Interpreter in the Lasal Class help). The ARITHM type is again used for the SelectArithm server. This setting is made in the Properties window of the Class View window by selecting the server, SelectArithm.
Page 260
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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 SelectArithm 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.
Version 7.0
Page 261
The Multiply method from the, Calculator class is called over the Connect client of the CallMethod class. The result of this method is then output to the Result server through the 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 destination system and test the function of the program as in the previous example:
Page 262
Version 7.0
5.1.8
Create a new project (here: OverwriteServer) as shown in the following illustration. Make sure that the write protection for the WriteServer, ReadServer and Server0 servers is deactivated!
Version 7.0
Page 263
CLASSES AND OBJECTS IN LASAL CLASS 2 Create a network (here: OverwriteServerNet) and place an object from both classes. Connect 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 264
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 Assign the Write method to the WriteServer server using the same process.
Double click on either the Read method from ReadServer or the Write method from Writeserver to display the program code.
Version 7.0
Page 265
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, ReadServer 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 processing 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 266
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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.
Version 7.0
Page 267
CLASSES AND OBJECTS IN LASAL CLASS 2 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 268
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 As can be seen, the input value (here: 5) is multiplied by 10 in the Read method of ReadServer. The method is 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).
Version 7.0
Page 269
5.2
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 discretion of the user, 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 refrigerator 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 270
Version 7.0
5.2.1
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:
Dont 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.
Version 7.0
Page 271
CLASSES AND OBJECTS IN LASAL CLASS 2 In addition, Trigger_Plus is required. In the libraries window, also load the Tools.lib. Select Copy in the context menu to import Trigger_Plus from the Tools library(/Logic/Trigger/Trigger_Plus).
The Trigger_Plus is needed to obtain a short pulse with the activation of a switch. If this class is not used then the parts, dependent on the defined CyclicTime, will continuously increment due to the += 1 instruction in the following program code.
Page 272
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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 function of the program.
Version 7.0
Page 273
CLASSES AND OBJECTS IN LASAL CLASS 2 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).
Page 274
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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, Trigger_Plus are also required. Next, set the cyclic time (here: 100 ms) and connect the objects 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 connected to the complex object.
Version 7.0
Page 275
CLASSES AND OBJECTS IN LASAL CLASS 2 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 276
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 Place the classes, PieceCounter, CDI16X and DiasMasterC in the network.
Connect the objects as illustrated below. In the properties window of the PieceCounter class, dont forget to set Required to false for the Reset client.
Version 7.0
Page 277
CLASSES AND OBJECTS IN LASAL CLASS 2 The object objPieceCounter of the class, PieceCounter is now a complex object. It contains the objects objCounter, ProducedPieces and objTrigger_Plus. The blue 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 object. When an upward pointing arrow appears, double click on it.
Page 278
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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.
Version 7.0
Page 279
CLASSES AND OBJECTS IN LASAL CLASS 2 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 280
Version 7.0
5.2.2
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.2.3
The Derivation of classes enables a class to take on the characters and process instructions of another class (the so called Base Class). The derived class has, therefore, a relationship 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 methods of the base class. Only classes are derived, not methods. Methods are overwritten. Methods can be overwritten.
Version 7.0
Page 281
CLASSES AND OBJECTS IN LASAL CLASS 2 To present the derivation of classes and overwriting of methods in a practical example, the project Derive was 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 (subtraction). 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 subtraction 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 282
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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
Version 7.0
Page 283
CLASSES AND OBJECTS IN LASAL CLASS 2 Open the program code editor to program the CyWork and Calculate Methods:
Page 284
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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).
Version 7.0
Page 285
CLASSES AND OBJECTS IN LASAL CLASS 2 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 286
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 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.
Version 7.0
Page 287
CLASSES AND OBJECTS IN LASAL CLASS 2 Open the DeriveAdd network with a double click.
By assigning the Subtract class 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 288
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 Select the Network tab in the 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 into the network with objSubtract as shown below.
Version 7.0
Page 289
CLASSES AND OBJECTS IN LASAL CLASS 2 When connecting the objDeriveAdd object, dont forget 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 addition operations. That means the Calculator method must still be changed (overwritten) from subtraction to addition.
Page 290
Version 7.0
CLASSES AND OBJECTS IN LASAL CLASS 2 To overwrite the method, select Overwrite, Calculate in the context menu of the Methods folder of the DeriveAdd class.
The Calculate method is then added and is opened in the program code editor with a double click, the program code editor then overwritten. Only the program code has to be completed to get an Addition.
Version 7.0
Page 291
CLASSES AND OBJECTS IN LASAL CLASS 2 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 292
Version 7.0
5.3
5.3.1
Topical Exercises
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. The generator should be triggered using a client (start). Two additional clients are needed to set the amplitude and change the time base. 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).
2. 3.
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 operating system variable ops.tAbsolute. The other client specifies the amplitude of the output signal.
Tips for completing the task
Start with the derivation of the class once the class for the delta signal functions error-free. In the derived class, only the Signal method is overwritten and programmed.
Version 7.0
Page 293
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 numbers. 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 variable.
Pointers are 4.byte variables, which are used for a specific memory area and are not assigned 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 294
Version 7.0
6.1.3
// 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^;
Version 7.0
Page 295
ADDITIONAL COMPONENTS OF ST PROGRAMMING The function of a pointer is explained on the following pages using examples. 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 defined as a pointer and assigned the address of the first variable. This variable points, with help from the pointer, to the first variable and transfers 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 create a network (here: PointerNet). Place an object of the class (PointerClass) in the network.
Page 296
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 defined as a pointer.
Version 7.0
Page 297
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the program code editor to program the Cywork method:
Save and compile the project. Go online, download the project to the destination system and start the program.
Page 298
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING In the network, enter the value 1 in the Switch server of the objPointerClass object 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).
Version 7.0
Page 299
6.1.4
In a project, it is possible that global and local variables as well as 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 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; b : DINT; b := a;
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 300
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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. When casting only variables with the same data width should be used. Otherwise 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 :INT; v3 :USINT; END_VAR v1 := 256; v2 := v1$UINT; // The variable v2 contains the value 256 because the same data width 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.
Version 7.0
Page 301
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 illustration 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 302
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Save and compile the project then download it to the destination system. Set a breakpoint by the first variable using the button and start the program.
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.
Version 7.0
Page 303
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 304
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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
Version 7.0
Page 305
6.1.5
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 DataElement and assign it to MYDATA. Create a network (here: PointerMethodNet) and place an object of the class, PointerClass).
Page 306
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
Version 7.0
Page 307
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 308
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the program code editor with a double click on a method.
Save and compile the project. Go online, download the project to the destination system and start the program.
Version 7.0
Page 309
ADDITIONAL COMPONENTS OF ST PROGRAMMING Place the cursor on the first program line in the InitData method. Set a breakpoint at this position by pressing the point(s) and Toggle Breakpoints in the menu bar. button or selecting Debug, Break-
Open the Watch tab in the debugger window and click on Click to add new. Insert ptr as shown below by pressing Enter.
Page 310
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 program.
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 corresponding values.
Version 7.0
Page 311
ADDITIONAL COMPONENTS OF ST PROGRAMMING As can now be see in the following illustration, the address of the DataElement variable is read with the help of the pointer.
Page 312
Version 7.0
6.1.6
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 alphanumeric element as an array of type CHAR. Define both the input parameter 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.
Version 7.0
Page 313
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the program code editor with a double click on a method and insert the following program code:
That means this variable can only be used for this function! Also see chapter Local Variables in LASAL CLASS 2.
Page 314
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 variable Address as a Pointer.
Next, select the client Connect in the Class View window and define it as an object channel of the Handling class in the properties window.
Version 7.0
Page 315
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 316
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 respectively. In addition, the fields 0 to 9 in the alphanumeric element have been assigned a letter.
Version 7.0
Page 317
ADDITIONAL COMPONENTS OF ST PROGRAMMING To observe how the address of the data is assigned to the pointer, set a breakpoint in 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 318
Version 7.0
6.1.7
Summary
Through the use of pointers, data is processed more flexibly since it is easier to access structures with them. 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 input parameters to which values can then be written!
6.2
6.2.1
Topical Exercises
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.
Version 7.0
Page 319
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 values 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 320
Version 7.0
6.3
6.3.1
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
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.
Version 7.0
Page 321
ADDITIONAL COMPONENTS OF ST PROGRAMMING To call 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 shown 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 object 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 322
Version 7.0
6.3.3
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 appears as follows:
MemSet(dest:=, value:=, size:=); Transfer Parameter dest = Pointer for the destination buffer value = Fill value for the individual bytes size = Number of bytes to fill Return Parameter retval = Pointer to the destination buffer
Version 7.0
Page 323
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 dest = Pointer for the destination buffer source = Pointer for source buffer size = Number of bytes to fill Return Parameter retval = Pointer to the destination buffer
MemCmp
This function is used to compare memory blocks with a defined number of bytes. The program code appears as follows:
MemCmp(dest:=, source:=, size:=); Transfer Parameter dest = Pointer for the destination buffer source = Pointer for source buffer size = Number of bytes for comparison Return Parameter retval = 0 means, the source and destination are equal <> 0 means, the source and destination are unequal
Alternatively, the available motion functions can also be used (seeLoader API.doc). Here, among other the following instructions are found:
_memmove _memicmp _memcm _memcp _memcpyre ... These functions can be used in the LASAL Class immediately. During input, however, the code is not automatically expanded.
Page 324
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Create a new project (UseOs) and define the components shown in the Class View window 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).
Version 7.0
Page 325
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 system.
Page 326
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
Version 7.0
Page 327
ADDITIONAL COMPONENTS OF ST PROGRAMMING Next, select the MemoryMove operation under the MemOp variable in the debugger window.
10 values starting from the 3rd field (3, 4, 5, ...) of the variable DataArray are then shifted to every field in the SplitData variable:
Page 328
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING With the MemoryCopy operation, the values in SplitData are copied to 8 fields (starting with field 4) of DataArray.
In the MemoryCompare operation, observe the Equal server. 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.
Version 7.0
Page 329
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
This function reserves a memory area in the CPUs RAM. The size of the memory block is determined using a input 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 input parameter contains the value 0.
ReAlloc
The ReAlloc function changes the size of a reserved memory block in the CPUs 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 existing address. If the size change is not possible, the return value is NULL
When using the ReAlloc function to change size, its possible that another 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, making the memory area is available again. This function supplies no return value.
Page 330
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING The following example demonstrates how 2 Arrays (Alphabet and Digits) can be copied after one another to a memory area that has been allocated 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 an object channel of the _StdLib class. Define the pMallocaddress as pointer. The variables Alphabet, Digits and MemResult are arrays of type Char. The STEPS type is an ENUM data type. Also create a network (here: StorageNet) and place an object of the Storage class.
Version 7.0
Page 331
ADDITIONAL COMPONENTS OF ST PROGRAMMING Now open the program code editor and insert the following program code:
Page 332
Version 7.0
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, the Malloc method is called via the ConLib client. The memory size (size of the Alphabeth variable) to reserve is defined as an input parameter. The method therefore obtains the required memory size. The pMallocAddress pointer is the return parameter of the method. Sizeof(Variable) returns a value including the required bytes for the variable. The Alphabet variable used here is an array with 36 CHAR fields. Since the size of CHAR is 1 byte, sizeof(Alphabet) will return the value 36.
If pMallocAddress > 0 then SSW := _NoOp; end_if;
With this if instruction, whether or not the pMallocAddress has been initialized can be checked.
_COPY_Alphabeth: ConLib.MemCpy(pMallocAddress,#Alphabeth[0],sizeof(Alphabeth)) ;
Here, the MemCpy method is called via the ConLib client. The content of the Alphabeth array is written to the memory area, starting from the pMallocAddress.
ConLib.MemCpy(#MemResult[0],pMallocAddress,sizeof(Alphabeth)) ;
Here, the memory area content is copied to the MemResult array, which can contain a maximum of 35 characters.
Version 7.0
Page 333
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), #Digits[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)). The MemResult array now contains all characters 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 in the objStorage object. Save and compile the project, start it in online mode.
Page 334
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the Debugger tab in the THIS window.
Here you can see the pre-initialization of the arrays Alphabet and Digits can be seen. The pointer variable still shows 0 (16#00000000). Thus no memory has been allocated. Now at the step control select _MemALLOC.
In the pMallocAddress pointer variable can now be seen that an address has been assigned.
Version 7.0
Page 335
ADDITIONAL COMPONENTS OF ST PROGRAMMING Now select the step _COPY_Alphabeth at your step control.
Watch the content of the MemResult array, which has been copied from the allocated memory area. Select _MemREALLOC afterwards.
The pointer variable now has 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 336
Version 7.0
The content of the Digit array (numbers from 0 to 9) can now be seen 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
Version 7.0
Page 337
6.3.4
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 Filename = Name of the file Return Parameter 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 ATT_READ_ONLY ATT_CREATE ATT_CREATE_ALWAYS File opened with read and write authorization File opened with read only authorization File is created if it none exists File is always created new whether or not it already exists
Page 338
Version 7.0
This function attempts to expand a file in bytes by the value "size" with assignment of consecutive clusters. If no sufficiently long cluster row is found, this function returns the RTF_DISK_FULL error code. This means: either the file must be fragmented or the hard drive is full.
Input parameters Return parameters 0...ok handle = handle for the file in which should be written -22...DISK_FULL Size = File is expanded by the value of size.
If the maximum size to which the file will be extended is known at the start, Extend should be used!Therewith the fragmentation of the CF card is minimized and the life span is extended.
With this function, the size of an existing file can be changed. FileLSeek moves the pointer to the file and can possibly expand the file size.
Input parameters handle = Handle for the file to process. Return parameters Retval = The number of bytes written or the error code in the event of an error.
offset = Number of bytes by which the pointer should be moved. fromwhere = Specifies the meaning of the offset The following values are allowed: FILE_BEGIN(0) -Offset starts at the beginning of the file. FILE_CURRENT(1) -Offset is added to the actual pointer FILE_END(2) -Offset starts at the end of the file.
If the function is successful, the new pointer value is returned or if the pointer is larger than 231-1, LONG_FILE_POS is returned. If the function not successful, a negative value is returned (see further below in this document).
Version 7.0
Page 339
Moving the pointer beyond the actual file size is supported; in this case the file is expanded. The data between the old file size and the new file size are undefined. With this method, a file can be expanded quicker than when the actual data is written in the file.
Shifting the pointer before the beginning of the file triggers an error! Ensure that the value for the pointer of this function is not larger than 231-1. 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 0 -3 Error code NO_ERROR INVALID_FILENAME Description No errors An invalid file name is entered (containing special characters, for example) This error code is given when using FindFirst() and FindNext() and no more files can be found. The file name entered was not found. 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. The directory entered was not found. To little memory space on the medium used. The selected drive or medium cannot be accessed. (i.e. accessing an unavailable USB interface) The file already exists. (Renaming a file to an existing file name)
Page 340
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Create a new project and begin by importing the _FileSys class from the OS interface library. 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).
Version 7.0
Page 341
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the program code editor to program the Background method:
Page 342
Version 7.0
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.
Version 7.0
Page 343
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 operating system now has a definitive identification for the opened file.
Page 344
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING In the next Step, select the operation Open4ReadWrite under the variable FileStep to open the file for read and write access.
Next, enter either a value or 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 between 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.
Version 7.0
Page 345
ADDITIONAL COMPONENTS OF ST PROGRAMMING Select CloseFile under the variable FileStep and Stop the program using the or the F8 key. Restart the program by pressing the initialized with 0. button
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 346
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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, it has to be closed. 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.
Version 7.0
Page 347
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 348
Version 7.0
...then the entered numbers are stored as ASCII values in the MyFile.txt file.
Version 7.0
Page 349
6.4
6.4.1
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 values - Providing parameters for various processes
6.4.2
Tables can only contain constant data, which cannot be changed while the control program is running. 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
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 350
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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)
Further information on linking header files and applications for preprocessor instructions is found in chapters 1.4 and 1.5.
Additional instructions
The LASAL Class 2 compiler always uses the smallest possible data type of 1 byte, for example, 16#00A2. This can be changed with casting or conversion. E.g.: TO_UINT(16#00A2) or 16#00A2$UINT
Version 7.0
Page 351
6.4.4
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 double click.
Page 352
Version 7.0
6.4.5
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).
Version 7.0
Page 353
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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
This line defines the data length of the table (here: 20 characters). As previously mentioned, 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 354
Version 7.0
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.
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.
Version 7.0
Page 355
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 356
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
Version 7.0
Page 357
ADDITIONAL COMPONENTS OF ST PROGRAMMING First import the OS Interface.Icp library and from it, the _StdLib class. Next, create a new client (ConnLib) and define it as an object channel of the class _StdLib. A new variable (NewChar) of type ARRAY OF CHAR is now required. For this array, 25 fields should be defined.
Page 358
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
Version 7.0
Page 359
6.4.6
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 360
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the program code editor and insert the following program code:
Version 7.0
Page 361
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 to 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 multiplied by 2 and/or 4 bytes (NextVal * sizeof(UINT) or NextVal * sizeof(UDINT)). If table values of different type sizes are available, the incrementation of the index must be adapted accordingly. Otherwise the result is incorrect!
Since only USINT values are available in the table (1-byte size), simply adding an index (here: NextVal) is sufficient. With 2 or 4-byte values, the index must be multiplied by 2 or 4 bytes respectively. E.g.: NextVal * sizeof(UINT) or NextVal * sizeof(UDINT). If table values of different type sizes are available, the index increase must be adjusted accordingly. Otherwise, a false result is given!
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.
Page 362
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING The values from the table, MyTable, can be observed in the Result of the objDiffValues server as they count up and down.
Version 7.0
Page 363
6.5
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. In addition import the _FileSys class from the OSInterface library.
Page 364
Version 7.0
Version 7.0
Page 365
This string is designed manually. Each string has to be teminatied with a null, to identify the end of the string (MyString[5] := 0; ) Possibility 2:
for i := 0 to #MyTable()^ - 1 do TableString[i] := to_usint((#MyTable() + 4 +i)^); end_for;
In this line on the Data server of the objString string object, objString, the string "User!" is written.
Connect.ReadDataOff( 0, #TextString[0]$USINT, 100);
Using the ReadDataOff string method the content of the Data server is read out and written to the TextString variable. Possibility 4:
Connect.Clear();
To write to the Data server of the objString object again, it is necessary to run the Clear() method.
Page 366
Version 7.0
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 in 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 newly created file and check that the program is functioning correctly. Saving a null voltage protected string: The StringRAM class has the same function as the String class, with the exception that stored string is still available after restarting the program.
Version 7.0
Page 367
6.6
6.6.1
Pre-Processor Instructions
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 parenthesis 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 doesnt change. Constants can be represented using either a fixed value (literal constant) or a constant name (symbolic constant).
6.6.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 program 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.
Via the TRACE0 constant it is possible to display a variable within the text. {0} is the placeholder 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 placeholders' position.
Page 368
Version 7.0
The TRACE1 constant has the same functionality as the TRACE0 constant but with 2 variables.
TRACE2(" {0} {1} {2] ", #Var0, #Var1, #Var2)
The TRACE1 constant has the same functionality as the TRACE0 constant but with 3 variables. TRACE0 example:
Version 7.0
Page 369
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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:
In addition, create a network (here: PreProcessorNet). Next, open the program code editor and insert the following program code:
Page 370
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Save and compile the project then go online and push start. Enter a value in both clients, Value1 and Value2 then 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 program code, after a successful arithmetic operation.
Version 7.0
Page 371
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 372
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
Version 7.0
Page 373
6.6.3
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 operation will be performed. The example will then be expanded and changed for pre processor instructions.
Page 374
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 after 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
With the #undef instruction, the constants lose their availability only.
Version 7.0
Page 375
ADDITIONAL COMPONENTS OF ST PROGRAMMING If the constants that have been undefined with the #undef instruction are used in the program code, the following message appears in the output window:
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 376
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 defined. Insert the following program code and start the program online. Because VALUE5 is not defined, the Result server outputs a value of 20
Version 7.0
Page 377
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 constant (here: 8) VALUE4 is displayed in the Result server.
Page 378
Version 7.0
6.6.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 usable instructions are specific to the compiler and operating system. The instructions not recognized 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 doesnt recognize an instruction, a warning message is displayed during 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 compiler warning that will subsequently be deactivated. Further Pragma Instructions will also be introduced through this project. Create a new class (PragmaInstruction) and a private method (Warning) with an input variable (Input1)
Version 7.0
Page 379
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 380
Version 7.0
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.
For example: a of Type DINT b of Type INT c of Type SINT
During 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)!
Version 7.0
Page 381
ADDITIONAL COMPONENTS OF ST PROGRAMMING To explain the function of the #pragma pack (push, n) and #pragma pack (pop) instructions, 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 382
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 Variable b => INT Variable c => SINT (requires 4 Bytes of memory) (requires 2 Bytes of memory) (requires 1 Bytes of memory)
Version 7.0
Page 383
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 384
Version 7.0
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:
Version 7.0
Page 385
With this instruction the compiler is told to compile this file (header file) only once. If a further #include file is available, it will not be opened and compiled by the compiler. The compilation time can therefore be optimized and no warnings concerning "identical redefinition" are triggered.
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.7.
Page 386
Version 7.0
In this branch, all settings required for compilation are made and are all set to true.
Version 7.0
Page 387
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 input parameter in the program 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
This message appears when the semicolon at the end of an instruction is missing.
Page 388
Version 7.0
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.
Version 7.0
Page 389
The alignment serves to align the data in an entire project. Complete projects and/or libraries 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 Properties window. Here, the user can align data in 1,2 or 4 bytes.
Page 390
Version 7.0
Reduced Client Dependencies (RCD) comes with projects carrying linked classes. Therefore 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 unnecessary classes in prohibited (a simple synchronization is executed however). If the RCD setting is deactivated while working with LASAL CLASS 2, the project must be reloaded 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.
CheckArrayAccess
If an index variable is accessed in an array during the runtime, the index value is tested against the array limits when this function is set to True. Array access is tested by the operation system during runtime. If the array limits are violated, the program processing stops.
Version 7.0
Page 391
6.6.5
Include Instructions
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 392
Version 7.0
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 Extras where the Include Paths parameter is assigned.
Version 7.0
Page 393
6.7
6.7.1
As soon as a project constant is used, it can be defined in a header file. This is not absolutely 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 class or linked project.
6.7.2
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 394
Version 7.0
6.7.3
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....
Version 7.0
Page 395
ADDITIONAL COMPONENTS OF ST PROGRAMMING Next, select the folder in which the header file should be saved and assign a name (MyHeader.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 396
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING Open the header file with a double click and define the following constants:
Version 7.0
Page 397
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 window:
Test the program by entering different values in the client, ActualTemperature and observe the messages in Debugger Trace register in the output window.
Page 398
Version 7.0
6.7.4
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 MyHeader.h file.
Version 7.0
Page 399
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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 available 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 400
Version 7.0
ADDITIONAL COMPONENTS OF ST PROGRAMMING 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.
Version 7.0
Page 401
ADDITIONAL COMPONENTS OF ST PROGRAMMING In Online mode, enter the value 60 in the client ActualTemperature to create a temperature 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 402
Version 7.0
7.2
The following illustration shows the schematic construction of a LASAL CPU. The memory area is shown with its individual components.
Version 7.0
Page 403
INSTRUCTION LIST PROGRAMMING 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, information over their length can be found.
Page 404
Version 7.0
7.3
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 divided further. The resulting half registers have their own name and are only one byte in size.
Register AX changed to BX changed to CX changed to DX changed to Half register AH BH CH DH Half register AL BL CL 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 expanded 32-bit register becomes the EAX register.
Inside the CPU, there is a special register that can be used to test specific 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.
Version 7.0
Page 405
7.3.1
Universal Registers
Several arithmetic operations (multiplication and division) can be performed using the accumulator. In addition, all I/O data is passed through 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
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 406
Version 7.0
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!
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
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 contains target operands.
Version 7.0
Page 407
7.3.4
Special Register
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.
Page 408
Version 7.0
7.4
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 one 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 directly. S (save): For everything that comes out of the processor. SIGMATEK L Number S Result INTEL MOV MOV
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 8bits, WORD PTR for 16 bits and DWORD PTR for 32 bits are placed before the address.
SIGMATEK uses the abbreviations: B Byte = 8-Bit W Word = 16-Bit D Double word= 32-Bit SIGMATEK Hand, 001 CMP.B INTEL CMP
Version 7.0
Page 409
7.5
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 is later 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 410
Version 7.0
7.6
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
L - 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 L.EAX L.BX
Source
//The EAX Register is loaded with //the value of the variable //The contents of AX are loaded to //BX
Variable AX
Version 7.0
Page 411
Save
Destination
Variable BX //The value of the EAX Registers //is saved in the Variable //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
O OR
Logic Instructions
Bitwise OR connection
Truth table: E1 0 0 1 1 E2 0 1 0 1 A 0 1 1 1
Page 412
Version 7.0
Truth table: E1 0 0 1 1 E2 0 1 0 1 A 0 0 0 1
X XOR
Exclusive OR connection
Truth table: E1 0 0 1 1 E2 0 1 0 1 A 0 1 1 0
Version 7.0
Page 413
Truth table: E1 0 1 A 1 0
7.6.3
CMP
Comparison Instructions
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 conditional jump. The CMP instruction sets the following bits in the EFL registers: AF, CF, OF, PF, SF and ZF.
CMP.AX JBE BX MAXI
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) JE SWITCHON //goes to jump marker //SWITCHON //If at least 1 bit in both //operands is set, a jump to //SWITCHON occurs
Page 414
Version 7.0
7.6.4
SHL
Shift Instructions
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
Version 7.0
Page 415
7.6.5
JE
Jump Instructions
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 instruction are equal.
CMP.AX JE BX LAB1 //Jump to LAB1, if AX = BX
JAE
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 instruction is processed.
CMP.AX JAE BX LAB1
JNZ
The jump is executed when ZF (Zero Flag in the flag register) is not set. This occurs when the result of a logic, arithmetic or write instruction is not equal to 0.
CMP.AX JNZ BX LAB1
Page 416
Version 7.0
The jump is executed when ZF (Zero Flag in the flag register) is not set. This occurs when the result of a logic, arithmetic or write instruction is not equal to 0.
CMP.AX JNE BX LAB1
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 program, 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 JE CALL JMP MANUAL CALL NEXT CALL MAN, 001 MANUAL AUTO NEXT //Query whether the machine is in //Manual operation mode. //No: Call automatic subroutine //--> See what happens next
MANFCT
SECURE
END_FUNCTION FUNCTION AWL AUTO .... END_FUNCTION FUNCTION AWL MANFCT //*** Subroutine: Manual **** .... END_FUNCTION
//Call higher //secure function //---- END MAIN PROGRAM ---//*** Subroutine: Automatic ***
Version 7.0
Page 417
7.6.6
ADD
Arithmetic Instructions
Add
The left operand is replaced by the sum of the left and right operands; the sum is then stored in the left operand. In this case, a carry over from a previous addition is not taken into consideration. If a carry results, the CF (Carry Flag in the flag register) is set.
ADD.AX 00020 //the number 20 is added to AX
SUB
Subtract
The left operand is replaced with the difference between left and right operands; the difference is then stored in the left operand.In this case, a carry over form a previous subtraction is not taken into consideration. If a carry over results, the CF (Carry Flag in the flag register) is set.
SUB.AX 00020 //AX is reduced by 20
7.6.7
STC
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
Page 418
Version 7.0
7.6.8
NOP
Special Instructions
No operation
NOP is a single byte instruction, which performs no operation and has no influence on the function of the program. This instruction changes the EIP register only.
CBW
CBW converts a byte in the AL register while retaining the sign of a signed word in the AX register in order to transfer the most significant bit from AL to all bits in the AH register.
Version 7.0
Page 419
7.7
7.7.1
Example Applications in SL
Creating an IL Method
In the following example, 2 values will be multiplied through IL programming and the result subsequently written to a server.
Also create a network (here: AWLMultiNet) and remember to remove the write protection from all three servers! Next, open the program code editor:
Page 420
Version 7.0
INSTRUCTION LIST PROGRAMMING 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
Version 7.0
Page 421
INSTRUCTION LIST PROGRAMMING The following error message appears in the output window when the project is compiled:
is not recognized in IL programming. Delete this line or define it as commentary so that the compiler will not read it. In IL programming the following lines are required instead:
L.EAX
READY
Saves READY to state. The EAX register is used since state is of type UDINT.
Page 422
Version 7.0
INSTRUCTION LIST PROGRAMMING When programming in IL programming, be careful 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.
Version 7.0
Page 423
INSTRUCTION LIST PROGRAMMING Enter the values in servers Value1 (here: 5) and value2 (here: 4) to be multiplied.
Open the Register window of the debugger 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 424
Version 7.0
INSTRUCTION LIST PROGRAMMING When the next line is processed the value in the server, Value2, is loaded to the EBX register.
In the next program Step, the result of the multiplication is written to 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.
Version 7.0
Page 425
7.8
7.8.1
Topical Exercises
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 description.
Page 426
Version 7.0
7.8.2
Arithmetic Operation
(Project Arithmetic2_AWL)
Requirements
In this example, a class is created which has 2 clients used as inputs for an arithmetic operation (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 be careful not to division by 0!
Version 7.0
Page 427
7.8.3
In the private method called LoopMethod, open the Properties window and set AWL implementation to true in order use the IL programming language.
Page 428
Version 7.0
Version 7.0
Page 429
INSTRUCTION LIST PROGRAMMING Open the program code editor and insert the following code:
Result := LoopMethod(7,3);
The LoopMethod with input and return parameters is called. The input 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 ECX register is loaded with the value of the input parameter, Input1 Page 430 Version 7.0
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 input 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 input 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.
Version 7.0
Page 431
INSTRUCTION LIST PROGRAMMING 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 432
Version 7.0
INSTRUCTION LIST PROGRAMMING Press F5 and observe how the value 7 is loaded to the input parameter input1 from the ECX register
With the next program Step, the value (3) of the input 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).
Version 7.0
Page 433
INSTRUCTION LIST PROGRAMMING 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 reduced 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 retcode.
Page 434
Version 7.0
INSTRUCTION LIST PROGRAMMING In the CyWork method, the value in the return parameter retcode is written in the Result server of the LoopMethod.
Version 7.0
Page 435
7.8.4
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 436
Version 7.0
INSTRUCTION LIST PROGRAMMING Open the program code editor and insert the following program code:
Version 7.0
Page 437
The operating system variable _firstscan is compared with the value 1. With the 11th program scan, this variable is set to 1. The .B (CMP.B) ending is used 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
Here, the value of the variable DIR is compared with the value 1. The .B (CMP.B) ending is used since the variable is of type USINT.
JE RIGHT
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 438 Version 7.0
Jumps to ENDOF. The instructions within the jump point RIGHT function the same as ShiftLeft, with the exception that the shift direction is to the right (see the commentary in the program code). FUNCTION AWL LightAWL::ShiftLeft
L.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 instruction is used to shift a bit to the right. Save and compile the project then go online and transfer the project to the destination system.
Version 7.0
Page 439
INSTRUCTION LIST PROGRAMMING 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 440
Version 7.0
INSTRUCTION LIST PROGRAMMING 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:
Version 7.0
Page 441
7.9
7.9.1
Topical Exercises
Pump station
(Project PumpControl_AWL)
Requirements
In this example the pump station 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 442
Version 7.0
7.9.2
Create a project with the components in the Class View window below:
Dont 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.
Version 7.0
Page 443
INSTRUCTION LIST PROGRAMMING 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 connection to another object exits, the value of the client is provided.
S.EAX GetResult
The value of the EAX register is saved to the GetResult server. Save and compile the project then go online and load the project into the destination system.
Page 444
Version 7.0
INSTRUCTION LIST PROGRAMMING 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. Create an additional client (here: cWrite) in the UseReadWrite class.
Over this client, a specific value is written to the Ram class server.
Version 7.0
Page 445
INSTRUCTION LIST PROGRAMMING Place an additional Ram class object in the network and connect it to the objUseReadWrite object as shown below:
Page 446
Version 7.0
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 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 system. Enter a value in the cWrite client (here: 7). This is then written to the Data server using the write method.
Version 7.0
Page 447
7.9.3
Create a project with the components show in the Class View window below:
Dont forget to set AWL implementation to true and to create a network (here: TableNet).
Page 448
Version 7.0
INSTRUCTION LIST PROGRAMMING Open the program code editor and insert the following program code:
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
Version 7.0
Page 449
4 bytes are added to the EDI register for the table length.
L.AL (EDI)
The contents of the AL register are saved to the address of the EBX.
INC EDI
Page 450
Version 7.0
INSTRUCTION LIST PROGRAMMING When the project is started in online mode, the table text can be seen in the THIS tab of the debugger window as its loaded in the array fields.
To better follow the individual program Steps, set a breakpoint and debug the program line by line.
Version 7.0
Page 451
INSTRUCTION LIST PROGRAMMING 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, changes in the register content can be observed with each scan.
Page 452
Version 7.0
TROUBLE SHOOTING
8 Trouble Shooting
In this chapter, how errors arise and/or approaches and remedies for correcting frequently occurring errors are discussed.
8.1
8.1.1
Debugging Programs
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 debugger. Because debugging is an essential part of programming, the user should have a good command of debugging techniques.
8.1.2
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.
Version 7.0
Page 453
TROUBLE SHOOTING
8.1.3
Debugging of a Program
Debugging a Program can best be explained using the previously created Arithmetic example. 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 input parameters and return parameters of a function can only be displayed in the Watch windows 1 to 3 during debugging! See also chapter Local Variables in LASAL CLASS 2.
Page 454
Version 7.0
TROUBLE SHOOTING 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 screen shot using the symbol or with the F4 button. The breakpoint is set in the program code where the cursor is located.
The breakpoint is set at the Multiply operation to see how the multiplication is executed step for step. A breakpoint can be set at any line in the program to follow its process.
Version 7.0
Page 455
TROUBLE SHOOTING Select the objCallMethode in the network and in the debugger window, set the SelectArithm to Multiply.
Through these settings, the program jumps to the Multiply step in the program code editor and stops at the breakpoint.
Page 456
Version 7.0
the Multiply method is called by the Calculator class 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 in which the arithmetic operation was defined.
symbol indicates the line on which the program is currently loThe 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.
Version 7.0
Page 457
TROUBLE SHOOTING Since the program is still at the beginning of the method, the input parameters dont 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 458
Version 7.0
TROUBLE SHOOTING 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.
Version 7.0
Page 459
TROUBLE SHOOTING The possibility also exists in the debugger, to exit a function and/or program line. To demonstrate this, clear the existing breakpoint and set a new one at the following position:
Page 460
Version 7.0
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.
Version 7.0
Page 461
TROUBLE SHOOTING 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 debugger window. If the control box before the class name is checked, the breakpoint is active.
Page 462
Version 7.0
TROUBLE SHOOTING 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.
Version 7.0
Page 463
TROUBLE SHOOTING A further option for locating errors is provided by debugging in compiled code. First clear all breakpoints.
Press F5 to process this line and open the Multiply method in the program code editor window.
Page 464
Version 7.0
TROUBLE SHOOTING 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.
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 numbers at the beginning of each line of compiled code represents the byte offset relative to the corresponding module.
Version 7.0
Page 465
TROUBLE SHOOTING
8.1.4
AWL-Trigger
A further option to control whether a specific program line is processed is provided by AWLTrigger. 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 466
Version 7.0
TROUBLE SHOOTING
8.1.5
Conditional breakpoints are used in debugging when several objects of a class are available 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 variable as data type DINT.
Version 7.0
Page 467
TROUBLE SHOOTING 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 468
Version 7.0
TROUBLE SHOOTING 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 objTimeDelay1. The breakpoint is now valid for the selected object. Click on OK to exit the window.
Version 7.0
Page 469
TROUBLE SHOOTING 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 contains 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 continuously. 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 470
Version 7.0
TROUBLE SHOOTING Since the breakpoint was defined for this object in the breakpoints window, the program stops at the position where it was set.
The program now steps through using the debug symbol bar.
Version 7.0
Page 471
TROUBLE SHOOTING If the program doesnt 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 before stopping.
Page 472
Version 7.0
TROUBLE SHOOTING
8.1.6
Clients, servers and data elements from objects of a class have defined 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.
Version 7.0
Page 473
TROUBLE SHOOTING 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 474
Version 7.0
TROUBLE SHOOTING 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 address is divisible by 1 (1 byte), therefore 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 program.
Version 7.0
Page 475
TROUBLE SHOOTING 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 object only.
Page 476
Version 7.0
TROUBLE SHOOTING 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.
Version 7.0
Page 477
TROUBLE SHOOTING
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 message or compiler warning appears 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 several others.
The following program code shows typical errors, which trigger two error messages 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 478
Version 7.0
TROUBLE SHOOTING If several errors or warnings occur after the compiling process, the error messages can be selected sequentially with the F12 button. The cursor then 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
The following error message occurs when variables, clients or servers of different types are assigned.
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 Casting of Types.
Version 7.0
Page 479
TROUBLE SHOOTING
8.2.2
If a method is called whose name is not recognized by the class or the wrong name was written, the compiler displays 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 480
Version 7.0
TROUBLE SHOOTING
8.2.3
When creating a Step control, the following message is supplied by the compiler. The variable 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.
Version 7.0
Page 481
TROUBLE SHOOTING
8.2.4
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.
The cursor buttons and can be used to move the cursor from the beginning of an if-instruction to the end_if. With this method a missing end_if can be easily found.
Page 482
Version 7.0
TROUBLE SHOOTING
8.3
Messages regarding the CPU status are displayed in the status bar of LASAL Class2. However, 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 regarding the status of the CPU are also shown. If other text is displayed in this field, it means that there is an error.
Version 7.0
Page 483
TROUBLE SHOOTING
8.4
Program errors dont 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
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 484
Version 7.0
TROUBLE SHOOTING 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.
Version 7.0
Page 485
TROUBLE SHOOTING 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 program code).
Page 486
Version 7.0
TROUBLE SHOOTING
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 occurred. 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.
Version 7.0
Page 487
TROUBLE SHOOTING 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 488
Version 7.0
TROUBLE SHOOTING 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 load and confirm with OK.
Select the path and name for the file to be saved in the following window.
Version 7.0
Page 489
TROUBLE SHOOTING 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 several blocks.
The first line contains the time the log file was created including the 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 490
Version 7.0
TROUBLE SHOOTING
The file, method and class in which the error occurred are logged (see file path). The affected 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.
Version 7.0
Page 491
TROUBLE SHOOTING
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 area is 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 492
Version 7.0
TROUBLE SHOOTING Open the program code window and press the Shift + Ctrl buttons simultaneously. Then press the D button. With the same keystroke combination, change back to the structured text code. The assembler code can only be shown when the program was previously 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.
Version 7.0
Page 493
TROUBLE SHOOTING
8.4.2
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.
Page 494
Version 7.0
TROUBLE SHOOTING 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.
Version 7.0
Page 495
TROUBLE SHOOTING 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 496
Version 7.0
TROUBLE SHOOTING 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 program 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).
Version 7.0
Page 497
TROUBLE SHOOTING A division error doesnt 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 compare 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 7segment display. In addition, these CPU status codes can be found in the LASAL CLASS 2 help (Online Status Message).
Page 498
Version 7.0
TROUBLE SHOOTING
8.4.3
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.
Version 7.0
Page 499
TROUBLE SHOOTING Create the EndlessLoop class using the Class View window below:
Page 500
Version 7.0
TROUBLE SHOOTING 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 runtimes 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.
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 doesnt recognize signed values, the value 255 follows 0 and an infinite loop is generated!
Version 7.0
Page 501
TROUBLE SHOOTING To monitor the CyWork tasks, a runtime monitor must be set in the AUTOEXEC.LSL file located in the destination system. If a monitor is set in the AUTOEXEC.LSL, all cyclic tasks must be processed after this time has elapsed, otherwise the control remains frozen with a Runtime 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 destination system with help from LASAL CLASS 2, then 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 502
Version 7.0
TROUBLE SHOOTING Enter the name of the file to transfer (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.
Version 7.0
Page 503
TROUBLE SHOOTING
If a 0 is written next to SET RUNTIME or no value is present, the runtime monitor is inactive. 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 504 Version 7.0
TROUBLE SHOOTING 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 special cases. Once the changes in the AUTOEXEC.LSL file are made, it can be downloaded back to the control as follows. Select Debug, Extras, Save File to PLC in the menu bar to save files in the destination system.
Version 7.0
Page 505
TROUBLE SHOOTING 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 restart the control to reset the CPU with the new settings.
Page 506
Version 7.0
TROUBLE SHOOTING After the CPU has reset, start the application and enter a value in the server of the EndlessLoop 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.
Version 7.0
Page 507
9.2
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 508
Version 7.0
CONTACT PLAN (COP) IN LASAL CLASS 2 Next select the class and in the Properties window, set CyclicTask to true.
By activating the CyclicTasks, the other two tasks (Realtime and Background) are deactivated automatically and can no longer be selected. Only one task at a time can be selected for a ladder diagram class.
Version 7.0
Page 509
CONTACT PLAN (COP) IN LASAL CLASS 2 Create a new network (here: LadderNet) and place the ORFunction class within. Remember 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 510
Version 7.0
CONTACT PLAN (COP) IN LASAL CLASS 2 Open the network with a double click. Open the context menu with a right click in the network. Next, select Contact, Contact to create a new connection (input).
Version 7.0
Page 511
CONTACT PLAN (COP) IN LASAL CLASS 2 Select Coil, Coil from the context menu to place an output.
Page 512
Version 7.0
CONTACT PLAN (COP) IN LASAL CLASS 2 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 name 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).
Version 7.0
Page 513
CONTACT PLAN (COP) IN LASAL CLASS 2 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 514
Version 7.0
CONTACT PLAN (COP) IN LASAL CLASS 2 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.
Version 7.0
Page 515
CONTACT PLAN (COP) IN LASAL CLASS 2 To connect Input2 with the Output, the corresponding input is set to 1 in the objORFunction object.
Page 516
Version 7.0
9.3
9.3.1
The normally open contact switches the left current path to the right current path as long as its activated (TRUE, on or 1). When the contact is deactivated, the status of the right current path is 0.
Version 7.0
Page 517
The closed contacts 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.
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 in the contact plan network is used.
Page 518
Version 7.0
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.
Version 7.0
Page 519
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
Page 520
Version 7.0
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.
Version 7.0
Page 521
The Memory coil saves the status of the left current path. After the CPU is restarted, the value is retained in the memory coil. However, this value is stored in the memory module for the duration of the object's cycle time only.
Example application: In the following screen shots, the signal flow can be seen when the control is restarted after the input has been set. The signals are delayed according to the cycle time of the object. Program restart
This coil is the same as the Set Coil, except this coil retains the status even after the CPU is restarted.
Page 522
Version 7.0
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 sets the right path to one for a cycle (Note: cycle time of object).
Version 7.0
Page 523
9.4.1
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 a different program location with a jump instruction, it must be identified with a label. The label is always placed in the left frame.
Page 524
Version 7.0
With this option, a new line can be added to the contact plan.
Delete Empty Row
Version 7.0
Page 525
9.5
9.5.1
If 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 diagram, is no longer supplied with power.
This display helps to identify the status of the switches in the contact plan.
Page 526
Version 7.0
9.5.2
If a class is created with the following contact plan, it will have 5 clients and 2 servers extending outward. To make classes as small as possible (meaning as few clients as possible), 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 clients is shown below to the right.
Hiding clients and servers have no effect on the function of the class.
Version 7.0
Page 527
9.5.3
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.
Page 528
Version 7.0
9.5.4
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).
Version 7.0
Page 529
CONTACT PLAN (COP) IN LASAL CLASS 2 As previously mentioned, remember to define the Read method for the OnOff server. Program this function as shown below to create a time delay:
Next, Create a ladder Diagram (here: SetInOut) and in the Properties window, set CyclicTask to true.
Page 530
Version 7.0
CONTACT PLAN (COP) IN LASAL CLASS 2 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 diagram class SetInOut.
Version 7.0
Page 531
CONTACT PLAN (COP) IN LASAL CLASS 2 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 DelayTime client (here: 3000 ms). Define the two outputs (here: Output1 and 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 532
Version 7.0
Version 7.0
Page 533
USING C-FILES
10 Using C-Files
10.1 Application
In LASAL CLASS 2, the possibility exists to link existing or newly created C-Files. The advantage of linking C-Files is that available program code doesnt have to be written again in structured text, which significantly shortens the project development time.
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 SIGMATEK. Every LASAL project linked to C-files must be compiled with the C-files at least once.
Page 534
Version 7.0
USING C-FILES 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, C-Files are not compiled by the compiler. With true they are compiled. The detail debuginfo setting allows the use the LASAL CLASS 2 debug function for CFiles as well. Version 7.0 Page 535
USING C-FILES
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 536
Version 7.0
USING C-FILES To create a C-File, select File, New File... in the menu bar
To save the C-File, select File, Save File As... in the menu bar.
Version 7.0
Page 537
USING C-FILES 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 538
Version 7.0
USING C-FILES
Explanation of the program code extern "C" int MyCFunc => Required for calling the following function from LASAL CLASS 2
=> Data type for the return parameter of the C-Function => Name of the C-File
(int value1, int value2) => Data type and name of both input parameters { int result;
=> Start of the function => Data type and name of the local Variables in the C-function => Multiplication and assignment to the return parameter, result
=> Assignment to the return parameter (always return) => End of the function
In the project folder under "Compiler" set the property "CompileCFiles" to TRUE!
Version 7.0
Page 539
USING C-FILES 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 540
Version 7.0
USING C-FILES 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).
Version 7.0
Page 541
USING C-FILES 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 program code editor. Insert the following program code:
__cdecl
=> Means the input and return parameters of the function are written in Cnotation. 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 appearance of the function (MyHeader.h-file).
Page 542
Version 7.0
USING C-FILES 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.
Version 7.0
Page 543
Page 544
Version 7.0
The addition of as batch is assigned so that the complete module name doesnt have to be used.
The pump station example should be generated automatically with help from a script file. The complete description of the Pump station example is found in chapter 4.6.2. To create a script file, select File, New File... in the menu bar. Open the Save File As window 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!
Version 7.0
Page 545
SCRIPTING (BATCHFILE PYTHON) 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 546
Version 7.0
SCRIPTING (BATCHFILE PYTHON) To create the pump station, 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 commentary. To create a new project, the CreateProject project instruction must be used. All required classes are then copied with the CopyClass instruction.
Version 7.0
Page 547
SCRIPTING (BATCHFILE PYTHON) 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 coordinates (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 548 Version 7.0
SCRIPTING (BATCHFILE PYTHON) 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.
Version 7.0
Page 549
SCRIPTING (BATCHFILE PYTHON) 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 550
Version 7.0
SCRIPTING (BATCHFILE PYTHON) 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.
Version 7.0
Page 551
SCRIPTING (BATCHFILE PYTHON) To generate an error in this script file, the last letter was removed when loading the PumpControl (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 occurred, appears in the log file. The interruption of the script file is also shown in the Python Script window and the corresponding line number is referenced.
Page 552
Version 7.0
SCRIPTING (BATCHFILE PYTHON) 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 finished, appears after the project has been successfully downloaded. When a transfer error occurs, Download on address...failed appears. Next the bExceptionOnError is reactivated.
Version 7.0
Page 553
SCRIPTING (BATCHFILE PYTHON) Run the modified script file. If the connection, which was assigned with a symbolic name, is correct then the following message appears:
Page 554
Version 7.0
CreateProject(strFilename)
The destination project to which the class should be added. The source project from which the class comes. The name of the class to be copied. true = overwrites an existing class with the same name in the destination project (Default=False).
CreateNetwork(prjDst, keyNetwork)
The project in which the network should be placed. The name of the new network.
Version 7.0
Page 555
The project, which contains the network. The name of the network. The name of the class on which the object is based. The name of the object created. The x position of the object in the graphic view. The y position of the object in the graphic view.
The destination project. The name of the network, which contains the object whose channel should be changed. The name of the object. The name of the channel whose start value should be changed. The new start value of the channel.
Page 556
Version 7.0
Creates a new connection between a client and a server channel. Input parameters:
prjDst
The destination project. The name of the object, which contains the start of the client channel. The name of the client channel from which the connection starts. The name of the network in which the connection ends. The name of the object, which contains the server channel. The name of the server where the connection ends.
strSourceNetworkName The name of the network from which the connection starts. strSourceObjectName strSourceClientName strTargetNetworkName strTargetObjectName strTargetServerName
Input parameters:
prjDst strNetworkName strObjectName strTask strTime
The destination project. The name of the network, which contains the object. The name of the object whose process time should be changed. The name of the application [realtime | cyclicwork | background]. The new cyclic time.
Save(prjDst)
Version 7.0
Page 557
Download(prjDst)
CloseProject(prjDest)
The name of the log file. Optional parameter for formatting the layout of the error messages. true = Reports attached to an existing log file. False = A new log file is created. Closes the log file
Page 558
Version 7.0
Whether a message is returned 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). Input parameter:
strText
Version 7.0
Page 559
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 respective product manuals. Here, the settings required for communicating with the LARS simulation program are explained.
Page 560
Version 7.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.
Version 7.0
Page 561
ONLINE WITH THE CONTROL The LASAL Online configurations window opens.
Regardless of whether a project is loaded or not, the LASAL Online configurations window can be opened with the Ctrl key + the online symbol . Therefore 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 section, 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 nection is deleted. button an existing con-
Page 562
Version 7.0
ONLINE WITH THE CONTROL 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.
Version 7.0
Page 563
are discussed. In addition, the difference between the individual connection types in speed and configurations are illustrated and explained.
Page 564
Version 7.0
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.
Version 7.0
Page 565
The BU106 Adapter is simply connected to the USB interface of the PC. Before the required drivers have to be installed on the PC. Further details at www.canusb.com.
Establish a new connection (here: CAN new) or select an already existing CAN connection. Afterwards select CAN-BUS under Connect Type:. Then choose the USB adapter (USBCAN Adapter Lawicel) under Interface:. Insert the values of the target system under Baudrate and PLC station or press the CAN-Finder button. For PC station,be sure 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 at the desired interface (here: USB-CAN Adapter Lawicel).
Page 566
Version 7.0
The DIAS adapter (pictured right) is connected to the LPT printer port of the PC. Therefore, the operating system configuration must be changed.
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 any interrupt assigned to the port option field as shown in the following screen shot.
Version 7.0
Page 567
The PC must be restarted in order for the modifications to take effect. Page 568 Version 7.0
Create a new connection (CAN new) or select the existing CAN connection. Under Connect 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 project. It is recommended to activate the Hardmode selection, as the connection is faster.
Version 7.0
Page 569
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 instructions 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 properties in the context menu. 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 items:, select Properties. Page 570 Version 7.0
ONLINE WITH THE CONTROL The Internet Protocol (TCP/IP) Properties 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!
Version 7.0
Page 571
Create a new connection (TCP/IP Connection new) or select the existing TCP/IP connection. Next, select TCP/IP under Connection Type:. Under IP Address:, assign an IP address 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.
Page 572
Version 7.0
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.
Version 7.0
Page 573
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
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 574
Version 7.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 Edit Autoexec.lsl... (as shown below). context menu that opens select File Transfer
Version 7.0
Page 575
The autoexec.lsl can now be changed directly. To now load the modified autoexec.lsl in or button to reboot the CPU after saving. the target system, press the
When changes are made in the AUTOEXEC.LSL, the CPU must be restated so that the changes are assumed!
Page 576
Version 7.0
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 correction is allowed. No data flow controls can be activated (RTS-CTS or XON-XOFF).
Version 7.0
Page 577
Page 578
Version 7.0
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 ATE0 AT&K0 AT\N1 ATS0=2 AT&W0
Quiet mode, no return messages No echo from commands (not required) No data flow control Direct mode Automatic pick up after to call signals Save as actual configuration
With the AT\S command, the actual configuration can be tested and should correspond to the list shown below:
Version 7.0
Page 579
To start, the Modem must first be installed. In Windows SP, open the system controls and then the Phone and Modem Options window:
Select the Modems tab in the above window and click on Add.
Page 580
Version 7.0
ONLINE WITH THE CONTROL In the Add Hardware Wizard window, the decision can now be made as to whether the Modem is selected automatically or manually.
When automatically selected, make sure that a Modem is connected and turned on. Click on Next > to start the automatic search.
To select the Modem from a list manually, activate the Modem select function (Don't detect my modem; I will select it from a list.)
Version 7.0
Page 581
Select the corresponding Modem from the list. If a data carrier with the driver information is available, push the Have Disk button to install the Modem then click on Next >.
Next, select the PC connection (here: COM1) for which the Modem should be installed the click Next >.
Page 582
Version 7.0
ONLINE WITH THE CONTROL A window then appears in which the Modem configuration is confirmed. Click on Finish.
Version 7.0
Page 583
ONLINE WITH THE CONTROL 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 115200 as shown above and click OK to confirm the selection.
Page 584
Version 7.0
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.
Version 7.0
Page 585
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 586
Version 7.0
ONLINE WITH THE CONTROL A connection to the user computer can be made in 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, its 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.
The predefined
Version 7.0
Page 587
If connected to a network, this type can be used to establish a connection to LARS. The users own IP address must be assigned as the destination.
Page 588
Version 7.0
FAQs
13 FAQs
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?
Version 7.0
Page 589
FAQs
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 a whole, parts and dependencies etc. In information technology a formal grammar is defined to establish allowable and nonallowable 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 keywords and other program language elements are highlighted. Syntax highlighting improves the readability of text: structures in the text are easier to recognize, 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 590
Version 7.0
FAQs
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 doesnt 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 interrupted and another process is run for a time slice.
IEC is the abbreviation for International Electro technical Commission, which is the international standardization committee for standards in the area of electro technology and electronics 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.
Version 7.0
Page 591
FAQs
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 input 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.
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 arent 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 592
Version 7.0
FAQs
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 covered. 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 memory. 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 variable. Uninitialized 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 programs 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 doesnt translate a program to the target language rather executes it directly step by step.
Version 7.0
Page 593
FAQs
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 describes 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 594
Version 7.0
FAQs
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 (depending 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.
The Handle is a 4-byte identification for an opened file. Using this identification, it is possible to distinguish files opened at the same time.
The Extended Instruction Pointer (EIP) is a register, that tells the processor which instruction should be processes next.
Version 7.0
Page 595
FAQs
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. rC:\Lasal2\...).
Page 596
Version 7.0