4 Situación sociodemográficadel medio rural
4. SITUACI ´ ON SOCIODEMOGR ´ AFICA DEL MEDIO RURAL
4.4. Convivencia con personas en Situaci ´on de Dependencia 10
All the operation with variables must be done following the C language Syntax. In the following example there are three contacts that carry out comparison operation with variables, if all comparisons are true (segment true), three assignments of variables take place in the coils. Look how variable T1 (int type) is compared with 1 value ( == ), Value (float type) is checked grater that 45 and DelayTime (long type) must be different from variable WaitTime (long type). If the segment is true,
variable IntVar (int type) is assigned with value, variable T2 (int type) is incremented in one unit (++) and variable Message (string type) is assigned with the string “HELLO”.
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.
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.
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.
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.
2.4.1.9 Data Blocks
With Ladder language is possible make operations with Data Blocks.
Data Blocks Coils
To add a new Data Block coil press on the Ladder Tool bar Data Block Coil
If you make double click on the Data Block, the Data Blocks Parameters will open in order to parameterize the coil. First select the Data Block you want to work, then select the element number. Finally select the operation you want to assign when the segment condition will be true, for instance assignations (with numeric constants or variables) or operations allowed for the type of data that make up the Data Block.
If Run on Trigger is marked, the coil operation will be done once when the segment value pass form false to true, by default the coil operation will be done by level, this means the coil Data Block operation will be done while the segment condition will be true.
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
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.
2.4.1.10 Function Call
Other special coil is the Function Call. To add a Function Call coil press on the Ladder Tool bar Function Call coil.
This coil allows making a call to a previously defined function, configuring the passing parameters and the returned value (if it has it).
Once the coil is created, is necessary to select the function on the combo box control.
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.
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.
2.4.1.11 Register Transfer
The Register Transfer coil allows making common PLC register transfer operations. To add a Register Transfer coil press on the Ladder Tool bar Register Transfer coil.
Use the Register Transfer coil for transferring the status of the selected Input register to the selected register output. Also is
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.
2.4.1.13 Shortcuts Keys
The following short-cuts keys are available for ladder language:
• 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.
2.4.1.14 Special Coil (Return)
A special coil is available in Ladder language, the Return Coil. This coil allows breaking the current flow of the sequence, and jumping to the following sequence without finish the current where the return command is executed. Example:
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.
2.4.2 Script Language
EasyPLC sequences can be programmed using a Script language.
The EasyPLC Script language uses the C# syntax. You can find more information about EasyPLC C# language in the Appendix.