Escolar Documentos
Profissional Documentos
Cultura Documentos
Users Guide
Version 1.7
Disclaimer Every effort has been made to ensure the accuracy of the information in this guide. However, Techno Trade S.A. assumes no responsibility for the accuracy of the information. Product information is subject to change without notice. TWinSoft and A are registered trademark of Techno Trade s.a.
Windows '95, '98, NT, 2000, XP are trademark of Microsoft Corp. Internet Explorer is a trademark of Microsoft Corp.
Version: 1.7
TABLE OF CONTENTS
1. PROGRAMS - BASIC ........................................................................................... 9
1.2. GENERAL ........................................................................................................ 10 1.2.1. Case ................................................................................................................... 10 1.2.2. Variable not declared ........................................................................................... 10 1.2.3. Statements and 'Line Feed'................................................................................... 10 1.2.4. Colors ................................................................................................................. 10 1.2.5. Access from the process to the variable................................................................. 10 1.2.6. Cycle time ........................................................................................................... 11 1.2.7. Distinction between Local Global System variables ........................................... 11 1.2.8. Break Line ........................................................................................................... 11 1.2.9. Precautions / Miscellaneous .................................................................................. 12 1.3. COMMENT ....................................................................................................... 13 1.4. CONSTANT ...................................................................................................... 13 1.5. ASSIGNMENT ................................................................................................... 14 1.6. DIM STATEMENT ............................................................................................... 15 1.7. COMPARISON ................................................................................................... 16 1.8. IF ...THEN ... ELSE ELSEIF STATEMENT ............................................................... 17 1.9. ARITHMETIC OPERATORS ..................................................................................... 19 + (Addition) ............................................................................................................. 19 - (Subtraction) ....................................................................................................... 19 * (Multiplication) ................................................................................................. 20 / (Division) ........................................................................................................... 20 Modulo Operator ........................................................................................................ 21 1.10. LOGICAL OPERATORS .................................................................................... 22 Introduction...................................................................................................................22 AND .............................................................................................................................. 22 OR ................................................................................................................................ 23 XOR .............................................................................................................................. 23 NOT .............................................................................................................................. 24 1.11. 1.12. FOR...NEXT ...STEP
STATEMENT
..................................................................... 25
WHILE...WEND ........................................................................................... 27
1.13. MATHEMATICAL FUNCTIONS ............................................................................ 28 Trigonometric ................................................................................................................ 28 Logarithmic....................................................................................................................29 Exponential.................................................................................................................... 29 Power............................................................................................................................ 30 Square root ................................................................................................................... 30
Version: 1.7
1.14. FUNCTIONS (VARIOUS).................................................................................. 31 INC................................................................................................................................33 DEC ...............................................................................................................................33 ABS ...............................................................................................................................33 LOBYTE .........................................................................................................................34 HIBYTE..........................................................................................................................34 LOWORD .......................................................................................................................34 HIWORD........................................................................................................................35 SWAPBYTES...................................................................................................................35 SHL ...............................................................................................................................35 SHR...............................................................................................................................36 Bit .................................................................................................................................36 SetBit ............................................................................................................................36 PackBits .........................................................................................................................37 SplitBits .........................................................................................................................38 Split32 ...........................................................................................................................39 Pack32...........................................................................................................................39 TriggerPos .....................................................................................................................40 TriggerNeg.....................................................................................................................40 PutChrono......................................................................................................................41 Truncate ........................................................................................................................41 Odd ...............................................................................................................................41 BCD...............................................................................................................................42 Sampling tables..............................................................................................................42 Type Casting ..................................................................................................................43 1.15. TIMERS / COUNTERS .................................................................................... 44 1.16. INDIRECT ADDRESSING .................................................................................. 44 Reading functions...........................................................................................................44 Writing functions ............................................................................................................44 Initialization of a Pointer .................................................................................................44 1.17. 1.18. 1.19. GOTO ..................................................................................................... 45 KEYWORDS ................................................................................................ 46 POU........................................................................................................ 47
1.20. POU PROGRAM ........................................................................................ 48 1.20.1. The Program 'Main'...........................................................................................48 1.20.2. Creating a Program...........................................................................................49 1.20.3. Calling a Program .............................................................................................49 1.21. 1.22. POU FUNCTION ....................................................................................... 50 POU FUNCTION BLOCK .............................................................................. 53
Version: 1.7
2.
2.2. LADDER PRINCIPLE ......................................................................................... 58 2.2.1. Inputs ................................................................................................................. 58 2.2.2. Outputs ............................................................................................................... 58 2.2.3. Cycle time ........................................................................................................... 59 2.3. LADDER - MODES.............................................................................................. 59 2.3.1. Display mode....................................................................................................... 59 2.3.2. Edit mode............................................................................................................ 60 2.4. LADDER - TOOLBAR ........................................................................................... 61 2.4.1. Display mode....................................................................................................... 61 2.4.2. Edit mode............................................................................................................ 62 2.5. VARIABLES ...................................................................................................... 63 2.5.1. Local Tags ........................................................................................................... 63 2.5.2. Global Tags ......................................................................................................... 63 2.5.3. The colors of the Tags.......................................................................................... 63 2.6. CREATE LADDER DIAGRAM ................................................................................... 64 2.6.1. Inserting items .................................................................................................... 65 2.6.2. The colors of the Tags.......................................................................................... 65 2.6.3. The Keys ............................................................................................................. 65 2.7. STEP BY STEP CREATING OF LADDER ....................................................................... 66 2.8. DRAWING LINES IN LADDER . ............................................................................. 70 2.9. FUNCTIONS ..................................................................................................... 71 2.9.1. Analog Comparison Functions ............................................................................... 72 2.9.2. Special Functions ................................................................................................. 72 2.9.3. Timer & Counter Functions .................................................................................. 73 2.9.4. Math. Assignments functions ................................................................................ 73 2.9.5. Math. Arithmetic functions .................................................................................... 74 2.9.6. Math. Bitwise functions ........................................................................................ 74 2.9.7. Math. Shift functions ............................................................................................ 75 2.10. MATHEMATICAL BLOCK .................................................................................. 76 2.10.1. Introduction..................................................................................................... 76 2.10.2. Assignments .................................................................................................... 78 2.10.3. Arithmetic operations ....................................................................................... 78 2.10.4. Comparisons .................................................................................................... 79 2.10.5. Bit manipulations.............................................................................................. 79 2.10.6. Boolean operations........................................................................................... 80 2.10.7. Conversion + Indirect addressing ...................................................................... 81 2.10.8. Miscellaneous................................................................................................... 82 2.11. POU (PROGRAM ORGANIZATION UNITS)............................................................ 83 2.12. POU PROGRAM ........................................................................................ 84 2.12.1. The Program 'Main' .......................................................................................... 84 2.12.2. Creating a POU Program ................................................................................... 84
Version: 1.7 BASIC & Ladder 5
2.12.3.
2.13. POU FUNCTION ....................................................................................... 86 2.13.1. Creating a POU Function ...................................................................................86 2.13.2. Example of a Function ......................................................................................88 2.13.3. Calling a POU Function in a POU Program ..........................................................89 2.14. POU - FUNCTION BLOCK ............................................................................... 90 2.14.1. Creating a POU Function Block ..........................................................................90 2.14.2. Example of a Function Block..............................................................................92 2.14.3. Calling a POU Function Block in a POU Program .................................................93 2.14.4. Debugging of a Function block ..........................................................................94
3. TIMERS.............................................................................................................95
3.1. PRESENTATION ................................................................................................. 95 3.2. INTRODUCTION ................................................................................................ 96 3.3. CREATING A TIMER............................................................................................ 96 3.4. THE VARIABLES OF A TIMER ................................................................................. 97 3.5. USING TIMERS IN LADDER ................................................................................... 98 3.5.1. The instance name ...............................................................................................98 3.5.2. The Preset ...........................................................................................................99 3.6. USING TIMERS IN BASIC.................................................................................. 100 3.6.1. Reminder...........................................................................................................100 3.6.2. Syntax ...............................................................................................................100 3.6.3. Reset Timer Function..........................................................................................101 3.6.4. Examples ...........................................................................................................101 3.7. USING TIMERS IN POUS .................................................................................. 101 3.8. TIMER SINGLE SHOT ..................................................................................... 102 3.9. TIMER MONOSTABLE ..................................................................................... 103 3.10. 3.11.
4.
4.1. PRESENTATION ............................................................................................... 107 4.2. INTRODUCTION .............................................................................................. 108 4.3. CREATING A COUNTER ...................................................................................... 108 4.4. THE VARIABLES OF A COUNTER ........................................................................... 109 4.5. USING COUNTERS IN LADDER ............................................................................. 110 4.5.1. The contact used with the pulse input .................................................................110 4.5.2. The instance name .............................................................................................110 4.5.3. The Preset .........................................................................................................111 4.6. USING COUNTERS IN BASIC .............................................................................. 112 4.6.1. Reminder...........................................................................................................112 4.6.2. Syntax ...............................................................................................................112 4.6.3. Reset Counter Function ......................................................................................112
Version: 1.7 BASIC & Ladder 6
4.7. USING COUNTERS IN POUS............................................................................... 112 4.8. COUNTER - UP............................................................................................... 113 4.9. COUNTER - DOWN......................................................................................... 114 4.10.
5.
5.1. IMPORT OF POUS (SAVING POUS IN A LIBRARY) ..................................................... 119 5.2. EXPORT OF POUS (RETRIEVAL OF POUS FROM A LIBRARY) ......................................... 120 5.3. USE OF A LIBRARY IN A TWINSOFT DOCUMENT........................................................ 120
Version: 1.7
Version: 1.7
1. Programs - BASIC
TBOX MS and TBOX LITE support 2 languages: BASIC and Ladder. Both languages are used to execute process automation BASIC is a text language, very easy to use for making calculation. It supports all advanced mathematical functions. LADDER is a graphical language, which should be preferred when Boolean operations are required. LADDDER is much more efficient than BASIC for handling digital Tags.
BASIC and LADDER can be used together We suggest that you divide your process into several programs ( sub-programs) depending on the process concerned. According to the kind of process, you create programs in BASIC and programs in LADDER. Then you combine programs as you want: BASIC calling LADDER and reciprocal. This chapter explains the syntax of BASIC. To see an example, load the TWinSoft document 'MSBASIC.tws' that you find in the 'Samples' directory of TWinSoft.
Example:
' This is my first program If (Temperature > 70) or (Emergency=1) then Pump=1 Alarm=1 endif
Version: 1.7
1.2. General
1.2.1. Case
BASIC is not case sensitive.
Or a=50 : b=c
1.2.4. Colors
Comment : Constant : Keyword : Variable : the comments appear in green color a constant appears in red color a keyword appears in blue color (see the list at chapter 1.18) a variable appear in black color
Version: 1.7
10
1. To use System variables without declaring them as Tag, the suffix is mandatory. 2. If there is no suffix, the order of resolution is local Tag if it exists, then global Tag if it exists. Otherwise the compiler returns an error. 3. The suffix cannot be declared within a DIM statement (it is clear that the variable will be local).
Examples:
dim Temperature as integer if Temperature@ > 20 then if triggerpos(prgrun!) then ......
Temperature@ is the global Tag, if it exists, otherwise the compiler returns an error. It will not use the local Tag.
Examples:
If A=0 Or B=0 Or C=0 Or D=0 Or E=0 Or F=0 Or G=0 Or H=0 Or_ I=0 Or J=0 Or K=0 Or L=0 Or M=0 Or N=0 Or O=0 Or_ P=0 Or Q=0 Or R=0 Or S=0 Or T=0 then output=0 endif
Version: 1.7
11
With Timer/Counter functions, if you wish to associate a Tag to Value and/or Preset, they must be of type DWORD (32 bits).
Version: 1.7
12
1.3. Comment
Rules A comment can start with the keyword REM or with the single apostrophe ' REM : is considered as a statement. It can then only be used at the beginning of a line. ' : is not a statement. It can then be placed anywhere in the line. Examples
REM this is a comment ' this is a comment var1=var2 ' var2 is assigned to var1
1.4. Constant
Rules Constant statement can be expressed in: decimal hexadecimal (with prefix &H) floating point Limits To be accepted, the constant must hold into a INT 32 bits or into a IEEE 32 bits Floating. The 'time span' is limited to 49 days. Examples
a=123456 a=&H1E240 a=123.456
In an arithmetic operation, a constant is always converted into the format of the Tag it is associated to.
Integer / 2.5
Version: 1.7
13
1.5. Assignment
Syntax
' variable ' indexed variable, part of a table (array) VarName=expr Table[x]=expr
[x] is the index of the variable in the table. Only square brackets [ ] can be used. The keyword LET can be used but is optional: LET a=b
Indexing With a local variable 'simple', indexing is not allowed. With a local variable 'array', index must be specified with the Dim statement. With a global variable, indexing is allowed. The variable is then considered as the first of a virtual table composed of successive ModBus addresses. See For...next statement. with Global Tags. Examples
Temperature=Setpoint Delay=5 LET StartPump[2]=1
Version: 1.7
14
Table (array)
Dim Table[n] <as Type> ' Table is an array of n elements (1 to n) ' The types of the elements can also be declared
Each variable of the table can be represented with the name of the table and its index:
Table[1] Table[2] ....
Types available Types BOOL BYTE INTEGER WORD (*) LONG DWORD SINGLE description 1 bit - Digital 8 bits - Unsigned 16 bits - Signed 16 bits - Unsigned 32 bits - Signed 32 bits - Unsigned 32 bits - Float IEEE
(*) WORD is the default format when the type is not declared, or when a local Tag is used without Dim statement. Examples
Dim Temperature as Single Dim input2 as Bool Dim table[4] as Word
Version: 1.7
15
1.7. Comparison
The available comparison operators are: = < <= > >= <> : equal than : smaller than : smaller or equal than : bigger than : bigger or equal than : different
The comparison returns a Boolean result. It can be used to compare 2 numbers and get the result in a Bool, or in a sequence as condition; for instance if ..then. Syntax
Arguments
result :Bool expression :any expression composed of Bool, Byte, Word, Long, Float
Version: 1.7
16
In this example: If Condition1 is TRUE, Statement 1 and 2 are executed. If Condition1 is FALSE, Condition2 is tested. If Condition2 is TRUE, Statement3 is executed otherwise Statement4 is executed
Several Statements on the same line: the Statements must be separated by colons:
If Condition then Statement1 : Statement2 endif
Several If ... then statements chained It is possible to chain several If ... then statements. In such case, each of them must end with endif keyword.
If Condition1 then Statement1 If Condition2 then Statement2 endif endif
Arguments Condition The condition is Boolean. It can be any expression resulting in TRUE or FALSE status.
Examples:
If Button then If not Button then (is equivalent to: if Button=1 then) (is equivalent to: if Button=0 then)
Version: 1.7
17
Version: 1.7
18
Arguments
result :Byte, Word, Long, Float expression :any expression composed of Bool, Byte, Word, Long, Float
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' Examples
'Result in 'Word' format with Float rounded 'Result in Float
Word1=Word2+Float2+Float3 Float1=Word2+(Float2*2)
- (Subtraction)
Gives the difference between numbers or used to change a number to negative. Syntax
Arguments
result :Byte, Word, Long, Float expression :any expression composed of Bool, Byte, Word, Long, Float
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' Examples
'Result in 'Word' format with Float rounded 'Result in Float
Word1=Word2-Float2-Float3 Float1=Word2-(Float2*2)
With Addition and Subtraction, according to the types used, (Byte, Word or Int) be attentive to roll over
Version: 1.7
19
* (Multiplication)
Multiplies numbers. Syntax
result=expression1*expression2*expression3 ...
Arguments
result :Byte, Word, Long, Float expression :any expression composed of Bool, Byte, Word, Long, Float.
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' if expression1 and expression2 are WORD, the result is automatically changed to DWORD. This avoids over range problems. The rules are: BYTE * BYTE = WORD (16 bits) WORD * WORD = DWORD (32 bits - unsigned) INT * INT = LONG (32 bits - Signed) Examples
'Result in 'Word' format with Float rounded 'Result in Float
Word1=Word2*Float2*Float3 Float1=Word2*Float2*2
(Division)
Syntax
Divides numbers.
result=expression1/expression2/expression3 ...
Arguments
result :Byte, Word, Long, Float expression :any expression composed of Bool, Byte, Word, Long, Float
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' When a divisor=0 (zero) the result is unpredictable and depends on the type of 'result' variable. To avoid any problem, you have to check the divisor(s) before executing the division(s)
Examples
if (Float2>0) and (Float3>0) then Word1=Word2/Float2/Float3 'Result in Word with Float rounded endif if (Float2>0) then Float1=Word2/Float2/2 endif
'Result in Float
Version: 1.7
20
Modulo Operator
Divides 2 numbers and returns the remainder Syntax
result=number1 % number2
Arguments
You can mix numbers of 'Word' and 'Long' types together: the type of the numbers are automatically converted to the type of the 'result' Both numbers must be positive. If one number = 0 then result = 0
Examples
'Remainder=2
Remainder=47 % 15
Version: 1.7
21
Example:
Bitwise operators Those operators are used between 2 Tags and execute Bitwise operations on each bit of the Tags: AND Operator OR Operator XOR Operator NOT Operator When using several operators, be careful to the priority of the operations. We advise to use brackets to separate clearly the operations. Example: A=2 And B <>3 Without brackets, will be calculated like following: (A=((2 And B)<>3)) With brackets, like it is probably required: (A=2) And (B<>3)
AND
Performs a Bitwise AND operation on 2 expressions.
00110101 11010110 00010100
result :Word or Long expression :any expression composed of Bool, Byte, Word, Long
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' Examples
MyVal=Word1 And 255 'Mask to erase the MSB MyVal=(Word1*2) And Word2
Version: 1.7
22
OR
Performs a Bitwise OR operation on 2 expressions.
00110101 11010110 11110111
Syntax
result=expression1 Or expression2
Arguments
result :Word or Long expression :any expression composed of Bool, Byte, Word, Long
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' Examples
XOR
Performs a Bitwise XOR operation on 2 expressions.
00110101 11010110 11000011
Syntax
Arguments
result :Word or Long expression :any expression composed of Bool, Byte, Word, Long
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' Examples
Version: 1.7
23
NOT
Performs a Bitwise NOT operation on 2 expressions. It inverts the bits.
11010110 00101001
Examples:
Value -2 -1 0 1 2 NOT 1 0 -1 -2 -3 Inversion 2 1 0 -1 -2
Syntax
Arguments
result :Word or Long expression :any expression composed of Bool, Byte, Word, Long
You can mix several types of variables in the 'expressions': it is automatically converted to the type of the variable 'result' Examples
Version: 1.7
24
Be careful using big value for i. With function ForNext, the program jumps out of the routine when all steps have been executed. If there are too many, the program might generate a watchdog. You should then use For nextcycle
x : start index. Any number ( >= 1) n : last index. Any number > x step y : optional. Increment in the index at each next operation.
The Statement is executed once at each cycle of the program: This can be useful to balance the resources of a program, and mandatory when there are a lot of steps.
Dim i as Word For i=1 to n Statement nextcycle i
With local Tags To use index addressing with local Tags, you must declare a table (array) with its dimension and type. It cannot be declared from the list of POU Tags, but using code in the program.
Example:
In this example, [3] is the size of the array. Only square brackets [ ] can be used
Version: 1.7
25
With global Tags As global Tags have been created, they already have a type. The table is composed of the Tag selected and those following by in order of ModBus addresses in the list of Tags. Example: you have 'start' variables you want to activate at the same time. You create the 4 Tags, with successive ModBus addresses. Signal IN IN IN IN 0 1 2 3 Tag
Start1 Start2 Start3 Start4
Dim i as Word For i=1 to 4 Start1[i]=1 next i Start1[2] is then similar to Start2
Version: 1.7
26
1.12. While...Wend
While...Wend statement executes a loop as long as the condition is TRUE. Therefore, the rest of the program is not executed as long as the condition is TRUE. Be careful the loop does not exceed 1 second. A watchdog is generated after about 1.6 second. When it is possible, we advise to use the ForNext or ForNextcycle statements
Argument
Example
Version: 1.7
27
All trigonometric functions work with angles expressed in radian. A circle of 360 degree corresponds to 2 radian
Syntax
Argument
Examples
Calculation of pi Dim a as Single Dim Pi as Single a=arcsin(1) Pi=a*2 Implementation of a sinusoid if triggerpos (PrgRun) then Radian=0 if Radian < (Pi*2) then 'Pi*2 = 360 degrees Radian=Radian + (Pi/180) 'Pi/180 = 1 degree else Radian=0 endif Sine=sin(Radian) Sinusoid=(sine*90) + 200 Degree=(Radian*180)/pi
Version: 1.7
28
Logarithmic
The logarithmic functions supported are Logarithm and Natural logarithm The logarithm is the logarithm having base 10 Log (10) = 1 Log (100) = 2 Log (1000) = 3 The natural logarithm is the logarithm having base e. The constant e is approximately 2.718282. Syntax
Result=Log(x) Result=Ln(x)
Argument
Exponential
Exponential function returns e (the base of natural logarithm) raised to a power The constant e is approximately 2.718282 The Exp function is the complement to natural logarithm function (see above) Syntax Argument
Result=Exp(x)
Version: 1.7
29
Power
The Power function returns the value of a base expression taken to a specified power. Syntax Argument Single or constant Single or constant Single
Result=Pow(base, exponent)
Square root
Returns the square root of a number. Syntax Argument
Result=Sqrt(x)
2 3 4.796 0
Version: 1.7
30
Byte manipulation LOBYTE returns LSB of a WORD HIBYTE returns MSB of a WORD LOWORD returns Word 'Low' of a DWORD HIWORD returns Word 'High' of a DWORD SWAPBYTE switches bytes of a WORD Shift
SHL SHR
Shift left Shift right read a bit a Analog write the bit of an Analog putting bits in an Analog register extracting bits from an Analog register
to work on the positive edge of a digital Tag to work on the negative edge of a digital Tag to force the writing of a value into chrono to extract an Integer from a Float to indicate whether a Tag in Even or Odd to transform a decimal number to BCD format to to to to to check the size of a table access data of a Tag in Byte format access data of a Tag in Word format access data of a Tag in 32 bits-Long format access data of a Tag in 32 bits-Float format
Chrono
PutChrono
Various
Truncate Odd BCD
Sampling Table
Tablesize samplebyte Sampleword sampledword samplesingle
Version: 1.7
31
Type Casting
CBool CByte CDWord CInt CLng CSng CWord
to to to to to to to
Boolean format Byte format 32 bits-Long format (Unsigned) Integer format (Signed) 32 bits-Long format (Signed) 32 bits-Float format Word format (Unsigned)
Version: 1.7
32
INC
The INC function increments a variable (+1). Syntax
inc(Var)
Argument
Example
DEC
The DEC function decrements a variable (-1) Syntax
dec(Var)
Argument
Example
ABS
The ABS function returns the absolute value of any variable. Syntax
Result=abs(Var)
Argument
Version: 1.7
33
LOBYTE
Mask on the lowest Byte of a Word variable.
Example:
Result=LoByte(Var)
Argument
HIBYTE
Mask on the highest Byte of a Word variable.
Example:
Result=HiByte(Var)
Argument
LOWORD
Mask on the lowest Word of a DWord variable.
Example:
Result=LoWord(Var)
Argument
Version: 1.7
34
HIWORD
Mask on the highest Word of a DWord variable.
Example:
Result=HiWord(Var)
Argument
Example
HighestWord=HiWord(Long)
SWAPBYTES
Invert the bytes of a Word variable. Example: inversion Variable: 01111100 11000011 Result: 11000011 01111100 Syntax
Result=SwapBytes(Var)
Argument
SHL
Shift to the left of x bits (without roll over). Example: Shift left of 4 Variable: 00001111 00011000 Result: 11110001 10000000 Syntax
Result=SHL(Var,shift)
Version: 1.7
35
SHR
Shift to the right of x bits (without roll over). Example: Shift right of 4 Variable: 00001111 00011000 Result: 00000000 11110001 Syntax
Result=SHR(Var,shift)
Argument
Bit
This function allows reading a bit in a analog register. The bit number starts at bit0 (lsb).
Example:
bit # Syntax
.. .
0 7
1 6
1 5
0 4
1 3
0 2
1 1
1 0
Result=Bit(Register, BitNumber)
Argument
Result :Bool Register :Word, DWord BitNumber :Constant, Byte, Word, DWord
Example
SetBit
This function allows forcing a bit in an analog register. The bit number starts at 0 (lsb) Syntax
SetBit(Register, BitNumber, Value)
Argument
Register :Word, DWord BitNumber :Constant, Byte, Word, DWord Value :Bool
Example
PackBits
Those functions allow putting a series of addresses of digital Tags into an analog register. There are 3 PackBits functions:
PackBits8: PackBits16: PackBits32:
to put 8 Tags of successive addresses to a Byte register. to put 16 Tags of successive addresses to a Word register. to put 32 Tags of successive addresses to a DWord register.
Syntax
Byte_register = PackBits8(Value) Word_register = PackBits16(Value) DWord_register = PackBits32(Value)
Argument
Register : depending of the function it is a Byte, Word, or DWord Value : it is the ModBus address of the first bit. The value at this address becomes the
'Putting Digital DIR_0 to DIR_15 to register ANA_16 'ModBus address of DIR_0 = 20480 ANA_16 = PackBits16(20480) DIR_0 DIR_1 DIR_2 DIR_3 DIR_4 DIR_5 DIR_6 DIR_7 DIR_8 DIR_9 DIR_10 DIR_11 DIR_12 DIR_13 DIR_14 DIR_15 ANA_16 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 256 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 255 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 32769 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 65535
1. When creating the digital Tags, be sure you reserve enough addresses after the one declared in the function 2. Tags for all addresses do not need to be created, but it is advised to do it to avoid confusion when creating Tags afterwards
Version: 1.7
37
SplitBits
Those functions allow extracting bits from an analog register to a series of ModBus addresses of digital Tags. There are 3 SplitBits functions:
SplitBits8: extract the 8 bits of a Byte to 8 successive ModBus addresses of digital Tags. SplitBits16: extract the 16 bits of a Word to 16 successive ModBus addresses of digital
Tags. SplitBits32: extract the 32 bits of a DWord to 32 successive ModBus addresses of digital Tags. Syntax
SplitBits8(Byte_register, Value) SplitBits16(Word_Register, Value) SplitBits32(DWord_Register, Value)
Argument
Register : depending of the function it is a Byte, Word, or DWord Value : it is the ModBus address of the first bit. The value at this address
'Extracting bits of ANA_16 to DIR_0 ... DIR_15 'ModBus address of DIR_0 = 20480 SplitBits16(ANA_16,20480) ANA_16 DIR_0 DIR_1 DIR_2 DIR_3 DIR_4 DIR_5 DIR_6 DIR_7 DIR_8 DIR_9 DIR_10 DIR_11 DIR_12 DIR_13 DIR_14 DIR_15 256 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 255 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 32769 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 65535 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1. When creating the digital Tags, be sure you reserve enough addresses after the one declared in the function 2. Tags for all addresses do not need to be created, but it is advised to do it to avoid confusion when creating Tags afterwards
Version: 1.7
38
Split32
This function converts one 32 bits register to two 16 bits registers. This can be useful if you have to transfer 32 bits register, using a unique transaction including 16 bits and 32 bits registers. The 32 bits registers will be seen as 2 x 16 bits registers. Syntax
Split32(32bitsReg, Hword, Lword)
Arguments
32bitsReg : Register to split into 2 Words (DWord or Float) Hword : High 16 bits of the 32 bits register (Word) Lword : Low 16 bits of the 32 bits register (Word)
Example
'Converting the Floating register Temperature to TempHigh and TempLow Split32(Temperature, TempHigh, TempLow)
Pack32
This function converts two 16 bits registers into one 32 bits register. Syntax
Pack32(32bitsReg, Hword, Lword)
Arguments
32bitsReg : Register receiving the 2 Words following (DWord or Float) Hword : High 16 bits of the 32 bits register (Word) Lword : Low 16 bits of the 32 bits register (Word)
Example
Version: 1.7
39
Trigger
The Trigger function allows checking a transition in an expression.
TriggerPos
It informs on the transition '0' to '1' of a digital Tag. Syntax
X = TriggerPos(expression)
X = 1 at changing of the expression (FALSE to TRUE) during one cycle of the program. Argument
Examples
'To Set an Output when pressing a start button if TriggerPos(Start) then Output=1 endif 'To initialize a variable at start up of TBox MS Dim Setpoint as Word if TriggerPos(PrgRun!) then Setpoint=123 endif
TriggerNeg
It informs on the transition '1' to '0' of a digital Tag. Syntax
X = TriggerNeg(expression)
X = 1 at changing of the expression (TRUE to FALSE) during one cycle of the program. Argument
Example
'To Reset an Output when pressing a Stop button if TriggerNeg(Stop) then Output=0 endif
Version: 1.7
40
PutChrono
This function forces recording into the chronology. Depending on the type of the Tag selected, the value is written to the Analog chronology or Digital chronology. Syntax
PutChrono(variable)
Argument Tag to insert into the chronology digital Tag (Bool) writing to Digital chronology analog Tag (Byte, Word, Long, Single) writing to Analog chronology
variable :
Examples
then (Button) (Level) (Temperature)
Truncate
This function extracts the whole number from a Tag in Single format. Syntax
Long_register=Truncate(Single_register)
Long_register : Single_register :
Examples
Whole_value = Truncate(Floating_reg)
Odd
This function indicates whether an analog Tag is ODD or EVEN. Syntax
Bool_register=odd(analog_register)
Bool_register : analog_register :
Examples
Ouput=odd(Analog)
Version: 1.7
41
BCD
This function transforms a decimal number to BCD format. BCD format means that each 4 bits is considered as an entity corresponding to 1 number. Syntax
Word_output=bcd(Word_input)
Word_output : Word_input :
Examples
Ouput=bcd(Word)
If Word=4660 then Output=1234 decimal: binary: BCD 4660 0001 0010 0011 0100 1234
Sampling tables
Those functions allow accessing a specific value in sampling table. Those functions let you to take benefit of pre-computed values of sampling table, like illustrated in the example below: Syntax to check the size of a table to access data of a Tag in Byte format to access data of a Tag in Word format to access data of a Tag in 32 bits format to access data of a Tag in Float format
Arguments index of the sampling table (see list of sampling tables) sample you want to access. Offset=0 means the last sample
index: offset:
Examples Imagine you want to calculate the arithmetic average of a value based on a period of 15 minutes. You could do it using Ladder or BASIC. But you can make it much more easily using a sampling table and one of those functions. Sampling table configuration: Type= average period= 15 minutes Size= 1 You then use the function appropriate to the format of the Tag like following:
Average=sampleword(1,0)
Version: 1.7
42
Type Casting
TWinSoft handles type casting automatically, but in some cases it can lead to misinterpretation To prevent it, we have implemented Type Casting functions that make you be sure of the type used in the Functions. Syntax Type casting to Boolean format Type casting to Byte format Type casting to DWord format Type casting to Integer format Type casting to Long format Type casting to Single (Float) format Type casting to Word format
(CInt(A) * 3600)
(1 * 3600)
Type casting must be applied to the constant Imagine A as a WORD and A=65535 Imagine B as a INTEGER
B=Abs(A) the result will be 1 !! Abs(65535) 65535
B=Abs(CInt(A)) Abs(-1) 1
Version: 1.7
43
Reading functions
Syntax
'Reading 'Reading 'Reading 'Reading address address address address of of of of a a a a BOOL WORD FLOAT LONG Digital=PeekBool (Pointer) Analog16=PeekWord (Pointer) Float=PeekFloat (Pointer) Analog32=PeekLong (Pointer)
Arguments
Pointer Digital Analog16 FLOAT Analog32 : : : : :
Word register containing the ModBus address of the variables. Boolean variable to receive the status at the address of 'Pointer'. Analog variable to receive the value at the address of 'Pointer'. We advise to use a type of variable equivalent to the one of the address read (Float when addressing a Float, Long when addressing a Long, ...).
Writing functions
Syntax
PokeBOOL(Pointer, State) PokeWord(Pointer, Value) PokeFloat(Pointer, Value) PokeLong(Pointer, Value)
Arguments
Pointer :Word register or Expression containing the ModBus address of the variables. State :Value (0 or 1) to write in the address of 'Pointer' Value :Value or Expression to write in the address of 'Pointer'
Initialization of a Pointer
This function allows you to get the address of a Tag. It can be useful to initialize a Pointer from the first Tag that has to be treated by the indirect addressing functions. Syntax
1.17. GOTO
Label A label can be defined anywhere in a program like following:
Alarms: Pumps:
The semicolon " : " indicates it is a label. The name of a label must use the following rules: characters accepted are letters, numbers and underscore. the name cannot start with a number. the maximum length is of 15 characters. BASIC is not case sensitive. To avoid confusion, do not use keywords (see chapter 1.17) or Tag names. Syntax
Goto Label
Version: 1.7
45
1.18. Keywords
BASIC uses the following keywords. You should not use name similar to those keywords.
% _ Abs AdrOf And ArcCosine ArcSine ArcTangent As Bcd Bit Byte Call CBool CByte CDword CInt CLong Cosine CountDown CountUp CountRing CountReset CSng CWord Dec Dim DWord Else Elseif Endif Exp For Goto HiByte HiWord Integer If Inc Let LoByte Log Long LoWord Ln
Next Not Odd Or PackBit PeekBool PeekFloat PeekLong PeekWord PutChrono Pwr Rem Samplebyte Sampleword Sampledword Samplesingle SetBit Shl Shr Sine Single SplitBit Sqrt Step SwapByte Tablesize Tan Then TimerSS TimerMS TimerIN TimerOD TimerReset To TriggerNeg TriggerPos Truncate Xor Wend While Word
Version: 1.7
46
1.19. POU
According to IEC1131-3 standard, the programs are organized in POU, which stands for Program Organization Unit In order to organize the programming, 3 types of POU are available. Programs give you the possibility to divide your project into several subprograms (pump management, alarms, intrusion, ...) Each sub-program is POU Program. give you the possibility to create your own function. It is a piece of program leading to one result. Useful when there are repetitive calculations. give you the possibility to create your own 'applet' or procedure (starting a pump, regulating temperature). It is a piece of program composed of input and output arguments. Useful when the same process is applied to different sets of I/O (eg. Management of a pump in an application handling 4 pumps).
Functions
Function Blocks
Recursion is authorized but not for Function Block (A function cannot call itself): 1. We do not advise you use recursion 2. It is under your own responsibility
Version: 1.7
47
Changing language of Main To change the language of Main, right click the name Main, go to Properties and change language to
BASIC
Version: 1.7
48
Double click 'Add a POU', type a Name (No accent, space or keywords (see chapter 1.18)) and check the type 'Program'. Select language BASIC Click OK. You have created a Program and it appears in the 'Programs' folder. When you double click the name of the Program in the list, the window for BASIC edition appears with a new Tab for the current program. You use standard BASIC language for programming.
Version: 1.7
49
Creating a Function To create a Function, click the 'Programs' folder in the Project Workspace. In the window appears the list of existing POUs (all types of POU). When starting TWinSoft the first time, the only one is the 'main'.
Double click 'Add a POU', type a Name (No accent, space or keywords (see chapter 1.18)) and check the type 'Function'. Select the language BASIC Select the type of the output (result of the calculation): BOOL, WORD, LONG or FLOAT. Click OK. You have created a Function and it appears in the 'Programs' folder.
Version: 1.7 BASIC & Ladder 50
When you double click the name of the Function in the list, the window for BASIC edition appears with a new Tab for the current program.
The following Function is an analog Function (it means the output is analog). It performs the percentage of an input value.
Example of Function
The Tags When creating a Function, TWinSoft automatically creates the 'Output' Tag. It is the unique Output allowed. 'Inputs' and 'Outputs' of the Function are the arguments that will be replaced when calling the Function (see next). You create then the 'Inputs', corresponding to the arguments of the Function. Be careful with the 'type' associated to the arguments. If you need 'local' Tags, you can create them from the list, or using the DIM statement. The way a POU Function works, involves that one can define only local Tags in a POU Function. Percent: MAX, MIN, VAL: Delta, scale: the output of the Function. calculation. are the Inputs of the Function. local analog Tags used as temporary variables necessary to calculate the percentage. Global Timer and Counters are allowed in Function, but it is very uncommon and not logic. It is unique and is the result of the
Version: 1.7
51
The column Value in the list of POU Tags cannot be used. It displays random values. To check the Tags, look in the list of Tags to the global Tags associated to the arguments.
Arguments
Result Function Arg
the Tag receiving the result of the Function the name of the Function
the input arguments (Tags or constant) The Arguments have to be entered in the order they have been created in the list of Tags of the Function.
Example:
Example
'Call of Function: output=Percent(max,min,input) AIR0 = Percent(maximum, minimum, ana_0)
POU Functions can be exported to a Library to be used in other TWinSoft documents, using the Library manager menu (see chapter 5: The library manager)
Version: 1.7
52
eg.: The TBox needs to handle 4 identical pumps. No need to copy the same program 4
times. You call a Function Block from a Program every time you need to execute the process and you assign Tags to it.
We advise you against using Functions in a Function Block. In fact, a Function exists only once and uses always the same internal variables when it is called. A Function Block uses new Tags (local and global) every time it is called from a Program. Creating a Function Block To create a Function Block, click the 'Programs' folder in the Project Workspace. In the window appears the list of existing POUs (all types of POU). When starting TWinSoft the first time, the only one is the 'main'.
Double click 'Add a POU', type a Name (No accent, space or keywords (see chapter 1.18)) and check 'Function Block'. Select the language BASIC Click OK. You have created a Function Block and it appears in the 'Programs' folder.
Version: 1.7
53
When you double click the name of the Function Block in the list, the window for BASIC edition appears with a new Tab for the current program.
The following Function Block performs the start of a digital output with a programmable delay. This Function Block implementation describes the inputs and outputs involved in the management of the delay. It also specifies how the dcelay is applied to the ouput. It does not specify which Tags are physically connected to the delay: this is the job of the FB calling in a program (see below).
The Tags Inputs and Outputs of a Function Block are the arguments to be replaced when calling the Function Block. You create then the 'Inputs' and 'Outputs' in the list of POU Tags of the Function Block. If you need 'local' Tags, you can create them from the list, or using the DIM statement. INPUT OUTPUT DELAY
Version: 1.7
is a digital input that will activate the OUTPUT after the DELAY. is a digital output. It will be connected to a motor, for instance when calling the Function Block. is an analog input containing the number of seconds of the delay. It must be associated to the timer used in the Function Block.
BASIC & Ladder 54
is a local timer. is a local digital Tag of the type 'Timer - Valaue'. is a local digital Tag of the type 'Timer - Status'. is a local analog Tag of the type 'Timer - Preset'.
The programming You use standard BASIC language for programming. Calling a Function Block in a POU Program Instantiation A Function Block can be called several times, and for each call TWinSoft allocates new Tags. The Instantiation allows TWinSoft to distinguish each call. The Instantiation is done using a POU 'local' Tag. - From the Program where you wish to call the Function Block: - In the list of POU Tag, click Add a POU Tag - Type a name as Tag (the instance name) - Select as Type : FB Instance - Select as Name the name of your Function Block - Click OK - The instance appears in the list of POU Tag.
Example of Instantiation:
Version: 1.7
55
Arguments
Instance Arg
the name given to the local Tag used as Instantiation the input arguments (Tags or constant) The Arguments have to be entered in the order they have been created in the list of Tags of the Function Block
Example
'The function block [Start_w_Delay] activates an output after a entered 'delay in seconds; Arguments: (Input,Delay,Output). call Motor1(DI_4, 6, DO_3, COUNT)
POU Functions can be exported to a Library to be used in other TWinSoft documents, using the Library manager menu (see chapter 5: The library manager)
Version: 1.7
56
2. Programs - Ladder
TBOX MS and TBOX LITE support 2 languages: BASIC and Ladder. Both languages are used to execute process automation BASIC is a text language, very easy to use for making calculation. It supports all advanced mathematical functions. LADDER is a graphical language, which should be preferred when Boolean operations are required. LADDDER is much more efficient than BASIC for handling digital Tags.
BASIC and LADDER can be used together We suggest that you divide your process into several programs ( sub-programs) depending on the process concerned. According to the kind of process, you create programs in BASIC and programs in LADDER. Then you combine programs, as you want: BASIC calling LADDER and reciprocal. This chapter explains how to program in LADDER. To see an example, load the TWinSoft document 'MSLadder.tws' that you find in the 'Samples' directory of TWinSoft.
Version: 1.7
57
2.2.1. Inputs
All inputs, whether digital or analog, can be combined to create logical equations: <AND> using several inputs on the same line <OR> using several inputs one above each other. All analog comparison functions and/or digital inputs on the same program line will represent true or false. The result defines the actions of the output (will or will not be performed). The different types of Input conditions are accessible in the LD Toolbar.
2.2.2. Outputs
Digital output functions are engagements (SET relay) or disengagement (RESET relay), they can be the image or the opposite of the result of the tested input conditions (OUTPUT relay and NEGATIVE relay). Other functions have been introduced proper to telemetry like transmission of alarms, data logging, To process analog variables, many mathematical functions and POU (Program Organization Units) functions have been implemented, but you might find easier to use BASIC for making calculation (see chapter 1: BASIC) The selection of different types of Output is accessible in the LD Toolbar.
Example of Ladder
Version: 1.7
58
Version: 1.7
59
The Ladder diagram is made of several lines that are numbered starting at 1. Only one line at a time can be edited with only one rung (a rung is a set of Input conditions connected to only one set of Outputs). When editing is finished, the line must be compiled to proceed with the next one: To save and compile a line. If an error occurs, a dialog box informs you on the error. The key <+> can also be used to save and compile a line. If you were editing an existing line, you return to display mode. If you were inserting a new line, you stay in edit mode. To quit editing and discard changes. The key <ESC> can also be used. To select any item (line, contact, relays or Functions) of a Ladder line. Once selected it can be edited by a double click to replace Tags. You can also erase the selected item by pressing the key <Delete> or insert a new contact, relay or Function by selecting the proper icon in the LD Toolbar.
Inserting a new line as last line To insert a new line as last line, place the cursor at the end of the last line and click the icon corresponding to the type of line you wish to insert.
Inserting a new line between 2 existing lines To insert a line between 2 existing lines, place the cursor on the existing line that the new line will correspond to. The new line will move the existing line to next position after it is inserted. When a line is selected, it is surrounded. Then click the icon corresponding to the type of line you wish to insert. The line you placed the cursor on will be moved downwards. Using the keyboard UP and DOWN arrows moves the selected line.
Modifying an existing line To modify an existing line, place the cursor on the line you wish to modify. Then double-click it. The arrow icon of the LD Toolbar is automatically selected.
Version: 1.7
60
Version: 1.7
61
Version: 1.7
62
2.5. Variables
Introduction Variables can be physical I/O, internal variables: analog (AIV) or digital (DIV) and system variables. A variable becomes available when it is declared as a Tag. According to the use we make of the variables in Ladder programming, there are two families of Tags: Local Tags Global Tags
Version: 1.7
63
According to the item you wish to use, select the proper icon in the Toolbar.
To get used to ladder programming, go to chapter 2.7. Step by step creating of ladder and chapter 2.8. Drawing lines in ladder
Version: 1.7
64
According to the field you are in, you can select a Tag (digital or analog) or directly type a constant. Check the title of the insertion window; it informs you on what you can use.
<ESC>
When a line is selected: to quit edit mode. Similar to the icon When an item is selected: to release the item and return to selection mode (arrow). When Tag box is opened: to carry on without specifying a Tag. '???' will be inserted
instead. To enter a Tag afterwards, double click '??? '
<DEL>
Version: 1.7
65
We use the following Tags (see TBox manual chapter 10: Tags):
Level Manual Pump Timer_Status Maintenance Reset analog input (Float) digital input. digital output. digital internal variable associated to the timer Qty_minutes digital output. digital input.
Version: 1.7
66
Lines in Ladder
1st line of Ladder:
1. In the program MAIN, click the icon click OK. 2nd line of Ladder:
2. Click the icon to insert a new line. The edit block is ready to create the second line. The grid shows the position where you can place the items. 3. Click the icon to insert the function A>B and then click next to the left Rail.
4. Enter the Tag LEVEL or select it from the list of Tags and then enter the constant 150. 5. Click the icon to insert a digital contact, then click below the comparison Function close to the left rail. 6. Enter the Tag MANUAL or select it from the list of Tags. 7. Click the icon and draw a horizontal and vertical line to join the output of the comparison Function. 8. Click the icon to insert an output relay, then click on the output of the comparison Function. A horizontal line including the relay is automatically drawn to the right rail. 9. Enter the Tag PUMP or select it from the list of Tags.
Version: 1.7
67
11. Type the name of the Timer (instance name), or if it exists, you can browse it from the button
12. Type the Preset of 360000 (= 100 hours). Preset is always expressed in seconds. 13. Click the icon and draw a horizontal and vertical line to join the timer Function to the right rail and to the output of the comparison Function. 14. Press the key <+>, or click the icon is ready to create the third line. 3rd line of Ladder: 15. Click the icon rail. to insert a Positive edge trigger contact, then click next to the left to compile the line. Doing this, the edition block
16. Enter the Tag TIMER_STATUS. 17. Click the icon to insert a SET output relay, then click next to the right side of the contact TIMER_STATUS. A horizontal line including the relay is automatically drawn to the right rail. 18. Enter the Tag MAINTENANCE or select it from the list of Tags. 19. Press the key <+>, or click the icon is ready to create the fourth line.
Version: 1.7
68
4th line of Ladder: 20. Click the icon rail. to insert a Positive edge trigger contact, then click next to the left
21. Enter the Tag RESET or select it from the list of Tags. 22. Click the icon RESET. to insert the reset timer Function, then click next to the contact
23. Type the name of the Timer or select it from using the browse button 24. Click the icon 25. Click the icon timer Function.
and then click the reset timer Function; drag it one step to the right. and draw a horizontal line between the RESET contact and the reset
26. Click the icon to insert a output relay associated to the Tag MAINTENANCE, then click under the reset timer Function. A horizontal line is automatically drawn to the right rail. 27. Enter the Tag MAINTENANCE or select it from the list of Tags. 28. Click the icon and draw a horizontal and vertical line to join the input contact to the output relay MAINTENANCE. 29. Press the key <+>, or click the icon is ready to create the next line. 30. Press <ESC> to return to Display mode. to compile the line. Doing this, the edition block
Version: 1.7
69
drag the mouse to the right. When you cross to the cell next, a black line appears
when you have reached the end of the horizontal line, release the button. The line changes to red color. To continue, at the cursor position maintain the left button of the mouse drag the mouse to the bottom. When you reach the bottom of the cell a black line appears when you have reached the end of the vertical line, release the button. The line changes to red color. To continue, at the cursor position maintain the left button of the mouse drag the mouse to the right. When you cross to the cell next, a black line appears when you have reached the end of the horizontal line, release the button. The line changes to red color.
Thats it !
Version: 1.7
70
2.9. Functions
Ladder provides a series of pre-defined functions to perform operations like Comparisons, Assignment, Boolean operations,. Ladder provides also Timer functions (for counting time) and Counter functions (for counting pulses). Almost all functions have the 2 connections: - EN: - ENO: Enable Input: Connection to the Ladder line. EN must be TRUE to perform the Function. Enable Output: it is the image of EN. If EN is TRUE, ENO is TRUE. It can be connected to a contact or a relay, a Mathematical block or another Function.
To insert a Function, in the edit mode of Ladder Programming, click the icon Toolbar. The functions are divided into several folders:
of the LD
Version: 1.7
71
Version: 1.7
72
Q = -A: the Tag 'anaOUT' contains the invert value of the Tag 'anaIN'
Q = low(A): the Tag 'anaOUT' contains a copy of the 8 lowest bits of the Tag 'anaIN' A and Q must be WORD Q = high(A): the Tag 'anaOUT' contains a copy of the 8 highest bits of the Tag 'anaIN' A and Q must be WORD Q = abs(A): the Tag 'anaOUT' contains a copy of the absolute value of the Tag 'anaIN' A and Q must be WORD High-LowQ = Low-HighA: the Tag 'anaOUT' contains the inversion of the 8 highest bits and the 8 lowest bits of the Tag 'anaIN' A and Q must be WORD in(A): increase by 1 bit the Tag 'anaIN'.
Version: 1.7
73
The Tag 'anaOUT' is the addition of the Tags 'ana0' and 'ana1'
The Tag 'anaOUT' is the subtraction of the Tags 'ana0' and 'ana1'
The Tag 'anaOUT' is the multiplication of the Tags 'ana0' and 'ana1'
The Tag 'anaOUT' is the division of the Tags 'ana0' and 'ana1'
The Tag 'anaOUT' is the rest after the division of the Tags 'ana0' and 'ana1'. Example: 2 = 17 MOD 3
Version: 1.7
74
The status of digital Tag 'dig0' will be copied in the analog Tag 'anaOUT' at the position indicated by the Index. 1 Example: dig0: Index: 3 anaOUT: 0011010011001001 The status of the bit of the analog Tag 'ana0' indicated by the Index will be copied in the digital Tag 'digOUT'. ana0: 1100101000010010 Example: Index: 5 dig0: 0
Wraparound means that the bits scrolling out from one side of a Byte (8 bits) or Word (16 bits) are copied at the other side of the byte or word.
'anaOUT' has the number of 'Bit' shift to the left (max. 15) of the Word analog Tag 'ana0' (without wraparound). 'anaOUT' has the number of 'Bit' shift to the right (max. 15) of the Word analog Tag 'ana0' (without wraparound). 'anaOUT' has the number of 'Bit' shift to the left (max. 7) of the Byte analog Tag 'ana0' (with wraparound). 'anaOUT' has the number of 'Bit' shift to the right (max. 7) of the Byte analog Tag 'ana0' (with wraparound). 'anaOUT' has the number of 'Bit' shift to the left (max. 15) of the Word analog Tag 'ana0' (with wraparound). 'anaOUT' has the number of 'Bit' shift to the right (max. 15) of the Word analog Tag 'ana0' (with wraparound).
Version: 1.7
75
To insert a Math block, in the edit mode of Ladder Programming, click the icon LD Toolbar.
of the
2.10.1. Introduction
There are 7 categories of mathematical functions available (to use in math blocks): Assignments Arithmetic operations. Comparisons. Bit manipulations. Boolean Operations. Conversion + Indirect addressing. Miscellaneous.
In the functions, the Arguments to replace by Tags (or constant) are represented as follows: - A, B, C, and D Analog Tags. Depending on the functions the Tags can be: - Combination of any type of Tags (Byte, Word, Long, Float). TWinSoft will automatically converts to the type of the Tag Result. - Limited to Byte or Word (obvious according to some functions like Rotation, conversion of 16xBool to a Word, ) Pointer Doing indirect addressing, it is an Analog Tag Digital Tag
- Ptr - BOOL
An assignment operation is always executed from the right to the left. In other words, we have: result = operation or: output = input (meaning the value of Input variable is copied in the Output variable).
Version: 1.7
76
About Typecasting Typecasting means the conversion of a variables data type to another data type, for instance the conversion from Float to Long. TWinSoft executes typecasting to optimize the calculation, to be sure of the result. (See examples here below)
Examples of typecasting
The typecasting is specifically required when doing arithmetic operations. Long = Long + Float Long = Long + 12.365 Long = Word + Word Long = Word * Word The Input arguments are converted to the format of the Output (result). In those examples it means that the Float (or constant) is first converted to Long before executing the operation In case the result of the operation is > 65535, TWinSoft presumes the result will go to a Long. Be sure the Tag receiving the result is of format Long The result is in Word with the addition of the Float rounded The result is in Word
To insert a 'Math function' between 2 existing functions in a Math block, edit the line, place the cursor at the position you want to insert the function, and press the key <Insert> of keyboard.
Version: 1.7
77
2.10.2. Assignments
A = B A = -B A = Low(B) A = High(B) A = Abs (B) A = Swap(B) 'A' contains a copy of the value of 'B' 'A' contains the invert value of 'B' If B is a WORD: 'A' contains a copy of the 8 lowest bits of 'B' If B is a LONG: 'A' contains a copy of the 16 lowest bits of 'B' If B is a WORD: 'A' contains a copy of the 8 highest bits of 'B' If B is a LONG: 'A' contains a copy of the 16 highets bits of 'B 'A' contains a copy of the absolute value of 'B' 'A' contains the inversion of the 8 highest bits and the 8 lowest bits of 'B' B = 256 (00000001 00000000) Example: A=1 (00000000 00000001) increase the value of Tag 'A' by 1 unit decrease the value of Tag 'A' by 1 unit
A = B OR C
A = B XOR C
A = B MOD C
When doing logical operations, check you dont work with Float variable. There is no linear sequence in the binary format of Float register, like with Word or Long.
Version: 1.7
78
2.10.4. Comparisons
BOOL = B == C BOOL = B < C BOOL = B > C BOOL = B <= C BOOL = B >= C BOOL = B <> C BOOL = odd B 'BOOL' is TRUE if 'B' equal 'C', otherwise it is FALSE 'BOOL' is TRUE if 'B' is smaller than 'C', otherwise it is FALSE 'BOOL' is TRUE if 'B' is greater than 'C', otherwise it is FALSE 'BOOL' is TRUE if 'B' is smaller than or equal to 'C', otherwise it is FALSE 'BOOL' is TRUE if 'B' is greater than or equal to 'C', otherwise it is FALSE 'BOOL' is TRUE if 'B' and 'C' are different, otherwise it is FALSE 'BOOL' is TRUE if the value of 'B' is odd, otherwise it is FALSE
A = shl(B,shift)
A = shr(B,shift)
A = rol byte(B,shift)
A = ror byte(B,shift)
Version: 1.7
79
A = rol word(B,shift)
'A' has the number of Bits indicated by 'shift' shift to the left (max. 15) of the Word 'B' (with wraparound). B: 0000000011111111 Example: Shift: 4 A: 0000111111110000 'A' has the number of Bits indicated by 'shift' shift to the right (max. 15) of the Word 'B' (with wraparound). B: 0000000011111111 Example: Shift: 4 A: 1111000000001111
A = ror word(B,shift)
Version: 1.7
80
A = 16 x (BOOL)
16 x (BOOL) = A
places the 16 bits of the Word 'A' in the 16 digital variables of successive addresses, starting with the digital Tag 'BOOL'. Example: to SET or RESET 16 DO of an extension card using an analog variable.
When using the two above functions, check that there are 16 Tags with successive ModBus addresses, starting from the Tag BOOL
conversion from the Float 'Flt' to the Integer 'A' , with a possible scaling from 10E-4 to 10E+4. The exponent must be a constant:'Const'. conversion from the Integer 'A' to the Float 'Flt', with a possible scaling from 10E-4 to 10E+4. The exponent must be a constant:'Const'.
the Tag or Constant 'Ptr' contains the ModBus address of the digital variable that will have its status assigned to the digital Tag 'BOOL'. Example: to read the status of an output 'Q0' having 32 as ModBus address: DIV0 = indirect (Pointer). (Pointer = 32)
the status of the digital Tag 'BOOL' will be copied in the digital variable whose ModBus address is defined in the Tag or Constant 'Ptr'. Example: to write the status of DIV0 to the output 'Q2' having 34 as ModBus address: Indirect (Pointer) = DIV0. (Pointer = 34)
Version: 1.7
81
A = indirect (Ptr)
the Tag or Constant 'Ptr' contains the ModBus address of the analog variable that will have its value assigned to the analog Tag 'A' Example: to read the value of the input 'ana0' having 64 as ModBus address: AIV0 = indirect (Pointer). (Pointer = 64)
indirect (Ptr) = A
the value of the analog Tag 'A' will be copied in the analog variable whose ModBus address is defined in the Tag or Constant 'Ptr'. Example: to write the value of ana0 to the analog output having as ModBus address 288: Indirect (Pointer) = ana0. (Pointer = 288)
2.10.8. Miscellaneous
Adr = Tag (Tag) put Bit in dig chrono put A in ana chrono Gives you the ModBus address of the Tag. Number between 1 and 65535 Writing of the digital Tag 'Bit' in the Digital Chronology. Writing of the analog Tag 'A' in the Analog Chronology.
Version: 1.7
82
POU program: sub-program that is called in the Main program or any other POU program.
functions.
POU function: standard functions (comparison, math. Functions, timers,...) or user defined POU function block:
user defined small 'applet' that performs a function (start of a pump, regulating temperature...)
Recursion is authorized but not for Function Block (A function block cannot call itself): 1. We do not advise you use recursion, because of cycle time issue. 2. It is under your own responsibility
Version: 1.7
83
Double click 'Add a POU', type a Name (No accent, space or keywords (see BASIC)) and check 'Program'. Click OK. You have created a POU Program and it appears in the 'Programs' folder.
Version: 1.7 BASIC & Ladder 84
When you double click the name of the Program in the list, the window for Ladder programming appears with a new Tab for the current Program.
Now you can create a Ladder Diagram for the Program you have defined.
- ENO:
Calling a POU Program is like calling a sub-routine. The program associated to it is executed at the position where it is called.
Version: 1.7
85
Example:
You need regularly to execute the calculation: y= [(a+b) * (c+d)] /2. You will not find this formula in the Standard Functions or in the Mathematical Function block. You will then create your own Function that will execute your calculation every time you call it. According to the type of the output, there are 4 types of Functions: BOOL: digital output. INT: analog 16 bits output. LONG: analog 32 bits output. FLOAT: floating point output. An example of user defined Function is available in the TWinSoft document Ladder.tbox, in the 'Samples' directory of TWinSoft. The Function executes the scaling of an 8-bit analog input.
Version: 1.7
86
Double click 'Add a POU', type a Name (No accent, space or keywords (see BASIC)) and check 'Function'. Select the language Ladder Select the type of the output (result of the calculation): BOOL , WORD, LONG or FLOAT. Click OK. You have created a POU Function and it appears in the 'Programs' folder. When you double click the name of the Function in the list, the window for Ladder programming appears with a new Tab for the current Function.
1. By default, the name of the Output is the name of the Function. You can rename the output by using the context menu on its name (mouse right clicking on the name). 2. POU Functions can be exported in a Library to be used in other TWinSoft documents, using the Library manager menu
Now you can create Ladder Diagram for the Function you have defined.
Version: 1.7
87
The Tags : When creating a Function, TWinSoft automatically creates the 'Output' Tag. It is the unique Output allowed. Inputs and the Output of a Function are the arguments to be replaced when calling the Function. The way a POU Function works, involves that one can define only local Tags in a POU Function. Percent: MAX, MIN, VAL: Delta, scale: the output of the Function. calculation. are the Inputs of the Function. local analog Tags used as temporary variables necessary to calculate the percentage. It is unique and is the result of the
The Ladder : A math block using 3 functions is used. Global Timer and Counters are allowed in Function, but it is very uncommon and not logic.
Version: 1.7
88
- ENO:
When calling the Function in a POU Program, you must assign to the (unique) Output a Tag and for each Input a Tag or constant. All inputs are at the left side of the Function; the output at the right side. In this example, we wish to have the percentage of input ANA_0 on the range between 0 and 500.
Version: 1.7
89
Double click 'Add a POU', type a Name (No accent, space or keywords (see BASIC)) and check 'Function Block'. Click OK. You have created a POU Function Block and it appears in the 'Programs' folder.
Version: 1.7
90
When you double click the name of the Function Block in the list, the window for Ladder programming appears with a new Tab for the current Function Block.
POU Function Blocks can be exported to a Library to be used in other TWinSoft documents, using the Library manager menu (see chapter 5: The library manager)
Now you create Ladder Diagram for the Function Block you have defined.
Version: 1.7
91
The Tags: Inputs and Outputs of a Function Block are the arguments to be replaced when calling the Function Block. INPUT OUTPUT DELAY Timer Timer_preset Timer_status is a digital input that will activate the OUTPUT after the DELAY. is a digital output. It will be connected to a motor, for instance when calling the Function Block. is an analog input containing the number of seconds of the delay. It must be associated to the timer used in the Function Block. is a local timer. is a local analog Tag of the type 'Timer - Preset'. is a local digital Tag of the type 'Timer - Status'.
The Ladder : The DELAY is copied in the preset of the timer and multiplied by 1000 (the timer preset is expressed in milliseconds). When INPUT changes to 1, it starts the timer Single Shot Note: when working with an external Preset (the local variable 'Timer_preset'), the Preset of the timer can be set to any value; it is not used. Here = 0 When the timer has finished counting AND INPUT is still active, the output is set. A negative edge on INPUT resets the OUTPUT.
Version: 1.7 BASIC & Ladder 92
- ENO: Enable Output: it is the image of EN. If EN is TRUE, ENO is TRUE. It is usually connected to the right rail but can be also connected to a contact or a relay, a Mathematical block or another Function.
When Calling the Function Block in a POU Program, you are asked to enter an 'FB Instance name' (in this example Motor1). This name allows TWinSoft to distinguish between Function Blocks, when multiple calls of similar Function Blocks are defined. Afterwards you must assign to the Output(s) and Input(s) Tags or constant. All inputs are at the left side of the Function Block, all outputs at the right side. In this example, the FB is called Motor1, the input D0 activate the output Q2 with a delay of 5 seconds. Each call of Function Block is unique and different from each other; local Tags of the Function Block as well as timer and counter, will be assigned to free registers, timers and counters when compiling. 1. A Function Block accepts maximum 16 Arguments. 2. There is no limit in the quantity of Timers and Counters used in a Function Block.
Version: 1.7
93
The source code (Ladder) of the FB is then opened and dynamized according to its instance. In the list of POU Tags, the column 'Value' displays values of each local Tag.
Version: 1.7
94
3. Timers
3.1. Presentation
Timers are used for counting a time, a delay. The maximum working time of 1 hour for a pump The control of the time a modem is connected The flashing of a lamp, using building a Flip-Flop with 2 timers A delay before starting a motor A delay before detecting an intrusion
The mechanism of both functions is similar, the way they are used and the variable associated. The difference is that when a timer has been launched, it runs on its own until a defined preset of time when a counter increments every time it receives a pulse. Timers can be used either with BASIC of Ladder programming.
When created, Timers and Counters are available from the Resources in a folder: The List of Timers and the List of Counters
The way of using timer in Ladder is discussed chapter 3.5 and in BASIC chapter 3.6.
Version: 1.7
95
3.2. Introduction
Four models of timers are available: Single Shot: MonoStable: Integral: Delay On: time time time time cycle cycle cycle cycle resets on each input activation. does not reset until it is over. with accumulation. without accumulation.
Each model is presented with a diagram in chapters 3.8, 3.9, 3.10 and 3.11 In theory, the quantity of timers is not limited. Practically, it is limited to 32767 ! For each timer (regardless of type), there are two analog variables and one digital variable associated with it: Preset: analog variable with the Timer Preset. Value: analog variable with the Timer Value. Status: digital variable, i.e. the logical state of the Timer.
These three variables can be assigned as Tags and used in the BASIC or Ladder diagram (example: an automatic modification of a process at timed intervals). To see an example of using Timers, load the document 'MSTimer.tws' that you find in the sub-directory of TWinSoft 'Samples'.
Version: 1.7
96
1. Tags cannot be shared by several timers. 2. You dont have to create a variable if you dont need it. 3. Do not give the same name for Timer and Counter (see chapter 4)
Result in the list of Timers with when Tags are available, the current value:
Version: 1.7
97
The Function ResetTimer is used to reinitialize a timer, depending on the model (see next) or to clear it before it has reached its preset.
Once you have selected the type of timer, it appears in the Ladder line.
Example: Fan1
Version: 1.7
98
Examples:
1. The preset minimum and the resolution is of 0.10 sec (100 msec.) 2. The character used to separate units from decimals depends on your regional settings, typically , or .
Dynamic Preset
If you want to work with a dynamic preset, you will use a Tag (format DWord 32 bits) associated to the Preset (see chapter 3.4 here above). You still have to indicate a constant here, it will not be used but is mandatory when calling the function.
In Blue, its name (see instance name here above). Its Preset (see here above). EN Enable. It activates the timer function. ENO Enable Output : it is the image of EN. If EN is TRUE, ENO is TRUE. It can be connected to a contact or a relay, a Mathematical block or another Function. If you want to clear a timer, you select the Function 'Reset timer' associated to its name.
Version: 1.7
99
3.6.2. Syntax
Single Shot: MonoStable: Integral: On delay:
TimerSS TimerMS TimerIN TimerOD (Name, (Name, (Name, (Name, Start, Start, Start, Start, Preset) Preset) Preset) Preset)
Arguments Name : It is the name of the timer you have created (see chapter 3.3. here above)
Start :
INPUT Bool. The Tag or expression that activates the timer. INPUT. Constant giving the preset of the timer in sec. using a Floating register.
Preset:
To access other variables of a Timer (Status and Value), or to work with dynamic Preset, you have to create Tags and associate them to the timer while creating it (see chapter 3.3. and 3.4. here above)
Version: 1.7
100
TimerReset (Name)
Argument Name : It is the name of the timer you have created (see chapter 3.3. here above)
3.6.4. Examples
How to manage time sequences using a Timer. Upon a given event, one needs to start the following sequence: - 1 minute after event, execute Prog1 - 5 minutes after event, execute Prog2 - 10 minutes after event, execute Prog3 You create a Timer Monostable from the list of Timers. You name it for instance MyTimer.
'The variable Event is a digital input of the RTU TimerMS(MyTimer,Event,1800) if TriggerPos(Time>=60) then call Prog1 if TriggerPos(Time>=300) then call Prog2 if TriggerPos(Time>=600) then call Prog3
Flip-Flop using 2 Timers Single Shot. When you want to execute an operation alternatively on 2 equipments, you can easily create the alternation with 2 Timers: one starting the other. It is possible to adapt the frequency of the Flip-Flop by changing dynamically the value of Tags Preset1 and Preset2. You create 2 Timers Single Shot with for each of them a Tag Status and a Tag Preset. You name the timers, for instance MyTimer1. and MyTimer2
'Flip-Flop using 2 Timer SS / 2.5 sec. ON and 2.5 sec. OFF TimerSS (MyTimer1,not(Status2),2.5) TimerSS (MyTimer2,not(Status1),2.5)
Version: 1.7
101
Coming in following chapter, the presentation of each model of Timer with its implementation in Ladder and a timing diagram.
A rising edge on the Tag INPUT starts the timer for the PRESET time period (5sec.). The Tag STATE (which corresponds to the digital state of the timer) changes to 1 as soon as a rising edge of the Tag INPUT appears and changes to 0 when the PRESET time expires, or upon activation of a 'Reset Timer' Function associated with the timer. If a new rising edge of the Tag INPUT appears before the end of the Preset time the cycle is re-started
Version: 1.7
102
A rising edge on Tag INPUT starts the timer for the PRESET time period (5sec.). The Tag STATE (which corresponds to the digital state of the timer) changes to 1 as soon as a rising edge of the Tag INPUT appears and changes to 0 when the PRESET time expires, or upon activation of the Timer Reset function associated with the timer. If a new rising edge appears before the end of the PRESET time, it has no effect on the cycle
Version: 1.7
103
Version: 1.7
104
The Tag INPUT must remain at 1 for the duration of the time defined in PRESET, so that the Tag STATE (which reflects the digital state of the timer) can change to 1. It remains active until the first rising edge of the Tag RESET (re-initialization the timer). If Tag INPUT falls to 0 before the end of the PRESET time, the value of the timer is retained (except if the rising edge of the Tag RESET appears and resets the timer). The re-activation of the Tag INPUT allows the timer continuing and completes the cycle. The only way to reinitialize the timer is using the Reset Timer Function
Version: 1.7
105
If the Tag INPUT remains at 1 for the duration of time defined in PRESET, the Tag STATE (which reflects the digital state of the timer) changes to 1. This Tag returns to 0 as soon as INPUT changes to 0. If INPUT is deactivated before the end of the time cycle, the value of the timer is reset to 0. There is no accumulation. The Tags of the timer are updated when the timer is scanned. It means that the precision depends on the cycle time of the process.
Version: 1.7
106
4. Counters
4.1. Presentation
Counters are used for counting pulses Counters are used for asynchronous event counting. Timers are used for counting a time, a delay (see chapter 3) The maximum working time of 1 hour for a pump The control of the time a modem is connected The flashing of a lamp, using building a Flip-Flop with 2 timers A delay before starting a motor A delay before detecting an intrusion
The mechanism of both functions is similar, the way they are used and the variable associated too. The difference is that when a timer has been launched, it runs on its own until a preset when a counter increments every time it receives a pulse. Counters can be used either with BASIC of Ladder programming.
When created, Counters are available from the Resources in a folder in the List of Counters
The way of using counter in Ladder is discussed chapter 4.5 and in BASIC chapter 4.6.
Version: 1.7
107
4.2. Introduction
Three types of counters are available: Counter UP: Counter DOWN: RING counter: Counts up Counts down. Circular counter (it restarts itself when the Preset is reached.
Each model is presented with a diagram in chapters 4.8, 4.9 and 4.10 In theory, the quantity of counters is not limited. Practically, it is limited to 32767 ! For each counter (regardless of type), there are two analog variables and one digital variable associated with it: Preset: analog variable with the Counter Preset Value: analog variable with the Counter Value. Status: digital variable, i.e. the logical state of the Counter.
These three variables can be assigned as Tags and used in the BASIC or Ladder diagram (example: an automatic process at intermediate values).
Version: 1.7
108
Those variables are standard internal variables, with a free name. Once created in the list of Tags they can be associated to a counter. Probably Status will need to be created, as it will be required to control the counter: maximum number of pulses reached or not. Preset and Value are optional and only required when they needs to be monitored from the process or from external software.
1. Be sure you create different variables for each counter. TWinSoft will prompt you when you use a variable already used by another counter. 2. It is not needed to create a variable if you dont need it. 3. Do not give the same name for Counter and Timer (see chapter 3)
Result in the list of Counters with when Tags are available, the current value:
Version: 1.7
109
The Function ResetCount is used to reinitialize a counter, depending on the model (see next) or to clear it before it has reached the preset.
Once you have selected the type of counter, it appears in the Ladder line.
Example: Pump1_Hours
Version: 1.7
110
In Blue, its name (see instance name here above). Its Preset (see here above). EN Enable. Each pulse increments the counter with 1. ENO Enable Output : it is the image of EN. If EN is TRUE, ENO is TRUE. It can be connected to a contact or a relay, a Mathematical block or another Function. If you want to clear a counter, you select the Function 'ResetCount' associated to its name.
Version: 1.7
111
4.6.2. Syntax
CountUP (Name, Start, Preset) CountDown (Name, Start, Preset) CountRing (Name, Start, Preset)
Arguments Name : It is the name of the counter you have created (see chapter 4.3. here above)
Start :
INPUT Bool. The Tag or expression that increments the counter. The start input must be associated to a Trigger function (TriggerPos or TriggerNeg)
Preset:
CounterReset (Name)
Arguments Name : It is the name of the counter you have created (see chapter 4.3. here above)
Version: 1.7
112
Coming in following chapter, the presentation of each model of Counter with its implementation in Ladder and a timing diagram.
4.8. Counter - UP
Version: 1.7
113
Suppose that the Preset of the counter is 5. At each rising edge of the Tag PULSE, the value of the counter is incremented with 1, and when it reaches the value of the Preset, the Tag STATE (which represents the digital state of the counter) changes to 1. The count continues until the Tag RESET is triggered, which resets the value of the counter. At any given time, you can reset the counter with the help of the function CounterReset, activated in this example by the Tag RESET. You can pre-position the current value of the counter (using the Ladder diagram and the variable associated to the value) if you do not want the counting to start at zero, but at another value.
Version: 1.7
114
Suppose that the Preset of the counter is 3 and the variable associated to the value of the counter is initialized to 5 (Tag COUNT). The latter has priority on the preset defined in the Counter function. This operation can be done manually or by the Ladder diagram. In this example, it is the Tag INIT that initiates this operation. At each rising edge of the Tag PULSE, the value of the counter is decremented. The Tag STATE (which represents the digital state) remains at 1 as long as the current value is greater than the pre-selection. When the current value becomes less than the pre-selection, the Tag STATE changes to 0 and the counting continues to 0.
Version: 1.7
115
Version: 1.7
116
Suppose that the Preset of the counter is 5. At each rising edge of the Tag PULSE, the value of the counter is incremented, and when this value reaches the one of the Preset, the Tag STATE (which represents the digital state) changes to 1. During the next rising edge of the Tag PULSE, the value is set to 0. A new counting cycle begins. At any given time, you can reset the counter with the help of the function ResetCount, activated in the example by the Tag RESET. If the Tag RESET is associated to a normal contact, the counter is blocked until release of the RESET (see notes below).
1. 2.
When working with counters, work with edges (positive or negative). Do not drive more than once the same counter. If different input conditions are necessary to increase (decrease) a counter, use those on the same Ladder line, and if this is impossible, use a temporary digital variable to summarize all your conditions, then declare this variable, to drive the counter.
Version: 1.7
117
Version: 1.7
118
5. Library Manager
TWinSoft offers the possibility to save POU Functions and POU Function Blocks in external files called Libraries in order to use those POU in other TWinSoft documents. A library can contain several POUs. Function and Function Blocks from both BASIC and Ladder are concerned A library corresponds for instance to a customer or to a category of functions. A library is a file with the extension .LIB, saved by default in the directory of TWinSoft. POU Program cannot be saved.
Only POU Functions and Function Blocks can be saved in a library. 1. You select an existing library (File -> Open), or you create a new library (File -> New). 2. You open the list of available POUs of the current document (Edit ->Import POU...). 3. You select the POU you wish to save in the Library; you repeat operations 2 and 3 for each POU. 4. You save the Library (File -> Save).
Version: 1.7
119
Libraries can be protected by a password, so that it is impossible to Export it into a TWinSoft document, to see the internal code.
The Available Libraries are the ones present in the directory of the current TWinSoft document or in the directory of TWinSoft. When a library appears in the list, all its POU Functions, and POU Function Blocks are available to be used in Ladder programming: in the list of Functions, the Libraries appear as Folders, each containing their own POUs. To add a Library to the current TWinSoft document, select it from the list of Available Libraries and click Add. The button 'Manager' jumps to the creation of Library menu. To remove a Library from the current TWinSoft document, select the Library and click 'Remove'. This operation is available only if you dont use POU of the concerned library in the current document.
Version: 1.7
120
Version: 1.7
121
Version: 1.7
122