Escolar Documentos
Profissional Documentos
Cultura Documentos
5 Help Manual
v.1.3
Table of Contents
INTRODUCTION 1. General Description
1.1 EasyPLC Programs Group 1.2 EasyPLC Installation & Minimum requirements 1.3 Demo vs. registered version 1. !o" to #egister EasyPLC
2. EasyPLC Editor
2.1 Program Inter$a%e 2.2 !ard"are Con$iguration 2.2.1 &irtual PLC CP' Parameters 2.2.2 I() Devi%es 2.2.2.1 *dd a +e" Driver 2.2.2.2 #emove a Driver. 2.2.2.3 *vaila,le Drivers 2.2.2. !o" to Develop an EasyPLC Driver. 2.3 -o$t"are -tru%ture 2.3.1 &aria,les 2.3.2 Program Modules 2.3.2.1 Init 2.3.2.2 Main. 2.3.2.3 .un%tions 2.3.2. Common *rea 2.3.3 Data /lo%0s 2.3. Plugins 2. Languages 2. .1 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. .2 2. .3 2. . Ladder .1.1 Conta%ts .1.2 Coils .1.3 -egments .1. #ead(1rite *nalogi%(Digital I() .1.2 'sing varia,les .1.3 Comparator .1.4 Counters .1.5 6imers .1.7 Data /lo%0s .1.18 .un%tion Call .1.11 #egister 6rans$er .1.12 Comments .1.13 -9ort%uts :eys .1.1 -pe%ial Coil ;#eturn< -%ript .un%tion /lo%0s Gra$%et
2.2 !MI 2.3 Compilation & 6rans$erring logi% program to &irtual PLC 2.4 Cross #e$eren%es 2.5 Printing 2.7 Conne%tion "it9 &irtual PLC CP' 2.7.1 Lo%al & #emote %onne%tion modes 2.7.2 *vaila,le )perations 2.7.3 &ie"ing logi% programs running 2.7. -ee(.or%e &aria,les 2.18 EasyPLC Editor Customi=ation
www.nirtec.com
INTRODUCTION
1. General Description
EasyPLC Sofware Suite is a group of programs that allows to make automatism control and simulation. With EasyPLC you can write logic programs like commercials PLC for multiple uses like real automatism control, domotics, simulation, initialization to the PLCs world and much more The main characteristic of EasyPLC is that it emulates the operation of a PLC, using the programming languages most used in the industrial world: Ladder, Grafcet, Logic Function Blocks and Script. You will be able to learn how to use the automatic control systems used in the industry, only with your Personal Computer, the EasyPLC software and an input/output interface or a simulated one.
Easy Connection
EasyPLC is designed to work with the PC ports (Serial/Parallel/USB). It is not necessary to open the computer or do complex configuration tasks, only install the software, connect the interface and begin programming.
Applications
You can use EasyPLC to make automatisms control, PLC Training, domotics, initiation in the world of the PLC's, projects simulation and much more
Once your request has been processed and all commercial steps have been finished, you will receive a license file (if you have chosen the single modality). You must copy this file in the EasyPLC installation folder. Then you can use the registered EasyPLC version only in the computer that you have obtained the software Id code. If you have chosen the USB License mode, you will receive a USB Key, inside, there are the entire installations program. You can execute the registered EasyPLC software in all the computers where the USB will be connected. Remenber that if you use this license you need to insert the USB Key in the computer in order to make run Virtual PLC CPU. If the key is not connected Virtual PLC CPU will close. In some systems it is necessary to run the software in Windows administrator mode, in order to allow the software to access the USB key and running in registered mode.
How to Execute EasyPLC and Virtual PLC CPU in Windows (Vista, 7) Administrator Mode. 1) Make mouse right click in the EasyPLC v.5 desktop icon:
2) Select properties:
3) Select Shortcut tab, and make click in the advanced options tab:
5) Select the Compatibility tab, and check the Execute this program as Administrator check box.
6) Click the Accept button. Repeat the same steps for: virtual PLC CPU, Machines Simulator and Machines Simulator Editor. Then this programs always will be executed in administrator mode every time are clicked.
2. EasyPLC Editor
2.1 Program Interface
Here a screen shot of the visual interface of EasyPLC is shown. The following items are marked: Menu, from where all the Editor options can be chosen. Tool Bar, fast access to most common options. Project Explorer: here you can see/change the hardware parameters, program structure, data blocks, plugins and HMI Screens. Programming Area: there is where the logic programs will be created/edited.
10
11
Virtual CPU Start Mode: Stop: if selected the Virtual PLC CPU will start in Stop Mode when launched. Run: if selected the Virtual PLC CPU will start in Run Mode when launched.
Watchdog: Enabled: if this option is marked, the Virtual PLC CPU will make a control each scan cycle controlling that is smallest that the Control Time programmed. If is higher, the Virtual PLC CPU will pass to stop mode and launch a Watch Dog error message. This option is useful when must be done a very accuracy process, in order to be sure that the Virtual PLC do not have time loss.
Communication with Virtual PLC CPU: The communication between EasyPLC Editor and Virtual PLC CPU can be done in Local or Remote mode. EasyPLC Editor can connect with Virtual PLC in order to read the current status of the running program, in this way is possible to make task like debug, diagnosis or others. Local: if this option is selected, EasyPLC Editor and Virtual PLC CPU will be executing in the same computer. Remote: if this option is selected, EasyPLC Editor and Virtual PLC CPU will be executing in different computers, the computers must be connected to the same net. IP Address: the Ip Address of the computer that will be executing Virtual PLC CPU. Port: the listening port using to attend the Editor connection (remember to open this port in your Firewall).
Set Parameters Button: use this button to accept a configuration, useful when theres no project on the Editor and the objective is to connect with Virtual PLC CPU to upload a program. Virtual PLC CPU Properties: Here is showed the information about the Computer microprocessor performance. These values will change in function of the computer microprocessor. Its highly recommended to use computer with more that one microprocessor in order to have the best performance. PLC Scan Cycle Speed: The Fastest: if selected the Virtual PLC CPU will run the logic program at the maximum speed available by the system. Limit to: if selected the Virtual PLC CPU will run the program at the selected speed, this means for example that if 10ms is selected, the cycle time will be ten milliseconds, then each loop of the logic program will be executed every 10 ms. Useful when we must to use hardware devices with limited speed transfer rates.
Disable Safe Mode Program Execution: if selected the program will execute the logic program without internal errors check, could be faster but if an error appears the Virtual PLC CPU will crash. Frequency Signals: the Virtual PLC CPU can generate an internal frequency signal (square wave) with a time base programmed by the user. The output signal is applied to the selected variable in Variables node. The maximum number of frequency signals are 25.
12
Always a new Driver is added, is necessary to click it and configure it, in order to be able to use in your project.
There are some Drivers that offers some configurations options, others not. If the driver have this possibility, make click on the Configure Button, a new window will appear where is possible to parameterize it.
13
Clicking in the Test Button is possible to test directly the device if is connected to the computer (only in the registered version). Click the Exit from test Mode Button to exit from this mode. A useful option is the possibility to disable any driver. If you uncheck the Driver Enabled mark, this driver will be not processed by Virtual PLC (useful for test porpoises or when the physical device is not present).
14
If you click on each Driver, a description about this driver will be refreshed on the description area.
If you want to eliminate an existing driver, click it in the I/O Devices node, press right mouse button and select Remove Device form the contextual menu.
15
Simulation Driver running with Virtual PLC CPU Available Drivers on request: Siemens Drivers: communication driver between Simatic S7 - PLCSIM and Virtual PLC CPU. With this driver you will be able to communicate your Step 7 logic programs directly with Virtual PLC without any additional hardware. Create your Step 7 programs and use Machines Simulator to test it, simple, fast and secure, no additional hardware are needed (expensive PLC's, I/O cards, connections interfaces,...) only your PC and the following software: Siemens Simatic Step 7 v.5.4 (SP3) Siemens S7-PLCSIM v.5.4 EasyPLC Software Suite Simatic S7-PLCSIM EasyPLC Driver
16
Linked variables take automatically the data type of the linked PLC element, being impossible to change their type. Its possible to add a description for each variable, then will be easiest to debug the logic programs.
17
Clicking in the Address column of each variable, is possible to assign easily this variable with the available PLC objects like analogic/digital I/O, CPU frequency signals, data blocks, counters or timers. Once the user makes click on the column button, the Select Address window will appear, from there, is possible making double click to select the item to link with the variable.
From Variables Tool Bar are available the following tools: Delete Variable: use it to delete variables. Copy Variable. Paste Variable. Import Variables: with this option is possible to import variables from external sources. The following options are available: o Import from Machines Simulator: an ios file (exported from Machines Simulator) can be selected, then automatically are created the analogic/digital input/outputs used in Machines Simulator installation. o Import from csv file: the csv file must follow this format: variable name, address, type, description. Fields must be separated by comma or point and comma. Here an example is showed:
Automatic;I.0.0;bool;variable for automatic mode Manual;I.0.1;bool;variable for manual mode Motor_ON;i.0.2;bool;motor is on Motor_OFF;i.0.3;bool;motor is off switch_1;i.0.4;bool;part detection text;;string;user text
An variable cannot: Start with a numeral. Start with a symbol, To have a keyword name (check Keywords in Appendix). Have more than 511 characters.
18
2.3.2.1 Init
The sequences inside the Init Program node only will be executed once, when the program starts. Useful to program initialization routines.
2.3.2.2 Main
The sequences inside the Main Program node will be executed cyclically and in the order showed in the node tree. Using the jump tools will be possible to change the sequences order if the program requires it.
2.3.2.3 Functions
In this node are programmed the functions, the functions are sequences called from the Init or Main sequences. Functions also can be called from others functions. Functions can return a value or not. Only the functions written in Script language can return a value, using the return keyword. The functions written in Ladder or Function Blocks cant return any value.
19
In order to insert a sequence in the Init or Main Program Module, click it and press right mouse button, click Add Sequence on contextual menu. Also from the EasyPLC menu -> Program -> Add new Init Sequence or Add new Main Sequence. The Create New Sequence window will appear, there you can write the sequence Name (without spaces) and the sequence language. Pressing Accept button, the new sequence will be created.
To insert a new function click in the Functions Program node, press right mouse button, click Add Function on contextual menu. Or from the EasyPLC menu -> Program -> Add new Function. The Create New Function window will appear, there you can write the function Name (without spaces), the sequence language, the returned data type and the parameters passed to this function with their data types. Pressing Accept button, the new function will be created.
Only functions written in Script language can return a value (with the return keyword)
20
A special function is available, the Exit function. When you create a function called Exit (must be without parameters and void returned value), Virtual PLC CPU will call this function when pass to Stop Mode. This feature could be useful to call to finish routines (for hardware or software unloads tasks). In order to software reusability, Functions can be exported or imported to use in other programs, you can refer to Appendix 4.2 to learn more about this feature and to view some functions examples usage with different languages.
Once the common area is declared, will be available like an icon in the Program tree.
21
Once the Data Block is created must to be parameterized, type the Data Blocks name, type and length (the number of elements that contain this data block). Then press Create Data Block button to create it. The Non Volatile attribute is used to store the Data Block value when the Virtual PLC pass to stop mode and when finish. The data blocks marked with this attribute will maintain the last value stored when Virtual PLC pass to Run Mode also if is closed and re launched. Is possible to initialize the data blocks with the values typed in the Value field.
22
2.3.4 Plugins
The Plugins are an extensibility tool that adds specific abilities to EasyPLC. These libraries can be created by the users allowing any kind of customization giving more power to the language, or creating special functions to communicate with third party devices or softwares. Please refer to the EasyPLC v.5 SDK guide, in order to know more about this item. All the plugins libraries must to be copied in the EasyPLC Plugins folder.
To add a new Plugin, select the Plugin node, and make right click, next select Add Plugin from the contextual menu.
Then you must select a valid EasyPLC Plugin dll file, if the library is a valid EasyPLC Plugin library, a new node will be added to the Plugins node. Making click on the new plugin node, will show all the methods information, about their name, parameters, and returned value.
23
2.4 Languages
2.4.1 Ladder
The Ladder is a programming language that represents a program by a graphical diagram based on the circuit diagrams of relay-based logic hardware. It is primarily used to develop software for Programmable Logic Controllers used in industrial control applications. Then Ladder allows making programs in a graphic way like you where connecting circuits with relays, counters, timers, sequencers, etc... The basic elements of a Ladder program are the contacts and the coils. The programs written in Ladder are compound by segments. A segment its a contact/coil group. The contacts are the conditions that are evaluated to make an action, the coils are the actions. Now lets see the EasyPLC Ladder structure.
24
The Ladder tool bar offers the followings tools: Add Contact: adds a new open contact in the selected cell position. Add negate Contact: adds a new closed contact in the selected cell position. Add Comparator: adds a new comparator contact in the selected cell position. Add Coil: adds a new coil in the selected cell position. Add Set Coil: adds a new Set coil in the selected cell position. Add Reset Coil: adds a new Reset coil in the selected cell position. Add Trigger Upper Coil: adds a new Upper Trigger coil in the selected cell position. Add Trigger Down Coil: adds a new Lower Trigger coil in the selected cell position. Add Jump coil: adds a new Jump coil in the selected cell position. Serialize Coil: adds a new coil serialized with the current selected coil. Add Counter Coil: adds a new Counter coil in the selected cell position. Add Timer Coil: adds a new Timer coil in the selected cell position. Add Data Block Coil: adds a new Data Block coil in the selected cell position. Add Function Call: adds a Function call in the selected cell position. Add Register Transfer: adds a new Register Transfer in the selected cell position. Add Jump Label: adds a new Jump Label in the selected cell position. Add Comment: adds a new Comment in the selected cell position. Add Header Text: adds a header Text coil in the selected row position. Add Cable: adds a new wire connection in the selected cell position Cable Down: makes a connection with the lower cell. Cable Up: makes a connection with the upper cell. Delete Connections: deletes the current connection in the selected cell. Add Space between Segments: adds space between segments in the current selected cell Reduce Space between Segments: erases space between segments in the current selected cell. Move segment to right: move the segment to the right adding a wire in the current selected cell. Zoom Out: reduces the zoom. Zoom In: increases the zoom Standard view: set the segments size to the standard one. Selection Tool: allow to select segments for copy/paste operation. Copy: copy the current selection. Paste: paste the last selection.
25
2.4.1.1 Contacts
Ladder has contacts that make or break circuits to control coils. Each coil or contact corresponds to the status of a single bit in the PLC memory. Unlike electromechanical relays, a ladder program can refer any number of times to the status of a single bit, equivalent to a relay with an indefinitely large number of contacts. So-called "contacts" may refer to physical ("hard") inputs to the programmable controller from physical devices such as pushbuttons and limit switches via an integrated or external input module, or may represent the status of internal storage bits which may be generated elsewhere in the program (Variables).
The Contact shows two areas, the elements area and the Operation area, depending what type the variable assigned to the contact, is possible to type and see different information in the contacts area. In the previous picture we see a segment with five contacts, there are: I.0.0: this means the digital input number 0.0 this is the input number 0 from the diver number 0. Due digital inputs are Boolean conditions no additions information is shown in the operation area. PushButton: this is a variable linked with the digital input 1 of driver number 0, all the linked variables will show in the operation area the linked element between brackets. num: is a variable of numeric value, in order to evaluate the contact, is necessary to type the condition that will allow the contact activation, this will be that the num variable will be grater that 20. cont: is a variable linked with the counter number 2, the contact activation condition will be greater than 12. tim: variable linked with Timer number 1, like the Timer elements are Boolean conditions, this contact will be activated when the timer 1 reaches the programmed time.
Contacts can be set as negated, then will be activated if the activation condition is false.
2.4.1.2 Coils
Each segment of ladder language has one coil at the far right. Also is possible to connect more that one coil in the same segment (serialize coils). The "coil" (output of a segment) may represent a physical output which operates some device connected to the PLC, may represent an operation with variables or a call to other element in the program. The coils could be activated in several ways, in EasyPLC exists the following coils type:
Level Coils: these coils are activated by level, this means, the coil status is always true while the segment is true. If the segment is false, the coils status is always false. Set Coils: used for Boolean variables, if the segment is true, the coil will set to true the variable assigned, if is false nothing is done. Reset Coils: used for Boolean variables, if the segment is true, the coil will set to false the variable assigned, if is false nothing is done. Trigger Up Coil: these coils are activated by upper flank, this means, the coil status is true only the first time the segment pass from false to true. Trigger Down Coil: these coils are activated by lower flank, this means, the coil status is true only the first time the segment pass from true to false. Jump Coil: used to jump to a label in any sequence. Serialize Coil: sets a coil serialized with the selected one, then when the segment condition will be true, this new coil also will be activated.
26
The Coils shows two areas, the elements area and the Operation area, depending what type the variable assigned to the coil, is possible to type and see different information in the coils areas. In the left picture a segment with four coils is shown, there are: O.0.1: this means the digital output number 0.1 this is the output number 1 from the diver number 0. Due digital outputs are Boolean conditions no additions information is shown in the operation area. Delay: variable linked with Timer number 1, when this coil will be activated, the timer number 1 will be initialized with value 100 milliseconds. PartCounter: is a variable linked with the counter number 2, when the coil is active, will increase in one unit the value of counter 2. Value: numeric variable, when coil will be active, will add 2 to the current variable value.
Making double click on the contacts/coils Description and Operation area is possible to edit their values in order to modify it.
The assistant help contains tour tabs, the first tab (Help) explain the possible operations for the current contact/coil and shows some examples, the second tab (Variables) shows the available variables on our project, making double click on the selected variable, is added to the text operation without writing, the third tab (Functions) shows the available contact/coils functions to write in the operations area, and the last one (Plugins) shows the available plugins defined in our project.
27
The available operations for contacts and coils are different, due contacts operations always are of comparison type (must return a Boolean value), and coils operations are assignments. All operations must be done following the syntax of C programming language.
2.4.1.3 Segments
A segment is a group of Boolean conditions that ends in one o more coils. The writing of segments should always be from left to right and from up to down. Imaginarily, the current continues the sense from left to right
Using the contacts, coils and wirings tools is possible to create the desired segments. The wiring tools are: Cable Left: allows drawing a horizontal wire of one grid unit. Cable Down: draws a wire from the current position to one lower grid position. Cable Up: draws a wire from the current position to one upper grid position. Cable Eraser: deletes any connection in the current cell.
The ladder draw area is designed like a grid, divided in cells. In each cell position an element can be draw (contact, coil or cable). Writing segments must be done in order form left to right, is not allowed to insert an element in an empty location.
28
Lets see some examples: For a fast way, in the ladder programming area, make click on the first cell, then the selection dotted square will be shown:
Press Insert Key or make click in the ladder tool bar contact button.
A text area appears over the contact, also a wizard windows appears in order to select the element to assign to this contact. Type I.0.0 in the contact text area and press Enter Key.
29
Now we have created the first contact that will be active when the input number 0 from the Driver 0 (Simulated) will be active. Now were using the variables linked method. Go to the Variables node in the Project Explorer, and in the last empty row, column Variable Name, type the name of your variable (NewInput in the example), now click on the Address button, the Select Address window appear to select the element. Select the desired one (I.1.0 in the example).
Once selected, the Address Button will show the linked element with the created variable.
Now, go to the ladder programming area, and select the cell following to the last created contact, press Insert Key or make click in the ladder tool bar contact button. When the wizard window appears, select the new created variable, and make double click.
30
Then the Input number 0 from the second driver will be assigned to the new contact.
Now you know the two modes to assign digital inputs to the contacts. This is the same for the digital outputs and analogic inputs and outputs, applying also in the coils. For the outputs is used the syntax: O.X.Y (where X is the driver number and Y the output number). For the analogic inputs is used the syntax: AI.X.Y (where X is the driver number and Y the output number). For the analogic outputs is used the syntax: AO.X.Y (where X is the driver number and Y the output number). Following the example, now select the cell at the right of the last contact, and press Shift key + B key or make click in the ladder tool bar coil button, then write O.0.2 and press Enter Key. Now you have created a new segment, where the digital output number 2 from the driver number 0, will be activated if are actives digital input number 0 from driver 0 and digital input number 0 from driver number 1, if some of this inputs are deactivated, the output also.
31
Then the Create New Variable window appears, there you can customize your variable like link it with any available element, or if is not a linked variable you can define the variable type. Also is possible to insert a description about the variable.
Once the OK button is pressed, the new variable is added to the Variables project table, and is visible in the ladder wizard window. You can make double click in order to assign it to the selected contact.
32
Example of mode 3: In the text area of a Contact or Coil, write your variable name, if this variable do not exists, the New Variable Window appears in order to create it, once accepted, this variable will be added to your project, being available at the ladder wizard window, making double click will be assigned to the selected contact or coil.
33
2.4.1.6 Comparator
The comparator is a contact element designed to make comparisons easily between variables or data blocks elements. To create a comparator make click in the ladder tool bar comparator button. To make comparisons, click in the combo box to select the comparison operation, this could be equal (==), different (!=), greater than (>), minor than (<), greater or equal (>=), minor or equal (<=). Click in the IN1 text filed, the wizard window appears, making double click over the desired variable will assign to the fist comparison operator, the same operation for the second operator (IN2). In the example two variables are compared is are equal will activate the coil, assigning the value 125 to the variable Value.
IMPORTANT: variables compared MUST BE of the SAME TYPE. Also is possible to write a constant in the second operator (IN2)
To make comparisons with Data Blocks, is possible to use the variables linked with each element, or if is necessary, is possible to use the function ReadDB(id, elem), that will return the element number elem from the data block number id. Is required that the first parameter will be a numeric constant, but the second parameter can be a variable.
34
2.4.1.7 Counters
EasyPLC offers a special variable (long type) used to make counter operations, the counters can be used by several ways in the contacts/coils. Counter Coils To add a new Counter coil press on the Ladder Tool bar Counter Coil You can type in the Id text area the counter number, and in the Increment text area the quantity to the counter must to be incremented when the coil is active. The counter will increase their value only in the upper trigger of the segment activation.
If the Counter has linked a variable, the variable name will be shown.
Counter also can be written using the standard coils, using the syntax CNT.X, where X is the counter number. Clicking in the coils operation area is possible to customize the counter operation.
Be careful with the coil type used, in the previous example, a standard coil has been using, this coils works in level mode, this means that while the segment condition is true, the coil will be executing the counter operation. The most common counter coil usage is to use a triggered coil, in the next example, when the output 0.1 is active the counter number 1 will increment their value in 5 units, but only once, the counter will not be updated since the output 0.1 will be deactivated and activated again.
Counter Contacts To add a new Counter contact press on the Ladder tool bar coil, then type the variable name linked with the counter or use the syntax CNT.X, where X is the counter number. After, you can type the counter comparison operation, the syntax must be done in C programming syntax. .
35
2.4.1.8 Timers
EasyPLC offers a tool to control time, this is the Timer. By default the timers works for retard to the connection. According to the following segments the timer 1 level signal would be:
Timer Coils To add a new Timer coil press on the Ladder Tool bar Timer Coil You can type in the Id text area the timer number, and in the Time text area the timer countdown time (could be a numeric value or a variable of Long type). In the upper trigger of the segment activation the timer will start to count, when the timer countdown arrives to zero the timer will have a true value.
Timers also can be written using the standard coils, using the syntax TMR.X, where X is the timer number. Clicking in the coils operation area is possible to customize the timer countdown time. Be careful with the coil type used, in this example, a standard coil has been using, this coils works in level mode, this means that while the segment condition is true, the coil will be executing the timer loading value operation. The most common timer coil usage is to use a triggered coil.
36
Timer Contacts To add a new Timer contact press on the Ladder tool bar coil, then type the variable name linked with the timer or use the syntax TMR.X, where X is the timer number. The contact associated to the timer will be true when the timer previously has been activated and their countdown will arrive to zero.
Data Blocks also can be written using the standard coils, using the syntax D.X.Y, where X is the Data Block number and Y the element number of the Data Block. Clicking in the coils operation area is possible to customize the Data Block element operation.
See in the example how the sum operations are performed by trigger.
37
Data Blocks Contacts To add a Data Block contact press on the Ladder tool bar coil, then type the variable name linked with the Data Block element or use the syntax D.X.Y, where X is the Data Block number and Y the element number of the Data Block. The Data Blocks comparison operations must be written in C language syntax.
Next the Function Parameters window will open in order to parameterize the parameters passed to the function and the returned value. Clicking in the Variable button for each parameter is possible to assign it to the selected variable from the list making double click on the variable name. Also is possible to assign a constant value clicking in the Set Constant button. If Run on Trigger is marked, the Function will be called once when the segment value pass form false to true, by default the calling will be done by level, this means the calling will be done each PLC scan time cycle while the segment condition will be true.
38
When confirmed, the Function Call coil will show the information about the called function name, the passed parameters and the returned value.
If you make right click on the Function name node, is possible to change the function name, change the parameters or to delete the function.
Use the Register Transfer coil for transferring the status of the selected Input register to the selected register output. Also is necessary to configure the length of the copied register.
2.4.1.12 Comments
With the Comments Ladder tool will be possible to document the Ladder programs. There are two types of comments, the text and the Header comments. To insert a comment select it from the Ladder Tool bar.
39
Making double click on the comment is possible to customize it, changing the text, Background colour, text colour, text font and message border.
Text comments can be moved in the Ladder programming area clicking on the text and moving with mouse.
Insert Key: Insert Contact. Shift + Insert Key: Insert negate Contact. Shift + B : Insert Coil. Shift + C: Insert horizontal Cable. Shift + U: Insert Upper Vertical Cable. Shift + D: Insert Lower Vertical Cable. Shift + S: Activates Selection tool. Control + C: copy current selection. Control + V: pastes current copied selection.
In this example is input number 0.0 is active, the control flow of the program pass to the following sequence (Main_Sequence_2) and the second segment I.0.1 O.0.1 is not executed.
40
Cut text: cuts the selected text. Copy text: copies the selected text. Paste text: pastes the previously selected text. Comment: comments the selected text area.(this commented text will be not compiled). Un Comment: erases the comments of the selected commented text. Undo. Redo. Check Syntax: checks if the current sequence syntax is ok. Add Bookmark: add a bookmark in the selected position. Previous Bookmark: moves to previous bookmark position. Next Bookmark: moves to next bookmark position. Delete all Bookmarks: deletes all existing bookmarks. Find text: finds a text on the sequence. Find & Replace: replaces all the matches of the selected text on the sequence. Code Wizard: allow to insert code snippets on the current sequence, also is possible to call to the Script Wizard.
Pressing F2 Key will show the script Wizard on the current Script sequence.
In script language is possible to use the variables defined in the project to make any kind of operation. To do it Press F2 Key and from the Script Wizard window, select the variable you want to use making double click on the variable name.
41
42
Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description:
SetTimer(timerVariableName, v) none string timerVariableName, long v sets the timer timerVariableName with value v GetTimer(timerVariableName) bool string timerVariableName returns if the timer timerVariableName has been activated ResetTimer(timerVariableName) none string timerVariable resets the timer timerVariableName Key(key) bool int key returns the state of the passed key (ASCII value) Key('key') bool char key returns the state of the passed key (char value) PlaySound(path) none string path plays the wav file with path 'path' KeyPad("variableName") none string variableName Assigns a numeric value (double type) typed by the user to the variableName variable (declared of double type) KeyPadInt("variableName") none string variableName Assigns a numeric value (int type) typed by the user to the variableName variable (declared of int type) KeyPadLng("variableName") none string variableName Assigns a numeric value (long type) typed by the user to the variableName variable (declared of long type) KeyPadFlt("variableName") none string variableName Assigns a numeric value (float type) typed by the user to the variableName variable (declared of float type)
43
Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description:
Keyboard(variableName) none string variableName Assigns a string value typed by the user to variableName variable Plugin(pluginName, methodName, parameters) object string pluginName, string methodName, object[] parameters executes the method 'methodName' of the plugin 'pluginName' passing an array of objects 'parameters' StopPLC() none none makes a PLC Stop DriverStatus(number) bool int number returns the driver status number 'number' StartHMI() None None Launchs the HMI System application CloseApp(name) None String name Closes the name application
44
Condition Block: this block represents a condition, if is true their output will be true and can activate other blocks. Action Block: this block represents an action that will be done when other block actives it. Set/Reset Action Block: like Action block but with possibility to make set/reset operations. AND Block: makes the logic AND operation of the state of their two inputs, the result is present in their output. OR Block: makes the logic OR operation of the state of their two inputs, the result is present in their output. NOT Block: makes the logic NOT operation of the state of their input, the result is present in their output. Label: inserts a text label for documentation porpoises. Zoom in Zoom out Normal Zoom. Delete Selected Block/Wire.
45
Now, create other condition block and select a numeric type variable (DelayTime in the example is float type), then automatically the condition operation is filled. As you can see by default the condition is that DelayTime will be equal to zero, if you want to change the condition, click in the block and make mouse right click, a contextual menu will appear, then click Set Operation in order to change the condition operation.
The following operations will be to wire the two condition Blocks with the AND Block. To do it click on the first created Block, and make mouse right click, select Connect Out form the contextual menu, then the mouse cursor will change indicating that we are in edition connection mode. If the connection to the element on which the cursor is located is not possible, the cursor will have an icon shaped like a prohibition, if the connection is allowed, the icon will have a hand. If you click on the F.B empty area the block will exit from the connection edition mode and will not be connected.
46
Following the example, click on the AND Block, then the NewInput condition block will be connected with one input of the AND Block.
Now we are going to add an Action Block, to do it make click in the tool bar action block and place it in the programming area. Then select a Boolean variable (for example a digital output).
47
Then make mouse right click and select from the contextual menu, Connect In, then click the AND Block.
We have written your first Function Blocks sequence!. This program will work in the following way: if the digital input associated to the variable name NewInput is true, and the variable DelayTime is greater than ten, the digital input associated with the variable MotorOn will be activated, else will be deactivated.
Clicking in the Assign Variable contextual menu Blocks is possible to change the associated variable. Clicking in the Set Operation is possible to change the condition operation (for Condition Blocks) or the action operation (for Action Blocks). For Boolean variables theres no possibility to change the operation because for condition blocks always will be checked the true condition and for Action Blocks the action to make will be to assign true or false state, in function if is activated or not. Pay attention at the Activate by trigger / Activate by Level contextual menu items of Action Blocks. If Level mode is selected, the Action Block will be executing the action each scan loop of the PLC, while their input is true. If Trigger mode is selected, the Action Block executes the action once (the first time their input is true). Probably for the next example, you wish the auto increment of the variable Value, will be done once, then you must to select Trigger mode for the Action Block.
48
The Set/Reset Action Blocks are more flexible because allow to set/reset boolean variables and take out the result in their output. In the following example, if variable NewInput is true, MotorOn variable will be set to true, also variable Data5 will be matched to three. If variable T2 is equal to zero, MotorOn variable will be set to false.
Condition and Action Blocks allows to use internal PLC functions and Plugins, in order to select it, click on the wizard window help button, here you can see help syntax examples, access to variables, functions and plugins. Make double click on the desired name to be automatically added.
49
In order to delete connections between blocks make click in the wire you want to delete, then will be marked in yellow color. Now press Delete Block/Connection tool bar button.
50
2.4.4 Grafcet
The GRAFCET (Graph of Control of Steps of Transitions) it is a normalized functional diagram that allows to make a model of the process to automate, contemplating inputs, actions to carry out, and the intermediate processes that cause these actions. It is not a language, is a design type to elaborate the pattern thinking of the direct execution of the automatism. The Grafcet Level is compound of Steps and Transitions, the steps and transitions can be programmed in Ladder, Script or Function Blocks languages. The Grafcet Levels are compound by the following elements:
Initial Step: is activated when the level starts by first time, at least one initial step must be present. Step: is a subprogram that is executed continuously while their associated transition is false. Transition: is the condition that must be true to allow the pass to the next connected step. Structural Parallelism: allows to execute simultaneously all the connected steps to their output. For the Parallelism actives their outputs its necessary that all theirs inputs conditions must be true, this is, all the process that the Parallelism has been launched, must been ended to allow their finalization. In a Grafcet level can exist all diagrams you need.
At least an initial step should exist, (can be more than one). In a step output (normal or initial) a transition should always be connected. It is not possible to connect two transitions together or two stages together.
Add Initial Step: adds an initial step. Add Step: adds a new step. Add Transition: adds a new transition. Add Parallelism: add a new structural parallelism. Add Label: add a label for documentation porpoises. Zoom in. Zoom out. Normal Zoom Hide/view grid points. Delete selected item.
51
3. Click on the Grafcet tool bar Add Transition button, and place the transition down to the initial Step.
4. Click on the Grafcet tool bar Add Step button, and place the new Step down to the transition. Write 1 in the step number window.
6. Now we are going to connect the steps and the transitions. Click in the Initial Step in order to select it. Then make right click with mouse and click in the Connect Output form contextual menu. The mouse icon will change their shape, showing a prohibition image if the cursor is placed in a item that can not be connected, if the connection is possible, the icon image will change to a hand.
52
7. Click over the first transition, then a connection between the initial step and the transition will be done.
8. Click in the first transition, then a make mouse right click, select Connect Output from contextual menu and click over the Step number 1. Then a new connection between transition and Step 1 is done.
9. Click in the last transition, then a make mouse right click, select Connect Input from contextual menu and click over the Step number 1. A new connection between transition and Step 1 is done.
10. Now the last connection, Click in the last transition, then a make mouse right click, select Connect Output from contextual menu and click over the initial Step number 0. A connection between last transition and initial Step 0 is done. And our Grafcet diagram is totally connected.
53
11. Now is the time to write some code, click on the initial step 0, mouse right click and select from contextual menu Sequence Code -> Ladder.
13. A new Ladder sequence is created, write a segment like the example showed.
14. Click on the Grafcet Sequence in Main node Project. Next click in the first transition, once selected, mouse right click and select Sequence Code -> Ladder.
54
16. As you can see automatically is created a coil labelled with Transition word. Write in this segment the conditions to enable the transition, allowing passing the control to the transition connected step.
17. Select Grafcet sequence, and click on the Step number 1, right click with mouse to show their contextual menu, and select Sequence Code -> Script. Write Step_2 in the Step Name window.
55
18. Now write the code in Script language for Step 2. In this example is assigned the value of the digital input number 2 from driver number 0, to digital output number 1 from driver number 0.
19. Click on the Grafcet sequence node, select last transition and from contextual menu click on Sequence Code -> Script.
20. Click on the Grafcet sequence node, select last transition and from contextual menu click on Sequence Code -> Script. Write Transition_3 in the Transition Name window. See how automatically a snippet code is shown, you must fill in the if() sentence the conditions to activate this transition, in Script code the Transition keyword is used to activate the transition.
56
21. Write the code in the example, here if digital input number 3 from driver 0 is active, the transition will be activated.
Now our Grafcet sequence is complete. See how in the Grafcet node from Project tree, are showed all the sequences that compounds the Grafcet sequence. You can access each sequence making double click in the Grafcet item or directly from each item in the Grafcet node.
Be careful with the Steps and Transitions names. This follows the same rules that Variables names declarations, is not allowed spaces, or not valid characters.
57
Transitions also can be programmed in Function Blocks language. When a Transition is created in this language a new action block is created labelled with transition keyword. When this block is activated, the transition will be true.
58
2.5 HMI
In the HMI Project node are programmed the HMI screens of the project. With the HMI System application it is possible to create a visual interface between the user and Virtual PLC, for example you can show messages, images, values of the variables or data blocks, introduce values and much more. EasyPLC offers a tool to create easily screens for the HMI System program, this tool is integrated in the programming environment and allows to create the screens dragging the desired controls from the Control Tools window to the Screen creation area, after is possible to customize the controls behaviour, selecting the available options from the Controls Property grid. If you need more advanced behaviour you can write C# script code in order to customize totally the HMI Screen, controlling the controls events, timers and forms. Lets see the HMI Interface available in EasyPLC Editor.
59
Copy Button: used to copy the current selected control Paste Button: pastes the previously copied control. Control Properties: changes the current selected control properties, is possible to change the control order in the form, and program the control events. Delete control: deletes the current selected control Test HMI Page: This will launch the current screen in test mode in order to see the results.
Controls Tools:
Offers two tabs, one with standard windows controls and other with specialised graphical controls to add in the HMI screen. To add a control click on it in the control tool tab and then click in the Screen creation area in order to place it.
Here you can place and move the added controls, also is possible to change the form properties clicking on it.
Property Grid:
Here is possible to write the C# script code for the screen behaviour customization.
Example
Now an example is showing about how to create a simple screen. 1. Create a new project, then go to Variables node and create two new variables like the example.
2. Create a new Ladder sequence and two segments like the example.
60
3. Right click on the HMI Project node, select New HMI Page.
4. Click on the new HMI Page node created, then the screen will be showed.
5. Click on the Button control from Control Tools window. The mouse cursor will change to a cross shape, then click on the screen creation area in order to place it in the desired place.
61
7. In the property grid, change the Text property, and type Automatic On, then the button text will change for the new one.
8. Now change the Linked Variable property, and select form the variables list Automatic.
62
9. Now change the Linked Variable property, and select form the variables list Automatic. 10. Click on the Label control from Controls Tools window, and place it in the screen area.
11. Click on the Label control from Controls Tools window, and place it in the screen area. Change the Text property for Value:
12. Add a new Label control and change the Text property for 0 value, change ForeColor and Font properties like in the example. Then change Linked Variable for Num.
63
13. Select the button control, and press Tool bar copy button.
14. Press Tool bar paste button. Click on the new button and place it in the new location.
Now the program is showed in run mode, if the HMI Automatic On button is pressed, will activate the digital output 0.0, if the digital input 0.0 is activated the Num variable will be incremented in one unit, this value will be refreshed in the HMI label control linked with this variable.
64
The HMI System is composed by all the created screens in the HMI node project. When the HMI System application will be started, the screen with the StartUpPage property set to true will be launched. The screens also can be called with C# Script code, using the HMI.ShowHMI(screenName) method, for example using the click controls event.
65
Important tools are the external HMI Controls. These controls have a special behavior. Can be added to EasyPLC copying the necessary dll files inside the EasyPLC\ and HMILib\ folders. These controls can be made by the users, allowing a total customization of the HMI system.
The events of these controls must be programmed directly in the script code.
66
67
ChartPoints(serieName, values, chartName, legend, chartType none string serieName, double[] values, string chartName, bool legend, int chartType Draws a serie values in the chartName Chart control. If legend true shows the legend, chartType is the Chart type (from 0 to 9) ClearChart(chartName) none string chartName Clears the Chart control MessageBox.Show("text") none string text Displays a standard Windows Message Box HMIScreen The current Form object
Function Name: Returned Value: Parameters: Function Description: Function Name: Returned Value: Parameters: Function Description: Object Object Description
Click on the Tool Bar Control properties button, and select Events, then a list about the available events for the selected control will be shown. From the list select Click event.
68
In the below area the Script Programming Window will appear, if you press F2 key, the HMI Script code Wizard will be shown, making double click in the desired function will be added to the script programming window.
Write the code showed in the example, as you see, the Controls added in the screen can be referenced in the code with their name. The controls have some common properties like Text, Location, Name, and more that we can use in the code. Then with this program when the user presses the button Read Data Block, the Label3 control will show the value of the element number 2 of the data block number 0. The Label3 Text property is a string type, but the ReadDB function returns a object type, then is necessary to make a conversion operation, is possible to use the C# ToString() method to convert form any kind of type to string type.
69
Controls Events
The controls have some common properties and others have special ones, here is described some of the special properties. Common event for controls:
Click: event launched when the user makes click on the control.
Click: event launched when the user makes click on the form. Double click: launched when the user makes double click on the form. Form Closing: launched when the user makes closes the form. Common. This is not an event, the code writing here is available for all the controls in the screen (useful to make global variables declarations). Key Down: launched when the user pressed any key in the form. Load: launched when the form is loaded the first time.
Check Box:
Checked changed: launched when the user changes the check box mark.
Combo Box:
Selected Index changed: launched when the user changes the current combo box selected value.
Data Grid:
Cell Content Click: launched when the user makes click inside a cell.
Check Box:
Checked changed: launched when the user changes the check box mark.
Scroll Bars:
Scroll: launched when the user changes the scroll bar value.
Check Box:
Timer:
Checked changed: launched when the user changes the check box mark.
Tick: launched every tick Timer elapsed time, this time is configured in the Interval property of the timer.
Check Box:
Checked changed: launched when the user changes the check box mark.
70
HMI Configuration
The HMI offers the following configuration possibilities.
Local mode: both programs are running in the same computer. Remote mode: Virtual PLC CPU and HMI System are running in different computers connected in the same net. To configure this communication mode is necessary to type the IP address and the Port of the computer that is running Virtual PLC CPU.
71
When the program makes the compilation, compiles each sequence one by one separately, but could be necessary if the project requires it, make a special compilation, where the program compiles the sequences all together, to do it select from menu -> Program -> Compile -> Compilation Options. Then a windows appears, where is possible to insert command line parameters for the compilation. Available commands:
\nocheck
Once the program is compiled, is necessary to transfer it to Virtual PLC CPU, to do it, launch Virtual PLC CPU (if is not running), is possible also to launch it from EasyPLC Editor tool bar. Then EasyPLC Editor must to be connected with Virtual PLC CPU in order to transfer the logic program. Press Connect OnLine with PLC to connect, or press menu Connection -> Connect with Virtual PLC. When connected, press Transfer Program to PLC tool bar icon or from menu Program -> Transfer to PLC. A progress bar will indicate the transfer status. A faster way is possible, if you press Compile and Send from tool bar or click on menu Program -> Compile and Transfer, then automatically will be done the compilation and the transfer of the program to Virtual PLC CPU. When a compilation is made, the object code of the program is saved inside it. When the program is transferred to Virtual PLC, a new file is created in the \Slot\ folder of EasyPLC installation path. This file is called logic.cmp and has all the necessary information to run the program by Virtual PLC CPU and for HMI System (if the logic program has screens). If the program is transferred in local mode, the file is copied locally, if is transferred in remote mode, Virtual PLC will generate it.
72
2.8 Printing
The logic programs can be printed. If you want to print your program, select Program -> Print Program from EasyPLC Editor menu. The Print Program Window appears and the user can select the sequence to be printed. Also is possible to select the printer, and change the zoom factor, useful for the graphic diagrams that must to be resized in order to fill it in the page. When the sequence is selected to be printed, the preview printer window appears in order to see the final results before to be printed.
73
Upload a logic program (from EasyPLC to Virtual PLC) Download a program (from Virtual PLC to EasyPLC) Make a program debug, is possible while the program is running: o See Variables values o See Data blocks values. o See Graphic sequence status: the Ladder, Function Blocks and Grafcet sequences can show how their elements are changing during the program running. o Force variables.
The communication between EasyPLC and Virtual PLC CPU can be local or remote:
Local: the communication is done in the same machine. Remote: the communication is done in different computers connected to the same net.
To connect with Virtual PLC CPU from other computer connected in the same net, is necessary to set the Virtual PLC CPU Hardware parameters, indicating the IP address of the computer where Virtual PLC will be running and the listening Port.
The listening Port must be opened in the Firewall software available in the computer where Virtual PLC CPU is running.
74
In order the communication between EasyPLC editor and Virtual PLC CPU will be made successfully, Virtual PLC CPU must be running. To start the communication press Connect On-Line with PLC tool bar icon or select Connection -> Connect with Virtual PLC CPU from EasyPLC Editor menu. Once connected, the Editor will show the Virtual PLC Status.
75
Also is possible to transfer the program form Virtual PLC CPU to EasyPLC Editor, this is called a download program operation. To download a program, EasyPLC must be connected with Virtual PLC, then press the Transfer Program from PLC tool bar button, or select Program -> Receive from PLC in EasyPLC menu. When EasyPLC is connected to Virtual PLC CPU, is possible to change the PLC working status clicking in the tool bar buttons: An important EasyPLC feature is the possibility to see the graphic languages progress while the Virtual PLC is running the logic program, EasyPLC Editor must be connected with Virtual PLC in order to allow this feature. In the next item is explained how.
76
In red color is showed the active items. Also the Variables and Data Blocks states can be read.
Using this tool is possible to debug the logic programs, and to detect software or hardware anomalies. The Script C# language is the only is one without debug mode.
77
Read/Force PLC Items only is available when EasyPLC Editor is connected with Virtual PLC CPU
78
None: then the editor won't open any program when start. Last Project: the editor will open the last loaded project. Select Project: the editor will open the selected project.
Also is possible to change the Font name and size of the Ladder and Logic Blocks Languages.
79
Other important tool is the possibility to unlock the logic program, then users can not modify it, but can run it with Virtual PLC and can transfer it. To protect a program, click on the program node name with right mouse button and select Project Properties, then in the project description window, select the check box Protect Logic Program. You must to inset a password. Once finished save the program, when you restart EasyPLC the program must to be locked.
To unlock the logic program, you must to select Program -> Program Password and type in the password window the correct password.
80
If you click with mouse right button a menu appears where is possible to:
View the PLC Rack. Change PLC Mode. Exit and close Virtual PLC CPU.
Clicking in the View PLC CPU Rack, will open the visual interface of Virtual PLC CPU. From this interface is possible to make some PLC operations like:
Change the PLC working status. Reset PLC program. Launch HMI System application. See connection parameters and status. See I/O status bits. See CPU clock parameters. See PLC Cycle Time Graph.
81
In Stop mode the PLC is stopped and the logic program is not executed. In Run Mode the PLC is executing the logic program cyclically; making the PLC scan cycle: the PLC program is executed as part of a repetitive process referred to as a scan. A PLC scan starts with the CPU reading the status of inputs. The application program is executed using the status of the inputs. Once the program is completed, the CPU performs internal diagnostics and communication tasks. The scan cycle ends by updating the outputs, then starts over. The cycle time depends on the size of the program, the number of I/Os, and the amount of communication required. Busy Mode: this mode is set when EasyPLC Editor transfers a program to Virtual PLC, once the program is loaded, Virtual PLC pass to Stop mode.
3.3.1 CPU
In the CPU module is possible to:
View current PLC working mode. Change PLC Mode to Run/Stop modes.
3.3.2 Communication
In the Communication module is possible to see if EasyPLC Editor is connected or not.
Yellow light in connector: EasyPLC Editor is not connected. Green Light: EasyPLC Editor connected.
In order to connect with EasyPLC Editor in remote mode, is necessary to type the IP address of the computer where is running Virtual PLC CPU, if you click on the first Status Bar icon, you will see the available computer IP address to parameterize in the Virtual PLC CPU node of the EasyPLC Hardware Project tree.
82
83
Close communication with drivers. Reset all variables. Reset all Data Blocks.
84
4. HMI System
The HMI system will show and manage all the HMI screens available in the project. These screens make up the man machine interface for the exchange of information between the plc and the user. HMI System program can be launched from:
EasyPLC Editor menu (select Connection -> Launch HMI System). Virtual PLC CPU menu (select HMI -> Launch HMI Application). Executing directly the file HMI_System.exe.
HMI System can run in local mode (in the same computer where is running Virtual PLC) or in remote mode (in a different computer connected in the same net). You must to be careful in the case HMI System is running in remote mode, because the logic program executed by Virtual PLC, located in the \Slot\ logic.cmp of the remote machine, must to be copied manually in the computer where is executing HMI System (in the location \Slot\ logic.cmp). When the program starts, will load the screen selected as default, and will be in communication with Virtual PLC CPU, executing the screens programs.
If the project does not have screens, HMI system will be empty. In the bottom status bar will display the status and connection mode of the PLC.
85
Here an example is showed of a HMI screen running with Virtual PLC CPU. Pressing the command buttons is possible to change PLC variables values, also using the chart contro,l the value of variables are showed in a graphic format.
86
APPENDIX
4.1 EasyPLC Script C# Language Quick Guide
C# is case-sensitive. Semi colon (;) is the statement separator. Data Types
Arrays
String Operations
87
Struct
Enum
88
89
Language Fundamentals
90
Class Definition
91
Keywords
Keywords are predefined reserved words with special syntactic meaning. The language has two types of keyword contextual and reserved. The reserved keywords such as false or byte may only be used as keywords. The contextual keywords such as where or from are only treated as keywords in certain situations
C# keywords, reserved words abstract as base bool break by byte case catch char checked class const continue decimal default delegate do double descending explicit event extern else enum false finally fixed float for foreach from goto group if implicit in int interface internal into is lock long new null namespace object operator out override orderby params private protected public readonly ref return switch struct sbyte sealed short sizeof stackalloc static string select this throw true try typeof uint ulong unchecked unsafe ushort using var virtual volatile void while where yield transition Transition
Literals
Integers hexadecimal decimal float double date char
0xF5, 0x[0..9, A..F, a..f]+ 245, [0..9]+
Floating-point values
23.5F, 23.5f; 1.72E3F, 1.72E3f, 1.72e3F, 1.72e3f 23.5, 23.5D, 23.5d; 1.72E3, 1.72E3D, ...
Dates
not possible
Characters
'a', 'Z', '\u0231'
92
Strings String
"Hello, world" "C:\\Windows\\", @"C:\Windows\"
Characters escapes in strings Unicode character \u followed by the hexadecimal unicode code point \t Tab \b Backspace Carriage return \r \f Form feed \\ Backslash \' Single quote Double quote \" \n Line feed
Constants
Constants are values that are immutable and can not change.
const
When declaring a local variable or a field with the const keyword as a prefix the value must be given when it is declared. After that it is locked and cannot change. They can either be declared in the context as a field or a local variable. Constants are implicitly static. const double PI = 3.14;
Operators Operator category Operators + - * / % Arithmetic & | ^ ! ~ && || Logical (boolean and bitwise) + String concatenation ++ -Increment, decrement << >> Shift == != < > <= >= Relational = += -= *= /= %= &= |= ^= <<= >>= Assignment . Member access [ ] Indexing ( ) Cast ? : Conditional Delegate concatenation and removal + new Object creation as is sizeof typeof Type information checked unchecked Overflow exception control * -> [] & Indirection and Address 93
Mathematic Operations
Below are the mathematical functions available for all languages.
FUNCTION
Sin(float v) Sin(double v) Cos(float v) Cos(double v) Tan(float v) Tan(double v) Asin(float v) Asin(double v) Acos(float v) Acos(double v) Atan(float v) Atan(double v) Abs(float v) Abs(double v) Pow(float v, float y) Pow(double v, double y) Log(float v) Log(double v) Log10(float v) Log10(double v) Sqrt(float v) Sqrt(double v)
RETURNS
Returns the sine of the specified angle (float) Returns the sine of the specified angle (double) Returns the cosine of the specified angle (float) Returns the cosine of the specified angle (double) Returns the tangent of the specified angle (float) Returns the tangent of the specified angle (double) Returns the angle whose sine is the specified number (float) Returns the angle whose sine is the specified number (double) Returns the angle whose cosine is the specified number (float) Returns the angle whose cosine is the specified number (double) Returns the angle whose tangent is the specified number (float) Returns the angle whose tangent is the specified number (double) Returns the absolute value of a floating-point number. Returns the absolute value of a double-precision floating-point number. Returns a specified number raised to the specified power (float) Returns a specified number raised to the specified power (double) Returns the natural (base e) logarithm of a specified number (float) Returns the natural (base e) logarithm of a specified number (double) Returns the base 10 logarithm of a specified number (float) Returns the base 10 logarithm of a specified number (double) Returns the square root of a specified number (float) Returns the square root of a specified number (double)
94
Function Add is written oin script code, return an integer value and are passed two parameters of integer type. Function Activate is written in ladder none is returned and is passed to Boolean values. Alarms function is written in logic blocks language, none returns and is passed three boolean values. Lets see the functions codes:
95
You can see how the parameters declared in the functions can be used in the different languages to operate with them. Now lets see how these functions can be called from other sequences (or functions):
96
In this example, in Main_Sequence_1 (Ladder) is used the special coil Function, there is possible to call to the declared functions (in any language written) and passing the parameter with variables or constants. In Main_Sequence_2 (script) is show how to call the Alarms function.
97
Functions can be exported and/or imported, to do it select from menu Program -> Export/Import Functions or from program tree in Functions node, right mouse click and select Export/Import Functions.
Functions can be exported and/or imported, to do it select from menu Program -> Export/Import Functions or from program tree in Functions node, make right mouse click and select Export/Import Functions. Then in the new window, you can export the defined functions in your program, selecting the desired one in the Export list and clicking in the Export Function to File. To import a function form other program, press Import Function from File button, then a dialog box appears to select the file that contains the previously exported function.
98
More
Please visit often www.nirtec.com web site and Nirtec forum to check for new information, updates and new articles like new tutorials or programming examples. I hope you enjoy EasyPLC Software Suite. If you have some question or doubt, please email me to: Info@nirtec.com easyplc@nirtec.com
99
Idea, Design & Programming by Rafael Izquierdo Valencia (Spain) Copyright Rafael Izquierdo 2011
www.nirtec.com
100