You are on page 1of 278

FactoryLink ECS

Core Tasks
Confi gurati on Gui de
Persistence
Timer
Counter
File Manager
Print Spooler
Math and Logic
Scaling and Deadbanding
FactoryLink ECS 6.0 / March / 1996 C1

Copyright 1984 - 1996 United States Data Corporation. All rights reserved.
- NOTICE -
The information contained herein is confidential information of United States Data Corporation, a Delaware corporation,
and is protected by United States copyright and trade secret law and international treaties. This document may refer to
United States Data Corporation as USDATA.
Information in this document is subject to change without notice and does not represent a commitment on the part of United
States Data Corporation (USDATA). Although the software programs described in this document (the Software
Programs) are intended to operate substantially in accordance with the descriptions herein, USDATA does not represent
or warrant that (a) the Software Programs will operate in any way other than in accordance with the most current operating
instructions available from USDATA, (b) the functions performed by the Software Programs will meet the user's
requirements or will operate in the combinations that may be selected for use by the user or any third person, (c) the
operation of the Software Programs will be error free in all circumstances, (d) any defect in a Software Program that is not
material with respect to the functionality thereof as set forth herein will be corrected, (e) the operation of a Software
Program will not be interrupted for short periods of time by reason of a defect therein or by reason of fault on the part of
USDATA, or (f) the Software Programs will achieve the results desired by the user or any third person.
U.S. GOVERNMENT RESTRICTED RIGHTS. The Software is provided with RESTRICTED RIGHTS. Use, duplication, or
disclosure by the government of the United States is subject to restrictions as set forth in subparagraph (c)(1)(ii) of The
Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 or in subparagraphs (c)(1) and (2) of the
Commercial Computer SoftwareRestricted Rights clause at 48 CFR 52.227-19, as applicable. Contractor/Manufacturer
is United States Data Corporation, 2435 North Central Expressway, Suite 100, Richardson, TX 75080-2722. To the extent
Customer transfers Software to any federal, state or local government agency, Customer shall take all acts necessary to
protect the rights of USDATA in Software, including without limitation all acts described in the regulations referenced
above.
The Software Programs are furnished under a software license or other software agreement and may be used or copied
only in accordance with the terms of the applicable agreement. It is against the law to copy the software on any medium
except as specifically allowed in the applicable agreement. No part of this manual may be reproduced or transmitted in any
form or by any means, electronic or mechanical, including photocopying and recording, for any purpose without the
express written permission of USDATA.
Trademarks. USDATA, FactoryLink and FactoryLink ECS are registered trademarks of United States Data Corporation.
Open Software Bus is a registered trademark licensed to United States Data Corporation.
All other brand or product names are trademarks or registered trademarks of their respective holders.
FactoryLink ECS / Core Tasks Configuration Guide / 3
Table of Contents
Cor e Tasks
Confi gur ati on Gui de

Part I Persistence
1 Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Persi stence Overvi ew . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Resol vi ng Confi gurati on Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Confi guri ng Persi stence for Exi sti ng Appli cati ons . . . . . . . . . . . . . . . . . . . . 18
Confi guri ng Persi stence for New Appl i cati ons . . . . . . . . . . . . . . . . . . . . . . . 18
Confi guri ng Persi stence for I ndi vi dual El ements . . . . . . . . . . . . . . . . . . . . . 19
Confi guri ng Persi stence for Al l El ements i n a Domain . . . . . . . . . . . . . . . . 21
Confi guri ng the Persi stence Task. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Persi stence Task Star t Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Persi stence and Di gi tal El ements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Persi stence Save Fi l e Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Edi ti ng Tag Persi stence Setti ngs Usi ng BH_SQL Uti l i ty. . . . . . . . . . . . . . . 30
Part II Event and Interval Timer
2 Event and Interval Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Changi ng the Oper ati ng System Date and Ti me. . . . . . . . . . . . . . . . . . . . . . 40
Confi guri ng the Event and I nterval Ti mer Task . . . . . . . . . . . . . . . . . . . . . . 40
Event Timer I nformation Dialog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
I nterval Timer I nformation Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Part III Programmable Counters
3 Programmable Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Part title variable applied here in this
book
the Core Tasks Configuration Guide
4 / FactoryLink ECS / Core Tasks Configuration Guide

Core Tasks Configuration Guide


Digital and Analog Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Example One. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Example Two. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Pr ogrammabl e Counters I nformati on Panel . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Part IV File Manager
4 File Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Fi l e Manager Control Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fi l e Manager I nformati on Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Sampl e Fi l e Manager Operati ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Example 1: COPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Example 2: PRI NT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Example 3: REN (Rename) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Example 4: TYPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Example 5: DI R (Directory) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Example 6: DEL (Delete) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Usi ng Vari abl e Speci fi ers i n Fi l e Speci fi cati ons . . . . . . . . . . . . . . . . . . . . . . . 85
Usi ng Wi l dcard Characters i n Fi l e Speci fi cati ons. . . . . . . . . . . . . . . . . . . . . . 87
Usi ng the Fi l e Manager wi th Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Using the COPY Command with FLLAN . . . . . . . . . . . . . . . . . . . . . . . . 89
Using the COPY Command with a Network without FLLAN. . . . . . . . . 92
Techni cal Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Operati ng System Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
For Windows NT and Windows 95 Users . . . . . . . . . . . . . . . . . . . . . . . . 94
For OS/ 2 Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
For Unix Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Part V Print Spooler
5 Print Spooler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Confi guri ng the Pri nt Spool er . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Core Tasks Configuration Guide
FactoryLink ECS / Core Tasks Configuration Guide / 5
Part VI Math and Logic
6 Math and Logic Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Pr ocedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Creati ng Pr ograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Configuration Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
I nterpreted Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Switching from I ML to CML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Compiled Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
CML Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Tr i ggeri ng/Cal l i ng. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Triggering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Calling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
7 Configuring Math and Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Text Edi tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Math and Logi c Confi gurati on Tabl es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
.PRG Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Math and Logic Variables Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Math and Logic Triggers Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Math and Logic Procedure Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Confi guri ng the Math and Logi c Tabl es . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Choosing a Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Math and Logi c Vari abl es Tabl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Math and Logi c Tri ggers Tabl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Math and Logi c Procedures Tabl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Correcting Validation Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Configuration Examples Using Element Arrays . . . . . . . . . . . . . . . . . . 146
Compi l ed Math and Logi c. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
CML Requi rements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Enteri ng CML I nto the System Confi gurati on Tabl e . . . . . . . . . . . . . . . . . . 152
Runni ng CML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Running CML on a Development System . . . . . . . . . . . . . . . . . . . . . . . 153
6 / FactoryLink ECS / Core Tasks Configuration Guide

Core Tasks Configuration Guide


Running CML on a Run-Time-Only System. . . . . . . . . . . . . . . . . . . . . 153
How CML Operates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Editing CML.MAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Advanced Concepts for CML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Utilities and Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Cal l i ng C Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
8 Math and Logic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Procedure Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Naming Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Math and Logi c Reser ved Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Symbolic Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Numeric Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Str ucture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Declarations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
9 Math and Logic Procedures and Functions . . . . . . . . . . . . . . . . . . 231
Pr ogram Fi l es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Runni ng Programs as I nterpreted Programs . . . . . . . . . . . . . . . . . . . . . . . . 235
Techni cal Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Calling Procedures and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Local Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Library Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Calling Functions that Operate on Tag I Ds (CML Only) . . . . . . . . . . . 248
10 Compiled Math and Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
System Confi gurati on Panel Setup Under I ML/CML . . . . . . . . . . . . . . . . . . 253
Core Tasks Configuration Guide
FactoryLink ECS / Core Tasks Configuration Guide / 7
Makefi l es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Editing CML.MAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
The CML Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Generati on of CML Executabl es. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Part VII Scaling & Deadbanding
11 Scaling & Deadbanding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Defi ni ng Scal i ng and Deadbandi ng Operati ons . . . . . . . . . . . . . . . . . . . . . . 276
8 / FactoryLink ECS / Core Tasks Configuration Guide

Core Tasks Configuration Guide

Part I
Persistence
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 11
Table of Contents
Per si stence

1 Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Persi stence Overvi ew . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Resol vi ng Confi gurati on Changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Confi guri ng Persi stence for Exi sti ng Appli cati ons . . . . . . . . . . . . . . . . . . . . 18
Confi guri ng Persi stence for New Appl i cati ons . . . . . . . . . . . . . . . . . . . . . . . 18
Confi guri ng Persi stence for I ndi vi dual El ements . . . . . . . . . . . . . . . . . . . . . 19
Confi guri ng Persi stence for Al l El ements i n a Domain . . . . . . . . . . . . . . . . 21
Confi guri ng the Persi stence Task. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Persi stence Task Star t Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Persi stence and Di gi tal El ements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Persi stence Save Fi l e Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Edi ti ng Tag Persi stence Setti ngs Usi ng BH_SQL Uti l i ty. . . . . . . . . . . . . . . 30
Persistence in this book
Persistence in the Core Tasks Configuration
Guide
12 / FactoryLink ECS / Core Tasks Configuration Guide

Persistence
1
P
e
r
s
i
s
t
e
n
c
e
FactoryLink ECS / Core Tasks Configuration Guide / 13

Chapter 1
P er si stence
Use the Persi stence task to save the val ues of an acti veFactoryLi nk appli cati on at
predetermi ned ti mes so i f FactoryLi nk i s shut down unexpectedl y, useful data i s
not l ost. Then, when you restar t Factor yLi nk wi th the war m star t command-l i ne
opti on, the Run-Ti me Manager restores the l ast save of the real -ti me database
fr om the persi stence save fi l e.
PERSISTENCE OVERVIEW
The memory-based real -ti me database represents the current state (val ues) of
el ements. The real -ti me database i s a col l ecti on of domai n i nstances. El ements i n
the database may have defaul t val ues whi ch are pl aced i nto the domai n i nstance
when i t i s i ni ti al i zed.
The val ues of the el ements i n a domai n i nstance are l ost when the domai n
i nstance i s cl osed. When the domai n i nstance i s opened agai n, i ts el ements ar e
i ni ti al i zed to thei r defaul t val ues.
Thi s can be a probl em i f FactoryLi nk unexpectedl y shuts down because of an
event such as a power l oss or a faul ty process. Useful informati on can be l ost
because of the i ni ti al i zati on of the real -ti me database to i ts defaul t val ues when
the system i s restarted. Since most of the i nformati on i n FactoryLi nk appl i cati ons
i s the accumul ati on of data over ti me, you cannot r ecover thi s data unl ess i t i s
saved. Persi stence provi des a way of savi ng the state of an acti ve FactoryLi nk
appl i cati on.
Persi stence is the abi l i ty of an el ement to mai ntai n i ts val ue over an indefi ni te
peri od of ti me. Non-persi stent el ements l ose thei r val ue when the Run-Ti me
Manager exi ts and shuts down the real -ti me database. However , the val ues of
persi stent el ements are wri tten to di sk so they are not affected when the real -ti me
database shuts down.
The job of the Persi stence task, therefor e, is to save persi stent data. The task
offer s the fol l owing features.
Runs on al l FactoryLi nk pl atfor ms.
Lets you confi gure on a per-tag basi s or on enti re domai ns whi ch el ements are
persi stent and when thei r val ues are saved to di sk.
PERSISTENCE
Persistence Overview
14 / FactoryLink ECS / Core Tasks Configuration Guide

Saves one or al l domai n i nstances to di sk whi l e a FactoryLi nk appl i cati on i s


runni ng.
Al l ows you to speci fy ei ther a warm or col d star t when ini ti al i zi ng a domai n
i nstance.
Col d star t i ni ti al i zes al l el ements to thei r defaul t val ues as confi gured i n the
Confi gurati on Manager Mai n Menu. Persi stent el ements are not restored to
thei r previ ous val ues but are i ni ti al i zed to thei r defaul t val ues.
War m start i ni ti al i zes al l non-persi stent el ements to thei r defaul t val ues just
l i ke a col d start and restores al l persi stent el ements in the domai n instance to
thei r previ ousl y saved val ues.
Uses i ts own i nternal di sk cache to i ncrease speed and reduce di sk I /O
overhead.
Resol ves confi gurati on changes to the appl i cati on.
Al l ows you to speci fy a tri gger el ement that tri ggers the Persi stence task to
copy the current save fi l e to a backup fi l e.
PERSISTENCE
Principles of Operation
FactoryLink ECS / Core Tasks Configuration Guide / 15
1
P
e
r
s
i
s
t
e
n
c
e
PRI NCIPLES OF OPERATION
Persi stence begi ns duri ng appl i cati on devel opment. Whether confi gur i ng a new
appl i cati on or reconfi guri ng an exi sti ng appl i cati on, you must fi r st determi ne
whi ch el ements are persi stent, when the val ues of the persi stent el ements are
saved to di sk, and how these saved val ues are restored duri ng a war m start. Then,
speci fy thi s i nformati on on the Tag Definition di al og when defi ni ng a persi stent
el ement.
At run ti me, the Persi stence task saves the val ues of the persi stent el ements to i ts
own i nternal di sk cache and the task wri tes the data to di sk fr om ther e. Savi ng
the persi stent val ues to memory fi rst increases processi ng speed and ensures al l
val ues meant to be saved are saved wi thi n the al l otted ti me.
The Persi stence task runs under each domai n that requi res persi stent data to be
saved. The RESOLVE program (executed by the FLRUN command) creates a
bl ank persi stence save fi l e for each domai n the fi rst ti me i t i s executed. Duri ng i ts
i ni ti al i zati on, the Persi stence task l oads the persi stence save fi l e to determi ne
whi ch el ements in the appl i cati on are persi stent and when the val ues of those
el ements are to be saved. I t al so l oads the PERSI ST.CT fi l e to get speci fi c
i nformati on about the confi gurati on of the Persi stence task i tsel f.
When you perform a war m star t, the cur r ent domai ns Run-Ti me Manager
restores the domai n instances real -ti me database fr om the persi stence save fi l e. I t
restores the val ues of the persi stent el ements to the l ast val ues saved by
Persi stence.
To per for m a war m star t of Factor yLi nk, use the war m star t ar gument -w. I n
Windows and OS/2, add the -w to the command l i ne for the i con used to star t
FactoryLi nk; i n UNI X, ei ther pass the -w to the FLRUN command, or add i t to the
l i ne i n the scri pt fi l e used to start FactoryLi nk.
See the tabl e bel ow for detai l s:
PERSISTENCE
Principles of Operation
16 / FactoryLink ECS / Core Tasks Configuration Guide

Before starti ng the Run-Ti me Manager , the FLRUN command executes the
RESOLVE program to check the persi stence save fi l e for any confi gurati on
changes you made. The need to check for confi gurati on changes i s di scussed i n
Resol vi ng Confi gurati on Changes on page 17.
Table 1-1
Starting FactoryLink using the -w (warm start)
Wi ndows Create a new Star t FactoryLi nk i con, fol l owi ng the
steps bel ow:
1. Cl i ck once on the Start FactoryLink i con to sel ect i t.
2. Cl i ck Edit>Copy.
3. Cl i ck Edit>Paste. A copy of the Star t FactoryLi nk
i con i s pasted into the FactoryLi nk Program Group.
I t i s l abel l ed Copy of Start FactoryLink.
4. Change i ts properti es by:
a.) cl i cki ng File>Properties
b.) cl i cki ng i n the command l i ne,
c.) pressi ng the End key (to get to the end of the
command l i ne)
d.) addi ng -w to the end of the command l i ne,
preceded by a space.
5. Cl i ck File>Rename and change the i cons l abel to
Warm Start FactoryLink. Press the Enter key.
OS/2 Create a new Run Ti me Manager i con, fol l owi ng the
steps bel ow:
1. Ri ght cl i ck once on the Run Time Manager i con to
sel ect i t.
2. Cl i ck Copy.
a. Enter Warm Start for the i cons new name.
b. Cl i ck Copy.
3. Ri ght cl i ck once on the Warm Start i con to sel ect i t.
4. Cl i ck Settings. I n Optional Parameters, type -w.
5. Cl ose window.
UNI X Edi t the command l i ne as
$ fl run -w -d -nshared <ret>
or add the -w to the scri pt fi l e usi ng above syntax.
PERSISTENCE
Resolving Configuration Changes
FactoryLink ECS / Core Tasks Configuration Guide / 17
1
P
e
r
s
i
s
t
e
n
c
e
RESOLVI NG CONFIGURATION CHANGES
After you shut down a FactoryLi nk appl i cati on, you mi ght reconfi gure part of the
appl i cati on usi ng the Mai n Menu or the Appli cati on Edi tor . Thi s means the
el ements and thei r val ues stored i n the persi stence save fi l e ei ther may not exi st
or mi ght not have the same data type when you restart the appli cati on. Befor e
each FactoryLi nk sessi on i s restarted, the el ement names stored i n the
persi stence save fi l e must be checked for changes agai nst the OBJECT.CT and the
DOMAI N.CT fi l es.
Thi s resol vi ng of confi gurati on changes i s done by the RESOLVE.EXE (resol ve on
UNI X systems) program. The FLRUN command automati cal l y executes thi s
program before i t starts the Run-Ti me Manager for a parti cul ar FactoryLi nk
sessi on.
The RESOLVE pr ogram serves three purposes.
Creates the bl ank persi stence save fi l e the fi rst ti me i t i s run.
Manages the changes between the persi stence save fi l e and the FactoryLi nk
confi gurati on fi l es.
Determi nes i f the persi stence save fi l e i s usabl e and, i f not, the pr ogr am l ooks
for and uses the persi stence backup fi l e.
RESOLVE makes the fol l owing changes.
Removes el ement names fr om the persi stence save fi l e that have been del eted
fr om the appl i cati on or changed to a di fferent data type.
Updates the el ement name I D for el ement names that wer e del eted, then
recreated.
Adds el ement names to the persi stence save fi l e that have been reconfi gured to
have persi stence. These el ement names are added wi th no data val ues.
Copi es the persi stence backup fi l e over the persi stence save fi l e i f the save fi l e i s
corrupted.
PERSISTENCE
Configuring Persistence for Existing Applications
18 / FactoryLink ECS / Core Tasks Configuration Guide

CONFIGURING PERSISTENCE FOR EXISTING APPLICATIONS


The methods for confi guri ng persi stence are the same for both new and exi sti ng
appl i cati ons. For exi sti ng appl i cati ons, however , you must fi rst run the
FactoryLi nk Conversi on Uti l i ty (FLCONV). FLCONV assi gns the fol l owi ng
defaul t persi stence opti ons to an exi sti ng appli cati on:
Savi ngNo persi stence
Restori ngSet Change Status OFF
After you run the FLCONV uti l i ty, you can change the persi stence opti ons for the
el ements i n that appli cati on. Determi ne the database el ements i n the appl i cati on
to be persi stent and confi gure persi stence for the el ements, ei ther i ndi vi dual l y or
for the enti r e domai n. These methods are expl ai ned in Confi guri ng Persi stence
for New Appl i cati ons on page 18.
CONFIGURING PERSISTENCE FOR NEW APPLICATIONS
To use the war m star t featur e, you must confi gur e whi ch el ements are persi stent,
when thei r val ues wi l l be saved, and how to restore thei r change-status bi ts
duri ng a warm start of FactoryLi nk.
You can confi gure persi stence i n one of two ways.
For indi vi dual el ements.
For al l of the el ements i n a domai n.
The fol l owi ng secti ons di scuss how to confi gure persi stence for both cases.
PERSISTENCE
Configuring Persistence for Individual Elements
FactoryLink ECS / Core Tasks Configuration Guide / 19
1
P
e
r
s
i
s
t
e
n
c
e
CONFIGURI NG PERSISTENCE FOR INDIVIDUAL ELEMENTS
Confi gure persi stence for indi vi dual el ements i n the Tag Definition di al og. The Tag
Definition di al og i s di spl ayed when you
Defi ne a new el ement i n ei ther a confi gurati on panel fr om the Mai n Menu or i n
an ani mati on panel i n the Appli cati on Edi tor .
Press Ctrl-T i n a Tag fi el d for a pr evi ousl y defi ned el ement.
Perfor m the fol l owi ng steps to confi gure persi stence for i ndi vi dual el ements.
1 Defi ne a new el ement or press Ctrl- to displ ay the Tag Definition di al og.
2 Choose the requi red opti ons fr om the Persi stence secti on of the Tag Definition
di al og.
Use Domain
Settings
Saves the val ue of the persi stent el ement accordi ng to the opti ons
chosen for the domai ns persi stence. The Savi ng and Restori ng
opti ons are di sabl ed when thi s opti on i s chosen.
Desel ect Use Domai n Setti ngs to enabl e the Savi ng and Restori ng
opti ons for thi s el ement speci fi cal l y.
PERSISTENCE
Configuring Persistence for Individual Elements
20 / FactoryLink ECS / Core Tasks Configuration Guide

Saving I ndi cates when the val ue of the persi stent el ement i s saved. Thi s
can be one of the fol l owi ng.
On Ti meSaves the val ue of the persi stent el ement on a ti med
tr i gger .
On Excepti onSaves the val ue of the persi stent el ement
whenever i ts val ue changes.
On Ti me and On Excepti onSaves the val ue of the persi stent
el ement on a ti med tri gger and when i ts val ue changes.
Restoring I ndi cates how to restore the persi stent el ement. Thi s can be one
of the fol l owi ng:
Set Change Status ONRestores the persi stent el ement wi th i ts
change-status bi ts set to 1 (ON) after a warm start.
Set Change Status OFFRestores the persi stent el ement wi th i ts
change-status bi ts set to 0 (OFF) after a warm start. Thi s i s the
defaul t.
No Opti ons Sel ectedThe el ement i s not marked as persi stent.
PERSISTENCE
Configuring Persistence for All Elements in a Domain
FactoryLink ECS / Core Tasks Configuration Guide / 21
1
P
e
r
s
i
s
t
e
n
c
e
CONFIGURI NG PERSISTENCE FOR ALL ELEMENTS IN A DOMAIN
Compl ete the fol l owi ng steps to confi gure persi stence for al l el ements i n a domai n
i n the Domain Element List.
1 Choose Vi ew>Domain List to displ ay the Domain Element List.
The l i st i ncl udes the domai n name, the parent domai n, the number of appli cati on
i nstances avai l abl e for the domai n, domai n persi stence, and the setti ng for change
bi ts. Use the Persistence and Change Bits fi el ds to confi gure persi stence for an
enti r e domai n.
2 Choose the Persistence fi el d for the row contai ni ng the domai n to be made
persi stent. Enter the method you want to use to save the el ements val ues. Thi s
can be one of the fol l owi ng.
None The el ements i n the domai n are not marked as persi stent.
Timed Saves the val ues of the domai ns el ements on a ti med tr i gger .
Except Saves the val ues of the domai ns el ements whenever thei r val ues
change.
Both Saves the val ues of the domai ns el ements both on a ti med tri gger
and whenever thei r val ues change.
3 Choose the Change Bits fi el d for the same domai n and enter how you want to
restore the el ements change-status bi ts. Thi s can be one of the fol l owi ng.
ON Restores the domai ns el ements wi th thei r change-status bi ts set
to 1 (ON) after a war m star t.
OFF Restores the domai ns el ements wi th thei r change-status bi ts set
to 0 (OFF) after a war m star t.
PERSISTENCE
Configuring Persistence for All Elements in a Domain
22 / FactoryLink ECS / Core Tasks Configuration Guide

For exampl e, you may have several Math & Logi c procedures
tr i ggered by di gi tal tags, but the appl i cati on control s when these
tags ar e force-wri tten to a 1 (val ue=1; change-status bi ts=1). I f
you per for m a war m star t wi th Change Bi ts ON, then al l of the
di gi tal tags change-status bi ts are wri tten to a 1 and al l of your
I ML procs run at once.
PERSISTENCE
Configuring the Persistence Task
FactoryLink ECS / Core Tasks Configuration Guide / 23
1
P
e
r
s
i
s
t
e
n
c
e
CONFIGURI NG THE PERSISTENCE TASK
I n addi ti on to confi guri ng persi stence for el ements and domai ns, you must al so
confi gur e the operati on of the Persi stence task i tsel f. Choose Persistence to di spl ay
the Persi stence Save I nformati on panel .
Fol l owi ng are fi el d descri pti ons for thi s panel .
Timed Save
Trigger
Name of an el ement used to tr i gger a ti med save of the val ues of
al l el ements marked as persi stent by ti me.
When the el ement defi ned here i s tri ggered at run ti me, the
Persi stence task reads al l el ements in the current domai n
i nstance confi gured to be saved on a ti med basi s and wri tes thei r
val ues to di sk (the persi stence save fi l e).
Leave thi s fi el d bl ank i f no ti med saves are requi red for the
appl i cati on.
A Tag Definition di al og i s di splayed when you cl i ck on Enter i f the
tag speci fi ed i n thi s fi el d i s not al ready defi ned.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, fl oat, message
PERSISTENCE
Configuring the Persistence Task
24 / FactoryLink ECS / Core Tasks Configuration Guide

Cache Buffers Number between 0 and 32766 indi cati ng the number of buffer s to
be set asi de for the Persi stence tasks i nternal di sk cache. The
defaul t i s 16. The gr eater the number of buffers, the l ess the task
wri tes to the di sk, whi ch i mproves performance.
Use the fol l owi ng gui del i nes to ai d i n determi ni ng the number of
buffers:
- How often the data i s changi ng
- How much of the data i s changi ng
- The si ze of the data that is changi ng
Whi l e there i s no defi ni ti ve way to determi ne the ideal number of
buffers, you can use the total number of tags of each data type
that ar e persi stent in the appl i cati on to cal cul ate an esti mati on of
the maxi mum buffer si ze. The for mul a i s gi ven as fol l ows:
max buffer si ze = [(#of anal og + di gi tal )*2] + [(#of l ongana)*4] +
[(#of fl oat)*8] + [(#of msg)*l en]
wher e len i s the message l ength fr om the Persi stence panel .
Then sel ect a combi nati on of number of buffer s mul ti pli ed by
buffer si ze that equal s thi s val ue. (See Buffer Si ze, bel ow.)
I f you enter 0, no di sk cachi ng i s done. Thi s can be desi rabl e i f the
operati ng system i tsel f uses an effi ci ent di sk cachi ng system
(such as UNI X).
Valid Entry: numeri c val ue of up to 32766 (defaul t = 16)
Buffer Size Number between 64 and 32766 i ndi cati ng the si ze, i n bytes, of
each buffer i n the cache. The defaul t i s 512. The l arger the buffer ,
the l ess the task wri tes to the di sk, whi ch i mpr oves performance.
Valid Entry: numeri c val ue of up to 32766 (defaul t = 512)
Message Copy
Size
Number between 80 and 32766 i ndi cati ng the maxi mum l ength
al l owed for message el ements duri ng persi stent saves.
FactoryLi nk uses the number entered here when i t reads
el ements fr om the real -ti me database, and when restori ng val ues
dur i ng a war m star t. The defaul t i s 2048.
Valid Entry: numeri c val ue of up to 32766 (defaul t = 2048)
PERSISTENCE
Configuring the Persistence Task
FactoryLink ECS / Core Tasks Configuration Guide / 25
1
P
e
r
s
i
s
t
e
n
c
e
Backup Trigger Name of an el ement used to tr i gger a backup of the cur r ent
persi stent save fi l e.
A Tag Definition di al og i s di splayed when you cl i ck on Enter i f the
tag speci fi ed i n thi s fi el d i s not al ready defi ned.
At run ti me, when the appl i cati on tri ggers the el ement defined
here, the Persi stence task copi es the current persi stence save fi l e
to a backup fi l e.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, fl oat, message
The compl eted panel resembl es the fol l owi ng sampl e:
I n thi s exampl e, when the val ue of the el ement persi st_tri g changes to 1 (ON), i t
tri ggers the Persi stence task to wr i te to di sk the val ues of al l el ements i n the
appl i cati on confi gured as persi stent by ti me. The number of buffers set asi de for
the i nternal cache i s 16 wi th 512 bytes per buffer . A di sk cache i s a way to
compensate for the sl owness of the di sk dri ve i n compari son to RAM (memor y).
The Persi stence tasks cache process speeds up computer operati ons by keepi ng
data i n memor y. Rather than wri ti ng each pi ece of data to be saved to the hard
disk, the task wri tes the data to i ts i nternal di sk cache (reserved memor y ar ea).
Then, when the di sk i s not busy wi th other processi ng or when the cache process
can per for m several wri tes i n an order that mi ni mi zes the movements of the disks
heads, the cache process wr i tes the saved data to the hard di sk.
The maxi mum l ength for message el ements duri ng persi stent saves i s 2048 bytes.
When the val ue of the el ement persi st_backup changes to 1, i t tri gger s Persi stence
to copy the cur r ent persi stence save fi l e to a backup fi l e.
PERSISTENCE
Persistence Task Start Order
26 / FactoryLink ECS / Core Tasks Configuration Guide

PERSISTENCE TASK START ORDER


Thi s secti on descri bes some possi bl e effects of warm restarts on the appl i cati on
dependi ng on when Persi stence starts and what has happened to the other tasks
duri ng the startup process. Thi s di scussi on ONLY appl i es i f the TASKSTART_?
tags (fr om the System Confi gurati on Tabl e) are made persi stent.
Example 1: Persi stence starts l ast and shuts down fi rst
After the appl i cati on star ts, the val ues of the TASKSTART_? tags ar e 1, so
Persi stence saves a 1 as thei r l ast known val ue. At shutdown, because Persi stence
stops fi rst, Persi stence does not see the change i n val ue of the TASKSTART_?
tags fr om 1 to 0 (zer o), so the saved val ues remai n as 1. On a war m star t of the
appl i cati on, the TASKSTART_? tags for al l tasks that were runni ng at shutdown
wi l l be restored to 1 and therefor e, thei r tasks wil l star t. I t i s i mportant to note
that these same tasks wi l l be started regardl ess of thei r R fl ag setti ngs in the
SYS.CT fi l e. (Thi s assumes no manual starts/termi nati ons.)
Example 2: Persi stence starts fi rst and shuts down l ast
Because Persi stence starts fi rst, i t sees the appli cati on starti ng and therefore
sees the val ues of the TASKSTART_? tags at 0. I f there i s a termi nati on duri ng
the startup process, then, because Persi stence stops l ast, i t saves a 0 as the l ast
known val ue of the TASKSTART_? tags. On a warm start of the appl i cati on, none
of the tasks wil l be started because al l of the tasks TASKSTART_? tags had a l ast
known val ue of 0.
The shutdown order i s more si gni fi cant than the startup order i f the tags ar e
saved on change. I n general , speci fy the Persi stence task to shutdown fi rst (and
therefor e, start l ast) so that the saved val ues i n the Persi stence save fi l e r efl ect
the l ast known runni ng state of the appl i cati on at shutdown. Then, the war m
star t wi l l restore i t to that state, whi ch i s the purpose of the Persi stence task.
PERSISTENCE
Persistence and Digital Elements
FactoryLink ECS / Core Tasks Configuration Guide / 27
1
P
e
r
s
i
s
t
e
n
c
e
PERSISTENCE AND DIGITAL ELEMENTS
The way a di gi tal el ement i s used i n an appli cati on affects how that el ement i s
confi gured for persi stence. Di gi tal el ements ar e often used to tri gger some acti on
i n an appl i cati on. Exampl es incl ude starti ng a Math and Logi c procedure or
starti ng a FactoryLi nk task. When a di gi tal el ement i s tri ggered (i ts val ue is
changed from 0 to 1 or force-wri tten to 1), FactoryLi nk starts the associ ated
procedure or task. When FactoryLi nk i s warm-started, these el ements are
restored to thei r l ast saved val ue. Confi guri ng a di gi tal el ement as persi stent wi th
i ts val ue to be restored wi th Force Change Status ON can be used to start any
procedure or task associ ated wi th thi s el ement after the system i s i ni ti al i zed.
However , the di gi tal el ements RTMCMD and RTMCMD_U, cannot be made
persi stent. Thi s is because when the val ue of these el ements i s set to 1, the
FactoryLi nk system shuts down. Therefor e, maki ng these el ements persi stent
i mmedi atel y shuts down the system as soon as i t comes up.
Note that the R (Run) fl ag for each task i n the System Confi gurati on I nformati on
panel supersedes the val ue of the di gi tal start tri gger associ ated wi th a task.
Examples
The fol l owi ng exampl es show the rel ati onshi p between the R fl ag i n the System
Confi gurati on I nformati on panel and the restored val ue of a di gi tal el ement:
Example 1:
The R fl ag i s NOT set for task A and the di gi tal start tri gger associ ated wi th task
A i s defi ned as persi stent by Excepti on (al ways updated) wi th Force Change
Status ON i f:
Task A i s runni ng when the system i s shut down, then the val ue of the tasks
di gi tal star t tr i gger i s 1. When a war m star t i s per for med, the system restar ts
task A because the val ue of the di gi tal start tri gger i s restored to 1.
Task A i s not runni ng when the system i s shut down, then the val ue of the
tasks di gi tal start tr i gger i s 0. When a war m start i s performed, the system
does not restart task A because the val ue of the di gi tal start tri gger i s restored
to 0.
PERSISTENCE
Persistence and Digital Elements
28 / FactoryLink ECS / Core Tasks Configuration Guide

Example 2:
The R fl ag I S set for task A and the di gi tal start tri gger associ ated wi th task A i s
defi ned to be persi stent by Excepti on (al ways updated) wi th Force Change Status
ON i f:
Task A i s runni ng when the system i s shut down, then the val ue of the tasks
di gi tal start tri gger is 1. When a war m star t i s performed, the system restarts
task A because the val ue of the di gi tal start tri gger i s restored to 1.
Task A i s not runni ng when the system i s shut down, then the val ue of the
task's di gi tal start tri gger i s 0. When a war m star t i s performed, the system sti l l
restarts task A because, even though the val ue of the di gi tal start tri gger is
restored to 0, the tasks Run fl ag is set and the Run fl ag supersedes the restored
val ue of the di gi tal start tr i gger .
PERSISTENCE
Persistence Save File Name
FactoryLink ECS / Core Tasks Configuration Guide / 29
1
P
e
r
s
i
s
t
e
n
c
e
PERSISTENCE SAVE FILE NAME
The persi stent data is saved i n a uni que persi stence save fi l e for each domai n
i nstance. The persi stence save fi l es have the extensi on.PRS and ar e l ocated i n the
/FLAPP/FLNAME/FLDOMAI N di rectory.
where
FLAPP i s the transl ated appl i cati on envi ronment vari abl e.
FLNAME i s the transl ated appl i cati on envi ronment vari abl e.
FLDOMAIN i s the transl ated domai n envi ronment vari abl e.
The name of each persi stence save fi l e i s {FLUSER}.PRS where FLUSER i s the
transl ated envi ronment vari abl e for the domai n user name. The persi stence save
fil e contai ns the saved val ues for that domai n user.
For exampl e, i n Wi ndows, where the FLRUN.BAT fi l e sets the Shared FLUSER
envi ronment vari abl e to SHAREUSR, but the User domai n FLUSER envi ronment
vari abl e remai ns at the defaul t setup i n the AUTOEXEC.BAT fi l e, the Shared
persi st fi l e i s named SHAREUSR.PRS and the User persi st fi l e i s named
FLUSER1.PRS.
The persi stence backup fi l es are i n the same pl ace and have the same name,
except they have the extensi on.BAK (.bak in UNI X).
PERSISTENCE
Editing Tag Persistence Settings Using BH_SQL Utility
30 / FactoryLink ECS / Core Tasks Configuration Guide

EDITING TAG PERSISTENCE SETTINGS USING BH_SQL UTILITY


I t may be useful for user s to be abl e to make mass edi ts to the current persi stence
setti ngs for defi ned tags i n the OBJECT confi gurati on tabl e, such as changi ng the
fi el d entri es for al l tags that currentl y are bl ank, to a speci fi c setti ng such as
NONE. Thi s can be done usi ng the BH_SQL uti l i ty pr ovi ded wi th al l FactoryLi nk
systems. Thi s uti l i ty
1. Modi fi es the OBJECT.CDB fi l e in the FLAPP di rector y.
2. Modi fi es the TAGPERWHEN fi el d in that fi l e.
TAGPERWHEN (meani ng Tag i s saved when? ) i s the text equi val ent of the radi o
buttons seen on the Tag Definition di al og when defi ni ng a tag or usi ng CTRL-T to
vi ew the tag defi ni ti on. The possi bl e val ues are:
NONE - tag i s not persi stent
l eft bl ank - same as NONE
DOMAI N - save based on domai n persi stence defi ni ti on as confi gured i n the
Domain confi gurati on panel .
TI MED- save on ti med tri gger
EXCEPT - save on change
The procedure updates the tabl e changi ng al l i nstances of a speci fi c entr y i n the
TAGPERWHEN fi el d at one ti me to a new val ue.
Pri or to executi ng the i nstructi ons bel ow, we r ecommend you make a backup of
the appl i cati on usi ng the FLSAVE uti l i ty or some other backup uti l i ty. At l east
make a backup copy of the OBJECT.CDB and OBJECT.MDX fi l es so i f anythi ng
goes wr ong duri ng the procedure, the backup can be restored wi th no damage
done to the appli cati on. The general syntax can be modi fi ed to update the
persi stence setti ng for any group of tags fr om the current setti ngs to any valid
new setti ng as a group, by varyi ng the l i teral val ues i n the fi rst and second
i nstance of tagperwhen = '????'.
Fol l ow the steps bel ow to use the BH_SQL uti l i ty:
1. Run BH_SQL by typi ng the program name at a prompt for al l systems except
MS Wi ndows. For MS Wi ndows, run the program from the Program Manager -
Fi l e>Run menu sel ecti on.
PERSISTENCE
Editing Tag Persistence Settings Using BH_SQL Utility
FactoryLink ECS / Core Tasks Configuration Guide / 31
1
P
e
r
s
i
s
t
e
n
c
e
2. Type at the BH_SQL pr ompt:
SQL > connect flapp <ret>
where fl app is the actual path to the fl app di rectory as defi ned i n the FLAPP
envi ronment vari abl e.
3. Type at the BH_SQL pr ompt (quote marks are al l si ngl e quotes not doubl e
quotes):
SQL > update object set tagperwhen = 'NONE' where tagperwhen =
'' <ret>
where the fi rst i nstance of tagperwhen = 'NONE' i s the desi red new val ue for the
fi el d and the second i nstance i s the current val ue of the fi el d (i n thi s case a bl ank
entr y). Thi s command fi nds al l records i n the OBJECT tabl e for whi ch the current
tag persi stence setti ng i s bl ank and changes al l the setti ngs to NONE.
Use the fol l owi ng command i f you have a l arge number of tags confi gured to be
saved as defi ned for the domai n confi gurati on and you want to change the setti ng
for al l of these tags to be saved i ndi vi dual l y when they change val ue or on
excepti on.
SQL > update object set tagperwhen = 'DOMAIN' where tagperwhen =
'EXCEPT' <ret>
Type QUI T at the BH_SQL prompt once al l desi red changes have been made.
PERSISTENCE
Editing Tag Persistence Settings Using BH_SQL Utility
32 / FactoryLink ECS / Core Tasks Configuration Guide

Part I I
Event and Interval Timer
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 35
Table of Contents
Event and I nter val Ti mer

2 Event and Interval Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37


Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Changi ng the Oper ati ng System Date and Ti me. . . . . . . . . . . . . . . . . . . . . . 40
Confi guri ng the Event and I nterval Ti mer Task . . . . . . . . . . . . . . . . . . . . . . 40
Event Timer I nformation Dialog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
I nterval Timer I nformation Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Event and Interval Timer in this book
Event and Interval Timer in the Core Tasks Con-
figuration Guide
36 / FactoryLink ECS / Core Tasks Configuration Guide

Event and Interval Timer


FactoryLink ECS / Core Tasks Configuration Guide / 37

2
E
v
e
n
t

a
n
d

I
n
t
e
r
v
a
l

T
i
m
e
r
Chapter 2
Event and I nter val
Ti mer
Use the Event and I nterval Ti mer task to defi ne ti med events and ti me interval s
that ini ti ate and control any system functi on in run-ti me mode.
Ti med events occur at a speci fi c ti me not mor e than once ever y 24 hour s (for
exampl e, Monday at 8:00 am). They are confi gured i n the Event Ti mer Tabl e.
Ti me i nterval s occur at l east once every twenty-four hours at regul ar i nterval s
of the system cl ock (for exampl e, ever y 60 seconds). They are confi gured i n the
I nterval Ti mer Tabl e.
The Event and I nterval Ti mer task l i nks ti med events and i nterval s to real -ti me
database el ements used as tr i gger s whenever the event or i nter val occur s. I t i s
defi ned i n the SHARED domai n.
The use of Event and I nterval ti mers requi res an understandi ng of change-status
fl ags. Refer to the FactoryLink Fundamentals manual for thi s di scussi on.
There i s no l i mi t, except the amount of avai l abl e memory, to the number of event
and interval ti mers that can be defi ned.
EVENT AND INTERVAL TIMER
Principles of Operation
38 / FactoryLink ECS / Core Tasks Configuration Guide

PRINCIPLES OF OPERATION
The Event and I nterval Ti mer task operates i n synchroni zati on wi th the system
cl ock. For each defi ned i nterval or event, you must create a di gi tal el ement in the
real -ti me database. When the system cl ock matches the speci fi ed event or
i nterval , the task forces the val ue of thi s di gi tal el ement to 1 (ON).
The Event and I nterval Ti mer task al so updates gl obal informati on used by
FactoryLi nk such as the current ti me, the day of the week, and the month. Such
gl obal i nformati on i s stored i n predefined FactoryLi nk real -ti me database
el ements, known as reserved el ements, each of whi ch i s one of the fol l owi ng data
types: anal og, l ong anal og, or message.
The fol l owi ng tabl e l i sts reserved el ements that ar e updated by the Event and
I nter val Ti mer task.
Whi l e the Ti mer task i s runni ng, these reserved el ements ar e constantl y updated.
I n order for the Ti mer task to r un, you must have entered an R fl ag for the Ti mer
task i n the System Confi gurati on Tabl e i n the Confi gurati on Manager Mai n
Menu.
Table 2-1
Reserved Element Data Type
A_SEC Anal og
A_MI N Anal og
A_HOUR Anal og
A_DAY (Day of month) Anal og
A_MONTH Anal og
A_YEAR Anal og
A_DOW (Day of week) Anal og
A_DOY (Day of year) Anal og
DATE (DOW MM-DD-YYYY) Message
TI ME (HH:MM:SS) Message
DATETI ME (DOW MM-DD-YYYY HH:MM:SS) Message
EVENT AND INTERVAL TIMER
Principles of Operation
FactoryLink ECS / Core Tasks Configuration Guide / 39
2
E
v
e
n
t

a
n
d

I
n
t
e
r
v
a
l

T
i
m
e
r
YYMMDD (YY-MM-DD) Message
SECDAY (Seconds si nce start of current day) Long Anal og
SECYEAR (Seconds si nce start of current year) Long Anal og
SECTI ME (Seconds si nce January 1, 1980) Long Anal og
Table 2-1 (Continued)
Reserved Element Data Type
EVENT AND INTERVAL TIMER
Changing the Operating System Date and Time
40 / FactoryLink ECS / Core Tasks Configuration Guide

CHANGING THE OPERATING SYSTEM DATE AND TIME


To change the operati ng system date and ti me whi l e FactoryLi nk i s runni ng, shut
down the Ti mer task, change the date and ti me, and restart the task. Otherwi se,
the Ti mer task tri es to catch up by processi ng mi ssed i nterval s.
CONFIGURING THE EVENT AND INTERVAL TIMER TASK
Use thi s task to si gnal the occurrence of speci fi ed events or i nterval s by wri ti ng to
di gi tal el ements in the FactoryLi nk real -ti me database.
The Event and I nterval Ti mer task uses the SHARED domai n. Before openi ng
and confi guri ng the Event and I nterval Ti mer task, ensur e the current domai n
sel ected i s SHARED i n the Confi gurati on Manager Domai n Sel ecti on box.
Event Timer Information Dialog
Use Event Ti mer to defi ne events that onl y occur not more than once every 24
hours. For exampl e, use event ti mers to start or stop reports, and as tri ggers to
read and wr i te reci pe fi l es.
Choose Event Ti mer to displ ay the Event Timer Information di al og.
EVENT AND INTERVAL TIMER
Configuring the Event and Interval Timer Task
FactoryLink ECS / Core Tasks Configuration Guide / 41
2
E
v
e
n
t

a
n
d

I
n
t
e
r
v
a
l

T
i
m
e
r
Fol l owi ng are fi el d descri pti ons for thi s di al og.
Tag Name El ement name (for exampl e, ti me8am) to be assi gned to the
event. When the event occur s, the el ement i s for ced to 1 so i ts
change-status bi t is set to 1. The Ti mer task resets al l event
ti mers back to zer o at mi dni ght. You can assi gn mor e than one
el ement to the same event.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter with a tag type
of digital in the Type field. Accept this default.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal (defaul t = di gi tal )
Year, Mon. Day
DOW
Speci fy a peri od when an event i s to occur . Enter a Year (Year )
month (Mon) day (Day) and day-of-the-week (DOW) or
combi nati on as expl ai ned bel ow.
When usi ng Day and Month, the event occur s onl y on thi s date i n
the speci fi ed month i n the speci fi ed year . I f you do not enter a
month, the event occurs on thi s date ever y month. I f you do not
enter a month and year, the event occurs on thi s date ever y
month of ever y year .
When usi ng DOW, i f you enter a month, the event occurs on thi s
day ever y week of that month onl y. I f you do not enter a month,
the event occur s on thi s day ever y week. I f you enter a month and
year, the event occurs on thi s day ever y week of the speci fi ed
month duri ng the speci fi ed year. I f you do not enter a month and
year, the event occurs on thi s day ever y week of every year.
Year 4-di gi t year such as 1994.
Month 1-12 or MMM (Exampl e: March i s 3 or MAR for
fi rst thr ee l etter s of the months name.)
Day 1-31 indi cati ng the day of the month the event is to
occur . I f the event i s to occur once ever y day, l eave
thi s fi el d bl ank.
DOW MON - SUN Fi rst three l etters of a weekday. I f the
event i s to occur once ever y day, l eave the fi el d
bl ank.
Hours Refer to the fol l owi ng discussi on of Hour s, Mi ns.,
and Secs.
EVENT AND INTERVAL TIMER
Configuring the Event and Interval Timer Task
42 / FactoryLink ECS / Core Tasks Configuration Guide

Mins. Refer to the di scussi on of Hour s, Mi ns., and Secs.


that fol l ows.
Hours, Mins. Secs. Hours, Mi ns. (mi nutes), and Secs. (seconds) fi el ds defi ne the
speci fi c ti me (i n 24-hour for mat) at whi ch an event i s to occur .
The event ti mer assumes a defaul t val ue of 0 for bl ank fi el ds. The
conventi ons for use ar e:
Hours Hour the event i s to occur (0 to 23).
Mins. Number of mi nutes (0 to 59) after the hour the
event i s to occur . I f the event i s to occur on the
hour, l eave thi s fi el d bl ank.
Secs. Number of seconds (0 to 59) after the mi nute (or
hour ) the event is to occur .
Between mi dni ght (00:00:00) and the ti me indi cated i n the Hours,
Mi ns., and Secs. fi el ds, the val ue of the el ement to whi ch an event
is li nked i s 0 (OFF). After the ti med event occur s, the el ements
val ue changes to 1 (ON) and stays thi s way unti l mi dni ght, when
i t changes back to 0 (OFF).
Hours 0 - 23 (0 i s mi dni ght and 23 i s 11:00 pm.)
Mins. 0 - 59
Secs. 0 - 59
First Val ue that determi nes the acti on taken upon system startup, i f
startup occurs after a ti med event. Because thi s fi el d onl y affects
events schedul ed for the current date, the system checks the date
befor e changi ng any val ues.
Yes The el ements val ue i mmedi atel y changes to 1
(ON), i ndi cati ng the ti med event has occur red for
that date. The change-status fl ags are al so set to 1
(ON).
No Defaul tthe el ements val ue i s l eft as i s and
does not change to 1 (ON) unti l the next
occur rence of the ti med event.
EVENT AND INTERVAL TIMER
Configuring the Event and Interval Timer Task
FactoryLink ECS / Core Tasks Configuration Guide / 43
2
E
v
e
n
t

a
n
d

I
n
t
e
r
v
a
l

T
i
m
e
r
When al l i nformati on has been speci fi ed, the di al og resembl es the sampl e di al og
bel ow:
I n thi s exampl e, the startday el ement has a val ue of 0 between mi dni ght and 8:00
am and 1 between 8:00 am and 11:59 pm and 59 seconds (23.59.59) each day of the
year .
Si mi l arl y, the endday el ement has a val ue of 0 between mi dni ght and 5:00 pm and
1 between 5:00 pm and 11:59 pm and 59 seconds.
The newyear el ements val ue has a val ue of 1 on January 1 of each year and 0 on
al l other days.
Si mi l arl y, the l astday el ements val ue has a val ue of 1 on December 31 of each
year and 0 on al l other days.
The fri 5pm el ement has a val ue of 1 each Fri day between 5:00 pm and mi dni ght.
Cli ck Enter to save the i nformati on and return to the Mai n Menu when you fi ni sh
setti ng the event ti mer s.
Interval Timer Information Dialog
Use I nterval Ti mer to defi ne events that occur at l east once every 24 hours at
regul ar i nterval s of the system cl ock, such as ever y second or ever y two hour s. For
exampl e, use i nterval ti mers as tri ggers i n Pol l ed Read or Wr i te PLC tabl es and i n
Send or Recei ve tabl es for FL/LAN Network confi gurati ons.
EVENT AND INTERVAL TIMER
Configuring the Event and Interval Timer Task
44 / FactoryLink ECS / Core Tasks Configuration Guide

Choose I nterval Ti mer to displ ay the Interval Timer Information di al og.


Fol l owi ng ar e fi el d descri pti ons for thi s di al og.
Tag Name Name of the el ement (for exampl e, sec5) to be assi gned to the
i nterval . You can assi gn the same i nterval to more than one
el ement.
I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag
Definition di al og i s displ ayed when you cl i ck on Enter with a tag type
of digital in the Type field. Accept this default.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal (defaul t = di gi tal )
Hours Mins. Secs.
10ths
Hours, Mi ns. (mi nutes), Secs. (seconds), and 10ths (tenths of a
second) fi el ds defi ne the i nterval at whi ch an event i s to occur . I f
these fi el ds ar e l eft bl ank, the i nterval ti mer assumes a defaul t
val ue of 0. At l east one of these fi el ds must be fi l l ed in wi th a
val i d entr y (not zer o, as i t i s not consider ed a val i d entry) or el se
the system does not al l ow the I Ti mer to star t, but i nstead
di spl ays the er r or message:
Bad data in ITimer record (record#), file (itimer.exe).
Dependi ng on the i nterval you speci fy, the ti mer starts at
mi dni ght or at system startup. I f the i nterval can be di vi ded
evenl y i nto 24 hours (86,400 seconds, or 1,440 mi nutes), the ti mer
runs as i f i t started at mi dni ght. I f the i nter val cannot be evenl y
di vi ded i nto 24 hours, the ti mer starts at system startup.
Conventi ons for use:
Hours A number between 0 and 23 that i ndi cates the
l ength, i n hours, of the i nterval . Exampl e: Ever y 2
hour s (2), ever y 3 hours (3), etc.
EVENT AND INTERVAL TIMER
Configuring the Event and Interval Timer Task
FactoryLink ECS / Core Tasks Configuration Guide / 45
2
E
v
e
n
t

a
n
d

I
n
t
e
r
v
a
l

T
i
m
e
r
Mins A number between 0 and 59 that i ndi cates the
l ength, i n mi nutes, of the interval . Exampl e: Ever y
5 mi nutes (5), every 10 mi nutes (10), etc.
Secs A number between 0 and 59 that i ndi cates the
l ength, i n seconds, of the i nterval . Exampl e: Every
second (1), every 7 seconds (7), etc.
10ths A number between 0 and 9 that i ndi cates the
l ength, i n tenths of a second, of the i nterval .
Exampl e: Every tenth of a second (1), ever y hal f
second (5), etc.
When al l i nformati on has been speci fi ed, the Interval Timer Information di al og
resembl es the sampl e di al og bel ow:
I n thi s exampl e, the sec5 el ements change-status fl ags are set to 1 ever y 5
seconds; that is, when the reserved anal og el ement A_SEC = 0, 5, 10, 15, ... 55.
Thi s ti mer runs as i f i t star ted at mi dni ght. Therefore, i f system startup ti me is
9:39:18, the sec5 el ements change-status fl ags are fi rst set 2 seconds l ater, at
9:39:20, and ever y 5 seconds thereafter .
The sec30 el ements change-status fl ags are set to 1 every 30 seconds, when
A_SEC = 0 and 30. Thi s ti mer runs as i f i t started at mi dni ght.
The mi n7 el ements change-status fl ags are set to 1 every 7 mi nutes after system
startup, because 1,440 i s not evenl y di vi si bl e by 7.
The mi n20 el ements change-status fl ags are set to 1 every hour, agai n at 20
mi nutes after the hour, and agai n at 40 mi nutes after the hour.
EVENT AND INTERVAL TIMER
Configuring the Event and Interval Timer Task
46 / FactoryLink ECS / Core Tasks Configuration Guide

The report1 el ements change-status fl ags are set to 1 ever y hour and 17 mi nutes,
after system startup.
The hour8 el ements change-status fl ags are set to 1 three ti mes a day: at 8:00 am,
4:00 pm, and mi dni ght, r egardl ess of system startup ti me.
When i nterval ti mers are used as tri ggers for other tasks, such as PLC read
tri ggers or Report Generator tri ggers, these tasks automati cal l y use the
change-status fl ags associ ated wi th these ti mers.

Part I I I
Programmable Counters
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 49
Table of Contents
Pr ogr ammabl e Counter s

3 Programmable Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Digital and Analog Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Example One . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Example Two. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Programmabl e Counters I nformati on Panel . . . . . . . . . . . . . . . . . . . . . . . . . 55
Programmable Counters in this book
Programmable Counters in the Core Tasks Con-
figuration Guide
50 / FactoryLink ECS / Core Tasks Configuration Guide

Programmable Counters
FactoryLink ECS / Core Tasks Configuration Guide / 51

3
P
r
o
g
r
a
m
m
a
b
l
e

C
o
u
n
t
e
r
s
Chapter 3
P r ogr ammabl e
Counter s
Use the Pr ogrammabl e Counters task to provi de count-per -uni t-of-ti me
measurements and to pr ovi de event del ays, such as defi ni ng a tri gger to unl ock a
door and then speci fyi ng a del ay before the door l ocks agai n.
A programmabl e counter i s a group of el ements wi th val ues that wor k together to
per for m a count. Outputs fr om pr ogrammabl e counters can be used to pr ovi de
input to Math and Logi c programs or other FactoryLi nk tasks or to tri gger Math
and Logi c programs.
There i s no l i mi t, except the amount of memor y, to the number of programmabl e
counters that can be defi ned.
The Programmabl e Counters task uses ei ther the SHARED or USER domai n.
The use of programmabl e counters requi res an understanding of change-status
fl ags. Refer to FactoryLink Fundamentals for thi s di scussi on.
PROGRAMMABLE COUNTERS
Principles of Operation
52 / FactoryLink ECS / Core Tasks Configuration Guide

PRINCIPLES OF OPERATION
A programmabl e counter i s a group of el ements wi th components that wor k
together to per for m a count. Each programmabl e counter i s made up of some or al l
of the fol l owi ng el ements and anal og and di gi tal val ues.
Elements
Enabletri ggers counti ng acti vi ty.
Up Clocki ni ti ates the count upward.
Down Clock i ni ti ates the count downward.
Clearresets the counted val ue to the starti ng poi nt.
Positive Outputcontai ns the val ue 1 (on) when the counti ng l i mi t has been
reached.
Negative Outputcontai ns the val ue 0 (off) when the counti ng l i mi t has been
reached.
Current Valuei ndi cates the current val ue of the count.
Digital and Analog Values
Preset Valueanal og val ue that speci fi es the starti ng val ue.
Increment Valueanal og val ue that speci fi es the amount by whi ch the count
i s to i ncrease or decrease each ti me.
Terminal Valueanal og val ue that speci fi es the counti ng l i mi t.
AutoCleardi gi tal val ue that resets the count to the starti ng poi nt whenever
the termi nal val ue i s reached.
Counti ng begi ns when another FactoryLi nk task, such as Math and Logi c or EDI ,
wri tes a 1 (ON) to the Up Cl ock el ement. Thi s tri ggers the Programmabl e
Counters task to move the Current Val ue toward the Termi nal Val ue by the
I ncrement Val ue. I f the Preset Val ue i s l ess than the Ter mi nal Val ue, the
I ncrement is added to the Current Val ue. I f the Preset Val ue i s more than the
Termi nal Val ue, the I ncrement i s subtracted fr om the Current Val ue.
PROGRAMMABLE COUNTERS
Principles of Operation
FactoryLink ECS / Core Tasks Configuration Guide / 53
3
P
r
o
g
r
a
m
m
a
b
l
e

C
o
u
n
t
e
r
s
Example One
I n thi s exampl e, counti ng i s tri ggered to count bottl es (20 per case). The Preset
Val ue (start count) i s 0, and the Termi nal Val ue (count l i mi t) for the number of
bottl es per case i s 20. The I ncrement Val ue of 1 represents one bottl e. When
counti ng i s tri ggered, each bottl e counted i ncreases the current count of bottl es
(starti ng wi th 0 i n the case) by 1 unti l the case contai ns 20 bottl es (unti l the
Current Val ue reaches the Ter mi nal Val ue of 20).
When the case contai ns 20 bottl es (when the Current Val ue reaches the Ter mi nal
Val ue), the Counter task i ndi cates the case i s ful l by for ce-wr i ti ng a 1 (ON) to the
Posi ti ve Output el ement and force-wri ti ng a 0 (OFF) to the Negati ve Output
el ement. At thi s poi nt, i f AutoCl ear = YES, the Current Val ue el ement i s reset to 0
(the Preset Val ue), and the count can begi n agai n. I f AutoCl ear = NO, the current
Val ue el ement remai ns at 20 (the Termi nal Val ue), unti l another task wri tes a 1
(ON) to the cl ear el ement, i ndi cati ng the count can begi n agai n. The count does
not conti nue past 20 (the Ter mi nal Val ue). Each ti me the bottl e count reaches 20
(the Termi nal Val ue), the Counter task agai n for ce-wr i tes a 1 (ON) and a 0 (OFF)
to the Posi ti ve and Negati ve Output el ements. When AutoCl ear = YES, or when
the Cl ear el ement i s tr i ggered, the bottl e count i s reset to 0 (the Preset Val ue),
ready for a repeat of the counti ng process.
Example Two
You can set up another task, such as EDI or Math and Logi c, to react to a
devi ati on (such as a defecti ve bottl e) duri ng the count by adjusti ng the count. To
adjust the count, that task wri tes a 1 (ON) to the Down Cl ock el ement to cause the
val ue of the Current Val ue el ement to move toward the Preset Val ue by the
I ncrement Val ue.
For exampl e, duri ng counti ng, i f a defecti ve bottl e i s counted but not packed i n the
case, the EDI or Math and Logi c task subtracts that bottl e fr om the total count by
wri ti ng a 1 (ON) to the Down Cl ock el ement to cause the Current Val ue to move
toward the Preset Val ue (0 in thi s exampl e) by the I ncrement Val ue (1 in thi s
exampl e).
Si x bottl es have been counted and packed i n the case. The Counter task counts the
seventh bottl e. But the seventh bottl e is defecti ve, so i t i s not packed i n the case.
Therefore, the EDI or Math and Logi c task subtracts that bottl e fr om the total
count by wri ti ng a 1 (ON) to the Down Cl ock el ement. Thi s causes the Current
Val ue to move fr om 7 down to 6.
PROGRAMMABLE COUNTERS
Principles of Operation
54 / FactoryLink ECS / Core Tasks Configuration Guide

I f al l counted bottl es are defecti ve and thus are not packed, the EDI or Math and
Logi c task subtracts them fr om the total count by causi ng the Current Val ue to
count down unti l i t matches the Preset Val ue (0). Al though the bottl e count i s now
0, the Output el ements have not been affected and the current counti ng operati on
conti nues unti l the case contai ns 20 bottl es.
PROGRAMMABLE COUNTERS
Programmable Counters Information Panel
FactoryLink ECS / Core Tasks Configuration Guide / 55
3
P
r
o
g
r
a
m
m
a
b
l
e

C
o
u
n
t
e
r
s
PROGRAMMABLE COUNTERS INFORMATION PANEL
The Programmabl e Counters task establ i shes parameters for the i ni ti ati on,
performance, and concl usi on of counti ng acti vi ty.
The Pr ogrammabl e Counters task uses ei ther the SHARED or the USER domai n.
We r ecommend the SHARED domai n, unl ess counters shoul d be uni que to each
User for the purposes of the appli cati on. Befor e openi ng and confi guri ng the
Programmabl e Counters task, ensure the current domai n sel ected is SHARED i n
the Confi gurati on Manager Domai n Sel ecti on box.
Wi th the -t progr am argument i n the System Confi gurati on i n effect for the
counter task, negati ve output, posi ti ve output, and current val ue are i ni ti al i zed.
Posi ti ve output i s set to 0. Negati ve output i s set to 1. Wi th no pr ogram ar gument,
those tags remai n at thei r defaul t/persi stent val ues.
Choose Programmabl e Counters to displ ay the Programmabl e Counters
I nformati on panel . Thi s panel contai ns el even fi el ds. Press Tab to displ ay other
fi el ds.
Fol l owi ng are fi el d descri pti ons for thi s panel .
Enable Name of an el ement that enabl es or tri gger s counti ng. I f thi s fi el d
i s l eft bl ank, counti ng i s al ways enabl ed because the tri gger
becomes ei ther the UP CLOCK or the DOWN CLOCK. When
the val ue of Enabl e is set to 1 (ON), counti ng occurs. I f the val ue
of Enabl e i s set to 0 (OFF), counti ng does not occur.
PROGRAMMABLE COUNTERS
Programmable Counters Information Panel
56 / FactoryLink ECS / Core Tasks Configuration Guide

I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag


Defi ni ti on panel i s di spl ayed when you cl i ck on Enter wi th a tag
type of di gi tal i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
Up Clock Name of an el ement that causes the val ue of the Current Val ue
el ement (present count) to move toward the Termi nal Val ue
(count l i mi t). When a 1 (ON) is wr i tten to the Up Cl ock el ement,
the val ue i n the Cur rent Val ue el ement is i ncreased by the
amount speci fi ed by the I ncrement Val ue el ement, descri bed
bel ow. I f the Preset Val ue (starti ng count) i s l ess than the
Termi nal Val ue, the I ncrement Val ue is added to the Current
Val ue. I f the Preset Val ue i s greater than the Ter mi nal Val ue, the
I ncrement Val ue i s subtracted fr om the Cur r ent Val ue.
I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter wi th a tag
type of di gi tal i n the Type fi el d. Accept thi s defaul t.
At l east one type of cl ock must be defi ned; that i s, an entry i s
requi red i n ei ther the Up Clock or Down Clock fi el d.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
Down Clock Name of an el ement that causes the val ue of the Current Val ue
el ement (present val ue) to move away fr om the Termi nal Val ue
(towar d the Pr eset Val ue). When a 1 (ON) i s wri tten to the Down
Clock el ement, the val ue i n the Current Val ue el ement i s
decreased by the amount speci fi ed by the I ncrement Val ue
el ement. I f the Preset Val ue i s l ess than the Termi nal Val ue, the
I ncrement Val ue i s subtracted fr om the Cur r ent Val ue. I f the
Preset Val ue i s gr eater than the Termi nal Val ue, the I ncrement
is added to the Cur rent Val ue. The Current Val ue does not move
past the Preset Val ue and the Posi ti ve/Negati ve Outputs are not
tr i ggered when the Preset Val ue i s reached. The data type for thi s
tag is di gi tal .
At l east one type of cl ock must be defi ned; that i s, an entry i s
requi red i n ei ther the Up Clock or Down Clock fi el d.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
PROGRAMMABLE COUNTERS
Programmable Counters Information Panel
FactoryLink ECS / Core Tasks Configuration Guide / 57
3
P
r
o
g
r
a
m
m
a
b
l
e

C
o
u
n
t
e
r
s
Clear Name of an el ement that causes the Current Val ue to be reset to
the Preset Val ue each ti me a 1 (ON) i s wri tten to i t (the Cl ear
el ement). Each ti me a 1 (ON) is for ce-wr i tten to the Cl ear
el ement, a 0 (OFF) i s for ce-wr i tten to the Posi ti ve Output
el ement and a 1 (ON) i s wri tten to the Negati ve Output el ement.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter wi th a tag
type of di gi tal i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
Positive Output Name of an el ement to whi ch a 1 (ON) i s wr i tten each ti me the
Current Val ue reaches the Termi nal Val ue. The val ue of the
Posi ti ve Output el ement remai ns 1 (ON) unti l a 1 (ON) is wri tten
to the Cl ear el ement.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter wi th a tag
type of di gi tal i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
Negative Output Name of an el ement to whi ch a 0 (OFF) i s wri tten each ti me the
Current Val ue reaches the Termi nal Val ue. The val ue of the
Negati ve Output el ement remai ns 0 (OFF) unti l a 1 (ON) i s
wri tten to the Cl ear el ement. Thi s tag i s set to 1 at task startup.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di splayed when you cl i ck on Enter wi th a tag
type of di gi tal i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
Current Value Name of an el ement to speci fy the name of an el ement that
contai ns the cur rent val ue of the counter. Thi s val ue is al ways
between the Pr eset Val ue and the Termi nal Val ue.
The defaul t i s 0.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di splayed when you cl i ck on Enter wi th a tag
type of anal og i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: anal og, l ongana
PROGRAMMABLE COUNTERS
Programmable Counters Information Panel
58 / FactoryLink ECS / Core Tasks Configuration Guide

Preset Value Enter a number between -32,768 and 32,767 to speci fy the
star ti ng val ue for a count. Thi s numeri cal val ue is wr i tten to the
Current Val ue el ement whenever the val ue of the Cl ear el ement
is set to 1 (ON). The defaul t is 0.
Valid Entry: numeri c val ue between -32,768 and 32,767
(defaul t = 0)
Increment Value Enter a number between 0 and 32,767 to speci fy the numeri cal
val ue that i s combi ned wi th the Current Val ue when the Up or
Down Clock i s tri ggered. The defaul t i s 1.
Valid Entry: numeri c val ue between 0 and 32,767 (defaul t = 1)
Terminal Value Enter a number between -32,768 and 32,767 to defi ne the
numeri cal val ue that speci fi es a l i mi t for counti ng acti vi ty. When
the Current Val ue i s the same as the Termi nal Val ue, counti ng
stops and Posi ti ve and Negati ve Outputs are tri ggered. Counti ng
remai ns stopped unti l the Cl ear el ement i s tr i gger ed. However , i f
AutoCl ear i s set, a Cl ear i s performed i mmedi atel y after the
Posi ti ve and Negati ve Outputs are tri ggered.
Valid Entry: numeri c val ue between -32,768 and 32,767
Autoclear I ndi cator that a Cl ear shoul d be per formed each ti me the
Termi nal Val ue i s reached. Thi s can be one of the fol l owing:
YES Cl ear i s performed each ti me the Ter mi nal Val ue
i s reached. Thi s is the defaul t.
NO Current Val ue remai ns equal to the Termi nal
Val ue unti l Cl ear i s tr i ggered.
PROGRAMMABLE COUNTERS
Programmable Counters Information Panel
FactoryLink ECS / Core Tasks Configuration Guide / 59
3
P
r
o
g
r
a
m
m
a
b
l
e

C
o
u
n
t
e
r
s
When al l i nformati on has been speci fi ed, the panel shoul d resembl e the sampl e
bel ow:
I n the fi rst exampl e (fi r st l i ne on the panel ), the counter, al ong wi th a Math and
Logi c procedur e that saves the count and resets the counter, counts the number of
bottl es packed per mi nute. Si nce the Enable fi el d i s l eft bl ank, counti ng i s al ways
enabl ed. Each ti me a bottl e i s packed, a 1 (ON) i s wri tten to the Up Clock el ement
btl _upcl ock. Thi s tri ggers the Counter task to i ncrease the Current Val ue
(btl _count) by 1. Each mi nute, FactoryLi nk tri ggers a Math and Logi c procedur e
to l og the Current Val ue and tri gger the Cl ear el ement (btl _cl ear) to reset the
count for the next mi nute.
PROGRAMMABLE COUNTERS
Programmable Counters Information Panel
60 / FactoryLink ECS / Core Tasks Configuration Guide

I n the second exampl e (second l i ne on the panel ), the counter is used to cr eate a
one-mi nute del ay of an event, such as bottl e capping. Si nce the Enable fi el d i s l eft
bl ank, counti ng i s al ways enabl ed. When the val ue of sec1 becomes 1 (ON), the
Counter task i ncreases the Current Val ue (mi n_del ay) by 1. The task conti nues to
i ncrease thi s val ue once each second unti l the Current Val ue matches the
Termi nal Val ue of 60. At thi s ti me, counti ng stops and the Counter task wri tes a 1
(ON) to the Posi ti ve Output el ement mi n_end, i ndi cati ng the end of the
one-mi nute del ay. Other FactoryLi nk tasks can moni tor the mi n_end el ement to
tri gger another operati on and then wri te a 1 (ON) to the Cl ear el ement
(mi n_start) to reset the count.

Part I V
File Manager
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 63
Table of Contents
Fi l e Manager

File Manager in this book


File Manager in the Core Tasks Configuration
Guide
4 File Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Fil e Manager Control Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fil e Manager I nfor mati on Panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Sampl e Fi l e Manager Operati ons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Example 1: COPY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Example 2: PRI NT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Example 3: REN (Rename) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Example 4: TYPE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Example 5: DI R (Directory) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Example 6: DEL (Delete) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Usi ng Vari abl e Speci fi ers i n Fi l e Speci fi cati ons . . . . . . . . . . . . . . . . . . . . . . 85
Usi ng Wi l dcard Characters i n Fi l e Speci fi cati ons . . . . . . . . . . . . . . . . . . . . . 87
Usi ng the Fi l e Manager wi th Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Using the COPY Command with FLLAN . . . . . . . . . . . . . . . . . . . . . . . . 89
Using the COPY Command with a Network without FLLAN . . . . . . . . . 92
Techni cal Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Operati ng System Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
For Windows NT and Windows 95 Users . . . . . . . . . . . . . . . . . . . . . . . . 94
For OS/ 2 Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
For Unix Users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
File Manager in this book
File Manager in the Core Tasks Configuration
Guide
64 / FactoryLink ECS / Core Tasks Configuration Guide

File Manager
4
F
i
l
e

M
a
n
a
g
e
r
FactoryLink ECS / Core Tasks Configuration Guide / 65

Chapter 4
F i l e Manager
The FactoryLi nk Fi l e Manager task can be used to perform basi c operati ng
system fi l e-management operati ons i ni ti ated by a Factor yLi nk appl i cati on at run
ti me. The task can wor k i n conjuncti on wi th FactoryLi nks FLLAN opti on to
i ni ti ate operati ons wi thi n other FactoryLi nk stati ons on a networ k. The Fi l e
Manager i ni ti ates the operati ons l i sted bel ow whi ch are per formed by the
operati ng system.
Copy a fi l e
Rename a fi l e
Del ete a fi l e
Pri nt a fi l e
Di spl ay a di rectory
Type a fi l e
Fil e Manager i ni ti ates these operati ons wi th si x commands: COPY, REN, DEL,
PRI NT, DI R, and TYPE. These commands perform the same functi ons as thei r
operati ng-system counterparts. The Fi l e Manager control s al l fi l e operati ons
through the FactoryLi nk real -ti me database.
You can confi gure other FactoryLi nk tasks to i ni ti ate Fi l e Manager operati ons.
For exampl e:
You can confi gure i nput functi ons i n Graphi cs so an operator can use them to
i ni ti ate fi l e-management operati ons at run ti me, such as to di spl ay a l i st of
reci pes or reports.
The Ti mer task can tri gger Fi l e Manager to automati cal l y back up fi l es to a
networked server at certai n interval s, such as each day at mi dni ght.
The Ti mer task can al so tri gger Fil e Manager to del ete l og fi l es automati cal l y at
certai n i nterval s, such as once every four hours, or after certai n events, such as
when l og fi l es reach a speci fi ed si ze.
Al arm Super vi sor can tri gger Fi l e Manager to pri nt al arm fi l es.
FILE MANAGER
File Manager Control Panel
66 / FactoryLink ECS / Core Tasks Configuration Guide

FILE MANAGER CONTROL PANEL


The Fi l e Manager Tabl e has two panel s.
Fi l e Manager Control (confi gure one)
Fi l e Manager I nformati on
All operati ons are defi ned in one Fi l e Manager Control panel . For COPY, REN,
DEL, and PRI NT operati ons, do not compl ete a Fi l e Manager I nformati on panel .
However , for each TYPE or DI R operati on defi ned i n the Fil e Manager Control
panel , compl ete one Fi l e Manager I nformati on panel .
Fil e Manager defaul ts to the USER domai n, but you can confi gure i t to run i n
ei ther domai n. Before openi ng and confi guri ng Fi l e Manager, ensure the domai n
sel ected i s the corr ect one in the Confi gurati on Manager Domai n Sel ecti on box.
Choose Fi l e Manager to displ ay the Fi l e Manager Control and Fi l e Manager
I nformati on panel s. Compl ete the Fi l e Manager Control panel fi r st:
Fol l owi ng ar e fi el d descri pti ons for thi s panel .
Table Name (Requi red for TYPE and DI R operati ons) Enter an al phanumeri c
stri ng of between 1 to 16 characters that speci fi es the name of the
operati on bei ng defi ned or modi fi ed. For TYPE and DI R
operati ons, thi s fi el d connects the entry i n the Fi l e Manager
Control panel wi th the associ ated Fi l e Manager I nformati on
panel for that entr y.
Thi s fi el d i s opti onal for COPY, REN, DEL, and PRI NT
operati ons. You can use i t to di sti ngui sh di fferent operati ons of
the same type.
Valid Entry: al phanumeri c str i ng of between 1 to 16
characters
FILE MANAGER
File Manager Control Panel
FactoryLink ECS / Core Tasks Configuration Guide / 67
4
F
i
l
e

M
a
n
a
g
e
r
Command Trigger Name of an el ement used to i ni ti ate the fi l e operati on.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, fl oat, message
Position Trigger Requi red onl y for DI R and TYPE operati ons; not used for COPY,
PRI NT, REN, and DEL operati ons. Name of an el ement whose
val ue tel l s the Fi l e Manager where i n a di rector y to start l i sti ng
fi l es, or where i n a fi l e to star t typi ng.
The Fi l e Manager starts readi ng after the li ne number speci fi ed
by the val ue of the Posi ti on Tri gger el ement. For exampl e, i f the
val ue of the Posi ti on Tri gger el ement is 6, the Fi l e Manager
begi ns readi ng the fi l e at l i ne seven. The number of l i nes
displ ayed or the number of fi l es l i sted depends on the number of
Tag Name el ements defi ned i n the Fi l e Manager I nformati on
panel , descri bed bel ow.
You can confi gur e the system so, at run ti me, you or any
FactoryLi nk task can change the val ue of thi s el ement so the Fi l e
Manager starts at a di fferent poi nt i n a di rectory or fi l e and
shows a di fferent subset of informati on.
Do not speci fy the same el ement name for DI R and TYPE
operati ons. I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned,
a Tag Definition di al og i s displ ayed when you cl i ck on Enter. Accept
thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: anal og
Command Fil e operati on to be per formed. Thi s can be one of the fol l owing.
COPY Copi es the source fi l e to the desti nati on fi l e.
Speci fy both the source and desti nati on paths.
Thi s operati on does not requi r e that you compl ete
a Fi l e Manager I nformati on panel .
REN Renames the source fi l e to the desti nati on fi l e.
Speci fy both the source and desti nati on paths.
Both the source and desti nati on paths must be the
same; that is, they must poi nt to the same
di rectory. Thi s operati on does not requi r e you
compl ete a Fi l e Manager I nformati on panel .
FILE MANAGER
File Manager Control Panel
68 / FactoryLink ECS / Core Tasks Configuration Guide

DEL Del etes the source fi l e. The DEL command


requi res onl y the source path; the desti nati on path
i s i gnored. Thi s operati on does not requi re you
compl ete a Fi l e Manager I nformati on panel .
PRINT Causes the fi l e speci fi ed by the source path to be
pri nted on the devi ce speci fi ed by the desti nati on
path. The desti nati on path must contai n the name
of a devi ce known to the Pri nt Spool er task. Thi s
operati on works onl y wi th the Pri nt Spool er and
does not requi re that you compl ete a Fil e Manager
I nformati on panel .
DIR Di spl ays a l i st of al l fi l es i n the di rectory speci fi ed
by the source path, whi ch can i ncl ude wil dcard
characters. The desti nati on path i s i gnored. Thi s
operati on requi res you compl ete a Fi l e Manager
I nformati on panel and you defi ne output text
objects i n Graphi cs to di spl ay l i nes fr om the fi l e.
TYPE Di spl ays the contents of the source fi l e. The
desti nati on path i s i gnored. Thi s operati on
requi res that you compl ete a Fi l e Manager
I nformati on panel and that you defi ne output text
objects i n Graphi cs to di spl ay l i nes fr om the fi l e.
Note that Fi l e Manager reads i n onl y 80
characters at a ti me, and puts the rest of the l i ne
(i f more than 80 characters) i nto the next message
tag. For exampl e, i f the message i n the li ne i s 140
characters l ong, i t puts the fi r st 80 i nto the fi rst
message tag, and the next 60 into the second
message tag.
FILE MANAGER
File Manager Control Panel
FactoryLink ECS / Core Tasks Configuration Guide / 69
4
F
i
l
e

M
a
n
a
g
e
r
Source File Spec. Ful l path name of the source fi l e. The source fi l e spec. can use the
fi l ename syntax for the operati ng system on whi ch ei ther the
r emote or the l ocal stati on resi des. I f you ar e usi ng FLLAN, the
source can reference a remote stati on.
I f you speci fy a remote stati on for the desti nati on and a remote
stati on for the source, the two remote stati ons must be the same.
I f the desti nati on i s l ocal , there i s no restri cti on on the source
stati on. Si mi l arl y, i f the source i s l ocal , there i s no restri cti on on
the desti nati on. Refer to Usi ng the Fil e Manager wi th Networ ks
on page 88 for i nformati on about referenci ng r emote stati ons.
Type wi l dcard characters i n the path name to show a root
di rectorys contents usi ng the DIR command. For exampl e, i n
thi s fi el d type:
C:\*.*
Onl y one fi l e i n a copy operati on can be remote. Both fi l es i n a
rename operati on must be on the same stati on.
For stand-al one systems:
/DEVICE_NAME/DIR_NAME/SUB_DIR_NAME/FILE_NAME
For networked systems:
\\STATION_NAME\DEVICE_NAME/DIR_NAME/SUB_DIR_NAME/FILE
_NAME
I n the case of the COPY, DEL, and DI R commands, the source fi l e speci fi cati on
may contai n vari abl e speci fi ers or wi l dcard characters (*). Refer to Usi ng
Vari abl e Speci fi ers in Fi l e Speci fi cati ons on page 85 and Usi ng Wi l dcard
Characters i n Fi l e Speci fi cati ons on page 87 for more i nformati on about vari abl e
speci fi ers and wi l dcard characters.
Valid Entry: ful l path name
FILE MANAGER
File Manager Control Panel
70 / FactoryLink ECS / Core Tasks Configuration Guide

Source Variables
1-4
Names of el ements whose val ues repl ace the vari abl e speci fi ers i n
the source path name. These fi el ds wor k i n conjuncti on wi th the
Source File Spec. fi el d to for m the path of the fi l e to whi ch the Fil e
Manager per forms operati ons. The val ue of the el ement i n the
Source Variable 1 fi el d repl aces the fi rst vari abl e speci fi er, the
val ue of the el ement i n the Source Variable 2 fi el d repl aces the
second vari abl e speci fi er, and so on.
I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag
Definition di al og is displ ayed when you cl i ck on Enter.
I f usi ng vari abl e speci fi ers, make the data type of the el ement
match the vari abl e speci fi er type. Refer to FactoryLink
Fundamentals for i nformati on about vari abl e speci fi ers.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, fl oat, message
Destination File
Spec.
Ful l path name of the desti nati on fi l e. The desti nati on fi l e spec.
can use the fi l ename syntax for the operati ng system on whi ch
ei ther the r emote or the l ocal stati on resi des. I f you are usi ng
FLLAN, the desti nati on can reference a r emote stati on.
I f you speci fy a r emote stati on for the desti nati on and a r emote
stati on for the source, the two r emote stati ons must be the same.
I f the desti nati on i s l ocal , there i s no restri cti on on the source
stati on. Si mi l arl y, i f the source i s l ocal , there i s no restri cti on on
the desti nati on. Refer to Usi ng the Fi l e Manager wi th Networ ks
on page 88 for i nformati on about r eferenci ng r emote stati ons.
For stand-al one systems:
/DEVICE_NAME/DIR_NAME/SUB_DIR_NAME/FILE_NAME
For networked systems:
\\STATION_NAME\DEVICE_NAME/DIR_NAME/SUB_DIR_NAME/FILE
_NAME
Unl ess you use wi l dcard characters i n the source fi l e spec.,
speci fy the ful l path name of the desti nati on. I f you use wi l dcard
characters, do not speci fy the ful l path; speci fy onl y the di rector y.
Refer to FactoryLink Fundamentals for i nformati on about
wi l dcard characters.
I n the case of the COPY, DEL, and DI R commands, the
desti nati on fi l e speci fi cati on can contai n vari abl e speci fi ers or
wi l dcard char acter s (*). Refer to FactoryLink Fundamentals for
i nformati on about vari abl e speci fi ers.
FILE MANAGER
File Manager Control Panel
FactoryLink ECS / Core Tasks Configuration Guide / 71
4
F
i
l
e

M
a
n
a
g
e
r
I f usi ng the PRI NT command, use the fol l owi ng desti nati on fi l e
spec. for mat:
[\\station_name\] [flags] [spool_device]
where
stati on_name is the opti onal FactoryLi nk stati on name
(defaul ts to LOCAL). The FactoryLi nk stati on
name i s not used on stand-al one systems.
fl ags are the opti onal fl ags. Thi s can be one of the
fol l owi ng.
NONEThi s i s the defaul t.
BBi nary fi l e
SSuppress Begi nni ng and End of Fi l e. Used to
concatenate fi l es
spool _devi ce is the opti onal spool devi ce (defaul ts to 1; l egal
devi ces ar e 1 through 5).
Destination
Variables 1-4
Names of el ements whose val ues repl ace the vari abl e speci fi ers i n
the desti nati on path name. These fi el ds work i n conjuncti on wi th
the Destination Format fi el d to form the path of the fi l e to whi ch the
Fil e Manager performs operati ons. The val ue of the el ement i n
the Destination Variable 1 fi el d repl aces the fi r st vari abl e speci fi er,
the val ue of the el ement i n the Destination Variable 2 fi el d repl aces
the second vari abl e speci fi er, and so on.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter.
I f you use vari abl e speci fi ers, make the data type match the
vari abl e speci fi er type. Refer to FactoryLink Fundamentals for
i nformati on.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, fl oat, message
Completion Trigger Name of an el ement used to i ndi cate that a fi l e-management
operati on is compl ete (not necessari l y successful ). Thi s el ement, i f
entered, is set by Fi l e Manager and can be referenced by any
FactoryLi nk task (i ncl udi ng Fi l e Manager) to moni tor
fi l e-management operati ons or tri gger an event.
FILE MANAGER
File Manager Control Panel
72 / FactoryLink ECS / Core Tasks Configuration Guide

I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag


Definition di al og is displ ayed when you cl i ck on Enter wi th a tag
type of di gi tal i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal
Completion Status Name of an el ement set by the Fi l e Manager task to i ndi cate the
status of an operati on. The Compl eti on Status el ement can be
r eferenced by any FactoryLi nk task (i ncl udi ng the Fi l e Manager)
to handl e fi l e error si tuati ons or tri gger the next Fi l e Manager
tabl e to start an operati on.
I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter wi th a tag
type of anal og i n the Type fi el d. Accept thi s defaul t.
The Fi l e Manager wri tes an anal og val ue to the Compl eti on
Status el ement to indi cate the status of a fi l e management
operati on.
Use the tasks TASKMESSAGE_U[6] tag to report messages on
the appl i cati on screen i n addi ti on to the Compl eti on Status tag.
For exampl e, i f you get a status 12 i n the Compl eti on Status tag,
you al so see the message: Cant open fi l e (path/fi l ename) i n the
tag TASKMESSAGE_U[6].
I f you want to use I ML for thi s functi on, set up a math procedure
tr i ggered by the status tag i tsel f. I n the pr ocedur e, assi gn the
appropri ate ASCI I stri ng for each possi bl e status code to a
message tag i n a seri es of I F THEN statements. For exampl e:
I F status = 1 THEN
MSG = whatever
ENDI F
FILE MANAGER
File Manager Control Panel
FactoryLink ECS / Core Tasks Configuration Guide / 73
4
F
i
l
e

M
a
n
a
g
e
r
Thi s el ement can have any of the fol l owi ng status val ues:
Refer to Sampl e Fi l e Manager Operati ons on page 76 for exampl es of Fi l e
Manager operati ons.
Valid Entry: standard el ement tag name
Valid Data Type: anal og
Table 4-1
Value Description Value Description
0 Operati on compl eted
successful l y
12 Cant open fi l e
(path/fi l ename)
1 Current operati on i n
progress
13 Er ror occurred whi l e
readi ng a fi l e
2 Speci fi ed fi l e(s) not found 14 Fi l e coul d not be created
* 3 Requested a li ne beyond end
of fi l e
15 Er ror occurred whi l e
wr i ti ng to a fil e
5 Remote system coul d not
perfor m requested acti on
16 I l l egal spool devi ce was
speci fi ed
6 Attempt to l og onto a r emote
stati on fai l ed
17 Not enough memor y to
per for m operati on
8 Network transmi ssi on er r or
occurred
97 I l l egal fi l ename was
speci fi ed
* I f the TYPE/DI R posi ti on tri gger offset val ues are i ncreased
beyond the end of the fi l e, the Fi l e Manager wi l l read i n as
many l i nes as possi bl e, set the compl eti on tri gger , and set the
compl eti on status to 3.
FILE MANAGER
File Manager Information Panel
74 / FactoryLink ECS / Core Tasks Configuration Guide

FILE MANAGER INFORMATION PANEL


Cli ck Enter to save the i nformati on after compl eti ng the Fi l e Manager Control
panel . Then, cl i ck Next to displ ay the Fi l e Manager I nformati on panel .
Fol l owi ng ar e fi el d descri pti ons for thi s panel .
Tag Name (Requi red onl y for DI R and TYPE operati ons; not used wi th
COPY, PRI NT, REN, and DEL operati ons) Name of a message
el ement that, as a resul t of a DI R or TYPE command, recei ves a
message val ue to be di spl ayed in a si ngl e l i ne on a graphi cs
scr een. The number of Tag Name fi el ds defi ned i n thi s panel
determi nes the number of l i nes displ ayed as a resul t of a DI R or
TYPE command at r un ti me.
I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag
Definition di al og is displ ayed when you cl i ck on Enter wi th a tag
type of message i n the Type fi el d. Accept thi s defaul t.
Val ues ar e wri tten to the el ements defi ned i n the Tag Name fi el d
whenever a DI R or TYPE operati on i s tri ggered, or whenever the
operator changes the val ue of the Posi ti on Tri gger el ement
defi ned i n the Control panel . (A di fferent val ue i n the Posi ti on
Tri gger el ement means i nformati on from a di fferent pl ace i n the
di r ector y or fi l e i s di spl ayed.)
Cli ck Enter to save the i nformati on when the Fi l e Manager I nformati on panel for
the speci fi ed command (DI R or TYPE) is compl ete.
Remember to confi gure one Fi l e Manager I nfor mati on panel for each DI R or
TYPE operati on defi ned i n the Fi l e Manager Control panel .
FILE MANAGER
File Manager Information Panel
FactoryLink ECS / Core Tasks Configuration Guide / 75
4
F
i
l
e

M
a
n
a
g
e
r
The Fi l e Manager Control and Fi l e Manager I nformati on panel s shoul d resembl e
the i l l ustrati ons shown i n Sampl e Fi l e Manager Operati ons on page 76.
Valid Entry: standard el ement tag name
Valid Data Type: message
FILE MANAGER
Sample File Manager Operations
76 / FactoryLink ECS / Core Tasks Configuration Guide

SAMPLE FILE MANAGER OPERATIONS


The exampl es bel ow i l l ustrate each type of fi l e-management operati on. I n these
exampl es, entri es for each type of fi l e-management operati on are di spl ayed i n
separate sampl e Control panel s (i n a real FactoryLi nk appl i cati on, al l
fi l e-management operati ons are confi gured i n one Control panel ).
The fi rst four exampl es do not requi re that you compl ete an associ ated Fi l e
Manager I nformati on panel . The l ast two exampl es do requi re that you compl ete a
Fil e Manager I nfor mati on panel .
Example 1: COPY
Exampl e 1 demonstrates how to confi gure a COPY operati on (usi ng Wi ndows fi l e
syntax). You can confi gure the Math and Logi c task or an anal og counter (i n the
Counters task) to use thi s operati on to i ncrement the al arm hi story fi l e number.
Thi s resul ts i n a rol l i ng count of the hi story fi l e bei ng transferred: Hi st.001,
Hi st.002, and so on. To confi gure a COPY operati on, fi l l out the Control panel as
shown bel ow:
Table 4-2
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
Tabl e Name WI NCOPY Because the COPY operati on does not
requi re compl eti on of the Fi l e Manager
I nformati on panel , you can l eave thi s fi el d
bl ank. However , we r ecommend you fi l l i n
thi s fi el d to di sti ngui sh di ffer ent
operati ons of the same type.
Command
Tri gger
copytri g Name of the di gi tal el ement that tri ggers
the copy operati on. You can confi gure other
tasks to wr i te to thi s el ement to tr i gger the
copy operati on.
Command COPY Desi gnates a COPY operati on
FILE MANAGER
Sample File Manager Operations
FactoryLink ECS / Core Tasks Configuration Guide / 77
4
F
i
l
e

M
a
n
a
g
e
r
Source
Fi l e Spec.
c:\hi story\
hi st.%03d
The path and fi l e name of the fi l e to be
copi ed. I n thi s exampl e, the source path
name contai ns a vari abl e speci fi er. At run
ti me, whenever the operator or another
task tri ggers the di gi tal el ement copytri g,
Fi l e Manager repl aces thi s vari abl e wi th
the val ue of the anal og el ement fx1_ext.
Source
Vari abl e 1
fx1_ext At run ti me, Fi l e Manager repl aces the
vari abl e %03d i n the Source File Spec. fi el d
wi th the val ue of thi s anal og el ement. I n
thi s exampl e, thi s val ue i s a three-number
fi l e extensi on, such as .001.
Desti nati on
Fi l e Spec.
a:\archi ve The path name where the source fi l e i s to
be copi ed. (Because thi s entr y contai ns a
stati c speci fi er, Desti nati on Vari abl es are
not necessary.)
Compl eti on
Tri gger
copydone When the COPY operati on has been
compl eted, Fi l e Manager forces the val ue
of thi s el ement to 1 (ON), i ndi cati ng that
the operati on is compl ete.
Table 4-2 (Continued)
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
FILE MANAGER
Sample File Manager Operations
78 / FactoryLink ECS / Core Tasks Configuration Guide

Compl eti on
Status
copystat When the COPY operati on i s compl ete,
Fil e Manager i ndi cates the status of the
operati on by wri ti ng an anal og val ue to
thi s el ement.Use the tasks
TASKMESSAGE_U[6] tag to report
messages on the appl i cati on screen in
addi ti on to the Compl eti on Status tag. For
exampl e, i f you get a status 12 i n the
Compl eti on Status tag, you al so see the
message: Cant open fi l e (path/fi l ename).
I f you want to use I ML for thi s functi on,
set up a math procedure tri ggered by the
status tag i tsel f. I n the procedure, assi gn
the appropri ate ASCI I stri ng for each
possi bl e status code to a message tag i n a
seri es of I F THEN statements. For
exampl e:
I F status = 1 THEN
MSG = whatever
ENDI F
Table 4-2 (Continued)
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
FILE MANAGER
Sample File Manager Operations
FactoryLink ECS / Core Tasks Configuration Guide / 79
4
F
i
l
e

M
a
n
a
g
e
r
Example 2: PRINT
Exampl e 2 demonstrates how to confi gure a PRI NT operati on. To confi gure a
PRI NT operati on, fi l l out the Control panel as shown bel ow:
PRI NT command fi l e syntax i s the same for al l operati ng systems.
Table 4-3
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
Tabl e
Name
PRI NT Desi gnates the name of a PRI NT operati on
Command
Tri gger
pri nttri g Name of the di gi tal el ement that tri ggers the
pri nt operati on. You can al so confi gure other
tasks to wri te to thi s el ement to tri gger a pri nt
operati on.
Command PRI NT Desi gnates a PRI NT operati on
Source
Fi l e Spec.
%s The name of the fi l e to be pri nted. I n thi s
exampl e, the fi l e name i s a vari abl e speci fi er. At
run ti me, Fi l e Manager repl aces thi s vari abl e
wi th the val ue of the message el ement pri ntpath,
speci fi ed i n the Source Variable 1 fi el d.
Source
Vari abl e 1
pri ntpath At run ti me, the Fi l e Manager repl aces the
vari abl e %s i n the Source File Spec. fi el d wi th the
val ue of thi s message el ement. I n thi s exampl e,
thi s val ue is a fi l e name.
Desti nati on
Fi l e Spec.
1 1 desi gnates the pri nt spool devi ce that pri nts
the fi l e speci fi ed by pri ntpath. Thi s exampl e
assumes you have al ready defi ned pri nt spool
devi ce 1 i n the Pri nt Spool er task. At r un ti me,
when the operator or a task tri ggers the di gi tal
el ement pri nttri g, Fi l e Manager pri nts the fi l e to
Pri nt Spool er devi ce number one.
FILE MANAGER
Sample File Manager Operations
80 / FactoryLink ECS / Core Tasks Configuration Guide

Example 3: REN (Rename)


Exampl e 3 demonstrates how to confi gure a REN (rename) operati on (usi ng
Wi ndows fi l e syntax). To confi gure a REN operati on, fi l l out the Control panel as
shown bel ow:
Table 4-4
Sample File Manager Control Panel
Field: Sample Entry: Explanation:
Tabl e Name WI NREN Desi gnates the name of a REN operati on
Command
Tri gger
rentri g Name of the di gi tal el ement that tri ggers
the rename operati on
Command REN Desi gnates a REN operati on
Source
Fil e Spec.
c:\temp\%s.l og Thi s fi el d contai ns a vari abl e speci fi er,
whi ch Fi l e Manager repl aces at run ti me
wi th the val ue of the message el ement
s_fi l e, speci fi ed i n the Source Variable 1
fi el d.
Source
Vari abl e 1
s_fi l e At run ti me, Fi l e Manager repl aces the
vari abl e %s i n the Source File Spec. fi el d
wi th the val ue of thi s anal og el ement.
Desti nati on
Fil e Spec.
%s.tmp %s.tmp contai ns a vari abl e speci fi er,
whi ch Fi l e Manager repl aces at run ti me
wi th the val ue of the message el ement
rento, speci fi ed i n the Destination Variable
1 field.
Desti nati on
Vari abl e 1
rento When the val ue of the di gi tal el ement
r entr i g i s for ced to 1 (ON), Fi l e Manager
renames the fi l e speci fi ed i n s_fi l e wi th
the fi l ename contai ned i n r ento.
FILE MANAGER
Sample File Manager Operations
FactoryLink ECS / Core Tasks Configuration Guide / 81
4
F
i
l
e

M
a
n
a
g
e
r
Example 4: TYPE
Exampl e 4 demonstrates the TYPE command: TYPE command fi l e syntax i s the
same for al l operati ng systems.
Table 4-5
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
Tabl e Name TYPE Desi gnates the name of a TYPE operati on
Command
Tri gger
typetri g Name of the di gi tal el ement used to tr i gger the type
operati on
Command TYPE Desi gnates a TYPE operati on
Posi ti on
Tri gger
typescrol l Name of the anal og el ement that control s the
output of the TYPE command
Source
Fi l e Spec.
%s Thi s fi el d contai ns a vari abl e speci fi er , whi ch the
Fil e Manager repl aces at run ti me wi th the val ue of
the message el ement typepath, desi gnated in the
Source Variable 1 fi el d.
Source
Vari abl e 1
typepath At run ti me, when the val ue of the di gi tal el ement
typetri g i s for ced to 1 (ON), the Fi l e Manager types
the fi l e speci fi ed by typepath. Because TYPE
operati ons do not need a desti nati on, the Destination
Variable fi el ds are l eft bl ank.
Tag Name typl i n1
typl i n2
typl i n3
typl i n4
typl i n5
typl i n6
typl i n7
typl i n8
At run ti me, when the val ue of the di gi tal el ement
typetri g i s for ced to 1 (ON), the Fi l e Manager reads
the fi l e speci fi ed i n the Source Tag 1 el ement
typepath. The Fi l e Manager starts readi ng after the
l i ne number speci fi ed by the Scrol l el ement
typescrol l . I n thi s exampl e, ei ght l i nes of text fr om
the speci fi ed fi l e are read i nto message el ements
typl i n1, typl i n2, ...typl i n8. These message el ements
may be referenced by other FactoryLi nk tasks, such
as the Graphi cs task, for di splay on a graphi cs or
text screen.
FILE MANAGER
Sample File Manager Operations
82 / FactoryLink ECS / Core Tasks Configuration Guide

Example 5: DIR (Directory)


Exampl e 5 demonstrates the DI R (Di rectory) command:
DI R command fi l e syntax i s the same for al l operati ng systems.
Table 4-6
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
Tabl e
Name
DI R Desi gnates the name of a DI R operati on
Command
Tri gger
di rtri g Name of the di gi tal el ement used to tri gger the di r
operati on
Posi ti on
Tri gger
di rscrol l Name of the anal og el ement that control s the output of
the DI R command
Command DI R Desi gnates a DI R operati on
Source
Fil e Spec.
%s Thi s fi el d contai ns a vari abl e speci fi er, whi ch the Fi l e
Manager repl aces at run ti me wi th the val ue of the
message el ement di rpath, desi gnated i n the Source
Variable 1 fi el d.
Source
Vari abl e 1
di rpath At run ti me, when the val ue of the di gi tal el ement
di rtri g i s forced to 1 (ON), Fi l e Manager di spl ays the
di rectory speci fi ed by di rpath. Because DI R operati ons
do not need a desti nati on, the Destination Variable fi el ds
are bl ank.
FILE MANAGER
Sample File Manager Operations
FactoryLink ECS / Core Tasks Configuration Guide / 83
4
F
i
l
e

M
a
n
a
g
e
r
At run ti me, when the val ue of the di gi tal el ement
di r tri g i s forced to 1 (ON), Fi l e Manager reads the
di r ector y speci fi ed in the Sour ce Tag 1 el ement di rpath.
Fi l e Manager starts readi ng after the l i ne number
speci fi ed by the Scrol l el ement di rscrol l . I n thi s
exampl e, ei ght l i nes of text from the speci fi ed fi l e are
read i nto message el ements di rl i n1, di rl i n2, ...di rl i n8.
These message el ements may be r eferenced by other
FactoryLi nk tasks, such as the Graphi cs task, for
di spl ay on a graphi cs or text screen.
Table 4-6 (Continued)
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
FILE MANAGER
Sample File Manager Operations
84 / FactoryLink ECS / Core Tasks Configuration Guide

Example 6: DEL (Delete)


Exampl e 6 demonstrates the DEL (Del ete) command usi ng Wi ndows fi l e syntax:
Table 4-7
Sample File Manager Control Panel
Field: Sample Entry: Explanation:
Tabl e Name WI NDEL Desi gnates the name of a DEL operati on
Command
Tri gger
del tri g Name of the di gi tal el ement used to
tr i gger the del ete operati on
Command DEL Desi gnates a DEL operati on
Source
Fil e Spec.
c:\hi st\%s.tmp Thi s fi el d contai ns a vari abl e speci fi er ,
whi ch Fi l e Manager repl aces at run ti me
wi th the val ue of the message el ement
del fi l e, desi gnated i n the Source Variable 1
fi el d.
Source
Vari abl e 1
del fi l e At run ti me, when the val ue of the di gi tal
el ement del tri g i s forced to 1 (ON), Fi l e
Manager del etes the fi l e speci fi ed by
del fi l e. Because DEL operati ons do not
need a desti nati on, the Destination Variable
fi el ds are l eft bl ank.
FILE MANAGER
Using Variable Specifiers in File Specifications
FactoryLink ECS / Core Tasks Configuration Guide / 85
4
F
i
l
e

M
a
n
a
g
e
r
USING VARIABLE SPECIFIERS IN FILE SPECIFICATIONS
I f the oper ator or the system i s to enter al l or par t of the sour ce or desti nati on
speci fi cati on, use vari abl e speci fi er s. However , i f the same fi l es ar e to be used for
al l operati ons, do not use vari abl e speci fi ers. Use the Source and Destination
Variable fi el ds to desi gnate vari abl es to repl ace the vari abl e speci fi ers.
You can incl ude up to four vari abl e speci fi ers (each one desi gnated by a l eadi ng
percent si gn %) in the path or fi l e name. These vari abl e speci fi ers i ndi cate a
porti on of the path or fi l e name that is vari abl e (repl aced wi th data fr om el ements
when the fi l e operati on i s performed). The vari abl es can be di gi tal , anal og, l ong
anal og, fl oati ng-poi nt, or message el ements. Mul ti pl e vari abl es can be used
together, as i n a fi l ename and extensi on (for exampl e, %8s.%3s).
I f you want to var y the actual path/fil es used in ei ther the sour ce or desti nati on
paths, use one or mor e of the four vari abl es and %xx type speci fi ers to
dynami cal l y bui l d these at r un ti me fr om tags. Other wi se, si mpl y hardcode the
exact path/fi l e names desi red and l eave the four tag vari abl e fi el ds bl ank.
The data type of the el ement must match the vari abl e-speci fi er type. Vari abl e
speci fi ers and thei r data types are l i sted bel ow:
Refer to FactoryLink Fundamentals for more i nformati on about vari abl e
speci fi ers.
Table 4-8
Variable
Specifier
Variable
Specifier Type
FactoryLink
Data Type
%d Deci mal Di gi tal , Anal og, Long
Anal og, Fl oati ng-poi nt
%s Stri ng Message
FILE MANAGER
Using Variable Specifiers in File Specifications
86 / FactoryLink ECS / Core Tasks Configuration Guide

The chart bel ow contai ns exampl es of vari abl e speci fi ers usi ng generi c syntax:
Table 4-9
Variable Specifier Examples
Variable Description Entry Sample Results
Di rector y, subdi rectory, or fi l ename %8s FLI NK
Numeri c fi l e extensi on .%d .1, .2, .3, etc.
%.03d .001, .002, .003, etc.
Fil ename and extensi on %8s.%03d fi l e.001
%8s.%3s fi l e.exe
FILE MANAGER
Using Wildcard Characters in File Specifications
FactoryLink ECS / Core Tasks Configuration Guide / 87
4
F
i
l
e

M
a
n
a
g
e
r
USING WILDCARD CHARACTERS IN FILE SPECIFICATI ONS
The Fi l e Manager task accepts the fol l owi ng wi l dcard character speci fi ers i n the
source and desti nati on path names:
* (asterisk) for stri ng repl acement
? (question
mark)
for si ngl e-character repl acement
Format path names as fol l ows:
Path names wi th wi l dcard characters in the fi l e speci fi cati ons mi ght resembl e the
fol l owi ng exampl es:
The fol l owi ng exampl e is of a Fi l e Manager operati on usi ng wil dcard characters
(usi ng Wi ndows fi l e syntax).
Table 4-10
source /DEVI CE_NAME/DI R_NAME/SUB_DI R_NAME/WI LDC
ARD FI LESPEC
desti nati on /DEVI CE_NAME/DI R_NAME/SUB_DI R_NAME
Do not speci fy a fi l ename for the desti nati on path wi th
COPY as Fi l e Manager does i t for you.
Table 4-11
source /DEVI CE/FLI NK/SAMPLE/SAMPLE.*
desti nati on /DEVI CE/FLI NK/EXE
Table 4-12
Sample File Manager Control Panel Using Wildcard Characters
Field: Sample Entry: Explanation:
Command COPY Desi gnates a COPY operati on
Tri gger copytri g Name of the di gi tal el ement used to
tri gger the copy operati on
FILE MANAGER
Using the File Manager with Networks
88 / FactoryLink ECS / Core Tasks Configuration Guide

USING THE FI LE MANAGER WITH NETWORKS


I n addi ti on to bei ng ful l y compati bl e wi th FactoryLi nk, the FactoryLi nk Fi l e
Manager i s compati bl e wi th networks usi ng the fol l owi ng protocol types:
DECnet
NETBI OS
TCP/I P
Fil e-management functi ons, such as copyi ng, del eti ng, pri nti ng, and renami ng
fi l es, can be performed between the l ocal FactoryLi nk system and any remote
computer runni ng Fi l e Manager as l ong as the FactoryLi nk system contai ns the
FactoryLi nk Local Area Networki ng (FLLAN) opti on.
I f usi ng FLLAN, create the LOCAL fi l e before fi l l i ng i n the confi gurati on tabl es.
Defi ne the l ocal stati on name i n the ASCI I fi l e LOCAL i n the FLAPP/NET
di rector y. Stand-al one systems do not requi re the LOCAL fi l e.
Ei ther the source or desti nati on path name can refer to a fi l e on a r emote stati on.
The for mat for a r emote fi l e path i s as fol l ows:
\\(station)\(path)
where
station is the name of the remote stati on.
path is the ful l path name of the fi l e on the remote stati on.
Source
Format
c:\hi st\report\
rpt*.*
Desi gnates the sour ce path
Desti nati on
Format
C:\HI ST\
RECORDS
At run ti me, al l fi l es i n the REPORT
subdi r ector y that begi n wi th RPT ar e
copi ed to the RECORDS subdi r ector y.
Table 4-12 (Continued)
Sample File Manager Control Panel Using Wildcard Characters
Field: Sample Entry: Explanation:
FILE MANAGER
Using the File Manager with Networks
FactoryLink ECS / Core Tasks Configuration Guide / 89
4
F
i
l
e

M
a
n
a
g
e
r
The source and desti nati on are i nterchangeabl e as l ong as one of them i s the l ocal
FactoryLi nk stati on. The onl y di fference between l ocal fi l e operati ons and remote
fil e operati ons i s remote fi l e names must incl ude the di sk/dri ve speci fi cati on (i f
requi red by the operati ng system) and must conform to the fi l e name syntax for
the r emote computers operati ng system.
I n a copy operati on, onl y one fi l e can be remote. I n a rename operati on, both fi l es
must be on the same stati on.
For exampl e, to copy a fi l e from a l ocal FactoryLi nk stati on to a remote
FactoryLi nk stati on, use the fol l owi ng for mat for the remote path name:
\\STATION_NAME\DEVICE_NAME/DIR_NAME/FILE_NAME
Other fi l e-management operati ons can be per formed wi th Fil e Manager usi ng the
same for mat.
Do not use the r emote fi l ename (\\(STATI ON)\) when per formi ng Fi l e Manager
operati ons on networks unl ess you instal l ed FLLAN on the l ocal and remote
computers. Usi ng the FLLAN FactoryLi nk stati on name i nstructs FLLAN, rather
than the networ k, to per form the oper ati on.
At run ti me, before i nvoki ng fi l e management operati ons between l ocal and
remote nodes, ensure the FLFM_SERVER task i s runni ng i n the SHARED
domai n on the remote node.
Using the COPY Command with FLLAN
COPY operati ons, the most common Fi l e Manager operati ons performed on a
networked system, have the fol l owi ng uses.
Copy l ocal fi l es to a r emote stati on
Copy r emote fi l es to a l ocal stati on
Copy l ocal fi l es to the l ocal stati on
FILE MANAGER
Using the File Manager with Networks
90 / FactoryLink ECS / Core Tasks Configuration Guide

The fol l owi ng exampl e i s of a copy operati on on a networked system. The source
and desti nati on paths are i n Wi ndows fi l e syntax.
Table 4-13
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
Tabl e Name WI NXFER Desi gnates a fi l e-transfer operati on on a
network usi ng FLLAN
Command COPY Desi gnates a COPY operati on
Tri gger fi l exfertri g Name of the di gi tal el ement used to tr i gger
the copy oper ati on
Source
Format
c:\arc\
%s.l og
Sour ce path wher e %s i s the vari abl e
speci fi er. The stri ng speci fi ed by the val ue
of the message el ement s_fi l e repl aces the
%s i n the source speci fi cati on.
Source Tag 1 s_fi l e At run ti me, Fi l e Manager repl aces the
vari abl e %s i n the Sour ce For mat fi el d wi th
the val ue of thi s anal og el ement.
Desti nati on
Format
\\nod2\%s Fi l e Manager computes the desti nati on
path i n the same way as the source path.
Desti nati on
Tag 1
s_path I f the message el ement s_path contai ns the
fol l owi ng message:
C:\FLINK\RECIPE
the computed desti nati on speci fi cati on i s as
fol l ows:
\\NOD2\C:\FLINK\RECIPE
Compl eti on
Tri gger
copydone When the COPY operati on i s compl ete, Fi l e
Manager forces the val ue of thi s el ement to
1 (ON). Thi s el ement can be used by
another FactoryLi nk task or to tri gger
another Fi l e Manager operati on.
FILE MANAGER
Using the File Manager with Networks
FactoryLink ECS / Core Tasks Configuration Guide / 91
4
F
i
l
e

M
a
n
a
g
e
r
Refer to FactoryLink Fundamentals for detai l s for i nformati on about vari abl e
speci fi ers.
Compl eti on
Status
copystat When the COPY operati on i s compl ete, Fi l e
Manager wri tes the status informati on to
thi s anal og el ement.
Table 4-13 (Continued)
Sample File Manager Control Panel
Field:
Sample
Entry:
Explanation:
FILE MANAGER
Using the File Manager with Networks
92 / FactoryLink ECS / Core Tasks Configuration Guide

Using the COPY Command with a Network without FLLAN


When speci fyi ng a COPY command for networ ks wi thout FLLAN, do not speci fy a
stati on name i n the Source Format and Destination Format fi el ds. I nstead, speci fy a
networ k devi ce whi ch i s any l ogi cal devi ce on a r emote computer used as i f i t wer e
a l ocal devi ce.
Di fferent operati ng systems reference network devi ces i n di ffer ent ways. To fi nd
the proper syntax for referenci ng these devi ces, consul t the users manual for the
appropri ate operati ng system.
FILE MANAGER
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 93
4
F
i
l
e

M
a
n
a
g
e
r
TECHNICAL NOTES
To enabl e a l ocal node to perform fi l e management operati ons wi th a r emote node
at r un ti me, the FLFM_SERVER task must be runni ng i n the SHARED domai n
on the node that does not i ni ti ate the FLFM command. Ei ther star t the
FLFM_SERVER task manual l y fr om the Run-Ti me Manager screen at startup or
confi gure FactoryLi nk to start the FLFM_SERVER task automati cal l y at system
startup. Compl ete the fol l owi ng steps to do thi s.
1 Open the System Confi gurati on I nformati on panel in the SHARED domai n fr om
the Mai n Menu on the remote node.
2 Locate the r ow contai ni ng the entry FLFM_SERVER i n the Task fi el d.
3 Pl ace the cursor over FLFM_SERVER.
4 Tab to the Flags fi el d.
5 Enter an R i n the Flags fi el d. Thi s confi gures the FLFM_SERVER task on the
remote node to start up automati cal l y whenever FactoryLi nk i s started.
FILE MANAGER
Operating System Notes
94 / FactoryLink ECS / Core Tasks Configuration Guide

OPERATING SYSTEM NOTES


For Windows NT and Windows 95 Users
Configuring File Manager
Source File Spec. (5-5) andDestination File Spec (5-7).
Using Wildcard Characters in File Specifications (5-17)
Format path names as fol l ows.
Do not speci fy a fi l ename for the desti nati on path as Fi l e Manager wi l l do i t for
you.
Path names wi th wi ldcard characters i n the fi l e speci fi cati ons mi ght resembl e the
fol l owi ng exampl es.
Table 4-14
Valid Entry Format Description Example
DRI VE:\DI R\SUBDI R\
FI LE.EXT
For
stand-al one
systems
C:\LOG\HI STORY\
HI STORY.ARC
\\STATI ON\DRI VE:\
DI R\SUBDI R\FI LE.EXT
For
networked
systems
\\NODE1\C:\HI ST\PI C\
SCREEN1.PI C
Table 4-15
source C:\FLINK\SAMPLE\SAMPLE.*
desti nati on C:\FLINK\EXE
FILE MANAGER
Operating System Notes
FactoryLink ECS / Core Tasks Configuration Guide / 95
4
F
i
l
e

M
a
n
a
g
e
r
Using Variable Specifiers in File Specifications (5-16)
The fol l owi ng chart contai ns Wi ndows-speci fi c exampl es of vari abl e speci fi ers
used to desi gnate paths. The l ast exampl e shows the path name of a stati on on a
networ k.
Table 4-16
Samples of Variable Specifiers in Path Names
Description Example Comments
Standard
path
c:\hi story\exe\sampl e.exe Base exampl e
1 vari abl e c:\%8s\exe\sampl e.exe Vari abl e for di rectory
2 vari abl es c:\%8s\%8s\sampl e.exe Vari abl es for di rectory and
subdi rectory
3 vari abl es c:\%8s\%8s\sampl e.%3s Vari abl es for di rector y,
subdi rectory, and
3-character fi l e extensi on
4 vari abl es %1s:\%.8s\%.8s\
sampl e.%3s
Vari abl es for dri ve,
di r ector y, subdi rectory, and
fi l e extensi on
Standard
path for a
networ k
stati on
\\node2\c:\hi story\exe\
sampl e.exe
\\node2\ i s the name of a
remote stati on
FILE MANAGER
Operating System Notes
96 / FactoryLink ECS / Core Tasks Configuration Guide

For OS/2 Users


Configuring File Manager
Source File Spec. (5-5) and Destination File Spec. (5-7)
Using Wildcard Characters in File Specifications (5-17)
Format path names as fol l ows.
Path names wi th wi ldcard characters i n the fi l e speci fi cati ons mi ght resembl e the
fol l owi ng exampl es.
Table 4-17
Valid Entry Format Description Example
DRI VE:\DI R\SUBDI R\
FI LE.EXT
For
stand-al one
systems
C:\LOG\HI STORY\
HI STORY.ARC
\\STATI ON\DRI VE:\
DI R\SUBDI R\
FI LE.EXT
For
networked
systems
\\NODE1\C:\FLI NK\PI C\
SCREEN1.PI C
Table 4-18
source DRIVE:\DIRECTORY\SUBDIRECTORY\WILDCARD FILESPEC
desti nati on DRIVE:\DIRECTORY\SUBDIRECTORY
Do not speci fy a fi l ename for the desti nati on path as Fi l e Manager wi l l do
i t for you.
Table 4-19
source C:\FLINK\SAMPLE\SAMPLE.*
desti nati on C:\FLINK\EXE
FILE MANAGER
Operating System Notes
FactoryLink ECS / Core Tasks Configuration Guide / 97
4
F
i
l
e

M
a
n
a
g
e
r
Using Variable Specifiers in File Specifications (5-16)
The fol l owi ng chart contai ns OS/2-speci fi c exampl es of vari abl e speci fi ers used to
desi gnate paths. The l ast exampl e shows the path name of a stati on on a networ k.
Table 4-20
Samples of Variable Specifiers in Path Names
Description Example Comments
Standard
path
c:\hi story\exe\sampl e.exe Base exampl e
1 vari abl e c:\%8s\exe\sampl e.exe Vari abl e for di rectory
2 vari abl es c:\%8s\%8s\sampl e.exe Vari abl es for di rector y and
subdi rectory
3 vari abl es c:\%8s\%8s\sampl e.%3s Vari abl es for di rector y,
subdi rectory, and 3-character
fi l e extensi on
4 vari abl es %1s:\%8s\%8s\sampl e.%
3s
Vari abl es for dri ve, di rectory,
subdi rectory, and fi l e
extensi on
Standard
path for a
networ k
stati on
\\node2\c:\hi story\exe\
sampl e.exe
\\node2\ i s the name of a
r emote stati on
FILE MANAGER
Operating System Notes
98 / FactoryLink ECS / Core Tasks Configuration Guide

For Unix Users


Configuring File Manager
Source File Spec (5-5) and Destination File Spec(5-7).
Using Variable Specifiers in File Specifications (5-16)
The fol l owi ng chart contai ns UNI X-speci fi c exampl es of vari abl e speci fi ers used to
desi gnate paths. The l ast exampl e shows the path name of a stati on on a networ k.
Table 4-21
Valid Entry Format Description Example
/di rectory/subdi rectory/
fi l ename.extensi on
For
stand-al one
systems
/l og/hi story/hi story.ar c
\\stati on\/di rector y/
subdi rectory/
fi l ename.extensi on
For
networked
systems
\\node1\/fl i nk/pi c\
screen1.pi c
Table 4-22
Samples of Variable Specifiers in Path Names
Description Example Comments
Standard
path
/fl i nk/exe/sampl e.exe Base exampl e
1 vari abl e /%s/exe/sampl e.exe Vari abl e for di rectory
2 vari abl es /%s/%8s/sampl e.exe Vari abl es for di rectory and
subdi rector y
3 vari abl es /%s\%s\sampl e.%s Vari abl es for di rectory,
subdi rector y,
and fi l e extensi on
FILE MANAGER
Operating System Notes
FactoryLink ECS / Core Tasks Configuration Guide / 99
4
F
i
l
e

M
a
n
a
g
e
r
Using Wildcard Characters in File Specifications (5-17)
Format path names as fol l ows.
Do not speci fy a fi l ename for the desti nati on path as Fi l e Manager wi l l do i t for
you.
Path names wi th wi l dcard characters in the fi l e speci fi cati ons mi ght resembl e the
fol l owi ng exampl es.
Standard
path for a
networ k
stati on
\\node2\/fl i nk/exe/
sampl e
\\node2\ i s the name of a
remote stati on
Table 4-23
source /directory/subdirectory/wildcard filespec
desti nati on /directory/subdirectory
Table 4-24
source /flink/sample/sample*
desti nati on /flink/exe
Table 4-22 (Continued)
Samples of Variable Specifiers in Path Names
Description Example Comments
FILE MANAGER
Operating System Notes
100 / FactoryLink ECS / Core Tasks Configuration Guide

Part V
Print Spooler
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 103
Table of Contents
Pr i nt Spool er

5 Print Spooler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105


Confi guri ng the Pri nt Spool er. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Print Spooler in this book
Print Spooler in the Core Tasks Configuration
Guide
104 / FactoryLink ECS / Core Tasks Configuration Guide

Print Spooler
FactoryLink ECS / Core Tasks Configuration Guide / 105

5
P
r
i
n
t

S
p
o
o
l
e
r
Chapter 5
P r i nt Spool er
The FactoryLi nk Pri nt Spool er task permi ts you to di rect data to pri nters or other
devi ces wi th paral l el i nterfaces, and al so to di sk fi l es.
The Pri nt Spool er task al so provi des other features:
Fi l e name spool i ng (l oads fi l e when pri nt devi ce is avai l abl e, mi ni mi zi ng
requi red memor y)
Management of pri nti ng and schedul i ng functi ons
Pri nt Spool er recei ves output fr om other FactoryLi nk tasks, such as Al arm
Supervi sor or Fi l e Manager, and sends thi s output to a pri nter or di sk fi l e.
Wi th Pri nt Spool er, you can defi ne up to fi ve devi ces to recei ve output fr om other
FactoryLi nk tasks. To send fi l es to one of these devi ces, FactoryLi nk tasks
r eference the correspondi ng devi ce number i n a confi gurati on tabl e.
PRINT SPOOLER
Configuring the Print Spooler
106 / FactoryLink ECS / Core Tasks Configuration Guide

CONFIGURING THE PRINT SPOOLER


Use the Pri nt Spool er Tabl e to speci fy the devi ces to whi ch the Pri nt Spool er task
di rects data. The Pri nt Spool er Tabl e consi sts of one panel : Pri nt Spool er
I nformati on.
Pri nt Spool er is normal l y confi gured in the SHARED domai n. Before openi ng and
confi guri ng Pri nt Spool er, ensure the current domai n sel ected i s SHARED i n the
Confi gurati on Manager Domai n Sel ecti on box. Choose Print Spooler to displ ay the
Pri nt Spool er I nformati on panel .
Fol l owi ng ar e fi el d descri pti ons for thi s panel .
Device Name of the output devi ce. Each li ne corresponds to a speci fi c
devi ce number. For exampl e, l i ne1 = devi ce 1 and l i ne 5=devi ce 5.
Wi th Pri nt Spool er, you can define up to fi ve devi ces (l i nes) to
recei ve output fr om other FactoryLi nk tasks.
You can assi gn two or more devi ce numbers to the same physi cal
devi ce. For exampl e, i f onl y one pri nter i s i nstal l ed and i t is
attached to paral l el port 1, you can enter the same devi ce name
for both Devi ce 1 (l i ne 1) and Devi ce 2 (li ne 2). Pri nt Spool er then
recogni zes Devi ces 1 and 2 are the same physi cal devi ce, and i t
acts accordi ngl y.
FactoryLi nk tasks use the fi rst entry i n the Pri nt Spool er
I nformati on panel as the defaul t output devi ce. For exampl e,
when you request a pri nt screen i n Run-Ti me Graphi cs, the
output goes to the fi rst devi ce defi ned the Pri nt Spool er panel .
PRINT SPOOLER
Configuring the Print Spooler
FactoryLink ECS / Core Tasks Configuration Guide / 107
5
P
r
i
n
t

S
p
o
o
l
e
r
You can change thi s defaul t by movi ng the i nformati on for
another defi ned devi ce to the panel s fi rst l i ne usi ng the cut and
paste featur es.
You can al so di rect output to a fi l e rather than to a por t by
speci fyi ng a path and fi l e name. I f Pri nt Spool er wr i tes to an
exi sti ng fi l e, the new val ues/text ar e appended to that fi l e i n the
speci fi ed for mat.
I f output is redi rected to a di sk fi l e (as opposed to a true devi ce),
the fi l e opens i n append mode before i t recei ves output. I f the fi l e
does not exi st when Pri nt Spool er i s fi rst started, i t i s created i f
any pri nt jobs are di rected to i t. The characters wri tten to i t are
preci sel y the same as i f i t were a true devi ce (i ncl udi ng al l devi ce
command sequences). You can use such fil e redi recti on to captur e
output for l ater exami nati on and/or pri nti ng at a ti me when
FactoryLi nk i s shut down.
The Pri nt Spool er task can send output to mul ti pl e devi ces at
once.
The fol l owi ng exampl e contai ns Val i d entri es.
Table 5-1
Operating
System
Printer
Specifications
Path and File Name Format
Windows
NT,
Windows
95, and
OS/2
l pt1
COM1
l pt2
COM2
l pt3
Note: I n OS/2
these val ues
must be entered
i n l ower case.
DRI VE:\DI RECTORY\
SUBDI RECTORY\FI LE.EXT
UNI X /dev/ttyn or /d
ev/l pn
wher e n i s the
uni t number. *
/DI RECTORY/SUBDI RECTORY/
FI LE.EXT
PRINT SPOOLER
Configuring the Print Spooler
108 / FactoryLink ECS / Core Tasks Configuration Guide

Initialization
Sequence/File
Separator
Sequence
The I ni ti al i zati on Sequence i s defi ned by enteri ng the acti on you
want i t to perfor m i n the I ni ti al i zati on Sequence col umn of the
Pri nt Spool er I nformati on panel . The I ni ti al i zati on Sequence
performs the acti on(s) you defi ne once at the begi nni ng of a
Spool er sessi on.
The Fi l e Separator Sequence is defi ned by enteri ng the acti on you
want i t to perfor m i n the Fi l e Separator Sequence col umn of the
Pri nt Spool er I nformati on panel . The Fi l e Separator Sequence
performs the acti on(s) you defi ne at the end of each fi l e of a
Spool er sessi on.
Enter an al phanumeri c stri ng of between 1 to 16 characters for
use onl y wi th the Report Generator and Fil e Manager, not for use
wi th the Al arm Supervi sor command sequences that
automati cal l y send character s to the pri nters to separate the
output of di ffer ent fi l es.
These command sequences can consi st of two types of characters.
Di spl ay charactersPri ntabl e ASCI I characters, such as A, that
can be pri nted between fi l es.
Control charactersCodes that instruct a pri nter to perfor m an
acti on. Control characters have ASCI I val ues fr om 00 through 1F
hexadeci mal . To pl ace a control character i n a sequence, enter a
backsl ash (\) fol l owed by the two-character hexadeci mal val ue of
the control character.
For exampl e, to i ncl ude a for m feed command between fi l es, enter
the command sequences as fol l ows (form feed has the ASCI I hex
val ue 0C):
Initialization Sequence:\0C
File Separator Sequence:\0C
The backsl ash character i tsel f can be entered as two backsl ashes
(\\).
Refer to the user manual for the appropri ate pri nter for
i nformati on about control characters and thei r hexadeci mal
val ues.
Valid Entry: al phanumeri c str i ng of between 1 to 16
characters
PRINT SPOOLER
Configuring the Print Spooler
FactoryLink ECS / Core Tasks Configuration Guide / 109
5
P
r
i
n
t

S
p
o
o
l
e
r
Binary On/Binary
Off
Enter an alphanumeri c stri ng of between 1 to 16 characters that
speci fi es for use onl y wi th the Report Generator and Fi l e
Manager ; not for use wi th the Al ar m Super vi sor command
sequences sent to the pri nters to pri nt bi nary fi l es.
These command sequences can consi st of two types of characters:
Di spl ay charactersPri ntabl e ASCI I characters, such as A, that
can be pri nted between fi l es
Control charactersCodes that i nstruct a pri nter to perform an
acti on. Control characters have ASCI I val ues fr om 00 thr ough 1F
hexadeci mal . To pl ace a control character i n a sequence, enter a
backsl ash (\) fol l owed by the two-character hexadeci mal val ue of
the control character.
For exampl e, the two-di gi t hex val ue for the ASCI I ESCAPE
character i s 1B. I f, on a parti cul ar pri nter, an ESCAPE character
fol l owed by G turns graphi cs mode ON and ESCAPE fol l owed by
g turns i t OFF, fi l l i n the command sequences as fol l ows:
Binary On:\1BG
Binary Off:\1Bg
Thi s sequence puts the pri nter i n graphi cs mode before i t begi ns
the pri nt job and takes the pri nter out of graphi cs mode upon
compl eti on of the pri nt job.
Valid Entry: al phanumeri c stri ng of between 1 to 16
characters
Status Tag Name of an el ement that contai ns one of three anal og val ues
representi ng the status of the pri nti ng devi ce:
0 Fi l e pri nt is compl ete
1 Devi ce acti ve
2 Error operati ng devi ce
I f you speci fy more than one devi ce, be sure to di sti ngui sh
between devi ces when assi gni ng el ement names.
I f the tag speci fi ed i n thi s fi el d is not al ready defi ned, a Tag
Definition di al og i s di spl ayed when you cl i ck on Enter wi th a tag
type of anal og i n the Type fi el d. Accept thi s defaul t.
Valid Entry: standard el ement tag name
PRINT SPOOLER
Configuring the Print Spooler
110 / FactoryLink ECS / Core Tasks Configuration Guide

Message Tag Name of an el ement that contai ns a message descri bi ng the


status of the pri nti ng devi ce. Thi s el ement i s useful i f you want to
di spl ay the status of a pri nti ng devi ce on a graphi cs screen. To
di spl ay the status of a pri nti ng devi ce on a graphi cs screen,
confi gure an output text object i n the Appl i cati on Edi tor to
contai n the val ue of thi s el ement. I f you speci fy more than one
devi ce, be sure to di sti ngui sh between devi ces when assi gni ng
el ement names.
I f the tag speci fi ed i n thi s fi el d i s not al ready defi ned, a Tag
Definition di al og is displ ayed when you cl i ck on Enter wi th a tag
type of message i n the Type fi el d. Accept thi s defaul t.
Valid Entry: .standard el ement tag name
When you have compl eted the panel , i t resembl es the sampl e panel shown i n the
fol l owi ng tabl e:
CAUTION
All Pri nt Spool er job requests are routed through the
/FLAPP/SPOOL di rectory. I f al l such requests ar e not effecti vel y
transferred (for instance, i f the pri nter is off-li ne), thi s di rector y
can get backl ogged. To ensure effecti ve processi ng, check the
di rector y peri odi cal l y and del ete any obsol ete job requests.
Table 5-2
Sample Print Spooler Information Panel
Field Sample Entry Explanation
Devi ce /dev/tty1 I ndi cates a pri nter on a UNI X system.
Fil e
Separ ator
Sequence
/0C I s a command sequence consi sti ng of
control character s. The /0C contr ol
characters i nstruct pri nti ng devi ce
/dev/tty1 to i nser t a for mfeed after each fi l e
i t pri nts. Thi s ensures that each fi l e pri nted
begi ns on a new page.
PRINT SPOOLER
Configuring the Print Spooler
FactoryLink ECS / Core Tasks Configuration Guide / 111
5
P
r
i
n
t

S
p
o
o
l
e
r
Status TAG devi ce1_status I s an anal og el ement contai ni ng the status
of the pri nti ng devi ce. Other tasks can read
the val ue of devi ce1_status to determi ne
whether the pri nter i s busy before they
send output to i t.
Message
TAG
devi ce1_msg I s a message el ement contai ni ng a message
about the status of the pri nti ng devi ce. Thi s
message is displ ayed on a graphi cs screen
because you al so confi gured an output text
object (i n the Appl i cati on Edi tor) to contai n
the val ue of thi s el ement.
Table 5-2 (Continued)
Sample Print Spooler Information Panel
Field Sample Entry Explanation
PRINT SPOOLER
Configuring the Print Spooler
112 / FactoryLink ECS / Core Tasks Configuration Guide

Part VI
Math and Logic
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 115
Table of Contents
Math and L ogi c

6 Math and Logic Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119


Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Creati ng Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Configuration Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
I nterpreted Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Switching from I ML to CML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Compiled Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
CML Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Tri ggeri ng/Cal l i ng . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Triggering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Calling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
7 Configuring Math and Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
Text Edi tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Math and Logi c Confi gurati on Tabl es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
.PRG Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Math and Logic Variables Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Math and Logic Triggers Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Math and Logic Procedure Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Confi guri ng the Math and Logi c Tabl es. . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Choosing a Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Math and Logi c Vari abl es Tabl e. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Math and Logi c Tri ggers Tabl e. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Math and Logi c Procedures Tabl e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Correcting Validation Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Configuration Examples Using Element Arrays . . . . . . . . . . . . . . . . . . 146
Compi l ed Math and Logi c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
CML Requi rements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Math and Logic in this book
Math and Logic in the Core Tasks Configuration
Guide
116 / FactoryLink ECS / Core Tasks Configuration Guide

Math and Logic


Enteri ng CML I nto the System Confi gurati on Tabl e . . . . . . . . . . . . . . . . . . 152
Runni ng CML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Running CML on a Development System . . . . . . . . . . . . . . . . . . . . . . . 153
Running CML on a Run-Time-Only System. . . . . . . . . . . . . . . . . . . . . 153
How CML Operates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Editing CML.MAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Advanced Concepts for CML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Utilities and Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Cal l i ng C Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
8 Math and Logic Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Procedure Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Naming Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Math and Logi c Reser ved Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Symbolic Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Numeric Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Str ucture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Declarations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
9 Math and Logic Procedures and Functions . . . . . . . . . . . . . . . . . . 231
Pr ogram Fi l es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Runni ng Programs as I nterpreted Programs . . . . . . . . . . . . . . . . . . . . . . . . 235
Techni cal Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Calling Procedures and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Local Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Library Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Calling Functions that Operate on Tag I Ds (CML Only) . . . . . . . . . . . 248
Core Tasks Configuration Guide
FactoryLink ECS / Core Tasks Configuration Guide / 117
10 Compiled Math and Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
System Confi gurati on Panel Setup Under I ML/CML . . . . . . . . . . . . . . . . . . 253
Makefi l es . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Editing CML.MAK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
The CML Process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Generati on of CML Executabl es. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
118 / FactoryLink ECS / Core Tasks Configuration Guide

Math and Logic


FactoryLink ECS / Core Tasks Configuration Guide / 119

6
M
a
t
h

a
n
d

L
o
g
i
c
Chapter 6
Math and L ogi c
Over vi ew
The FactoryLi nk Math and Logi c task coordi nates i nteracti ons among many of the
FactoryLi nk tasks. These features i ncl ude:
Uses a structured, BASI C-l i ke syntax
Executes in the background wi th no operator i nterventi on at run ti me
Supports both i nterpr eted and compi l ed Math and Logi c (I ML and CML)
Supports bl ock structures, l oopi ng constructs, and cal l abl e mathemati cal
functi ons
Supports automati c conversi on of data types
Supports mul ti -di mensi onal arrays
MATH AND LOGIC OVERVIEW
Uses
120 / FactoryLink ECS / Core Tasks Configuration Guide

USES
Math and Logi c i s cal l ed fr om other appl i cati ons to per for m functi ons such as:
Manipul ate real -ti me database el ements and l ocal vari abl es
Batch control
Per formi ng computati onal cal cul ati ons
Compari ng l ogi cal l y two val ues stored i n database el ements
Setti ng the val ue of an el ement to a val ue chosen by an end user at run ti me
Control l i ng the system acti vi ty resul ti ng fr om end-user i nteracti on wi th
on-screen buttons
Val i dati ng end-user i nput
Control l i ng screen changes
Control l i ng i nformati on fl ow i nto and out of an appl i cati on
MATH AND LOGIC OVERVIEW
Procedures
FactoryLink ECS / Core Tasks Configuration Guide / 121
6
M
a
t
h

a
n
d

L
o
g
i
c
PROCEDURES
Math and Logi c executes procedures contai ni ng l ogi cal l y grouped and organi zed
statements that have a si ngl e conti nuous thread of executi on, or control fl ow,
between the deci si on poi nts (branches). Typi cal l y, you anal yze the acti ons needed
i n the appli cati on and organi ze the operati ons needed for each acti on i nto one or
more procedures. At run ti me, procedures can be ei ther :
Tri ggered i n response to changes i n the real -ti me database
Executed di rectl y fr om wi thi n another Math and Logi c procedure
One or more procedures are contai ned wi thi n an edi tabl e pl ai n-text pr ogr am fi l e.
A program (.PRG) fi l e can contai n several separate pr ocedures that may cal l (or
refer to) one another.
MATH AND LOGIC OVERVIEW
Creating Programs
122 / FactoryLink ECS / Core Tasks Configuration Guide

CREATING PROGRAMS
I n or der to use Math and Logi c, you must fi r st cr eate a pr ogr am by confi guri ng
tabl es.
Configuration Tables
Use the Math and Logi c confi gurati on tabl es to:
Defi ne vari abl es used by a task.
I denti fy the type of pr ogram, ei ther interpr eted or compil ed.
I denti fy where the programs are stored.
I denti fy when a pr ogram shoul d be i nvoked.
The number of el ements, tri ggers, and pr ograms that can be defi ned i s l i mi ted
onl y by the amount of avai l abl e memor y, oper ati ng system, and/or compi l er (i n
compi l ed mode onl y). Refer to the documentati on suppl i ed for compi l er
i nformati on.
You must confi gure three tabl es to create a pr ogr am.
Math and Logic Variables tableDefi nes el ements Math and Logi c reads or
wri tes. An el ement must be defi ned before i t can be used i n a procedure or i t
wi l l be consi dered an undefi ned vari abl e and wi l l not val i date. Defi ne each
el ement referenced by the procedures i n a pr ogram fi l e by enteri ng i ts tag name
i n thi s tabl e. Thi s tabl e has one panel : Math and Logi c Vari abl es I nformati on.
Math and Logic Triggers tableDefi nes the el ements used to tr i gger the
Math and Logi c procedures to run. For each tri gger el ement defi ned, enter the
associ ated procedur e the tr i gger el ement i s responsi bl e for tri ggeri ng and the
method of executi on: i nterpreted or compi l ed. Thi s tabl e has one panel : Math
and Logi c Tri ggers I nformati on.
Math and Logic Procedure tableWri tes the Math and Logi c procedures
requi red by the appl i cati on. Each program fi l e must be named exactl y as i t is
named i n the Math and Logi c Tri ggers I nformati on panel but wi th a .PRG
extensi on. After wri ti ng a procedure and savi ng i t to a progr am fi l e name, edi t
i t i n thi s panel . Thi s tabl e i s a text-entry panel : Math and Logi c Procedure -
filename.prg.
MATH AND LOGIC OVERVIEW
Creating Programs
FactoryLink ECS / Core Tasks Configuration Guide / 123
6
M
a
t
h

a
n
d

L
o
g
i
c
Trigger Elements
Tri gger el ements used i n Math and Logi c procedures must fi r st be defi ned i n the
Math and Logi c Vari abl es tabl e. Because many Math and Logi c procedures can
access them, these el ements are gl obal i n scope. Remember : gl obal el ements are
not the same as gl obal vari abl es whi ch are decl ared i nsi de program fi l es and are
used onl y wi thi n procedures. When a procedur e i s tr i gger ed by an el ement, the
name of thi s el ement must be entered in the Math and Logi c Tri ggers tabl e so the
procedure wi l l l oad and run.
Completing the Tables
Compl ete the confi gurati on tabl es i n the fol l owi ng order .
Math and Logi c Vari abl es tabl e
Math and Logi c Tri ggers tabl e
Math and Logi c Procedures tabl e
Converting Previous Versions
Previ ous versi ons of Math and Logi c operated in the I ML mode onl y. Run the
FLCONV uti l i ty to convert previ ous versi ons to the new one.
Opening the Configuration Manager Main Menu
Refer to FactoryLink Fundamentals for i nformati on on how to open the
Confi gurati on Manager Mai n Menu screen.
MATH AND LOGIC OVERVIEW
Modes
124 / FactoryLink ECS / Core Tasks Configuration Guide

MODES
Math and Logi c runs i n one of two modes:
I nterpr eted mode
Compi l ed mode
Interpreted Mode
I nterpreted mode i s a subset of Compi l ed Math and Logi c. I ML means when the
val ues of tri gger el ements associ ated wi th one or more procedures change i n the
real -ti me database, I ML determi nes whi ch procedures are affected. Math and
Logi c then i nterpr ets ever y l i ne of the i nstructi ons and executes them for each
tri ggered change. I ML i s excel l ent for appli cati on prototypi ng and l ogi c
debuggi ng.
Most appl i cati ons wri tten i n the I nterpreted Mode functi on wi th no or ver y few
modi fi cati ons under the Compi l ed Mode. I f an appl i cati on runni ng i n I nterpreted
Mode uses any reserved words as vari abl es or procedure names, these wi l l need to
be modi fi ed so the compi l er wi l l be abl e to compi l e and li nk the procedures er r or
fr ee. These words i ncl ude any reserved by the C compi l er for the pl atfor m you are
runni ng on as wel l as those reserved by FactoryLi nk.
Using IML
When you use I ML, you create procedure fi l es that are scri pts and mani pul ate
both real -ti me database el ements and l ocal vari abl es.
I nterpreted mode i s most appropri ate when:
Onl y mathemati cal functi ons wi l l be performed
A compi l er i s not avai l abl e
Running IML
After starti ng the appl i cati on,
Load the pr ogram i nto memory
Val i date the program
Wai t for changes to the tri gger el ements i n the real -ti me database associ ated
wi th the procedures i n the program
Execute the pr ogr am associ ated wi th the tr i gger when the tr i gger el ement i s set
to 1 (ON)
MATH AND LOGIC OVERVIEW
Modes
FactoryLink ECS / Core Tasks Configuration Guide / 125
6
M
a
t
h

a
n
d

L
o
g
i
c
Executing IML
When procedure changes are tri ggered i n the real -ti me database, I ML determi nes
the proper procedur e requested and then i nterprets and executes the instructi ons
i n the procedur e.
Each ti me an I ML program i s executed, Math and Logi c fi rst reads, or i nterprets,
the i nstructi ons wi thi n the program to determi ne the acti ons to perform. Then, i t
executes those acti ons.
Switching from IML to CML
To make swi tchi ng fr om I ML to CML i n l ar ge appl i cati ons a one-step pr ocess, use
the fol l owi ng procedure.
From the BH_SQL prompt i n the FLAPP di rectory of the appl i cati on, i ssue the
fol l owi ng command:
To change from I ML to CML, use the fol l owi ng command:
SQL>update i ml tri g set mode = COMPI LED wher e mode i s not nul l
To change from CML to I ML, use the fol l owi ng command:
SQL>update i ml tri g set mode = I NTERPRETED wher e mode i s not nul l
Compiled Mode
Compi l ed mode i s a combi nati on of several FactoryLi nk uti l i ti es wi th a thi rd
party ANSI C l anguage compi l er wor ki ng together to gener ate ANSI C code fr om
user created *.pr g fi l es.
I n CML, the procedure progr am fi l e i s transl ated i nto C source code to create a
bi nary executabl e fi l e for the pl atform on whi ch the appli cati on i s devel oped.
Because the appl i cati on consi sts of both the SHARED and USER domai ns, CML
cr eates two executabl e fi l es, one for each domai n. These executabl es are uni que
and are named:
For SHARED domai n:/{FLAPP}/SHARED/CML/CSHARED.EXE
For USER domai n:/{FLAPP}/USER/CML/CUSER.EXE
These fi l es perform the same acti ons descri bed i n the pr ogr am fi l e when the
associ ated tri gger el ements are set. CML i ncreases the speed and functi onal i ty of
appl i cati ons that use I ML.
MATH AND LOGIC OVERVIEW
Modes
126 / FactoryLink ECS / Core Tasks Configuration Guide

Using CML
When you use CML, you make i mpr ovements on appli cati ons that use compl ex
l oops such as nested I F-THEN-ELSE cl auses or WHI LE l oops. I nterpr eted mode
handl es the executi on of ari thmeti c operati ons fai rl y qui ckl y, but CML adds more
functi onal i ty for you as an in-l i ne functi on to pass si mpl e parameters and as an
embedded C code bl ock to pass compl i cated parameters.
Compi l ed mode i s most appropr i ate when you want:
Faster startup and executi on for i mproved performance
Better handl i ng of compl ex, mul ti pl e condi ti onal statements
Abi l i ty to cal l C functi ons or to insert C code i nto procedures
Avai l abi l i ty of extensi ve fl ow contr ol for the appl i cati on
Running CML
After starti ng the appl i cati on:
Wai t for changes to the tri gger el ements i n the real -ti me database associ ated
wi th the procedures i n the program
Execute the pr ogr am associ ated wi th the tr i gger when the tr i gger el ement i s set
to 1 (ON)
Executing CML
Each ti me a compi l ed program is executed, CML:
Reads or i nterprets the i nstructi ons wi thi n the pr ogram to determi ne the
acti ons to perform
Executes these acti ons
CML Operation
CML uses three uti l i ti es for speci fi c rol es i n creati ng the executabl es used at run
ti me. These uti l i ti es are:
MKCML
PARSECML
CCCML
MATH AND LOGIC OVERVIEW
Modes
FactoryLink ECS / Core Tasks Configuration Guide / 127
6
M
a
t
h

a
n
d

L
o
g
i
c
MKCML
The MKCML uti l i ty is a shel l that cal l s the PARSECML and CCCML uti l i ti es as
needed for the cur r ent appl i cati on. For each domai n, MKCML checks the
dependenci es between the confi gurati on tabl es and the program fi l es by:
Ensuri ng the I ML.CT fi l e i s up to date by cal l i ng CTGEN. CTGEN compares
I ML.CT agai nst the database fi l es upon whi ch I ML.CT i s dependent. I f the
database fi l es have a l ater ti me/date stamp than I ML.CT, CTGEN rebui lds
I ML.CT to br i ng them up to date.
Checki ng the ti me/date of I ML.CT to determi ne i f the Math and Logi c
confi gurati on has changed. I f so, i t reproduces and recompi l es al l of the .C fi l es
by cal l i ng PARSECML and CCCML.
When you redi rect the output of MKCML to a fi l e, the messages in the dump may
appear out of or der because of the way the operati ng system buffers and outputs
messages when redi recti ng output. I f you do not redi rect the output of MKCML,
the MKCML reports the messages to the standard output i n the correct order.
PARSECML
The PARSECML uti l i ty parses the appli cati on program fi el d and produces .C fi l es
for a gi ven domai n. I t produces a .C fi l e for each program fi l e l i sted as compi l ed
(has COMPI LED i n the Mode fi el d) i n the Math and Logi c Tri ggers I nformati on
panel .
The uti l i ty al so checks the dependenci es between the pr ogram fi el d and the .C
fil es to deter mi ne i f any procedures have been updated si nce the .C fi l es were l ast
produced.
MATH AND LOGIC OVERVIEW
Triggering/Calling
128 / FactoryLink ECS / Core Tasks Configuration Guide

TRIGGERING/CALLING
Triggering
Developing Triggering Schemes
Mul ti pl e procedures ar e executed usi ng the tr i ggeri ng method of thi s system. To
devel op the most effi ci ent tri ggeri ng scheme, consi der the fol l owi ng:
What i nterval s or ci rcumstances tri gger i ndi vi dual procedures at a reasonabl e
rate for thi s data?
Tr y to use condi ti onal event tri ggeri ng based on changi ng data so procedures
run when data i s change-state dri ven or tri gger dri ven.
Single-threaded Task
Thi s task i s si ngl e-threaded. Thi s means tri ggered procedures are cued and
executed i n the or der i n whi ch they ar e tr i gger ed. A pr ocedur e that does not
compl ete because of an i nfi ni te l oop, for exampl e, wi l l stop the rest of the
procedur es fr om executi ng.
When runni ng one procedure, set a tr i gger for the next.
Calling
You can both tri gger and cal l procedures.
Trigger Procedure: I f you want to wai t unti l one pr ocedur e has compl eted
before executi ng another or i f your procedure has to execute when an event occurs,
tri gger a new procedure.
Calling Procedure: I f you want a procedur e to occur i mmedi atel y, you must cal l
the procedure.
Thi s system uses a compl ex cuei ng pr ocess that necessi tates usi ng cal l i ng
procedur es i f you want them to occur i n a di sti nct order.
MATH AND LOGIC OVERVIEW
Triggering/Calling
FactoryLink ECS / Core Tasks Configuration Guide / 129
6
M
a
t
h

a
n
d

L
o
g
i
c
Completing the Calling Sequence
Enter FLRUN command
FLRUN cal l s the MKCML uti l i ty
MKCML cal l s PARSECML to produce .C fi l es (C code) fr om the pr ogram fi l es
MKCML then cal l s CCCML to compi l e the .C fi l es i nto object fi l es usi ng an
external compi l er and to l i nk the object fi l es i nto bi nary executabl es usi ng an
object l i nker.
MATH AND LOGIC OVERVIEW
Triggering/Calling
130 / FactoryLink ECS / Core Tasks Configuration Guide

FactoryLink ECS / Core Tasks Configuration Guide / 131

7
M
a
t
h

a
n
d

L
o
g
i
c
Chapter 7
Confi gur i ng
Math and L ogi c
To use Math and Logi c, you must fi rst create a Math and Logi c program usi ng the
three Math and Logi c confi gurati on tabl es:
Math and Logi c Vari abl es tabl e
Math and Logi c Tri gger s tabl e
Math and Logi c Procedure tabl e
Thi s chapter descri bes how to confi gure the Math and Logi c tabl es. The number of
el ements, tri ggers, and pr ograms you can define i s l i mi ted onl y by the amount of
avai l abl e memor y, the operati ng system, and/or the compi l er (CML onl y). Refer to
the documentati on suppli ed wi th the compi l er for detai l s on compi l er l i mi tati ons.
CONFIGURING MATH AND LOGIC
Text Editor
132 / FactoryLink ECS / Core Tasks Configuration Guide

TEXT EDITOR
When wor ki ng i n Compi l ed Math and Logi c, you use a text edi tor to sel ect and
edi t i nformati on and to enter a new name.
You may al so choose to create your own procedures i n any text edi tor system for
more power for some tasks. I f you wr i te your own procedures, we recommend you
validate these wi th the FactoryLi nk edi tor .
Also, the defaul t font si ze in I nterpreted Math and Logi c i s 20 (Couri er). I t shoul d
be 10-12 pt (Couri er). To change the defaul t, use FLFONT. To change FLFONT,
set FLFONT=12. I f no Couri er font exi sts, then defaul t to the system fi xed font.
CONFIGURING MATH AND LOGIC
Math and Logic Configuration Tables
FactoryLink ECS / Core Tasks Configuration Guide / 133
7
M
a
t
h

a
n
d

L
o
g
i
c
MATH AND LOGIC CONFIGURATION TABLES
The confi gurati on of CML i s compl eted usi ng the same panel s i n the
Confi gurati on Manager used to confi gure I ML. A new fi el d has been added to the
Math and Logi c Tri ggers panel cal l ed the Mode fi el d. Thi s fi el d control s whether
the associ ated procedure i s to be run usi ng I ML or CML. The fi el d uses the key fil e
imlmode.key to val i date the fi el d.
You may choose ei ther Interpreted or Compiled to choose I ML or CML. We suggest
al l procedures i n an appl i cati on be confi gured as ei ther I nterpreted or Compi l ed.
I t i s possi bl e to run both I ML and CML, but the appl i cati on desi gner must be sur e
that any procedures cal l ed fr om a Compil ed procedure al so be confi gured as
Compi l ed.
Runni ng FLCONV properl y converts exi sti ng I ML tabl es to the new format.
Al though the Mode fi el d i s bl ank when the appli cati on i s i ni ti al l y converted, the
defaul t val ue for the fi el d i s I nterpr eted so the appl i cati on may be run
i mmedi atel y after restorati on. To convert to CML, enter Compi l ed i nto the Mode
fi el d of the desi red procedures to Compi l ed.
When you name any Math and Logi c objects, such as constants, vari abl es, tags,
and procedures remember that I ML and CML are very sensi ti ve to case and
speci al character s. For CML, the uni que nami ng i s not l i mi ted to appearance i n
Math and Logi c code but i s al so li mi ted to what the name becomes i n the
generated C code. For exampl e, speci al characters ($.*) become _ by the parsi ng
routi ne. Therefor e, the fol l owi ng decl arati ons
declare short lu$lu
declare short lu@lu
declare short lu_lu
al l become decl are short lu_lu wi th potenti al l y confusi ng resul ts such as dupl i cate
defi ni ti on er r or s or changes in one vari abl e are refl ected i n another. Remember
when nami ng objects, be sure al l of these objects have uni que names.
CONFIGURING MATH AND LOGIC
Math and Logic Configuration Tables
134 / FactoryLink ECS / Core Tasks Configuration Guide

.PRG Files
The .PRG fi l es are the substance of Math and Logi c. The .PRG fi l es contai n al l of
the procedures l i sted i n the Math and Logi c Tri ggers tabl e.
.PRG Name vs Proc Name
Every .PRG fil e must contai n one procedure defi ned wi th the same name as the
ei ght-character porti on of the fi l ename. That procedure must be l i sted in the Math
and Logi c Tri ggers tabl e. The I ML task onl y knows whi ch fi l enames to l oad by
readi ng the Tri ggers tabl e.
Errors that read I ML: PROC name not found are probabl y caused by a typi ng
er ror or fai l ure to l i st a .PRG fi l e i n the Tri ggers tabl e.
Procedure names ar e case sensi ti ve whi l e procedure filenames are always l ower
case (i f appl i cabl e to the oper ati ng system).
PROC Definitions
A .PRG fi l e groups several procedure defi ni ti ons. Procedure defi ni ti ons contai n a
mi ni mum of three statements: PROC name, BEGI N, and END. Procedure
defi ni ti ons are case sensi ti ve so the fol l owi ng defi nes two procedures.
proc Dave
begi n
pri nt Dave.
end.
proc dave
begi n
pri nt Li ttl e Dave
end
CONFIGURING MATH AND LOGIC
Math and Logic Configuration Tables
FactoryLink ECS / Core Tasks Configuration Guide / 135
7
M
a
t
h

a
n
d

L
o
g
i
c
Comments
The pound si gn (#) i ndi cates the I ML parser i gnor es a comment that i s al l text
after the #. The excepti on to thi s i s i f the #i s i nsi de the stri ng or escape usi ng the
backsl ash character (\). Wel l -commented code i s i ntegral to mai ntai n a
user/devel oper fri endl y code.
Math and Logic Variables Table
The Math and Logi c Vari abl es tabl e l ets you defi ne the database el ements Math
and Logi c reads or wri tes. An el ement must be defi ned before i t can be used i n a
procedure or el se the task wi l l not val i date the procedure (the el ement wi l l be
considered an undefi ned vari abl e). Defi ne each el ement referenced by the
procedures in a program fi l e by enteri ng i ts tag name i n thi s tabl e.
The Math and Logi c Vari abl es tabl e shoul d contai n ever y tag referenced i n the
.PRG fi l es. Fai l ure to l i st a tag i n thi s panel resul ts i n validati on errors and
run-ti me errors. Tags l i sted i n thi s panel for the SHARED domai n are handl ed
separatel y fr om the tags l i sted in the USER domai n. For thi s reason, i f a
SHARED tag i s used i n both SHARED and USER procedures, i t must be
referenced i n both the SHARED Math and Logi c Vari abl es tabl e and the USER
tabl e.
Array tags are handl ed di fferentl y i n thi s panel . To use any el ement of an array,
onl y the zeroth el ement (array [0]) shoul d be l i sted her e. A common mi stake i s
defi ni ng an ar r ay in thi s panel by typi ng ar r ay [19] to defi ne a 20 el ement ar r ay.
Thi s method of defi ni ti on i s fi ne for defi ni ti on purposes; but to ensure proper
functi oni ng of Math and Logi c, the subscri pt must be changed to zero (array [0]).
Thi s tabl e has one panel : Math and Logi c Vari abl es I nformati on.
CONFIGURING MATH AND LOGIC
Math and Logic Configuration Tables
136 / FactoryLink ECS / Core Tasks Configuration Guide

Math and Logic Triggers Table


The Math and Logi c Tri ggers tabl e l ets you defi ne the tri gger el ements used to
tri gger the Math and Logi c procedures to r un. For each tri gger el ement defi ned,
you enter the associ ated procedure the tri gger el ement i s responsi bl e for
tri ggeri ng.
The Math and Logi c Tri ggers tabl e l i sts a tri gger tag, a procedure name, and the
run mode of the procedur e. Di gi tal tags ser ve as the most common tr i gger type,
but any tri gger type (except mai l box) can operate as tri ggers. Di gi tal tags onl y
tri gger a pr ocedur e when the val ue i s TRUE and the change status bi t i s hi gh.
Other tag types tri gger whenever thei r val ue changes.
Thi s tabl e has one panel : Math and Logi c Tri ggers I nformati on.
Math and Logic Procedure Table
The Math and Logi c Procedure tabl e l ets you wri te the Math and Logi c procedures
requi red by the appli cati on. Each pr ogr am fi l e must be named exactl y as i t i s
named i n the Math and Logi c Tri ggers I nformati on panel , but wi th a .PRG
extensi on. After you wri te a procedure and save i t to a program fi l e name, you can
edi t i t i n thi s panel . Thi s tabl e i s a text-entr y panel : Math and Logi c Procedur e -
filename.pr g.
Trigger Elements
El ements used i n Math and Logi c procedures must fi rst be defi ned in the Math
and Logi c Vari abl es tabl e. Because any Math and Logi c procedure can access
them, these el ements ar e global i n scope. (Note that gl obal el ements are not the
same as global variables whi ch are decl ared i nsi de pr ogram fi l es and are used
onl y wi thi n procedur es. Refer to Str uctur e on page 187 i n Chapter 8, Math and
Logi c Syntax for further di scussi on of vari abl es and scope.) I f a Math and Logi c
procedur e is tr i ggered by an el ement, the name of thi s tr i gger el ement must be
entered i n the Math and Logi c Tri ggers tabl e so the procedur e wi l l be l oaded and
run.
CONFIGURING MATH AND LOGIC
Configuring the Math and Logic Tables
FactoryLink ECS / Core Tasks Configuration Guide / 137
7
M
a
t
h

a
n
d

L
o
g
i
c
CONFIGURI NG THE MATH AND LOGIC TABLES
Compl ete the confi gurati on tabl es i n the fol l owi ng order :
Math and Logi c Vari abl es tabl e
Math and Logi c Tri ggers tabl e
Math and Logi c Procedure tabl e
Choosing a Domain
Math and Logi c can operate i n ei ther the SHARED or the USER domai n. Except
i n cases where al l tasks must share the same Math and Logi c data, we
recommend usi ng the USER domai n for Math and Logi c i n order to prevent
unforeseen i nterference between tasks. Before openi ng the Math and Logi c tabl es,
ensure the current domai n sel ected is USER i n the Confi gurati on Manager
Domai n Sel ecti on box. Choosi ng a di fferent domai n for a task after i t has been
confi gured (wi thout maki ng supporti ng changes i n the appl i cati on) can resul t i n
unpredi ctabl e system behavi or.
CONFIGURING MATH AND LOGIC
Math and Logic Variables Table
138 / FactoryLink ECS / Core Tasks Configuration Guide

MATH AND LOGIC VARI ABLES TABLE


To confi gure the Math and Logi c Vari abl es tabl e:
1 Choose Math and Logi c Vari abl es fr om the Confi gurati on Manager Mai n Menu to
di spl ay the Math and Logi c Vari abl es I nformati on panel :
2 Speci fy the fol l owi ng informati on:
Tag Name Enter the name of an el ement or tag to be used i n a Math and
Logi c procedur e.
Do not use a Math and Logi c reserved keyword as an el ement
name.
I f the el ement i s to be an arr ay, speci fy 0 for each array
di mensi on when enteri ng i ts name here. (For exampl e,
batch[0][0]). Then, i n the Di mensi on fi el d of the Tag Defi ni ti on
di al og, speci fy the number of el ements for each ar r ay di mensi on.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, message
Tag Type Enter the data type of the el ement i denti fi ed i n the Tag Name
fi el d. Press ENTER for i nfor mati on fr om a predefi ned tag or to
compl ete a tag.
Valid Entry: data type
Tag Description Enter a descri pti on of the tag i denti fi ed i n the Tag Name fi el d.
Valid Entry: standard el ement tag name
3 I f a Tag Name fi el d entr y does not have a correspondi ng Tag Type fi el d entry for tag
types of di gi tal , anal og, l ongana, or message, a Tag Defi ni ti on di al og i s di splayed.
Choose the appropri ate data type.
CONFIGURING MATH AND LOGIC
Math and Logic Variables Table
FactoryLink ECS / Core Tasks Configuration Guide / 139
7
M
a
t
h

a
n
d

L
o
g
i
c
When you compl ete the confi gurati on process, the panel resembl es the fol l owing
exampl e:
I n thi s exampl e, Math and Logi c was confi gured to access the anal og el ements
l astcar and tempset and the l ong anal og el ement temp for val ues to use i n i ts
cal cul ati ons. The tag types and tag descri pti ons are displayed i n the panel when
you cl i ck Enter.
4 After al l vi si bl e fi el ds ar e compl ete, cl i ck on Enter to save the i nformati on and
return to the Mai n Menu.
CONFIGURING MATH AND LOGIC
Math and Logic Triggers Table
140 / FactoryLink ECS / Core Tasks Configuration Guide

MATH AND LOGIC TRIGGERS TABLE


To confi gure the Math and Logi c Tri ggers tabl e:
1 Choose Math and Logi c Tri ggers fr om the Mai n Menu to displ ay the Math and
Logi c Tri ggers I nformati on panel :
2 Speci fy the fol l owi ng informati on:
Trigger Tag Enter the name of an el ement whose val ue can tri gger a Math
and Logi c procedure. The associ ated procedure i s executed ei ther
when thi s el ements val ue changes to 1 (i f the el ement i s di gi tal )
or whenever the el ements val ue changes (for al l other data
types).
I f there i s a procedure or pr ogram fi l e that shoul d be l oaded but
does not have an associ ated tri gger el ement (that i s, i t i s i nvoked
di r ectl y fr om other progr ams you have defi ned and l oaded),
speci fy the name of that fi l es mai n procedure on a separate l i ne
and l eave the Trigger Tag fi el d bl ank.
Valid Entry: standard el ement tag name
Valid Data Type: di gi tal , anal og, l ongana, message
Procedure Enter an al phanumeri c stri ng of between 1 to 8 characters that
speci fi es the uni que name of the Math and Logi c procedure
(exactl y as entered in the PROC statement) to be tri ggered by the
el ement defi ned i n the Trigger Tag fi el d. Consider the fol l owi ng
gui del i nes when defi ni ng thi s entr y:
Procedur e names are case-sensi ti ve, but the fi l e names of the
program fi l es contai ni ng the pr ocedures are not.
CONFIGURING MATH AND LOGIC
Math and Logic Triggers Table
FactoryLink ECS / Core Tasks Configuration Guide / 141
7
M
a
t
h

a
n
d

L
o
g
i
c
Do not gi ve a procedur e a tag name or use the same name for two
procedures, even i f the procedures are i n di fferent domai ns. I f
ei ther of these two errors exi st, Math and Logi c cannot i ni ti ate
the pr ocedur e.
Al though the name of a tri ggered procedure cannot be l onger
than 8 char acter s, you may use l onger names for procedures that
are cal l ed (not tri ggered).
Every procedure fi l e must contai n a procedure wi th the same
name as the fi l e name.
The procedur e name must be al phanumeri c and must begi n wi th
an al phabeti c character .
Valid Entry: al phanumeri c stri ng
Valid Data Type: for Wi ndows NT, Wi ndows 95, and OS/2:
al phanumeri c stri ng of between 1 and 8
characters; for UNI X: al phanumeri c stri ng of
between 1 and 16 characters (al l l ower case)
Mode Enter the mode i n whi ch Math and Logi c wi l l operate. Ei ther:
I nterpreted Math and Logi c l oads the associ ated procedures
.PRG fi l e i nto memory at startup. Each ti me the
I nterpreted pr ocedure i s executed, the task
interpr ets the procedures i nstructi ons, and then
perfor ms the acti ons requi r ed.
Compi l ed The ori gi nal .PRG fi l e r emai ns unal tered. The
.C fi l e i s then compi l ed and l i nked wi th
FactoryLi nk and devel oper-suppli ed l i brari es to
create the Compi l ed Math and Logi c run-ti me
task.
The words, I nterpr eted and Compi l ed, can be i n al l upper case, al l
l ower case, or i ni ti al caps.
Description Enter an alphanumeri c stri ng of between 1 to 80 characters that
descri bes the i ntended use of the el ement speci fi ed in the Trigger
Tag fi el d.
Valid Entry: al phanumeri c stri ng of between 1 to 80
characters
3 When you have entered al l the i nformati on for thi s panel , cl i ck Enter to save the
data. I f you have entered the name of any tags not al ready defi ned, the Tag
Defi ni ti on di al og i s di spl ayed.
CONFIGURING MATH AND LOGIC
Math and Logic Triggers Table
142 / FactoryLink ECS / Core Tasks Configuration Guide

4 Enter data for any tags that di spl ay i n the Tag Defi ni ti on di al og. Refer to the fi el d
descri pti on where the tag name i s defi ned for detai l s on valid tag types.
When al l i nformati on i s speci fi ed, the panel resembl es the fol l owi ng exampl e:
I n thi s exampl e, the Math and Logi c procedure SETTEMP i s run as i nterpreted at
run ti me and the procedure PI D i s compi l ed at run ti me. When the val ue of tri gger
el ement SEC1 becomes 1 (ON), Math and Logi c runs SETTEMP. When the val ue
of tr i gger el ement SEC2 becomes 1 (ON), Math and Logi c runs the executabl e for
PI D.
CONFIGURING MATH AND LOGIC
Math and Logic Procedures Table
FactoryLink ECS / Core Tasks Configuration Guide / 143
7
M
a
t
h

a
n
d

L
o
g
i
c
MATH AND LOGIC PROCEDURES TABLE
To confi gure the Math and Logi c Procedures tabl e:
1 Choose Math and Logi c Procedures from the Mai n Menu to di splay the Sel ect a
Fi l e di al og:
2 Ei ther choose a pr ogram to edi t or enter the name of a program to create. (I n thi s
exampl e, the program name SETTEMP was entered.) The system automati cal l y
adds the .PRG (pr ogr am) extensi on.
3 Cli ck Enter. The Math and Logi c Procedure panel i s displ ayed.
I f you entered a new program name, the panel i s bl ank.
I f you sel ected an exi sti ng program, i t i s di splayed i n the panel .
CONFIGURING MATH AND LOGIC
Math and Logic Procedures Table
144 / FactoryLink ECS / Core Tasks Configuration Guide

ExampleThe program SETTEMP i s shown i n the panel bel ow:


The program fi l e SETTEMP contai ns a procedur e named SETTEMP. The
el ements tempset and temp wer e defi ned i n the sampl e Math and Logi c Vari abl es
I nformati on panel . SETTEMP i s executed when the val ue of the tri gger el ement
SEC1 becomes 1 (ON). I f the val ue entered for tempset i s gr eater than the current
temper atur e (temp), then temp i s i ncreased by 1. I f the val ue entered for tempset
i s l ess than the current temperature, then temp i s decreased by 1.
Coding Guidelines
Consi der the fol l owing gui del i nes when codi ng a procedure:
Star t the pr ocedur e wi th a BEGI N statement and concl ude i t wi th an END
statement.
The maxi mum l i ne l ength i s 80 characters. Runni ng a procedure wi th l i nes
l onger than 80 characters can cause unpredi ctabl e val i dati on resul ts; the
procedure may val i date even though ther e ar e er r or s. Math and Logi c wi l l not
functi on proper l y whi l e runni ng such a procedure.
For each I F statement, enter a matchi ng ENDI F, properl y nested.
Show al l keywor ds, such as I F, THEN, ELSE, and ENDI F, in uppercase
character s to di sti ngui sh them from el ement names. (Keywords are not
case-sensi ti ve, but el ement names ar e.)
CONFIGURING MATH AND LOGIC
Math and Logic Procedures Table
FactoryLink ECS / Core Tasks Configuration Guide / 145
7
M
a
t
h

a
n
d

L
o
g
i
c
4 After you have enter ed the pr ocedur e, you must val i date i t to check for syntax
err or s. Choose Validate fr om the Fi l e menu. I f ther e are no er rors, the system
repor ts nothi ng. I f ther e ar e er r or s, the fol l owi ng message i s displ ayed:
5 Choose Save fr om the Fi l e menu to save the procedure.
6 Choose Exit to exi t the Math and Logi c Procedure panel and return to the Mai n
Menu. I f you try to exi t a procedure contai ni ng validati on errors, the fol l owi ng
message is displ ayed:
Thi s warni ng remi nds you errors exi st so you do not run the appli cati on unti l the
errors are corrected. A procedure that fai l s val i dati on is not l oaded at run ti me
and can cause Math and Logi c to fai l . Exi ti ng an empty procedure resul ts i n a
val i dati on er r or , however, the exi stence of an empty pr ocedur e wil l not affect the
task duri ng run ti me.
Correcting Validation Errors
1 Cli ck OK fr om the Val idati on er r or message box. The l i nes of the procedur e that
the system coul d not val i date turn red and the cursor moves to the fi rst
non-val idated l i ne.
2 To displ ay error hel p for a non-val i dated l i ne, mark the l i ne marked as
non-val idated (red) and pl ace the cursor on the l i ne.
3 Choose Error Help fr om the Hel p menu. The system di splays the cause of the error
for that l i ne.
4 Choose Validate agai n after you have corrected an error. The system cl ears the red
l i nes for that er ror and moves the cursor to the next non-val i dated l i ne, i f any.
5 Repeat Steps 2 and 3 unti l al l errors are corrected.
Canceled
Validation error.
Warning
Validation error! Select OK to continue
CONFIGURING MATH AND LOGIC
Math and Logic Procedures Table
146 / FactoryLink ECS / Core Tasks Configuration Guide

You can cl ear the red l i nes fr om the scr een at any ti me by choosi ng Clear Err fr om
the Fi l e menu. However , you cannot displ ay error hel p.
Configuration Examples Using Element Arrays
Thi s secti on shows sampl e Math and Logi c confi gurati on panel s for an appli cati on
that contai ns el ement ar r ays. A sampl e Math and Logi c Vari abl es I nformati on
panel i s di spl ayed:
The cars array stores col or informati on about the col ors of cars produced duri ng
the current run wi th 1 i ndi cati ng a whi te car , 3 a red car, and so forth; the er r or s
array contai ns zeroes i n the fi rst col umn unl ess a probl em occurs i n pai nti ng a
car . Noti ce the ar r ay subscri pts are defi ned to i ndex fr om zero, so ar r ays
contai ni ng 100 el ements actual l y contai n el ements 0 to 99. The tri gger el ement
mi dni ght causes the executi on of the PRI NTRED procedur e, as defi ned i n the
sampl e Math and Logi c Tri ggers I nformati on panel :
CONFIGURING MATH AND LOGIC
Math and Logic Procedures Table
FactoryLink ECS / Core Tasks Configuration Guide / 147
7
M
a
t
h

a
n
d

L
o
g
i
c
A sampl e Math and Logi c Pr ocedures panel contai ni ng the pr ocedur e PRI NTRED
i s di spl ayed:
The sampl e procedure PRI NTRED, displ ayed i n the panel above, i s a procedur e to
pri nt i nformati on about red cars. PRI NTRED i s executed when the val ue of the
di gi tal el ement mi dni ght (defi ned i n the Math and Logi c Tri ggers I nformati on
panel ) i s forced to 1 (ON) at mi dni ght of each day.
The el ement array cars consi sts of el ements whose val ues i ndi cate the col ors cars
are pai nted. Val i d pai nt col ors here are 1 through 5. The val ues of the el ements i n
el ement array errors (al so defi ned i n the Math and Logi c Vari abl es I nformati on
panel ) i ndi cate whether a probl em occurred wi th the cars pai nt job; a val ue of 0
(OFF) i ndi cates no er r or s, and a val ue of 1 (ON) i ndi cates a probl em occurred. I f a
probl em occurs, the el ement array cars wi l l not contai n a valid pai nt col or val ue in
that ar r ay l ocati on.
CONFIGURING MATH AND LOGIC
Math and Logic Procedures Table
148 / FactoryLink ECS / Core Tasks Configuration Guide

Whenever the di gi tal el ement mi dni ght i s forced to 1 (ON), the PRI NTRED
procedur e tri ggers Math and Logi c to read the val ues of the real -ti me database
message el ements i n the el ement array cars. Whenever the val ue of one of these
message el ements i s 3, the val ue for red pai nt, the PRI NTRED procedur e tel l s the
FactoryLi nk Pri nt Spool er task to pri nt the index i nto the el ement array cars for
that car . I f the car i s not marked as red, the procedure tests the val ue of the
el ement array error and reports an error i f the val ue i s 1 (ON). I n thi s way, the
operator recei ves pri nted i nformati on about al l cars in a factor y pai nted red each
day
CONFIGURING MATH AND LOGIC
Compiled Math and Logic
FactoryLink ECS / Core Tasks Configuration Guide / 149
7
M
a
t
h

a
n
d

L
o
g
i
c
COMPILED MATH AND LOGIC
Compi l ed Math and Logi c (CML) i s a combi nati on of uti l i ti es and l i brari es that, at
run ti me, create bi nary executabl e fi l es fr om the pr ogr am fi l es you speci fi ed to run
i n the compi l ed mode.
The compi l e process begi ns at r un ti me when you enter the FLRUN command.
CML transl ates the pr ogr am (.PRG) fi l es i nto C sour ce code, puts the C code i nto
fil es wi th an extensi on of .C, compi l es the .C fi l es to produce object (.OBJ) fi l es,
and then l i nks the object fi l es to the appropri ate l i brari es to cr eate bi nar y
executabl e (.EXE) fi l es. Then, as each pr ograms associ ated tri gger i s set, CML
runs i ts executabl e rather than i nterpreti ng and executi ng the program fi l e.
Because FactoryLi nk appli cati ons can be confi gured i n two domai ns (USER and
SHARED), CML creates one executabl e fi l e for each domai n i n whi ch the .PRG
fil es are confi gured.
The fi l e name of each executabl e i s uni que, defi ned to be C fol l owed by the domai n
name:
/FLAPP/USER/CML/CUSER.EXE for the user domai n
/FLAPP/SHARED/CML/CSHARED.EXE for the shared domai n
Executabl e fi l es created i n the UNI X operati ng system do not have an extensi on
i n thei r fi l e names.
CONFIGURING MATH AND LOGIC
CML Requirements
150 / FactoryLink ECS / Core Tasks Configuration Guide

CML REQUIREMENTS
CML requi res the fol l owi ng software and hardware:
FactoryLi nk versi on 4.1.3 or l ater
Opti on bits:
Run-ti me-onl y systemsCML run-ti me opti on
Devel opment systemsCML run-ti me and devel opment opti ons
An ANSI-compati bl e C-l anguage compi l er for :
Devel opment systems
Run-ti me-onl y systems that run on an operati ng system di fferent from the
devel opment system. The fol l owi ng tabl e shows the supported C compi l ers
for each oper ati ng system:
Refer to the user manual for the parti cul ar compi l er i n use for i nformati on about
compi l er swi tches and setup opti ons.
Opti on bi ts:
Devel opment systems---the CML run-ti me and devel opment opti ons
Run-ti me onl y systems--the CML run-ti me opti on
Table 7-1
Operating System Supported Compiler
AI X I BM AI X XL C Compi l er/6000
HP-UX HP-UX C/ANSI C
MS Wi ndows NT Compi l er purchased wi th the
Mi crosoft Vi sual C++ 32-bi t Edi ti on
for Wi ndows NT
OS/2 I BM Vi sual Age C++
SCO Open Desktop SCO Open Desktop C
CONFIGURING MATH AND LOGIC
CML Requirements
FactoryLink ECS / Core Tasks Configuration Guide / 151
7
M
a
t
h

a
n
d

L
o
g
i
c
For Windows NT and Windows 95
Compi l ed Math and Logi c for Windows NT and Wi ndows 95 requi res the
envi ronment vari abl e FLCOMPI LE to be set. Thi s envi ronment vari abl e poi nts to
the di r ector y of the compi l er you ar e usi ng.
Enter the fol l owi ng l i ne i n the AUTOEXEC.BAT fi l e for Wi ndows 95 and the
Regi stry for Wi ndows NT to set the FLCOMPI LE envi ronment vari abl e.
For Wi ndows NT:
FLCOMPI LE=DRI VE:\COMPI LER_DI RECTORY
For Wi ndows 95:
set FLCOMPI LE=DRI VE:\COMPI LER_DI RECTORY
Example: set FLCOMPILE=c:\BC4
CONFIGURING MATH AND LOGIC
Entering CML Into the System Configuration Table
152 / FactoryLink ECS / Core Tasks Configuration Guide

ENTERING CML INTO THE SYSTEM CONFIGURATION TABLE


Before starti ng CML for the fi rst ti me, you must enter the name of i ts executabl e
fi l e i nto the FactoryLi nk system confi gurati on. For each domai n i n whi ch you ar e
confi gur i ng CML, you must enter the name of the appl i cabl e executabl e i n the
System Confi gurati on I nformati on panel .
Compl ete the fol l owing steps to enter the CML fi l ename. I f you confi gured CML to
run i n both domai ns, you must perform thi s procedure twi ceonce for each
domai n:
1 Open the System Confi gurati on I nformati on panel fr om the Confi gurati on
Manager Mai n Menu for the domai n(s) i n whi ch you confi gured CML.
2 Enter R i n the Flags fi el d to start CML at run ti me.
3 Enter CML in the Task Name fi el d.
4 Enter Compiled Math and Logic i n the Description fi el d.
5 Enter the executabl e name i n the Executable File fi el d for the domai n i n whi ch you
opened the System Confi gurati on I nformati on panel ; ei ther:
/FLAPP/USER/BIN/CML/CUSER.EXE for the user domai n
/FLAPP/SHARED/BIN/CML/CSHARED.EXE for the shared domai n
where FLAPP is the envi ronment vari abl e set to the path of the appl i cati on fi l es.
For exampl e:
Use the appropri ate syntax for your operati ng system.
6 Cli ck Enter to save the i nformati on.
7 I f you are confi guri ng CML to run in both domai ns, return to Step 1 and repeat
thi s procedure for the other domai n.
C:\PROCESS\USER\BIN\CML\CUSER.EXE
or
C:\PROCESS\SHARED\BIN\CML\CSHARED.EXE
.
CONFIGURING MATH AND LOGIC
Running CML
FactoryLink ECS / Core Tasks Configuration Guide / 153
7
M
a
t
h

a
n
d

L
o
g
i
c
RUNNI NG CML
CML compi l es and runs on both devel opment systems and run-ti me systems.
Running CML on a Development System
To run CML on a devel opment system, star t the appli cati on by typi ng FLRUN at
the system pr ompt. (Windows user s must open the command l i ne fr om the
Program Manager usi ng the Run opti on on the Fi l e menu.)
Before starti ng the Run-Ti me Manager, FLRUN i nvokes several uti l i ti es to
compi l e programs i nto a si ngl e executabl e, the CML task (one task per domai n).
The compil ed programs wi l l have COMPILED entered i n the Mode fi el d of the Math
and Logi c Tri ggers I nformati on panel .
Running CML on a Run-Time-Only System
To run CML on a run-ti me-onl y system, you must transfer the CML executabl es
fr om the devel opment system to the run-ti me system. How you do thi s depends on
whether the devel opment and run-ti me systems run on the same operati ng
system:
I f the operati ng system for the devel opment and run-ti me system i s the same,
perform the fol l owi ng steps to run CML on a run-ti me-onl y system:
1 Use ei ther of the fol l owi ng two methods to transfer the CML executabl es to the
run-ti me system:
Use the FLSAVE and FLREST uti l i ti es to per for m a pl atfor m-speci fi c save and
restore of the appl i cati on from the devel opment system to the r un-ti me system.
Thi s saves and restores the compi l ed CML task al ong wi th the rest of the
appli cati on.
Copy the executabl es fr om /FLAPP/USER/CML and/or /FLAPP/SHARED/CML on
the devel opment system to the same path on the run-ti me system.
2 Star t CML. Dependi ng on whether the R fl ag was set i n the System
Confi gurati on I nformati on panel , do one of the fol l owi ng. I f the R fl ag was:
Set, enter FLRUN
Not set, star t CML fr om the Run-Ti me Manager
The compi l e process begi ns and CML creates the executabl es. Because the
devel opment and run-ti me operati ng systems are the same, CML runs as i s.
CONFIGURING MATH AND LOGIC
Running CML
154 / FactoryLink ECS / Core Tasks Configuration Guide

Different Development and Run-time Operating Systems


I f the operati ng systems for the devel opment and run-ti me systems are di ffer ent,
per for m the fol l owi ng steps to run CML on a run-ti me-onl y system:
1 Use the FLSAVE uti l i ty to per for m a mul ti pl atfor m save of the appl i cati on from
the devel opment system.
Because of the di fferent operati ng systems, CML wi l l not run as ori gi nal l y
compi l ed and must be recompi l ed either on the run-ti me system or on a system
wi th the same operati ng system as the run-ti me system. A compi l er i s requi red for
the system on whi ch you wil l recompi l e CML.
2 Use the FLREST uti l i ty to per for m a mul ti pl atfor m r estor e of the appli cati on to
the system on whi ch you wil l recompi l e CML.
3 Enter FLRUN to begi n the compi l e process duri ng whi ch CML creates the
executabl es.
4 I f you recompi l ed on a system other than the run-ti me system, copy the CML
executabl es fr om /FLAPP/USER/CML and/or /FLAPP/SHARED/CML to the same
path on the run-ti me system.
CML does not recompi l e every ti me you enter FLRUN. Once CML has compi l ed
the pr ogr am fi l es i nto executabl e fi l es, i t recompi l es onl y i f you change a pr ogr am
fi l e.
CONFIGURING MATH AND LOGIC
How CML Operates
FactoryLink ECS / Core Tasks Configuration Guide / 155
7
M
a
t
h

a
n
d

L
o
g
i
c
HOW CML OPERATES
CML i ncl udes three uti l i ti es that create the executabl es CML uses at run ti me:
MKCML
PARSECML
CCCML
Each uti l i ty performs a speci fi c rol e i n the compi l e process. The compi l e process
occurs in the fol l owi ng cal l i ng sequence of the CML uti l i ti es, begi nni ng at r un
ti me when you enter the FLRUN command:
1. FLRUN cal l s the MKCML uti l i ty.
2. MKCML cal ls CTGEN, whi ch ensures the Math and Logi c .CT fi l e i s up to date.
3. MKCML cal l s PARSECML to produce .C fi l es (C code) fr om the pr ogr am fi l es.
4. MKCML then cal ls CCCML to compi l e the .C fi l es into object fi l es (usi ng an
external compi l er) and to l i nk the object fi l es wi th l i brary fi l es i nto bi nary
executabl es (usi ng an object l i nker).
The fol l owi ng di agram il l ustrates the cal l i ng hi erarchy of the CML uti l i ti es:
CONFIGURING MATH AND LOGIC
How CML Operates
156 / FactoryLink ECS / Core Tasks Configuration Guide

MKCML
The MKCML uti l i ty i s a shel l that cal l s the PARSECML and CCCML uti l i ti es as
needed for the cur r ent appl i cati on. For each domai n, MKCML checks the
dependenci es between the confi gurati on tabl es (named IML.CT for both I ML and
CML) and the program fi l es. MKCML performs the fol l owi ng tasks:
Cal l s CTGEN whi ch compares IML.CT agai nst the database fi l es upon whi ch
the IML.CT fi l e i s dependent. I f the database fi l es have a l ater ti me/date stamp
than IML.CT, CTGEN rebui l ds IML.CT to bri ng i t up to date.
Determi nes whether the ti me/date of IML.CT has changed. I f so, then MKCML
reproduces and recompi l es al l of the .C fi l es by cal l i ng PARSECML and CCCML.
When you redi rect the output of MKCML to a fi l e, the messages displ ayed i n the
dump seem to be out of order because of how the operati ng system buffers and
outputs messages when redi recti ng output. I f you do not redi rect the output of
MKCML, then MKCML reports the messages to the standard output i n the correct
order.
PARSECML
The PARSECML uti l i ty parses the appl i cati ons progr am fi l es and produces .C
fi l es for a gi ven domai n. I t produces a .C fi l e for each program fi l e l i sted as
compi l ed i n the Math and Logi c Tri ggers I nformati on panel (has COMPILED as
the Mode fi el d entry).
Thi s uti l i ty al so checks the dependenci es between the pr ogr am fi l es and the .C
fi l es to see i f any procedures have been updated si nce the .C fi l es were l ast
produced.
CCCML
The CCCML uti l i ty compi l es each .C fi l e produced by PARSECML i nto an object
fi l e usi ng an external compi l er. I t then li nks the object fi l es wi th the FactoryLi nk
and devel oper -suppl i ed l i brari es i nto a bi nary executabl e. To determi ne the name
of the compi l er to use for a speci fi c operati ng system, CCCML uses a speci al fi l e
cal l ed a makefi l e.
Running the Utilities from the Command Line
The FLRUN command sets the FactoryLi nk path, the appl i cati on di r ector y path,
the user name, and the domai n name to the envi ronment vari abl es and turns off
the verbose-l evel and cl ean-build parameters.
CONFIGURING MATH AND LOGIC
How CML Operates
FactoryLink ECS / Core Tasks Configuration Guide / 157
7
M
a
t
h

a
n
d

L
o
g
i
c
CML i s desi gned so each of the CML uti l i ti es can be star ted fr om the command
l i ne, i f requi r ed. Thi s can be useful i f, duri ng appl i cati on devel opment, you need to
perform onl y a porti on of the compi l e process.
The command l i ne parameters used by al l CML uti l i ti es are descri bed in the
fol l owi ng tabl e:
Table 7-2 CML Command Line Parameters
Parameter Description
-P Sets the path to the FactoryLi nk pr ogr am
fi l es.
-A Sets the path to the appl i cati on di rector y.
-U Sets the user name.
-N Sets the domai n name.
-Vx Sets the verbose (debug) l evel to x.
-C Performs a cl ean bui l d, reproduci ng al l
fi l es from scratch.
CONFIGURING MATH AND LOGIC
How CML Operates
158 / FactoryLink ECS / Core Tasks Configuration Guide

Verbose-Level Parameters
When you use a verbose-l evel parameter , the uti l i ty di spl ays messages about i ts
progress as i t performs i ts part of the compil e process. Thi s serves as a debuggi ng
aid.
The fol l owi ng chart shows the messages produced by each uti l i ty at the verbose
l evel i ndi cated:
Table 7-3
Verbose Level Utility Result Displayed
1 or higher MKCML Appl i cati on name and domai ns, as
they are processed
1 or higherr CCCML Message, Not authori zed to run Math and Logi c
i f the system cannot fi nd the run-ti me bi t
Cur rent appli cati on and domai n bei ng processed
Message, No .PRG fi l es are confi gured as
COMPI LED
Message echoi ng the command l i ne that cal l s the
compi l er or l i nker before maki ng the cal l
Names of each fi l e as i t i s compi l ed
Message i ndi cati ng al l fi l es are up to date
1 PARSECML Name of each .C fi l e name as i t i s produced
2 PARSECML Verbose l evel 1 message, pl us:
The comments, contai ni ng the ori gi nal source
li nes of the Math and Logi c progr am, pl aced by the
uti l i ty at the start of the generated C code
Al l programs as they are parsed
3 or higher PARSECML Verbose l evel 1 and 2 messages, pl us:
Lexi cal tokens from each pr ograms as i t i s parsed
CONFIGURING MATH AND LOGIC
How CML Operates
FactoryLink ECS / Core Tasks Configuration Guide / 159
7
M
a
t
h

a
n
d

L
o
g
i
c
Makefiles
A makefi l e i s a fi l e contai ni ng al l the i nformati on needed by the CCCML uti l i ty to
compi l e the .C fi l es produced by PARSECML and cr eate an executabl e for the
current domai n. The name of the makefi l e used by CCCML is CML.MAK, and i s
uni que for each operati ng system.
The CML.MAK fi l e, l ocated i n the /FLINK/CML di rector y, contai ns the fol l owi ng
i nformati on to create the fi nal executabl e fi l e:
Name of the C compi l er to use for a gi ven operati ng system
Command-l i ne swi tches to be used when compili ng
Name of the operati ng systems object l i nker
Li nker command-l i ne swi tches
References to the FactoryLi nk l i brari es to be l i nked
References to the devel oper -suppl i ed l i brari es to be l i nked
Editing CML.MAK
As an ai d for advanced users, CML provi des a method for edi ti ng the CML.MAK
fil e. You can change the compi l er and li nker opti ons, speci fy command-l i ne
swi tches, and speci fy whi ch object fi l es and l i brari es to l i nk, gi vi ng you the
fl exi bi l i ty to cr eate a makefi l e uni que to an appli cati on for a gi ven domai n.
CML provi des two opti ons on the Mai n Menu for edi ti ng CML.MAK:
Math and Logic System Makefile
Math and Logic Domain Makefile
Math and Logic System Makefile
Any changes made to thi s fi l e are gl obal ; they appl y to al l appl i cati ons on the
system. To edi t CML.MAK:
1 Choose Math and Logi c System Makefi l e from the Mai n Menu to di spl ay a text
edi tor contai ni ng the CML.MAK fi l e fr om the /FLI NK/CML di rector y.
2 Edi t the fi l e as requi red.
3 Save and exi t the fi l e.
CONFIGURING MATH AND LOGIC
How CML Operates
160 / FactoryLink ECS / Core Tasks Configuration Guide

Math and Logic Domain Makefile


The fi rst ti me you choose Math and Logi c Domai n Makefi l e from the Mai n Menu,
an empty text edi tor i s di spl ayed because a domai n-speci fi c makefi l e does not
exi st. You can create one usi ng the master makefi l e CML.MAK in the /FLINK/CML
di rector y as a model . To cr eate a domai n-speci fi c makefi l e:
1 Copy CML.MAK from the /FLINK/CML di rectory to ei ther:
/FLAPP/USER/CML di rectory for the user domai n
/FLAPP/SHARED/CML di rectory for the shared domai n
2 Open the Mai n Menu and ensure the current domai n sel ected i n the
Confi gurati on Manager Sel ecti on box matches the domai n of the makefi l e you are
cr eati ng.
3 Choose Math and Logi c Domai n Makefi l e from the Mai n Menu to di spl ay a text
edi tor contai ni ng the domai n-speci fi c makefi l e CML.MAK copi ed in Step 1.
4 Edi t the fi l e as requi red.
Any defi ni ti ons i n the domai n-speci fi c makefi l e i n the appl i cati on di rector y
overri de the defi ni ti ons in the master makefi l e i n /FLINK/CML di rector y.
5 Save and exi t the fi l e.
CONFIGURING MATH AND LOGIC
Advanced Concepts for CML
FactoryLink ECS / Core Tasks Configuration Guide / 161
7
M
a
t
h

a
n
d

L
o
g
i
c
ADVANCED CONCEPTS FOR CML
Utilities and Commands
CTGEN and GENDEF
CTGEN and GENDEF wil l run nor mal l y as par t of FLRUN; but, i f you ar e
debuggi ng and need to run the i tems separatel y, you shoul d al ways run CTGEN
and GENDEF before runni ng MKCML.
MKCML Utilities
The MKCML uti l i ty coordi nates the creati on of the CML executabl es. I t has three
functi ons:
Runs CTGEN to create to I ML.CT
Runs PARSECML (i n both domai ns) to conver t the .PRG fi l es to .C fi l es
Runs CCCML to compi l e and l i nk the CML domai n executabl es
PARSECML
The PARSECML uti l i ty gener ates ANSI C code fr om each .PRG fi l e. I t have
vari ous l evel s of debuggi ng vi a the -VX parameter that can si mpl e generate mor e
detai l ed output or even add debuggi ng statements to the C code.
CCCML
The CCCML uti l i ty compi l es and l i nks the CML domai n executabl es vi a the
FLI NK/CML/CML.MAK fil e. I ts debuggi ng l evel s onl y provi de such informati on
as the exact command l i ne used to compi l e and l i nk the code.
The FLI NK/CML/CML.MAK i s pl atfor m dependent and i s the heart of the
portabi l i ty of FactoryLi nk. Fol l owi ng i s an exampl e fr om OS/2:
SRCSUFFIX - c
OBJ SUFFIX - obj
These vari abl es cl ari fy the operati ng system/C compi l er nami ng conventi on for
source and object fi l ed.
CC
The CC vari abl e desi gnates the command li ne compi l er
CONFIGURING MATH AND LOGIC
Advanced Concepts for CML
162 / FactoryLink ECS / Core Tasks Configuration Guide

CCFLAGS - -dos2 -AL -Au -Od -Zp -G2s -nologo -c -I{FLINK}\ inc
CCFLAGS speci fi es al l of the command l i ne opti ons for compil i ng the .C fi l es.
CMLOBJ S - glvars.obj
cmlprocs.obj
CMLOBJS are the stock CML fi l es that ar e not appl i cati on dependent. They ar e
l i abl e to change as versi ons change.
USEROBJ S
Userobjs al l ows for the i ncl usi on of user-defi ned object modul e at l i nk ti me.
LINK
The LI NK vari abl e desi gnates the command l i ne li nker .
LKFLAGS - /NOE/ST:16384/se:512
CMLLKOBJ S
USERLKOBJ S
These vari abl es al so al l ow for the incl usi on of object modul es not usual l y part of
CML.
CMLLIBS - {FLINK}\ LIB\ FLIB.LIB\
{FLINK}\ LIB\ CML.LIB
USERLIBS
These vari abl es al so al l ow for the incl usi on of l i brari es not usual l y par t of CML.
User-defi ned C l anguage i ncl udes fi l es that use quotes; e.g, #i ncl ude sampl e.h
shoul d be pl aced in the {FLAPP}/{DOMAI N}/CML di rectory. I ncl ude fi l es of the
for m #i ncl ude <sampl e.h> shoul d be pl aced i n the path searched by the compi l er .
You may want to pl ace them i n the {FLI NK}/I NC di r ector y and thi s i s okay;
however , the i ncl ude fi l es wi l l not be saved wi th the appli cati on on an MPS. The
best pl ace to put the i ncl ude fi l es i s i n the {FLAPP}/{DOMAI N}/CML and then
they wi l l be saved wi th the appl i cati on when an [MPS] mul ti -pl atform save i s
performed. I f you pl ace the i ncl ude fi l es i n the l atter di rectory, you shoul d add the
fol l owi ng to the cml .mak fi l e on the li ne CFLAGS:
CONFIGURING MATH AND LOGIC
Advanced Concepts for CML
FactoryLink ECS / Core Tasks Configuration Guide / 163
7
M
a
t
h

a
n
d

L
o
g
i
c
-dos2 -AL -Au -Od -Zp -G2s -nologo -c -I{FLINK}\ inc -I{FLAPP}\
{FLDOMAIN}\ CML
DEFFILE - {FLINK}\ CML\ CML.DEF
Thi s speci fi es the l i nk defi ni ti on fi l e. Under some pl atfor ms i t contai ns speci al
i nformati on about wi ndow attri butes and resources. On others, i t contai ns
compi l ed output opti ons. I f thi s i s al tered, i t is out of the domai n of USDATA
techni cal support.
TARGET - {FLAPP}\ {FLDOMAIN}\ cm,l\ c{FLDOMAIN}.exe
Thi s is the desti nati on executabl e.
CONFIGURING MATH AND LOGIC
Calling C Code
164 / FactoryLink ECS / Core Tasks Configuration Guide

CALLING C CODE
To cal l C code i n a Math and Logi c program, use the CML-speci fi c keywords:
cfunc
cbegi n
cend
Using cfunc
Use the keyword cfunc to decl ar e standard C functi ons and user-defi ned C
functi ons as cal l abl e i n-l i ne functi ons wi thi n a CML program. I n-l i ne C functi ons
al l ow a CML progr am to cal l a C functi on di rectl y wi thout openi ng a C code bl ock.
The functi on must be decl ared befor e i t i s cal l ed.
The C code generated by CML provi des prototypes for standard l i brary functi ons;
however , i t does not i ncl ude prototypes for user-defi ned C functi ons. You must
provi de functi on prototypes for al l user -defi ned functi ons. I ncl udi ng a functi on
wi thout a prototype may resul t i n compi l er warni ngs regardi ng the mi ssi ng
functi ons.
Use onl y C functi ons that use the Math and Logi c data types of SHORT, LONG,
FLOAT, and STRI NG wi th cfunc. Although a C functi on may use any data type
i nternal l y, i ts i nter face to Math and Logi c must use onl y these types.
I n the fol l owing exampl e, testfunc i s decl ared to use four arguments whose val ues
ar e SHORT, LONG, FLOAT, and STRI NG data types, and to return a val ue wi th
a SHORT data type:
DECLARE cfunc SHORT testfunc(SHORT,LONG,FLOAT,STRING)
You may decl are C functi ons to return the fol l owing data types:
Function: Val ue returned:
SHORT Shor t-i nteger
LONG Long-i nteger
FLOAT Fl oati ng-poi nt
STRING Stri ng
VOID None
The VOI D data type is uni que to CML. Use VOID when decl ari ng a functi on not
requi red to r etur n a val ue.
CONFIGURING MATH AND LOGIC
Calling C Code
FactoryLink ECS / Core Tasks Configuration Guide / 165
7
M
a
t
h

a
n
d

L
o
g
i
c
Do not use VOI D i n pr ograms desi gned to run i n i nterpreted mode.
cfunc Examples
The fol l owi ng two exampl es show how to use cfunc:
Example 1uses cfunc to decl ar e the standard C functi on strcmp() for use wi thi n
a CML pr ogr am:
The functi on strcmp() compares two stri ngs and returns a val ue that indi cates
thei r rel ati onshi p. I n thi s progr am, strcmp compares the i nput stri ng s1 to the
stri ng QUIT and i s decl ared to have a return val ue of the data type SHORT.
I f the return val ue equal s 0, then s1 i s i denti cal to QUIT and the pr ogr am
pri nts the message QUITTING.
I f the return val ue is l ess than or greater than 0, the program pri nts nothi ng.
C functi ons decl ared usi ng cfunc have ful l data conversi on wrapped around them,
meani ng any data type can be passed to and returned fr om them.
Gi ven the sampl e code above, the fol l owing program i s l egal wi thi n CML:
DECLARE cfunc SHORT strcmp(STRING, STRING)
PROC TEST(STRING s1)
BEGIN
IF strcmp(s1,"QUIT")=0 THEN
PRINT QUITTING\n
ENDIF
END
PROC MYPROC
BEGIN
DECLARE FLOAT f
DECLARE LONG k
DECLARE STRING buff
buff=strcmp(f,k)
END
CONFIGURING MATH AND LOGIC
Calling C Code
166 / FactoryLink ECS / Core Tasks Configuration Guide

I n thi s program, strcmp converts the FLOAT val ue f and the LONG val ue k to
stri ngs, compares the two stri ngs, and then returns a number (buff) that indi cates
whether the compari son was l ess than, greater than, or equal to zer o. Thi s
compari son is shown bel ow:
I f f < k, then buff i s a number l ess than 0.
I f f = k, then buff i s equal to 0.
I f f > k, then buff i s a number greater than 0.
Example 2uses cfunc to decl are the functi on testfunc whi ch has a return data
type of VOI D:
I n thi s program, the decl ared fl oati ng-poi nt vari abl e flp is set to 100.0 and thi s
val ue i s passed to the functi on testfunc. Note that VOI D is entered i n pl ace of the
data type for the functi ons return val ue. Thi s i s because the program i s si mpl y
passi ng a val ue to testfunc and the functi on i s not requi red to return a val ue.
Using cbegin and cend
You can use the keywords cbegi n and cend to embed C code di rectl y into a CML
procedur e. Between these keywords, you can cal l external l i brary functi ons and
mani pul ate structures and poi nters Math and Logi c does not suppor t.
However , you cannot decl ar e C vari abl es i nsi de a cbegi n/cend bl ock al ready wi thi n
the scope of a procedure. When you decl are a C vari abl e, the decl arati on bl ock,
fr om cbegi n to cend, must be di splayed outsi de the procedure, above the PROC
statement. (Refer to the decl arati on of static FILE *Fp=stderr; i n Exampl e 2,
bel ow.)
The cbegi n and cend statement must each be on a l i ne by itself with no precedi ng
tabs or spaces. Al l l i nes between these two keywords (the C code bl ock) are passed
di rectl y to the .C fi l e PARSECML produces for thi s program.
DECLARE cfunc VOID testfunc(FLOAT)
PROC MYPROC
BEGIN
DECLARE FLOAT flp
flp=100.0
testfunc(flp)
END
CONFIGURING MATH AND LOGIC
Calling C Code
FactoryLink ECS / Core Tasks Configuration Guide / 167
7
M
a
t
h

a
n
d

L
o
g
i
c
The fol l owi ng two exampl es show how to use the cbegi n and cend keywords.
I n thi s pr ogr am, the spri ntf and fpri ntf functi ons, cal l ed between cbegi n and cend,
are passed di r ectl y to the .C fi l e PARSECML generates for TEST. Note that l ocal
vari abl es are wi thi n the scope of the C code bl ock and can be accessed duri ng cal l s
to external functi ons.
Any C code bl ocks outsi de the body of a CML program are col l ected and moved to
the top of the generated .C fi l e, as shown i n Exampl e 2:
# Example 1:
PROC TEST(STRING message)
BEGIN
DECLARE STRING buff
IF message="QUIT" THEN
PRINT FINISHED.\n
ENDIF
cbegin
sprintf(buff,"The message was %s\n",message);
fprintf(stderr,buff);
cend
END
CONFIGURING MATH AND LOGIC
Calling C Code
168 / FactoryLink ECS / Core Tasks Configuration Guide

I n thi s program fi l e, the statement:


static FILE *Fp=stderr;
wi l l be moved to the top of the pr ogr am fi l e just after the line:
include mylib.h
# Example 2:
cbegin
#include mylib.h
cend
PROC TEST(STRING s1)
BEGIN
PRINT The message is ,s1
END
cbegin
static FILE *Fp=stderr;
cend
PROC SOMETHING (FLOAT f1)
BEGIN
cbegin
fprintf(Fp,"%6.2g\n",f1);
cend
END
CONFIGURING MATH AND LOGIC
Calling C Code
FactoryLink ECS / Core Tasks Configuration Guide / 169
7
M
a
t
h

a
n
d

L
o
g
i
c
The fol l owi ng exampl e shows how to access real -ti me database el ements fr om
wi thi n embedded C code bl ocks. I t increments the val ues of two anal og el ements,
Tag1 and Tag2[5], by 10.
cbegin
int fl_tagname_to_id(TAG*, int, ...); /* function
prototype missing from CML.H*/
cend
PROC example
BEGIN
cbegin
{
TAG tag[2];
ANA value[2];
fl_tagname_to_id(tag,2, TAG1,TAG2[5]);
fl_read(Task_id,tag,2,value);
value[0] += 10;
value[1] += 10;
fl_write(Task_id,tag,2,value);
}
cend
END
CONFIGURING MATH AND LOGIC
Calling C Code
170 / FactoryLink ECS / Core Tasks Configuration Guide

The fol l owi ng exampl e shows how to manipul ate mess age tags wi thi n embedded C
code (cbegi n/cend code bl ocks). Thi s exampl e reads fr om TAG1, adds X to the
stri ng, then wri tes the resul t to TAG2.
PROC ADD_X
BEGIN
cbegin
{
#define MAX_LEN 80 /* default maximum
message length */
int fl_tagname_to_id(TAG*, /* function prototype
int,...); missing from CML.H */

TAG tags[2];
MSG tag1, tag2;
char string_buff[MAX_LEN+1]; /* max length plus
terminating 0 */
tag1.m_ptr=tag2.m_ptr=string_buf;
tag1.m_max=tag2.m_max=MAX_LEN;
fl_tagname_to_id(tags,2,TAG1,TAG2);
fl_read(Task_id,&tags[0],1,&tag1);
strcat(string_buf,X);
tag2.m_len=strien(string_buf);
fl_write(Task_id,&tags[1],1,&tag2);
}
cend
END
CONFIGURING MATH AND LOGIC
Calling C Code
FactoryLink ECS / Core Tasks Configuration Guide / 171
7
M
a
t
h

a
n
d

L
o
g
i
c
When val ues are assi gned to MESSAGE tags, the MAX LEN fi el d i s not
transferred. As a resul t, al l message val ues are truncated at 80 characters. To
store val ues l onger than 80 character s i nto a MESSAGE tag, the functi on f1_wr i te
must be cal l ed di rectl y. The fol l owi ng exampl e shows how to use a C macro to cal l
the procedure msgtest to store a 90-character constant i nto the MESSAGE tag
msgtag:
MSGTEST.PRG:
cbegin
void fl_tagname_to_id(TAG*,int,...);
#define assign_msg(tagname, value) {\
TAG tag; \
MSG msg; \
char buf[] = value; \
fl_tagname_to_id(&tag,1,tagname); \
msg.m_ptr = buf; \
msg.m_len = strlen(buf); \
msg.m_max = strlen(buf)+100; /* leave plenty of room */
fl_write(Task_id,&tag,1,&msg); \
}
cend
PROC msgtest
BEGIN
cbegin
assign_msg(msgtag,12345678901234567890123456789012345678
9012345678901234567890123456789012345678901234567890)
cend
END
CONFIGURING MATH AND LOGIC
Calling C Code
172 / FactoryLink ECS / Core Tasks Configuration Guide

FactoryLink ECS / Core Tasks Configuration Guide / 173

8
M
a
t
h

a
n
d

L
o
g
i
c
Chapter 8
Math and L ogi c Syntax
Math and Logi c Syntax is the l anguage of Math and Logi c.
Thi s chapter di scusses:
Pr ocedure Tokens
Reserved Keywords
Comments
Constants
Str uctur e
MATH AND LOGIC SYNTAX
Procedure Tokens
174 / FactoryLink ECS / Core Tasks Configuration Guide

PROCEDURE TOKENS
Procedure tokens are word-l i ke uni ts recogni zed by the Math and Logi c l anguage.
Thi s secti on descri bes procedure tokens used i n a Math and Logi c pr ogr am.
Naming Procedures
Local Variable Naming
declare short _x
declare short _counter
For reasons of cl ari ty, defini ti ons li ne _x shoul d be avoi ded. The vari abl e name
shoul d i ndi cate i ts functi on wi thi n the scope of the procedure. Al so, to
di fferenti ate l ocal vari abl es from tog vari abl es, l ocal vari abl e names shoul d start
wi th _.
Referenci ng the type i n the name of the vari abl e i s l ess i mpor tant wi th l ocal
vari abl es because the defi ni ti on i s near at hand.
Local vari abl e names transl ate di rectl y i nto the C code. I f you name any l ocal
vari abl e the same as a vari abl e or functi on i n another modul e or l i brary, you wi l l
have confl i cts at compi l e ti me. The uni que nami ng i s not li mi ted to thei r
appearance i n Math and Logi c code but i s al so li mi ted to what the name becomes
i n the generated C code. For exampl e, speci al characters ($,*) become _ by the
parsi ng routi ng. Therefore, decl arati ons l i ke:
declare short lu$lu
declare short lu@lu
declare short lu_lu
al l become declare short lu_lu wi th potenti al l y confusi ng resul ts such as dupl i cate
defi ni ti on errors or changes i n one vari abl e ar e r efl ected i n another .
MATH AND LOGIC SYNTAX
Procedure Tokens
FactoryLink ECS / Core Tasks Configuration Guide / 175
8
M
a
t
h

a
n
d

L
o
g
i
c
Tag Naming Conventions
These conventi ons are a combi nati on of the standards used i n programmi ng and
standards borrowed from exi sti ng FactoryLi nk appl i cati ons. These conventi ons
are necessar y when usi ng the FLDEMO appli cati on. I n a genui ne FactoryLi nk
appl i cati on that coul d have 10,000 or more di fferent tag names, sever al
devel opers, and take a year or two to compl ete, they are necessary.
An i nformati ve tag name shoul d contai n the fol l owing:
Appl i cati on meani ng
FactoryLi nk modul e
Type/functi on
Domain
The appl i cati on meani ng shoul d be cl ear and conci se to meet the typi ng
requi rement. The modul e and type porti on shoul d have standard abbrevi ati ons.
The appl i cati on meani ng shoul d be l ess than ei ght ch ar acter s to meet the
confi gurati on envi ronment l i mi ts.
Three major constrai nts exi st for nami ng tags:
The need for i nfor mati on
The need to mi ni mi ze typi ng
The need for l i mi ted col umn wi dths
We r ecommend you create a standard col umn-ori ented nami ng for the tags wi th
fi xed l ength fi el ds i n the name. Thi s l ets you browse a l i st of tags by attri bute by
l ooki ng for a par ti cul ar col umn.
MATH AND LOGIC SYNTAX
Math and Logic Reserved Keywords
176 / FactoryLink ECS / Core Tasks Configuration Guide

MATH AND LOGIC RESERVED KEYWORDS


A keyword i s a word that has a speci al meani ng i n a parti cul ar pr ogrammi ng
l anguage. Math and Logi c r eser ves a set of keywords for use i n Math and Logi c
programs. Because these keywords have predetermi ned meani ngs, they cannot be
used as pr ocedure names, l ocal or gl obal vari abl e names, constant names, or
database el ement names i n Math and Logi c.Math and Logi c keywords are not
case-sensi ti ve, so you cannot use them i n ei ther case.
Math and Logi c reserves use of the keywords i n the fol l owi ng l i st:
MATH AND LOGIC SYNTAX
Math and Logic Reserved Keywords
FactoryLink ECS / Core Tasks Configuration Guide / 177
8
M
a
t
h

a
n
d

L
o
g
i
c
MATH AND LOGIC RESERVED KEYWORDS
abs doand endwhile log setdir
add_tag doasc entry loge setdrive
alltrim doband equ long short
ana dobneg exit lower shutdown
and dobor exp lt short_pause
argcnt dochr extern ltrim signed
Argcount dodiv f2s main sin
Argvect doeq fatal msg sizeof
asc dogetarg fixtype mod sqr
asm dogetdir dolte fl_cmlpp mul static
auto dogetdrive fl_tagname_to_id nalloc status
begin ({) dogt float ne string
break dogte flp nfree struct
call doinstr for not substr
case dolenstr ge or switch
cbegin dolock getarg pop system
cend dolower getchng popdbvar tan
cfunc dolt getdir popflp Task_desc
changed doltrim getdrive popint Task_name
char domod get_entry popstr Task_id
check_security domul get_tag_types poplong then
chk_prot_bit doneg goto pow tos
chkz doneq gt print tosflp
chr donot i2f proc tosint
ckalloc door idl process toslong
clrstack dopow in procnam tosstr
cml_force_math doprint if push trace
cmlpp_listconst dosetdir include pushdbvar trprint
cmlpp_options dosetdrive init pushflp trim
continue dosub input pushint typedef
connect dosubstr instr pushlong union
cos dosys int pushstr unlock
ct_load dotrans l2f register unsigned
debuge dotrim l2s resetstack upper
declare double lana return void
default dounlock le rnd wait
dig doupper len run time wend
div doxor line s2f while
do else load_trig s2i xor
doabs end (}) lock savestr
doadd endif
MATH AND LOGIC SYNTAX
Math and Logic Reserved Keywords
178 / FactoryLink ECS / Core Tasks Configuration Guide

The reserved keywords i n bol dface-i tal i c type are C keywords reserved by the
C compi l er. Pr ogr am fi l es cannot use C keywords because, when Math and Logi c
i s runni ng in the CML mode, i t conver ts the pr ogr ams i nto C sour ce code. Other
such keywords may exi st. Refer to the user manual suppl i ed wi th the parti cul ar C
compi l er i n use.
The keyword begin i s i nterchangeabl e wi th the openi ng brace ({), and the
keywor d end i s i nterchangeabl e wi th the cl osi ng brace (}). You can use ei ther the
keyword or the brace anywhere i nsi de Math and Logi c pr ograms.
Do not wri te procedures that use forms of these keywords as names because they
may not be upward-compati bl e wi th l ater rel eases of Math and Logi c and may
cause unpredi ctabl e system behavi or duri ng executi on.
MATH AND LOGIC SYNTAX
Comments
FactoryLink ECS / Core Tasks Configuration Guide / 179
8
M
a
t
h

a
n
d

L
o
g
i
c
COMMENTS
Comments are text used to annotate a program. Comments are not executabl e
code and are i gnored duri ng executi on. Effecti ve commenti ng shoul d be si mi l ar to
effecti ve nami ng. I t shoul d be cl ear and conci se. Three areas to consider ar e:
Usage: When defi ni ng a functi on, expl ai n i ts purpose, what the ar gument types
and uses are, and external si de effects (or does i t al ter gl obal vari abl es or tags,
and why).
Scope: When defi ni ng vari abl es, expl ai n the scope and what procedures wr i te
to them and use thei r val ues.
Reference: When you reference a functi on (especi al l y i f i t i s i n a di fferent fi l e),
note the fi l e i t i s defi ned i n and what i t does to l ocal vari abl es.
Comments begi n wi th the pound si gn (#) and end wi th the end-of-l i ne character
(). They can be nested or wri tten on l i nes by themsel ves. I f the li ne of code to be
annotated i s short, they can be wri tten on the same l i ne as the code.
Al ways i ncl ude comments i n procedures for l ater r eference. They pr ovi de
programmers wi th informati on about the i ntended functi on of the procedur e.
Comments are al so useful on vari abl e decl arati on l i nes to expl ai n how the
vari abl e i s to be used and i ts val ue l i mi ts. Standard codi ng practi ce cal l s for one
comment for approxi matel y ever y fi ve l i nes as wel l as at the top of any l oop and
befor e a functi on cal l .
MATH AND LOGIC SYNTAX
Comments
180 / FactoryLink ECS / Core Tasks Configuration Guide

The fol l owi ng exampl e i l l ustrates the use of comments:


# declare global variables
DECLARE SHORT init_flag # decision flag
PROC EXAMPLE
BEGIN
DECLARE SHORT _n # declare local variables
DECLARE SHORT tub_array[100]
# Do initialization procedure, but only once
init_flag = 0 # initially, init_flag = 0
IF NOT init_flag THEN
# Initialize database variables
pressure == 10 # force-write pressure in
product tubs
tubs = 20 # number of tubs to fill
tempset = 71 # degrees Celsius; warm
# Set tub_array[_n] = _n for _n =0,1,...,(tubs-1)
_n = 0 # start loop index at 0
WHILE _n < tubs
tub_array[_n] = _n
_n = _n + 1
WEND
init_flag = 1 # done, so set init_flag ON
ENDIF
# Continue here with main section of procedure
# . . .
# . . .
END # PROC EXAMPLE
MATH AND LOGIC SYNTAX
Constants
FactoryLink ECS / Core Tasks Configuration Guide / 181
8
M
a
t
h

a
n
d

L
o
g
i
c
CONSTANTS
A constant i s a numeri c or character val ue that remai ns unchanged duri ng the
executi on of a program. Constants can be used anywhere i n a cal cul ati on a
numeral can be used and are faster to use i n cal cul ati ons than vari abl es.
Constants are especi al l y useful i n appl i cati ons i n whi ch the boundar y val ue of a
l oop or ar r ay must be modi fi ed. When the constant i s modi fi ed, i ts val ue can be
changed i n onl y one pl ace wi thi n the appli cati on, instead of i n many di fferent
pl aces.
For exampl e, a factor y upgrades fr om three dryi ng beds to fi ve and the constant
BED_MAX i s used as:
A l oop i ndex--to i ndex through the operati ons on the groups of beds
An array i ndex--for the array contai ni ng i nformati on on each bed
As a l i mi ti ng factor on the number of beds pol l ed
The val ue of BED_MAX can be modi fi ed from 3 to 5, thus preventi ng the need for
massi ve search-and-repl ace operati ons on hard-coded val ues.
Three types of constants are di scussed here:
Symbol i c
Numeri c
Stri ng
Symbolic Constants
A symbol i c constant is a name you defi ne to represent a si ngl e known numeri c
val ue. You can defi ne a symbol i c constant usi ng ei ther of two for mats:
You can use ei ther an equal si gn or a space to separate the name and val ue.
CONST name value
or
CONST name=value
MATH AND LOGIC SYNTAX
Constants
182 / FactoryLink ECS / Core Tasks Configuration Guide

For exampl e, to defi ne a symbol i c constant PI to represent the val ue 3.14159, use
ei ther:
Then you can use the constant PI wherever needed in pl ace of the val ue 3.14159.
Numeric Constants
Numeri c constants can be assi gned to di gi tal , anal og, l ong anal og, or
fl oati ng-poi nt el ements as wel l as to numeri c l ocal vari abl es. Constants can be
used i n expressi ons wherever a numeri c operand (argument) i s val i d, provi ded
they are not the objects of an assi gnment operator.
The object of an assi gnment i s the argument on the l eft-hand side of an
assi gnment operator; that i s, the argument assi gned a new val ue. Because
constants cannot take on new val ues, they must never be pl aced on the l eft-hand
side of an assi gnment operator. Math and Logi c uses three types of numeri c
constants:
I nteger
Fl oati ng-poi nt
Exponenti al
Integer constantsYou can assi gn i nteger (whol e number ) constants to
el ements and l ocal vari abl es depending on thei r data types and the operati on
For an el ement, i ts data type must be one of the FactoryLi nk data types di gi tal ,
anal og, or l ong anal og and i ts val ue must be an i nteger.
For a l ocal vari abl e, i ts data type must be one of the l ocal vari abl e types shor t or
l ong and i ts val ue must be an i nteger.
CONST PI 3.14159
or
CONST PI=3.14159
MATH AND LOGIC SYNTAX
Constants
FactoryLink ECS / Core Tasks Configuration Guide / 183
8
M
a
t
h

a
n
d

L
o
g
i
c
I nteger constants can be represented i n bi nary, deci mal , octal , or hexadeci mal
notati on:
Binary Stri ngs of 0s and 1s i n whi ch the fi rst two characters are ei ther
0b or 0B (to i ndi cate base-two representati on).
Decimal Stri ngs of any di gi ts 0 through 9 wi th the fi rst di gi t ei ther
non-zer o, 0d or 0D (to indi cate base-ten representati on).
Octal Str i ngs of any di gi ts 0 thr ough 7 wi th the fi r st di gi t a 0.
Hexadecimal Stri ngs contai ni ng any combi nati ons of the di gi ts 0 through 9
and/or the characters A through For a through f, i n whi ch the
fi rst characters are 0x or 0X (to i ndi cate base-si xteen
representati on).
For exampl e, to defi ne the l ocal vari abl e _length as 28, use any of the fol l owing
defi ni ti ons.
Furthermore, some val ues are too l arge to be represented as short ANALOG
val ues and must be represented as LONGANA val ues. Any i nteger constant to be
represented as a LONGANA (l ong i nteger) FactoryLi nk data type must be
fol l owi ng by a trai l i ng L.
The fol l owi ng val ue ranges must be represented as LONGANA val ues:
Notation Definition
Bi nary _l ength = 0b11100
Deci mal _l ength = 28
Octal _l ength = 034
Hexadeci mal _l ength = 0x1C
Notation Value Range
Deci mal x < -65,536 and
x > 65,535
Octal x> 177777
Hexadeci mal x> 0xFFFF
MATH AND LOGIC SYNTAX
Constants
184 / FactoryLink ECS / Core Tasks Configuration Guide

For exampl e, i f a constant i s to be l arger than 65,535, pl ace a trai l i ng L after the
number to i ndi cate l ong anal og representati on, as shown bel ow:
Notati on: Long Anal og Representati on:
Deci mal _upperl i m = 123456L
Hexadeci mal _maxval ue = 0xFFFFFFFFL
Mi ni mum and maxi mum l ong anal og val ues can range between -2,147,483,647
and 2,147,483,647.
Floating-point constantsTo represent fl oati ng-poi nt constants, use standard
fl oati ng-poi nt notati on or exponenti al notati on. Fl oati ng-poi nt constants are
stri ngs of any di gi ts, 0 through 9, that ei ther contai n or end i n a deci mal poi nt.
Exponential constantsExponenti al constants ar e stri ngs of any di gi ts, 0
through 9, wi th an E, E-, e, or e- precedi ng the exponenti al porti on of the val ue.
The fol l owi ng tabl e shows numeral s represented by numeri c constants in the
vari ous notati ons just descri bed:
String Constants
A stri ng i s a sequence of ASCI I characters encl osed in doubl e quotati on marks
( ). Str i ng constants can be fr om 0 to 79 characters and the endi ng character
must al ways be the fi nal char acter in the stri ng. For exampl e, the stri ng ABC i s
made up of the characters A, B, C, i n that order . A stri ng wi th no characters is an
empty stri ng and is a val i d stri ng. An empty stri ng i s a space encl osed i n doubl e
quotati on marks. I f an operator enters more than 79 characters as the val ue of a
message, the task truncates the stri ng to i ncl ude onl y the fi rst 79 char acters.
Binar y Ob101 Ob001 Ob111
Deci mal 12908 562334L 10
Octal 0123 033 05670222L
Hexadeci mal Ox45AB OxOaOd OX7CEFOAF4L
Fl oati ng-Poi nt 465.95 0.0 24567.90667
Exponenti al 9780e12 332e-4 54221E234
MATH AND LOGIC SYNTAX
Constants
FactoryLink ECS / Core Tasks Configuration Guide / 185
8
M
a
t
h

a
n
d

L
o
g
i
c
You can assi gn stri ng constants to message-type el ements or stri ng-type l ocal
vari abl es. Math and Logi c supports operator i nput in both i nterpreted and
compi l ed modes.
I n stri ng constants, the si ngl e backsl ash (\) character i ntroduces pri nt-formatti ng
char acter s. (Pri nt-for matti ng char acter s ar e shown on the fol l owing page.) The
Math and Logi c parser recogni zes the si ngl e backsl ash as a si gnal that a
pri nt-format character (that i s, an escape code) fol l ows. Therefor e, the stri ng \
causes a parsi ng er r or dur i ng Math and Logi c pr ocessi ng because nothi ng fol l ows
the backsl ash. I f you requi re a backsl ash wi thi n the stri ng i tsel f, use a doubl e
backsl ash (\\).
The fol l owi ng tabl e l i sts the meani ngs of the pri nt-formatti ng characters i n Math
and Logi c:
Other speci al ASCI I characters, such as non-pri nti ng contr ol character s (for
exampl e, the escape character), are someti mes needed as constants. Use the chr
functi on to refer to these characters, as descri bed in the Techni cal Notes on page
236 i n Chapter 9, Math and Logi c Procedures and Functi ons.
Table 8-1
Character sequence
Meaning
(print result)
\b backspace
\f for m feed
\t hori zontal tab
\v ver ti cal tab
\\ backsl ash
\ doubl e quote
\ si ngl e quote
\r carri age return
\n new l i ne (car r i age r etur n/l i ne
feed combi nati on; end-of-l i ne
character)
MATH AND LOGIC SYNTAX
Constants
186 / FactoryLink ECS / Core Tasks Configuration Guide

To store ASCI I data, i ncl udi ng non-pri nti ng ASCI I characters, as stri ng
constants, enter the ASCI I code i n a cal l to the bui l t-i n Math and Logi c functi on
chr, whi ch has the fol l owi ng for mat:
chr(xx)
where xx i s the ASCI I code to generate the character.
For exampl e:
Refer to any chart of standard ASCI I character codes to determi ne the proper
ASCI I val ue of any character. The fol l owi ng exampl es i l l ustrate the use of str i ng
constants:
Use doubl e-quotes to i ncl ude speci al characters inside quoted stri ngs.
Refer to the system software documentati on suppli ed wi th that operati ng system
for speci al i zed informati on about ASCI I characters and the detai l s of stri ng
handl i ng under a parti cul ar operati ng system (such as val ues of the machi nes
character set).
Table 8-2
Constant Resulting String
CHR(27) ESC character
ABC\n A, B, C, new l i ne, NUL
MENU M, E, N, U, NUL
\ Doubl e quotati on mark, NUL
x = chr(27) # sets the string variable x to the escape
character
x = chr(124) # assigns to x the vertical bar symbol (|)
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 187
8
M
a
t
h

a
n
d

L
o
g
i
c
STRUCTURE
Thi s secti on descri bes the ways the procedure tokens can be grouped together to
for m decl arati ons, expressi ons, statements, and di recti ves.
Declarations
Vari abl e decl arati ons cr eate stor age i n memor y for val ues. A CONSTANT
decl arati on creates a READ ONLY storage area i n memor y. CONST decl arati ons
store val ues that remai n constant throughout the enti re process. For exampl e,
CONST PI -3, E-2.718281828459. A DECLARE decl arati on creates a ful l y
functi onal vari abl e. A DECLARE vari abl e behaves l i ke a tag except i t does not
change status.
Vari abl es can be di ffer ent data types.
Declare short_counter: SHORT vari abl es hol d a si gned i nteger whose val ue
ranges fr om -32768 to 32768. SHORT l ocal vari abl es and anal og tag vari abl es
store the same i nformati on. Thi s i s the same as a Ctype I NT on most pl atfor ms (u
16 or ana val ue i n FLI B).
Declare long_initial_time: LONG vari abl es hol d a si gned i nteger whose val ues
range fr om -32768 to 32768. LONG l ocal vari abl es and l ongana tag vari abl es store
the same i nformati on. Thi s i s the same as a C type LONG I NT on most pl atforms
(u32 or LANA val ue i n FLI B).
Declare float_average_temp: FLOAT vari abl es hol d a 64-bi t fl oati ng poi nt
val ue. Thi s gi ves fl oats an 18-di gi t si gned manti ssa wi th a two di gi t si gned
exponent. FLOAT l ocal vari abl es and FLOAT tag vari abl es hol d the same for mat
for i nformati on as the same accuracy. Thi s i s the same as a C type DOUBLE on
most pl atfor ms (FLP val ue i n FLI B).
Declare string_old_name: STRI NG vari abl es are essenti al l y arrays of shorts
compri sed of a maxi mum of 80 characters. The l ength of the array is dynami c and
a val ue of zer o mar ks the l ast el ement. STRI NG l ocal vari abl es and message tag
vari abl es are functi onal l y the same. Thi s is the same as a C type CHAR on most
pl atforms. I f you want to reference _worthl ess i n another .PRG i n thi s domai n,
you must put a decl are short _worthl ess i n the header of that fi l e.
The decl arati on tel l s the procedur e:
A vari abl e or a constant is to be created or a vari abl e or a procedur e i s to be
referenced.
The scope of the created vari abl e or constant or the referenced vari abl e or
procedur e.
MATH AND LOGIC SYNTAX
Structure
188 / FactoryLink ECS / Core Tasks Configuration Guide

Scope
Scope is that part of a pr ogram i n whi ch a vari abl e, constant, or procedur e can be
used. The scope of a l ocal vari abl e and i ts C code vari abl e defi ni ti on is the secti on
of codes where thi s vari abl e can be referenced. Thi s vari es accordi ng to wher e the
decl arati ons take pl ace. For exampl e,
FILENAME: DO_NOT.PRG
declare short_worthless
# _worthless can be used anywhere in this domain of IML
proc do_not (short_nocount)
begin
declare short_unimportant
#_nocount and _unimportant can only be used inside proc do_not
worthless--_nocount + _unimportant
#This is valid code
call do_less
end
proc do_less
begin
declare short_wasted
declare short_space
_wasted - worthless
# This is valid code because _wasted is local to proc
do_less
# and_worthless is global to this domain of IML
_space-_unimportant
# While this is invalid because _unimportant has not been
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 189
8
M
a
t
h

a
n
d

L
o
g
i
c
# defined in proc do_less
end
Math and Logi c uses two categori es of scope: bl ock (or l ocal ) and fi l e (or gl obal ):
Block scopeStar ts at the decl arati on poi nt and ends at the end of the bl ock
contai ni ng the decl arati on.
File scopeStar ts at the decl arati on poi nt and ends at the end of the source
fi l e.
General l y, use a vari abl e, constant, or procedur e after i ts decl arati on poi nt i n a
program.
Therefore, where vari abl es, constants, and procedures are decl ared i n a Math and
Logi c pr ogram depend on thei r i ntended scope.
Variable Declarations
Vari abl es can be decl ared i n a Math and Logi c program as procedure vari abl es or
as el ements. Vari abl es decl ared as procedure vari abl es are used to store val ues
used onl y by Math and Logi c to per for m operati ons. These val ues cannot be used
by other FactoryLi nk tasks because they ar e not stor ed i n the real -ti me database.
Therefore, procedure vari abl es are not database el ements.
Procedure vari abl es decl ared i nsi de a parti cul ar procedure wi thi n a fi l e are
accessi bl e onl y by that procedur e and are cal l ed l ocal procedur e vari abl es.
Procedure vari abl es decl ared outsi de of a procedure (but wi thi n i ts program fi l e)
are shared by al l pr ocedures i n that fi l e and are cal l ed gl obal procedure vari abl es.
Note that procedure vari abl es can be of one of the fol l owing data types:
SHORT (di gi tal )
SHORT (anal og)
LONG (l ong anal og)
FLOAT
STRI NG (message)
MATH AND LOGIC SYNTAX
Structure
190 / FactoryLink ECS / Core Tasks Configuration Guide

Al though procedure vari abl es ar e not el ements i n the real -ti me database, they ar e
sti l l represented i n system memory and can be saved and opened repeatedl y or
pri nted duri ng the runni ng of those procedures that can open them.
Use the fol l owing gui del i nes to determi ne whether to decl are a vari abl e as a
procedur e vari abl e or as a el ement:
I f the vari abl e i s opened fr om an external source, decl are i t as a database
el ement.
I f the vari abl e i s a tri gger for any procedure, i t must be decl ared as a database
el ement defi ned as a tri gger el ement wi th an associ ated tri gger tag name.
I f the vari abl e i s used onl y by Math and Logi c and must be accessi bl e by al l of
the procedures wi thi n a progr am fi l e, decl are the vari abl e as a procedure
vari abl e wi th a gl obal scope by decl ari ng i t outsi de the fi rst procedur e in the
pr ogr am fi l e.
I f the vari abl e i s used onl y by Math and Logi c and is used onl y wi thi n a
parti cul ar procedure, decl are the vari abl e as a procedure vari abl e wi th a l ocal
scope by decl ari ng i t i nsi de that procedure.
Local Procedure VariablesDecl are l ocal procedure vari abl es i mmedi atel y
after the BEGI N statement. A l ocal vari abl e decl arati on must precede al l other
i nstructi ons i n a procedur e.
Local vari abl es are decl ared, one data type to a l i ne and normal l y onl y one data
i tem per l i ne i n statements si mi l ar to the ones shown bel ow:
Initialized Value Each ti me a procedure i s cal l ed i n the i nterpreted mode, a
new instance of each l ocal vari abl e i s created and the val ue of each vari abl e is
i ni ti al i zed to 0. Each ti me the executabl e i s run i n the compi l ed mode, the val ue of
each l ocal vari abl e i s i ni ti al i zed to 0 whi ch redefi nes the vari abl e. When a
procedur e is compl eted, vari abl es defi ned i nsi de the procedure are destroyed.
When l ar ge numbers of l ocal vari abl es are decl ared i n a program fi l e and ar e
meant to be accessi bl e to al l the procedures i n that fi l e, per formance can be
i mproved by pl aci ng the decl arati ons at the top of the fi l e in whi ch the procedures
ar e stored before the start of the fi rst procedure. Thi s makes the decl arati ons
gl obal to the program fi l e.
DECLARE short itotal
DECLARE float ftotal
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 191
8
M
a
t
h

a
n
d

L
o
g
i
c
A l ocal procedure vari abl e may be decl ared as a scal ar l ocal vari abl e or as a l ocal
array.
Scalar Local VariableI f decl ared as a scal ar l ocal vari abl e, the decl arati on
has the fol l owi ng for m:
DECLARE type name
where
type i s one of the fol l owing:
SHORT si gned short i nteger
LONG si gned l ong i nteger
FLOAT doubl e-preci si on fl oati ng-poi nt number
STRI NG ASCI character stri ng of up to 79 characters
and
name contai ns onl y alphabeti c characters (A-Z, a-z), di gi ts (0-9), peri ods
(.), dol l ar si gns ($), at-si gns (@), and underscores (_).
has a maxi mum l ength of 30 characters.
does not have a peri od as i ts fi r st or l ast char acter .
does not have a di gi t as i ts fi rst character i n a name.
I n the compi l ed mode, the peri ods (.), dol l ar si gns ($), and at-si gns (@) ar e al l
converted to underscores (_) i n the resul ti ng C source fi l e.
For exampl e, the vari abl e names
.temp
$temp
@temp
al l equal _temp when they are transl ated i nto C sour ce code. Therefore, avoi d
vari abl e names wi th peri ods, dol l ar si gns, and at-si gns.
The peri od (.) can be used i n el ement tag names i n thi s rel ease; however, i f i t i s
used i ncor r ectl y, futur e software updates may produce undesi rabl e resul ts. I n
future rel eases of FactoryLi nk, the peri od wi l l be used to represent an object that
has i ts own members. Therefore, we recommend you not use the peri od i n tag
names. Contact Customer Suppor t for addi ti onal i nfor mati on.
MATH AND LOGIC SYNTAX
Structure
192 / FactoryLink ECS / Core Tasks Configuration Guide

Separate the names wi th commas, as shown i n the fol l owing exampl e, to decl are
more than one vari abl e of the same type on the same l i ne:.
However, we recommend vari abl es be decl ared one to a l i ne wi th comments on the
same l i ne after each decl arati on bri efl y descri bi ng the use of the vari abl e.
Consi der the fol l owing exampl es:
Local ArrayA l ocal vari abl e can al so be decl ared as a l ocal arr ay. A l ocal array
represents a set of val ues of the same type. An array is decl ared by speci fyi ng the
si ze (di mensi on) of the ar ray after the ar r ay type. An ar r ay can have a maxi mum
of 16 di mensi ons. An array wi th more than one di mensi on may be thought of as an
array whose el ements are al so arrays rather than scal ar vari abl es; each
addi ti onal di mensi on gai ns the array another set of r ow and col umn indi ces. Each
of the di mensi ons, whi ch must be constant, ar e encl osed i n brackets.
Use one of the fol l owing forms to decl are a l ocal vari abl e as a l ocal ar r ay:
The second for m defi nes a three-di mensi onal ar r ay. The total number of el ements
i n array _cal is the product of the si ze of each di mensi on.
Local vari abl e arrays functi on l i ke scal ar l ocal vari abl es i n many ways except
nei ther an array nor an array el ement can be passed as an argument to a
procedur e.
DECLARE SHORT _s1,_s2,_s3 # loop & array indices/3D array
DECLARE SHORT_itotal # total number of vats heated
DECLARE FLOAT_ftempm # mean temperature held in vats
DECLARE SHORT _week[7] # days of the week
or
DECLARE SHORT _cal[12][31][10] # ten-year calendar array
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 193
8
M
a
t
h

a
n
d

L
o
g
i
c
Global Procedure VariablesYou must decl are gl obal vari abl es outsi de of any
procedure that references them. How you decl are them depends on whether you
are runni ng I nterpr eted or Compi l ed Math and Logi c:
For I nterpreted Math and Logi c, decl are gl obal procedure vari abl es before the
fi rst procedure defi ni ti on i n a pr ogr am fi l e. For purposes of val i dati on, decl are
gl obal vari abl es i n each pr ogr am fi l e i n whi ch they ar e used. After the fi r st
invocati on, they retai n thei r val ues across procedure cal l s.
The fol l owi ng model shows where you decl are gl obal and l ocal vari abl es:
For Compi l ed Math and Logi c, you can decl are gl obal procedure vari abl es i n
ei ther of two ways:
Befor e the fi r st pr ocedur e defi ni ti on i n a program fi l e, as i n I nterpreted
I n an i ncl ude fi l e
An i ncl ude fi l e contai ns al l of the gl obal vari abl es and procedures that woul d
otherwi se be decl ared at the top of each progr am fi l e that r eferenced them.
Create and edi t an i ncl ude fil e usi ng any text edi tor as i n the fol l owi ng exampl e.
# comments
DECLARE . . .# comments
DECLARE . . .
# comments
PROC name
BEGIN
DECLARE . . .
DECLARE . . .
A = A + 1
A = B + 1
END
Gl obal
Vari abl es
Local
Vari abl es
DECLARE PROC testproc
DECLARE SHORT val1
DECLARE FLOAT val2
MATH AND LOGIC SYNTAX
Structure
194 / FactoryLink ECS / Core Tasks Configuration Guide

Save the fi l e wi th an .I NC extensi on. I ncl ude fi l es must have an .I NC extensi on so


the system can open and save them duri ng an FLSAVE. I ncl ude fi l es are l ocated
i n the PROCS di rectory of the current domai n and cur rent appli cati on.
For exampl e, the above i ncl ude fi l e i s saved to the fol l owi ng path:
FLAPP\FLDOMAIN\PROCS\MYPROG.INC
where MYPROG.I NC i s a devel oper-defi ned fi l e name.
Use the keyword i ncl ude to decl ar e the i ncl ude fi l e wi th any pr ogr am fi l e to be run
i n the compi l ed mode. The syntax i s:
include MYPROG.INC
The keyword i ncl ude i nstructs Math and Logi c to read the contents of the i ncl ude
fi l e and i ncl ude i t as par t of the cur r ent pr ogr am fi l e.
I ncl ude fil es can be nested to a depth of 64 fi l es to protect you from r ecur si ve
i ncl udes.
The fol l owi ng exampl e shows how to use an i ncl ude fi l e.
Procedures p1 and testpr oc wi thout an i ncl ude fi l e:
Procedure p1
DECLARE PROC testproc()
DECLARE SHORT val1
DECLARE FLOAT val2
PROC p1
BEGIN
CALL testproc()
END
Procedure testproc
DECLARE SHORT val1
DECLARE FLOAT val2
PROC testproc()
BEGIN
val1=0
val2=0.0
END
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 195
8
M
a
t
h

a
n
d

L
o
g
i
c
Procedures p1 and testpr oc wi th an i ncl ude fi l e:
Constraints on using variablesVari abl es decl ared i nsi de a procedur e must
have di fferent names from vari abl es decl ared outsi de of a procedure. The case of a
vari abl e name i s si gni fi cant.
A vari abl e name cannot begi n wi th a di gi t (0-9).
Vari abl es cannot be i ni ti al i zed at decl arati on.
Arrays cannot be passed as arguments to a procedure, but i ndi vi dual arr ay
el ements can.
Constant Declarations
Constants are shared by al l procedures and must be decl ared before any
procedure i n whi ch they are used. Therefore, pl ace constant decl arati ons above
the procedur e statement of the fi rst procedur e wi thi n the program fi l e i n whi ch
the constant i s referenced.
Onl y one constant can be decl ared on each l i ne.
Include file test.inc
DECLARE PROC testproc()
DECLARE SHORT val1
DECLARE FLOAT val2
Procedure p1
include test.inc
PROC p1
BEGIN
CALL testproc()
END
Procedure testproc
include test.inc
PROC testproc()
BEGIN
val1=0
val2=0.0
END
MATH AND LOGIC SYNTAX
Structure
196 / FactoryLink ECS / Core Tasks Configuration Guide

Procedure Declarations
A procedur e decl arati on identi fi es a procedure ei ther defi ned l ater i n the cur rent
program fi l e or i s r eferenced (cal l ed) by a procedure i n the current program fi l e. I t
i s comparabl e to a forward reference in the Pascal pr ogrammi ng l anguage used
when a procedure cal l s another procedure not yet encountered but al ready exi sts.
Use one of the fol l owi ng forms to decl are a procedur e depending on whether or not
the procedure wil l accept arguments:
I f a procedur e is to take arguments, use the second for m gi ven above. Onl y the
data type of each argument i s gi ven in a procedure decl arati on. The data type of
each ar gument i s the same as the ori gi nal l ocal vari abl e (SHORT, LONG, FLOAT,
STRI NG).
The number of arguments i n the decl arati on, the order i n whi ch the arguments
are entered, and thei r data type must match the procedur e defi ni ti on. Refer to
Procedures on page 232 i n Chapter 9, Math and Logi c Procedures and
Functi ons for mor e i nfor mati on about arguments.
Remember procedure decl arati ons are conveni ent when a custom-wri tten
procedur e must refer to another custom-wri tten procedure not yet been
encountered because i t is contai ned wi thi n another program fi l e or occurs l ater i n
the same pr ogr am fi l e.
When the procedure bei ng cal l ed i s di spl ayed i n the same fi l e but befor e the
current procedure, procedure decl arati ons are not requi r ed.
DECLARE PROC name
or
DECLARE PROC name (type[,type])
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 197
8
M
a
t
h

a
n
d

L
o
g
i
c
The fol l owi ng exampl e shows how pr ocedure decl arati ons affect procedur e cal l s:
Usi ng the same exampl e, by decl ari ng PROC B above the defi ni ti on of PROC A,
then PROC B can be cal l ed:
PROC A
BEGIN
.
.
CALL B
.
.
END
PROC B
BEGIN
.
.
CALL A
.
.
END
Because Procedure B has not been declared and does
not appear before Procedure A, this call is not
allowed. Procedure B must be declared.
Because Procedure A is displayed before Procedure
B, this call is allowed.
DECLARE PROC B
PROC A
BEGIN
.
.
CALL B
.
.
END
PROC B
BEGIN
.
.
CALL A
.
.
END
Declare PROC B.
PROC B can be called here because it was declared
previously.
MATH AND LOGIC SYNTAX
Structure
198 / FactoryLink ECS / Core Tasks Configuration Guide

You can al so cal l a procedure or functi on defi ned i n another pr ogr am fi l e. I f no


tri ggered procedures exi st i n the referenced program fi l e, then the Math and Logi c
Tri ggers tabl e must contai n an entry for that fi l e. I n the exampl e bel ow, Func1 i s
cal l ed i n PROC1.PRG, but i t is defi ned i n PROC2.PRG. Therefore, PROC2
requi res an entry i n the Math and Logi c Tri ggers Tabl e.
PROC1.PRG
DECLARE PROC func1
PROC PROC
BEGIN
.
.
.
CALL func1
.
.
.
.
END
PROC2.PRG
PROC PROC2
BEGIN
.
.
.
END
PROC func1
BEGIN
.
.
.
END
Func 1 i s cal l ed i n
PROC1.PRG, but i t is
defi ned i n PROC2.PRG.
Therefore, PROC2
requi res an entry i n
the Math and Logi c
Tr i ggers Tabl e.
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 199
8
M
a
t
h

a
n
d

L
o
g
i
c
Data Types and Variable Types
Because Math and Logi c supports both el ements and procedure vari abl es,
procedure vari abl es can be defi ned as any of the FactoryLi nk data types.
The tabl e bel ow shows the FactoryLi nk data types and thei r correspondi ng
vari abl e types:
Fl oati ng-poi nt data i tems confor m to ANSI doubl e-preci si on standards. The
FactoryLi nk data type MAI LBOX has no counterpart in Math and Logi c.
MAI LBOX data types cannot be defi ned as l ocal procedure vari abl es.
Use the fol l owi ng gui del i nes to choose whi ch data type to use i n a parti cul ar
i nstance:
I f the val ue wi l l ever need to mai ntai n a fracti onal porti on (to the ri ght of the
deci mal poi nt), defi ne i t as a FLOAT (fl oati ng-poi nt).
I f i t i s a fl ag or an ON-OFF type of deci si on poi nt, decl are i t as a DI GI TAL (thi s
is anal ogous to the bool ean or l ogi cal data types i n other programmi ng
l anguages).
I f i t is an integer wi thi n the defi ned range of the machi ne, decl are i t as ei ther
an ANALOG (i f i t fi ts i n the shor t range) or a LONGANA (l ong anal og) (i f i t
wi l l not fi t i n the shor t r ange, but i s sti l l expected to be wi thi n the stated
al l owabl e range for i ntegers). I ntegers are numbers wi thout a fracti onal
porti on.
Decl ar e text vari abl es to be wri tten to the screen or to a fi l e as MESSAGE.
Table 8-3
FactoryLink Data Types Procedure Variable Types
DI GI TAL short
ANALOG short
LONGANA l ong
FLOAT fl oat
MESSAGE stri ng
MAI LBOX N/A
MATH AND LOGIC SYNTAX
Structure
200 / FactoryLink ECS / Core Tasks Configuration Guide

For Windows NT and Windows 95


The 64K barri er under segmented archi tectures such as Mi crosoft Wi ndows NT
and Wi ndows 95 presents a l i mi tati on on the si ze of some vari abl e data i n Math
and Logi c. Nei ther gl obal nor l ocal vari abl e arrays or data i tems (such as stri ng
arrays or message/buffer data, both of whi ch tend to become l ar ge) may exceed
64K. I tems decl ared l arger than 64K wi l l , neverthel ess, be al l ocated onl y 64K
under Mi crosoft Wi ndows; no compi l e-ti me or panel -entr y checki ng is pl anned to
l i mi t the si ze of decl arati ons because of the mul ti -pl atfor m natur e of the cur r ent
FactoryLi nk software system. Note al so that the i ndex (si zi ng) val ue for a vari abl e
ar r ay i s li mi ted to 32K (32,767); ar r ay di mensi ons must be decl ared so as not to
exceed thi s l i mi t.
Note these l i mi tati ons when pl anni ng appl i cati on data desi gn; i n other words, any
gl obal or l ocal vari abl es whi ch must be l arger than 64K to serve the needs of the
appl i cati on desi gner shoul d be parti ti oned l ogi cal l y duri ng desi gn so no data i tem
as decl ared exceeds 64K. Contact Customer Support for suggesti ons on
workarounds (such as decl ari ng several l i nked data i tems) i f l arge buffers ar e
needed i n an appl i cati on.
For OS/2
The 64K barri er under segmented archi tectures such as OS/2 presents a
l i mi tati on on the si ze of some vari abl e data i n Math and Logi c. Nei ther gl obal nor
l ocal vari abl e arrays or data i tems (such as stri ng arrays or message/buffer data,
both of whi ch tend to become l ar ge) may exceed 64K. I tems decl ared l arger than
64K wi l l , neverthel ess, al l ocated onl y 64K; no compi l e-ti me or panel -entr y
checki ng i s pl anned to l i mi t the si ze of decl arati ons because of the mul ti -pl atfor m
nature of the current FactoryLi nk software system. Note al so that the i ndex
(si zi ng) val ue for a vari abl e array i s li mi ted to 32K. Decl are array di mensi ons that
do not exceed thi s l i mi t.
Note these l i mi tati ons when pl anni ng appl i cati on data desi gn; i n other words, any
gl obal or l ocal vari abl es whi ch must be l arger than 64K to serve the needs of the
appl i cati on desi gner shoul d be parti ti oned l ogi cal l y duri ng desi gn so no data i tem
as decl ared exceeds 64K. Contact Customer Support for suggesti ons on
workarounds (such as decl ari ng several l i nked data i tems) i f l arge buffers ar e
needed i n an appl i cati on.
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 201
8
M
a
t
h

a
n
d

L
o
g
i
c
For UNIX
The si ze of gl obal and l ocal data decl ared i s l i mi ted onl y by the amount of
avai l abl e memory avai l abl e to the task runni ng under UNI X. However , i f the
appl i cati on i s to be ported back down to a segmented archi tectur e, such as OS/2,
the 64K barri er presents a li mi tati on on the si ze of some vari abl e data i n ML. I n
procedures to be ported l ater to an OS/2 system, gl obal and l ocal vari abl e arrays
or data i tems (such as stri ngs or message/buffer data, whi ch tend to become l arge)
shoul d be par ti ti oned so no data i tem as decl ared exceeds 64K. Al so note that the
i ndex (si zi ng) val ue for a vari abl e array under OS/2 i s l i mi ted to 32K (32,767); i f
softwar e i s to be por tabl e, ar r ay di mensi ons must be decl ared so as not to exceed
thi s l i mi t. The l i mi t under UNI X i s normal l y 64K (65,534), dependi ng on the
amount of fr ee memor y al l ocated to the run-ti me process.
Note thi s l i mi tati on when pl anni ng appl i cati on data desi gn for such appl i cati ons.
Contact Customer Suppor t for suggesti ons on wor karounds (such as decl ari ng
several l i nked data i tems) i f l ar ge buffer s ar e needed i n an appli cati on to be
ported.
Data Type Conversion
Cr eate a new vari abl e of a parti cul ar data type for accuracy i n computati on, such
as fl oati ng-poi nt, and i ni ti al i ze the new i tem to the cur r ent val ue of another
vari abl e of a di fferent data type, such as a l ong anal og. Thi s conversi on pr events a
possi bl e l oss of accuracy i n upcomi ng cal cul ati ons, as expl ai ned bel ow. Use the
new vari abl e to do operati ons wi th other vari abl es of the same type as the new
vari abl e.
Automati c conversi on of any numeri c data type (di gi tal , anal og, l ong anal og, or
fl oati ng-poi nt) takes pl ace when a vari abl e of one type i s assi gned the val ue of
another vari abl e of a di fferent data type. Use the si mpl est type of assi gnment
statement necessary for the conversi on to obtai n the most effi ci ent performance.
Refer to Statements on page 220 for i nformati on about assi gnment statements.
I ncl ude the new vari abl e i n a confi gurati on tabl e or i n a program fi l e (dependi ng
on whether the ori gi nal vari abl e i s a el ement or i s l ocal to program operati ons).
Thi s wi l l greatl y si mpl i fy the debuggi ng process shoul d a probl em occur duri ng
startup.
Data type conversi ons are not often needed, but they can be useful i n parti cul ar
si tuati ons. Convert vari abl es whenever the resul t requi res the accuracy of the
most preci se data type invol ved or when i ncompati bl e operati ons are taki ng pl ace
between di gi tal and anal og val ues. Data type conversi on can ensure the accur acy
of the resul ts of certai n cal cul ati ons wi th a few excepti ons. The fol l owi ng
gui del i nes i ndi cate when and why data types shoul d be converted.
MATH AND LOGIC SYNTAX
Structure
202 / FactoryLink ECS / Core Tasks Configuration Guide

Guidelines for Converting Data Types


Floating-point
truncation
I f a fl oati ng-poi nt val ue i s assi gned to a di gi tal , anal og, or l ong
anal og vari abl e, Math and Logi c truncates the fracti onal part of
the fl oati ng-poi nt val ue i nstead of rounding i t up or down befor e
assi gni ng the val ue to the vari abl e. Thi s resul ts i n a l oss of
accuracy. Thi s may be acceptabl e when the fracti onal val ues are
not si gni fi cant i n the resul t of the cal cul ati on.
Non-zero
conversion
Assi gni ng an anal og, l ong anal og, or fl oati ng-poi nt val ue to a
di gi tal vari abl e converts any non-zero val ue to 1 and returns 0 i f
the val ue i s 0. Thi s can be useful when al l one needs to know i s
whether a parti cul ar vari abl e's contents are non-zer o (for use as a
tri gger el ement, perhaps), but i t can resul t i n a l oss of preci si on i n
other si tuati ons. Because a di gi tal data type hol ds onl y a si ngl e
bi t of data, the operati on has onl y two possi bl e resul ts: i f the
assi gned val ue i s 0 after any fracti onal part i s truncated, the
di gi tal vari abl e takes on a val ue of 0; i f the assi gned val ue i s
non-zer o after any fracti onal par t i s truncated, the di gi tal
vari abl e takes on a val ue of 1.
Floating-point
conversion
Assi gni ng a fl oati ng-poi nt val ue to an anal og or l ong anal og
vari abl e can resul t i n a l oss of preci si on [l oss of l east-si gni fi cant
bi t(s)] when the system truncates the fracti onal por ti on of the
val ue. The i nteger porti on of the fl oati ng-poi nt val ue mi ght al so
exceed the maxi mum number of bi ts al l ocated to an i nteger whi ch
causes an over fl ow i n the anal og el ement.
The maxi mum number of bi ts used by an i nteger depends on the
data type of the el ement or vari abl e. Data types and maxi mum
number of bi ts are as fol l ows:
Table 8-4
Data Types: Maximum Number of Bits:
SHORT (anal og) 16
LONG (l ong anal og) 64
FLOAT (fl oati ng-poi nt) 64
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 203
8
M
a
t
h

a
n
d

L
o
g
i
c
Data type precision When numeri c data types are used i n ari thmeti c operati ons
(+, -, *, /), the resul t has the preci si on of the most accur ate data
type. I f ei ther data type i s fl oati ng-poi nt, the resul t i s
fl oati ng-poi nt. Otherwi se, the resul t i s anal og. Di gi tal and anal og
data types are internal l y represented as si gned i ntegers.
Overflow Executi on of ari thmeti c operati ons can resul t i n an out-of-range
val ue bei ng pl aced i nto an anal og or fl oat vari abl e. Thi s resul ts in
a condi ti on known as overfl ow [l oss of most si gni fi cant bi t(s)] i n
that vari abl e.
To avoi d causi ng over fl ow, do not use cal cul ati ons i n your
appl i cati on that di vi de ver y smal l numbers by ver y l ar ge
numbers, those that di vi de ver y l arge numbers by ver y smal l
numbers, or those that di vi de a number by zero.
We r ecommend you test for i nteger over fl ow (anal og val ues)
condi ti ons and for fl oati ng-poi nt overfl ow (fl oat val ues)
condi ti ons. I t i s i mportant before performi ng computati ons,
ensure the resul ts wil l be wi thi n the stated maxi mum and
mi ni mum ranges of the system i tsel f. However, i f you need to use
l arger anal og val ues than the system can handl e, use
fl oati ng-poi nts as a workaround; si tuati ons requi ri ng numbers
l arger than the fl oat representati ons possi bl e on most systems
wi l l al most never ari se.
Short to long
analog conversion
Short anal og val ues are si mpl e to convert to l ong anal og val ues.
The fi r st exampl e bel ow shows how overfl ow condi ti ons on l ong
anal og val ues can be corrected by converti ng the val ues to
fl oati ng-poi nt pri or to attempti ng the computati on i n whi ch
errors are l i kel y to occur. The second exampl e shows a
workaround for fl oati ng-poi nt over fl ow condi ti ons.
Long anal og val ue overfl ow correcti onI f temp is a 16-bi t anal og
vari abl e that currentl y has the val ue 30,000, then (because of the
l i mi tati ons i nherent i n representi ng numbers i n the computer)
the erroneous resul t of the computati on 2Xtemp wi l l be -5,536,
i nstead of the expected val ue of 60,000. I n other words, the resul t
of thi s computati on does not fi t into the i nteger fi el d al l ocated to
the anal og vari abl e, but i t i s not automati cal l y converted to
fl oati ng-poi nt. I f you anti ci pate worki ng wi th l ar ge val ues such as
thi s or detect thei r presence duri ng the executi on of a program, i t
woul d be wi se to provi de for the conversi on of the val ue. For ce
thi s conversi on by creati ng a fl oati ng-poi nt vari abl e fptemp and
setti ng fptemp = 2.0Xtemp.
MATH AND LOGIC SYNTAX
Structure
204 / FactoryLink ECS / Core Tasks Configuration Guide

Fl oati ng-poi nt val ue overfl ow correcti onAl though i t i s r ar e,


over fl ow condi ti ons can al so occur i n operati ons on fl oati ng-poi nt
data types. The resul t of an over fl ow i s unpredi ctabl e and usual l y
fatal ; ther efore, set up the pr ogr ams to detect and avoi d overfl ow
condi ti ons. For exampl e, di vi si on by zer o al ways resul ts in
over fl ow. I f thi s happens, modi fy the pr ograms invol ved so any
vari abl e about to be used as a di vi sor i s tested for zer o and
provi de for a method to ski p the operati on (or to wri te an al ert
message) whenever these condi ti ons ari se. I f over fl ow occur s,
check stri ng concatenati on (joi ni ng) operati ons to determi ne i f
they are resul ti ng i n the assi gnment of i nappropri ate stri ngs to
fl oati ng-poi nt val ues. Thi s i s discussed in Stri ng conversi on bel ow
and i n Exampl e 4 on page 206.
String conversion A stri ng type can be used in an ari thmeti c or l ogi cal operati on i f
and onl y i f the stri ng i s a sequence of di gi ts (i ncl udi ng the natural
l ogari thm constant e, as noted bel ow). The stri ng i s converted to a
number before the operati on i s performed; conversi on stops at the
fi r st non-numer i c char acter (except e). A stri ng can be fr om 0 to
79 characters. I f an operator enters more than 79 characters as
the val ue of a message, the task truncates the stri ng to i ncl ude
onl y the fi rst 79 characters.
Stri ng-to-numeri c conversi on stops at the fi rst non-numeri c
character. I n general , when al phabeti c characters are used i nsi de
a stri ng that contai ns onl y numeri c data, the task someti mes
i nterprets the char acters di ffer entl y fr om the way you i ntended.
We recommend you set up some type of i nput checki ng i f stri ngs
are to be routi nel y accepted as operands for computati ons.
A speci al case i s when the l etter e is i ncl uded i nsi de the stri ng.
Duri ng stri ng conversi on, e i s i nterpreted as exponenti al , an
indi cati on the stri ng of di gi ts i s to be consi dered wri tten i n
sci enti fi c notati on. Refer to Numeri c Constants on page 182 for
i nformati on about numeri c representati on. Thi s al l ows the
representati on of l arger numbers i n a mor e compact format. I t
can, however , cause probl ems i f you have not pl anned for l i mi ts
on the type, number , and l ocati on of al phabeti c characters i nsi de
these stri ngs, and i f you do not i nvoke l ogi c to test the contents of
the stri ng for appropri ateness before cal l i ng the conversi on
routi ne. (For an exampl e, and a descri pti on of the resul ti ng
workaround, see Exampl e 4 on page 206.)
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 205
8
M
a
t
h

a
n
d

L
o
g
i
c
I f the + (pl us) operator is used i n an expressi on wi th an operand
of the stri ng type, the other operand i n the expressi on wi l l be
automati cal l y converted to a stri ng (i f i t i s not al ready a stri ng),
and the + operator wi l l concatenate the two stri ngs. Thi s type of
operati on i s consi dered to be a stri ng operati on, not a l ogi cal or
ari thmeti c operati on. (See Exampl e 3 on page 206.)
Array Conversion I f converti ng a l ocal vari abl e decl ared as an array, conver t each
array el ement separatel y. I f the conversi on computati on is wi thi n
a l oop, use one temporary vari abl e of the new data type to
represent the array index or create an array of the same si ze and
of the new data type and l oad i t wi th the converted val ues.
MATH AND LOGIC SYNTAX
Structure
206 / FactoryLink ECS / Core Tasks Configuration Guide

Examples of Data Type ConversionThe fol l owing four exampl es i l l ustrate


data type conversi on.
Example 1Converti ng anal og val ues to di gi tal
Let swi tch be a di gi tal el ement. The statement
switch = 25.2
resul ts i n swi tch havi ng a val ue of 1 (ON) because the as si gned val ue (after the
fracti onal part i s truncated) i s non-zero.
Example 2Fl oat truncati on i nto i nteger
Let l astcar be an anal og el ement (16-bi t i nteger). The statement
lastcar = 47.1
resul ts i n l astcar havi ng the val ue 47, not 47.1. Si nce l astcar is an i nteger , the
deci mal porti on of the fl oati ng-poi nt constant i s truncated before the assi gnment.
Example 3Appendi ng numeri cs to messages
Let pressure be an anal og el ement wi th the val ue 99. stri ng1 i s a message
el ement. The statement
string1 = RPT + pressure
resul ts i n stri ng1 havi ng the val ue RPT99. pressure i s converted to a stri ng and
then concatenated to the stri ng constant RPT. The resul t (RPT99) i s then
assi gned to stri ng1.
The compil ed mode of Math and Logi c does not support appendi ng numeri cs to
messages.
Example 4Equati ng a fl oati ng-poi nt el ement to the contents of message data
Let message1 be a message el ement set to 1e308 (representi ng the number 10
rai sed to the power 308, a l arge fl oati ng-poi nt constant stated i n stri ng for m).
Assume you set message2, defi ned the same way as message1, to a val ue of
-1e-308 (representi ng the ver y smal l fl oati ng-poi nt constant 10 rai sed to the power
-308).
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 207
8
M
a
t
h

a
n
d

L
o
g
i
c
Let fl oat1 be a fl oati ng-poi nt el ement that recei ves the total of these two message
el ements. The statement
float1 = message1 + message2
whi ch shoul d add the two val ues, i nstead resul ts i n fl oat1 recei vi ng an undefi ned
val ue represented i n the system as 1.#I NF (i s not fl oat ) or somethi ng si mi l ar,
l eadi ng to an unpredi ctabl e resul t. Thi s happens because the system perfor ms
stri ng concatenati on (the + operator acts as concatenati on operator i n regard to
stri ng operands), whi ch yi el ds 1e3081e-308. The system stops converti ng at the
second occurrence of e (di scardi ng the -308 por ti on) and attempts to pl ace i nto the
vari abl e fl oat1 the out-of-range val ue (10 rai sed to the power of 3081), whi ch i s too
l arge to fi t i nto the fl oati ng-poi nt constant, and whi ch i s not the desi red val ue.
Convert each of these val ues before addi ng them to prevent thi s type of error and
avoi d unpredi ctabl e system behavi or . Create two conversi on vari abl es, fl oat1 and
fl oat2, and repl ace the statement above wi th the fol l owing statements:
The computati ons can then be carri ed on usi ng onl y fl oat1.
Expressions
An expressi on i s a set of arguments (operands) that r esol ve to exactl y one val ue.
An expressi on consi sts of some combi nati on of the fol l owi ng el ements:
Operators (symbol s or keywords that speci fy the operati on to be performed)
Vari abl es (database el ement tag names and procedure vari abl es)
Constants (symbol i c, numeri c, and stri ng constants)
Functi ons
float1 = message1 # get first user input
float2 = message2 # get second input
float1 = float1 + float2 # sum the inputs
MATH AND LOGIC SYNTAX
Structure
208 / FactoryLink ECS / Core Tasks Configuration Guide

I n an expressi on, parentheses and brackets are bal anced and al l operators have
the cor r ect number and types of operands. The fol l owi ng exampl es i l l ustrate
wel l -formed expressi ons (assumi ng the data types of each operand are val i d wi th
the operators):
Operators
Operators are symbol s or keywords that ar e used i n expressi ons to speci fy the
type of operati on to be performed. Operators can be ei ther unary or bi nary. Unary
operators operate on onl y one operand at a ti me whi l e bi nary operator s oper ate on
two operands at a ti me.
Math and Logi c empl oys the fol l owi ng operator groups. They ar e li sted i n order of
rel ati ve precedence; that i s, the order i n whi ch the task per forms the operati ons i n
an expressi on:
Ari thmeti c
Rel ati onal
Logi cal
Bi twi se
Groupi ng
Change-Status
Assi gnment
5
x + 1
X + 3.5
temp < 0 OR temp > = 100
outrange AND (valve1 = 1 OR valve2 = 1)
100*sin(voltage1 - voltage2)
(display = MENU) # logical comparison (for IF or
# WHILE not an assignment!)
This is a message to the operator!
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 209
8
M
a
t
h

a
n
d

L
o
g
i
c
Arithmetic Operators
Ari thmeti c operators per for m ari thmeti c operati ons on thei r operands. The
fol l owi ng chart i l l ustrates ari thmeti c operators:
Pl ace spaces befor e and after the keyword MOD to avoi d confusi on wi th vari abl e
names when the program parses the formul a.
All ari thmeti c operators except modul o operate on any type of numeri c operands,
i ncl udi ng fl oati ng-poi nt. MOD functi ons wi th onl y i ntegers (i n the case of tag
names, thi s means any combi nati on of anal og or l ong anal og data types).
Math and Logi c defi nes modul o as fol l ows:
x MOD y
(Thi s operati on returns the remai nder after di vi di ng x by y.)
Table 8-5
Operator Type Usage Operands Operation Name
+ bi nary x + y numeri c addi ti on
+ bi nary x + y stri ng concatenati on
- bi nary x - y numeri c subtracti on
- unar y -x numeri c negati on
* bi nary x*y numeri c mul ti pl i cati on
/ bi nary x/y numeri c di vi si on
^ bi nary x^y numeri c exponenti ati on
MOD bi nary x MOD y i nteger modul o (or modul us)
MATH AND LOGIC SYNTAX
Structure
210 / FactoryLink ECS / Core Tasks Configuration Guide

The fol l owi ng exampl es i l l ustrate ari thmeti c operati ons:


Relational Operators
Rel ati onal (or compari son) operators compare one numeri c operand wi th another
and generate a resul t that descri bes the outcome of the compari son.
The resul t of a gi ven compari son i s 1 (TRUE) or 0 (FALSE). Math and Logi c
resol ves al l operands to numeri c for m.
The fol l owi ng char t i l l ustrates rel ati onal operators used i n compari sons:
Table 8-6
Operation Results
17/5 = 3 Returns quoti ent of 3; remai nder i s l ost
17 MOD 5 = 2 Returns remai nder of 2; quoti ent i s i gnored
17.0/5 = 3.4 Resul t is converted to fl oati ng-poi nt; returns
quoti ent
and remai nder
Table 8-7
Keyword Type Usage Operation Name Operation Definition
= bi nary x = y equal to I f x = y, resul t i s 1.
I f x != y, resul t is 0.
!= or <> bi nary x != y not equal to I f x = y, resul t i s 0.
I f x != y, resul t is 1.
< bi nary x < y l ess than I f x < y, resul t i s 1.
I f x >= y, resul t i s 0.
> bi nary x . y greater than I f x > y, resul t i s 1.
I f x<= y, r esul t i s 0.
<= bi nary x <= y l ess than or equal
to
I f x <= y, resul t i s 1.
I f x > y, resul t i s 0.
>= bi nary x >= y greater than or
equal to
I f x >= y, resul t i s 1.
I f x < y, resul t i s 1.
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 211
8
M
a
t
h

a
n
d

L
o
g
i
c
Gi ven the shor t anal og vari abl e x = 3, the resul ts of vari ous rel ati onal operati ons
done usi ng x as an operand are shown i n the fol l owi ng chart:
Table 8-8
Operation Return Value
x < 10 1
x < 3 0
x < 2 0
x > 12 0
x > 2 1
x > 3 0
x != 4 1
x != 3 0
x = 4 0
x = 3 1
x <= 3 1
x <= 4 1
x <= 2 0
x >= 2 1
x >= 3 1
x >= 1 1
MATH AND LOGIC SYNTAX
Structure
212 / FactoryLink ECS / Core Tasks Configuration Guide

Logical Operators
Logi cal operators test operands for TRUE (non-zer o) or FALSE (zer o) val ues and
r eturn a resul t of 1 (TRUE) or 0 (FALSE). Math and Logi c resol ves al l operands to
numer i c for m.
The fol l owi ng chart i l l ustrates l ogi cal operators:
Pl ace spaces befor e and after the keywords AND, NOT, and OR to avoi d confusi on
wi th vari abl e names when the pr ogram parses the formul a.
The fol l owi ng exampl es i l l ustrate l ogi cal operati ons:
Table 8-9
Operator Type Usage
Operation
Name
Operation Definition
NOT unary NOT x l ogi cal NOT
(negati on)
I f x i s zer o, resul t is 1.
I f x i s non-zer o, resul t is 0.
AND bi nary x AND y l ogi cal AND
(conjuncti on)
I f x != 0 and y != 0, resul t is 1.
I f x or y (or both) are 0, resul t
i s 0.
OR bi nary x OR y l ogi cal OR
(di sjuncti on)
I f x or y (or both) ar e != 0,
resul t i s 1. I f x i s zer o and
y i s zer o, r esul t i s 0.
Table 8-10
Operation Return Value
NOT 3 0
NOT 0 1
NOT - 1 0
0 AND 1 0
0 AND 0 0
1 AND 2 1
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 213
8
M
a
t
h

a
n
d

L
o
g
i
c
Bitwise Operators
Bi twi se operators compare and manipul ate the i ndi vi dual bi ts of thei r operands.
Math and Logi c resol ves al l operands to i ntegers.
The fol l owi ng chart i l l ustrates bi twise operators:
0 OR 2 1
0 OR 0 0
2 OR 3 1
Table 8-11
Operator Type Usage Operands Operation Name
! unary !x i nteger bi twise ones
compl ement
& bi nary x & y i nteger bi twise AND
| bi nary x | y i nteger bi twise OR
(i ncl usi ve OR)
~ bi nary x~y i nteger bi twise XOR
(excl usi ve OR)
Table 8-10 (Continued)
Operation Return Value
MATH AND LOGIC SYNTAX
Structure
214 / FactoryLink ECS / Core Tasks Configuration Guide

Math and Logi c defi nes bi twi se operati ons as demonstrated i n the fol l owi ng
exampl es:
Grouping operators
The fol l owi ng operators pr ovi de grouping i nformati on about an operati on:
ParenthesesUse these to group sub-expressi ons. Thei r mai n purpose i s to
overri de the precedence of operati ons by forci ng the eval uati on of other
operati ons fi rst. Al so, use parentheses to encl ose arguments bei ng passed to a
functi on or procedure.
BracketsUse these to encl ose array i ndi ces. For doubl e- or tri pl e-i ndexed
ar r ays, use mul ti pl e pai rs of brackets.
Table 8-12
Operation Bit Value Return Value
9 & 10 9 = 1001
10 = 1010
1000
8
9 | 10 9 = 1001
10 = 1010
1011
11
9 ~ 10 9 = 1001
10 = 1010
0011
3
9 ~ - 10 9 = 0000000000001001
-10 = 1111111111110110
1111111111111111
-1
! 9 9 = 0000000000001001
bi twi se fl i p produces
11111111111110110
!9 = 11111111111110110
-10
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 215
8
M
a
t
h

a
n
d

L
o
g
i
c
CommasUse these to separate the arguments (i f mor e than one) bei ng
passed to a functi on. Al so, use commas between types i n procedure decl arati ons
and between type-argument name pai rs i n procedure defi ni ti on header
statements (proc statements). Refer to the fol l owi ng chart for addi ti onal
informati on.
The fol l owi ng chart i l l ustrates speci al groupi ng operators:
Change-status Operators
The change-status operator checks whether the val ue of a el ement has changed
si nce Math and Logi cs l ast read operati on (returni ng TRUE i f the el ements
change-status bi t has been set for any reason, i ncl uding a forced-wri te operati on).
Use of the change-status operator i tsel f resets the el ements change-status bi t
wi th respect to Math and Logi c.
The chart bel ow shows the characteri sti cs of change-status operators:
When checki ng change status, do not encl ose the database el ement name
(operand) i n parentheses. The construct ?(x) i s mi si nterpreted by Math and
Logi c i n thi s context and wi l l not produce the desi red resul t. Al ways use the
construct ? x or (changed x).
Table 8-13
Operator Type Usage Operands Operation Name
( N/A N/A any type l eft (open) parenthesi s
) N/A N/A any type ri ght (cl ose) parenthesi s
[ N/A N/A any type l eft (open) bracket
] N/A N/A any type ri ght (cl ose) br acket
, N/A N/A any type comma (between ar guments)
Table 8-14
Operator Type Usage Operands Operation Name
?
changed
unary (? x)
(changed x)
tag name change-status
MATH AND LOGIC SYNTAX
Structure
216 / FactoryLink ECS / Core Tasks Configuration Guide

A change-status operator is defi ned as fol l ows:


The fol l owi ng exampl e i l l ustrates two change-status operati ons:
Do not per for m change-status operati ons on el ements bei ng used as procedure
tri gger s (tri gger el ements). Thi s may prevent the correspondi ng procedure(s) fr om
bei ng tri ggered at the proper ti me. Thi s i s because checki ng the change status of
the el ement r esets the change bi t for that el ement.
Assignment Operators
Assi gnment operators assi gn a val ue to a vari abl e. Refer to the di scussi on of
assi gnment statements i n Assi gnment Statements on page 221.
Table 8-15
Operator Definition
? x
changed x
The operati on returns TRUE (1) i f the val ue
of x has changed si nce i t was l ast read or
change-read by Math and Logi c and FALSE
(O) i f i t has not.
Table 8-16
Operation Results
y = y + ?x I ncrements the val ue of y by 1
whenever the val ue of x changes.
I f changed tag_name then
cal l proc proc_name
Endi f
I ni ti ates the procedure proc_name
whenever the val ue of the el ement
tag_name changes.
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 217
8
M
a
t
h

a
n
d

L
o
g
i
c
Operator Precedence
Most hi gh-l evel l anguages use rel ati ve operator precedence and associ ati vi ty to
determi ne the order i n whi ch procedures perfor m operati ons.
I f one operator has hi gher precedence than another, the procedure executes i t
befor e the other . I f two oper ator s have the same pr ecedence, the procedure
eval uates them accordi ng to thei r associ ati vi ty (whi ch i s ei ther l eft to ri ght or
ri ght to l eft and i s al ways the same for such operators). Because parentheses ar e
operators wi th very hi gh precedence, they can be used to al ter the eval uati on
order of other operators i n an expressi on.
The Math and Logi c operators are di vi ded i nto ten categori es i n the fol l owi ng
chart of operator precedence. The Change-status category has the hi ghest
precedence, the Grouping categor y takes second precedence, and so on to the
Assi gnment categor y whi ch has the l owest precedence. The operators wi thi n each
categor y have equal precedence.
The Unary (thi rd category) operators associ ate fr om ri ght to l eft; al l other
operators associ ate from l eft to ri ght.
Table 8-17
Precedence
(1 is highest)
Category Operator Description
1 Change-status ? Checks change-status of
database el ements
2 Groupi ng ( ) Groupi ng or functi on call
[ ] Ar r ay subscri pt
3 Unary - Unary mi nus
NOT Bi twi se !s compl ement
! Logi cal negati on
4 Bi nary & Bi twi se AND
| Bi twi se OR
~ Bi twi se XOR
MATH AND LOGIC SYNTAX
Structure
218 / FactoryLink ECS / Core Tasks Configuration Guide

5 Mul ti pl i cati ve ^ Exponenti ati on


* Mul ti pl i cati on
/ Di vi si on
MOD Modul us (remai nder )
6 Addi ti ve + Binar y pl us (addi ti on)
- Binar y mi nus (subtracti on)
7 Rel ati onal < Less than
<= Less than or equal to
> Gr eater than
>= Gr eater than or equal to
8 Equal i ty = Equal to
!= Not equal to
9 Logi cal AND Logi cal AND
OR Logi cal OR
10 Assi gnment = Vari abl e or database el ement
assi gnment
== Forced wri te (database
el ement onl y)
Table 8-17 (Continued)
Precedence
(1 is highest)
Category Operator Description
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 219
8
M
a
t
h

a
n
d

L
o
g
i
c
The fol l owi ng exampl es i l l ustrate operator precedence:
Table 8-18
Example Statement Explanation of Operator Precedence
x , 5*y + 10 AND NOT zfl ag Accordi ng to precedence rul es, the order of
eval uati on i s NOT, then *, then +, then <,
then AND. The program eval uates the
expressi on as i f i t contai ned the fol l owi ng
parentheses:
(x < ((5*y) + 10)) AND (NOT zfl ag)
To perfor m the addi ti on before the
mul ti pli cati on, add parentheses to al ter
pr ecedence, as fol l ows: x < 5*(Y + 10) AND
NOT zfl ag
x * y/z Because * and /have the same precedence
and they associ ate l eft to r i ght, the
pr ogr am per forms * befor e?. The pr ogr am
eval uates the expressi on as i f i t contai ned
the fol l owi ng parentheses: (x * y)/z
x = NOT NOT y The program eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses:
x = (NOT (NOT y))
Thi s expressi on assi gns the val ue 1 to x i f y
i s nonzer o. Other wi se, the expressi on
assi gns 0 to x and i s equi val ent to x = y ! =
0.
x = NOT ?y The program eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses:
x = (NOT (?Y))
x = NOT y = z The program eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses:
x = ((NOT y) = z)
Thi s expressi on i s di fferent fr om x = NOT
(y=z). The l atter i s equi val ent to x = y ! = z.
a = 1 AND b ! = 2 OR c = 3
AND d ! = 4
The program eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses: ((a
+ 1) AND (b ! = 2)) OR ((c = 3) AND (d !=4))
MATH AND LOGIC SYNTAX
Structure
220 / FactoryLink ECS / Core Tasks Configuration Guide

Statements
A statement i s an i nstructi on that descri bes mathemati cal and/or l ogi cal
operati ons to be per formed i n a speci fi ed order . A di agrammed statement, wi th
each of i ts components l abel ed, is i l l ustrated bel ow:
Statements can be one of thr ee types:
Assi gnment Statements
Control statements
Pr ocedur e cal l s
x = a = b < c The pr ogr am eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses:
x = (a = (b < c))
Thi s expressi on assi gns x the fl ue 1 i f a has
the same truth val ue (1 or 0) as the
compari son b < c. Other wise, the
expressi on assi gns 0 to x.
x & 1 | y & 2 | z & 4 The pr ogr am eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses:
((x & 1) | (y & 2) | (Z & 4)
I f thi s case, i t does not real l y matter whi ch
| the program executes fi rst, the program
executes fi r st; the pr ogr am eval uates the
expressi on fr om l eft to ri ght.
f(2*x + 3, 4*y + 5) - g(x, y) /2 The pr ogr am eval uates the expressi on as i f
i t contai ned the fol l owi ng parentheses: f
(((2*x) = 3), ((4*y) = 5)) - (g(x,y)/2)
Table 8-18 (Continued)
Example Statement Explanation of Operator Precedence
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 221
8
M
a
t
h

a
n
d

L
o
g
i
c
Assignment Statements
Assi gnment statements assi gn val ues to Math and Logi c procedure vari abl es or
database el ements and can have ei ther of the fol l owi ng forms:
x = expr
Onl y wri tes i f val ue of x is to be changed; val i d for procedure vari abl es and
database el ements.
or
x == expr
Forced wri te, regardl ess of vari abl e's present val ue. Turns on change-status fl ags.
Val i d onl y for database el ements.
where = and == are the assi gnment operators. Refer to Operators on page 208
for more i nformati on.
The assi gnment statement i s wri tten (whether in a formul a or wi thi n a procedure)
wi th the vari abl e to be changed on the l eft-hand si de of the assi gnment operator
and the ter m or expressi on whose val ue shoul d be taken (l eavi ng i t unchanged) on
the ri ght-hand si de. Math and Logi c computes the expressi on expr and assi gns the
resul t to the procedure vari abl e or el ement 5 x. Refer to Expressi ons on page 207
for more i nformati on.
A si gni fi cant di fference exi sts between the two assi gnment operators. Refer to the
exampl es bel ow usi ng database el ements fptemp and i temp:
fptemp = itemp
Wil l not change the val ue of fptemp unl ess i t i s di fferent fr om the val ue i n i temp
(al though i t wi l l sti l l pl ace the i nteger val ue i nto a fl oati ng-poi nt stor age for mat).
Thi s for m i s used to assi gn val ues to l ocal and gl obal vari abl es as wel l as database
el ements.
fptemp == itemp
Forces the val ue of i temp to be stored i n the vari abl e fptemp whether or not
fptemp al ready contai ns that val ue and sets al l the change-status fl ags associ ated
wi th fptemp.
Thi s form i s used onl y to assi gn val ues to database el ements.
MATH AND LOGIC SYNTAX
Structure
222 / FactoryLink ECS / Core Tasks Configuration Guide

Syntax: To obtai n the most effi ci ent FactoryLi nk task performance, use the
si mpl est assi gnment statement necessary. The fol l owing char t summari zes
assi gnment statement syntax:
End an assi gnment statement wi th an end-of-li ne character () or a semi -col on (;).
To set the change-status bi t for database el ement x wi thout al teri ng i ts val ue, use
the forced-assi gnment operator == to equate the el ement to i tsel f, as shown i n the
exampl es bel ow:
Table 8-19
Assignment
Operator
Data Types
of Operands
Operation Result
gvar1 = 1var2 any Normal l ocal /gl obal vari abl e
assi gnment.
tag1 = var1 any Assi gnment i s made vi a database wr i te
cal l .
tag1 == var 1 database Assi gnment i s made vi a database
forced-wri te el ements onl y cal l .
Table 8-20
Example Explanation
a[3] = (a[0]+a[1]+a[2]+a[3])/4
rtdb2 == rtdb2
Local array assi gnment.
Forced-wri te assi gnment, l eavi ng the
val ue of r tdb2 unchanged.
x = 47.1
x = x+1
x i s a l ocal FLOAT.
rtdb1 == x Forced-wri te assi gnment of el ement
RTDB1.
rtdb2 == rtdb2 Forced-wri te assi gnment, l eavi ng the
val ue of r tdb2 unchanged.
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 223
8
M
a
t
h

a
n
d

L
o
g
i
c
Control Statements
Control statements, someti mes cal l ed condi ti onal statements, i ncl ude
i nstructi ons about the ci rcumstances under whi ch a bl ock of procedure code (a
sequence of consecuti ve statements) i s to be executed. End a control statement
l i ne wi th an end-of-l i ne character () onl y. Never end a control statement wi th a
semi col on.
There are two types of control statements:
I F...ENDI F
WHI LE...WEND (ENDWHI LE)
IF...ENDIFAn I F...ENDI F statement speci fi es an acti on i s to be executed onl y
i f a speci fi ed condi ti on i s tr ue.
SyntaxThe I F...ENDI F control statement has the fol l owi ng syntax:
I f the test expressi on of the statement i s tr ue, the THEN bl ock i s executed. I f the
test expressi on i s not true and an ELSE cl ause exi sts, the ELSE bl ock i s executed.
The ELSE bl ock i s opti onal .
The I F...THEN bl ock is not opti onal and the THEN verb must i mmedi atel y fol l ow
the test expressi on on the same li ne as I F. Each I F statement must be ended wi th
an ENDI F statement on a l i ne by i tsel f.
IF expr THEN # Block to be executed if expr is true.
[ELSE] # Optional block to be executed if expr
# is false.
ENDIF
MATH AND LOGIC SYNTAX
Structure
224 / FactoryLink ECS / Core Tasks Configuration Guide

The fol l owi ng exampl es i l l ustrate the use of I F...ENDI F control statements:
# Example 1:
IF x = 1 THEN
a = a + 1;
b = 20;
ELSE
a = a - 1;
b = 0;
ENDIF
# Example 2:
IF NOT initflag THEN
IF (alrm gt 6) THEN
initflag = 1;
alrm = alrm + 1;
CALL initproc; # call another proc
ENDIF
ELSE
b = 20;
tag2 == a - 1;
procadd; # call another proc
ENDIF
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 225
8
M
a
t
h

a
n
d

L
o
g
i
c
WHILE...WENDA WHI LE...WEND statement speci fi es a bl ock of code i s to be
executed repeatedl y unti l the test expressi on becomes fal se.
SyntaxThe WHI LE...WEND control statement has the fol l owi ng syntax:
I f the expressi on test_expr i s i ni ti al l y fal se, the bl ock is never executed. I f the
expressi on never becomes fal se, the l oop never termi nates unti l the operator or
another run-ti me process forces the procedure to stop runni ng. Ensure the val ue
of test_expr can become fal se at some poi nt i n the l oops executi on to prevent the
program from hangi ng.
The keyword ENDWHI LE can be substi tuted for WEND.
# Example 3:
# take determinant of 2x2 array
det = a[0][0]*a[1][1]t-ta[0][1]*a[1][0]
# if nonzero, then invert 2x2 array a
# place resulting array in 2x2 array b
IF (det != 0) THEN
b[0][0] == a[1][1]/det
b[0][1] == -a[0][1]/det
b[1][0] == -a[1][0]/det
b[1][1] == a[0][0]/det
ELSE
PRINT Cannot invert this matrix!\n
ENDIF
WHILE test_expr # Block to be executed while
test_expr remains true.
.
.
.
WEND
MATH AND LOGIC SYNTAX
Structure
226 / FactoryLink ECS / Core Tasks Configuration Guide

The fol l owi ng exampl es i l l ustrate the use of WHI LE...WEND control statements:
I ndent condi ti onal l y executed bl ocks for readabi l i ty. Thi s does not affect pr ogr am
executi on.
Procedure Calls
Procedure cal l s are statements that cause speci fi ed procedures to execute.
Procedure cal l s are used to r eference custom-wri tten procedures or l i brary
functi ons whi ch are bui l t i nto the FactoryLi nk system.
SyntaxProcedur e cal l s have the fol l owi ng syntax:
The keyword CALL and the endi ng semi col on, both shown i n brackets, ar e
opti onal . When addi ti onal arguments exi st, the i tems shown i n braces are
present.
# Example 1:
n = 0
WHILE n < 10
a[n] = -1
n = n + 1
WEND
# Example 2:
fib[0] = x
fib[1] = y
n = 2
WHILE n < 100 AND fib[n-1] < 10000
fib[n] = fib[n-2] + fib[n-1]
n = n + 1
WEND
[CALL] proc_name[;]
or
[CALL] proc_name(arg1{,arg2,arg3,...})[;]
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 227
8
M
a
t
h

a
n
d

L
o
g
i
c
Math and Logi c copi es the val ues used as arguments so the procedure modi fi es
the copi es, not the ori gi nal val ues of the vari abl es or database el ements. Refer to
Ar guments on page 233 i n Chapter 9, Math and Logi c Procedures and
Functi ons, for more i nformati on.
Block Nestability
Bl ocks del i mi ted wi th control statements can be nested, pr ovi ded each I F or
WHI LE statement contai ns an appropri ate matchi ng ENDI F or WEND
statement. Bl ocks cannot overl ap and must be matched pai rs enti rel y wi thi n any
other bl ocks to whi ch they are i nternal . I mproperl y nested l ogi c causes
unpredi ctabl e resul ts.
The fol l owi ng exampl e il l ustrates proper procedure nesti ng:
Excessi ve nesti ng of bl ocks or procedure cal l s can cause the operati ng system to
hal t the procedure and return a Stack over fl ow er r or . I f thi s er r or occurs, ei ther
restructure the procedures to reduce the number of nesti ng l evel s or i ncrease the
stack si ze for Math and Logi c. Contact Customer Suppor t for i nfor mati on about
i ncreasi ng the stack si ze.
IF x = y THEN
n = 0
WHILE n < 10
a[n] = 0
n = n + 1
WEND
ELSE
IF x > y THEN
a[x-y] = 1
ELSE
a[y-x] = -1
IF alert THEN
PRINT FOUND IT \n
ENDIF
ENDIF
ENDIF
MATH AND LOGIC SYNTAX
Structure
228 / FactoryLink ECS / Core Tasks Configuration Guide

Directives
Di recti ves are symbol s used i n statements and determi ne the type of statement
performed. Di recti ves must not be used i n expressi ons. Math and Logi c recogni zes
the fol l owing di r ecti ves:
Table 8-21
Directive Usage*** Meaning
= x = expr Assi gn expr to x (vi a database wri te or
l ocal l y)
== x == expr Assi gn expr to x vi a a forced database
wri te
i f i f expr Test por ti on of i f statement
then then bl ock (requi red) I f test i s TRUE, begi n then
bl ock
el se el se bl ock (opti onal ) I f test i s not TRUE, begi n
el se bl ock
endi f endi f End of i f- then or i f-then-el se bl ock
whi l e whi l e expr Whi l e expr i s TRUE, do whi l e bl ock
wend wend End of whi l e bl ock
begi n (or { ) begi n Begi n pr ogr am
end (or *}*) end End program
cal l cal l pr oc01 Execute a procedur e and r eturn (opti onal
keywd)
proc proc bl ock Defi ne a procedure
system x = system(* *)* Execute a system cal l and return
decl are decl are short x Defi ne a vari abl e or decl are a procedure
pri nt pri nt starti ng Pri nt a l i ne of text
l ock l ock Lock the database
MATH AND LOGIC SYNTAX
Structure
FactoryLink ECS / Core Tasks Configuration Guide / 229
8
M
a
t
h

a
n
d

L
o
g
i
c
unl ock unl ock Unl ock the database
*** Terms used i n thi s tabl e are defi ned as fol l ows:
x is a vari abl e capabl e of bei ng assi gned a val ue. I t may be a
database vari abl e (tag name), a Math and Logi c vari abl e, or a
constant, but i t may not be a functi on.
expr stands for an arbi trary expressi on.
block r efers to any sequence of consecuti ve statements.
* Encl ose a system cal l appropr i ate to the oper ati ng system wi thi n the
doubl e quotati on marks. Vi rtual l y any system cal l , such as the di r
command, i s val i d.
The SYSTEM di recti ve requi res operati ng system-speci fi c arguments.
Table 8-21 (Continued)
Directive Usage*** Meaning
MATH AND LOGIC SYNTAX
Structure
230 / FactoryLink ECS / Core Tasks Configuration Guide

FactoryLink ECS / Core Tasks Configuration Guide / 231

9
M
a
t
h

a
n
d

L
o
g
i
c
Chapter 9
Math and L ogi c
P r ocedur es and
F uncti ons
PROGRAM FI LES
A program fi l e i s a text fi l e contai ni ng the text of one or mor e Math and Logi c
procedures and has the extensi on .PRG. A pr ogr am fi l e is composed of procedures
and decl arati ons. Pr ogr am fi l es can contai n mul ti pl e procedures; however, a
program fi l e must contai n one procedure, cal l ed the mai n procedur e, that fi ts two
cri teri a:
The mai n procedur e has the same name as the name of the pr ogr am fi l e, mi nus
the extensi on. For exampl e, the pr ogr am fi l e MYPROC.PRG must contai n a
mai n procedure wi th the name MYPROC, mypr oc, MyPr oc, or some vari ati on.
Pr ogr am fi l e names are not case-sensi ti ve.
The procedure name entered i n the Math and Logi c Tri ggers tabl e must be
exactl y the same as the name entered i n the pr ogr am fi l e, i ncl udi ng upper and
l owercase characters.
Procedure names, el ement names, vari abl es, and constants are al l case-sensi ti ve
i n Math and Logi c and must be uni que. However , to avoi d confusi on and a
possi bl e error, do not gi ve any two procedures, el ement names, vari abl es, or
constants the same name, even i f the case i s di fferent. Remember in UNI X, names
must be l ower case.
Be careful not to confuse the name of a procedure wi th the name of the program
fi l e i n whi ch the procedure is contai ned. Whi l e procedure names are
case-sensi ti ve, the name of the program fi l e i n whi ch the procedures are contai ned
i s not case-sensi ti ve.
At run ti me, i f a pr ogr am fi l e does not contai n a procedure that fi ts these cri teri a,
no procedures in that fi l e are tr i ggered, and the error message Proc (procedure
name) does not exi st i s displ ayed on the Run-Ti me Manager screen and i n the l og
fi l e.
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Program Files
232 / FactoryLink ECS / Core Tasks Configuration Guide

Procedures
A procedur e is a sequenti al arrangement of statements that mani pul ate data
i tems i n a repeatabl e fashi on, al ways behavi ng the same way under the same
ci rcumstances and provi di ng a wel l -defi ned and l ogi cal fl ow of control through the
procedur e.
Defi ne procedures usi ng the fol l owing general for m (wi th no arguments):
Each procedure defi ni ti on statement or proc statement starts wi th the word
PROC, fol l owed by the uni que name of the procedure, fol l owed by any arguments
(parameters) the procedure requi res. (Any procedure, except the mai n procedure
for the fi l e, can have arguments.) Pl ace the keyword BEGI N on the next l i ne.
For exampl e:
where
type is SHORT, LONG, FLOAT, or STRI NG.
name1 is the name of a vari abl e or constant or a database el ement tag
name.
name2 is the name of a vari abl e or constant or a database el ement tag
name other than name1.
Math and Logi c does not pr ovi de return codes for devel oper-defi ned procedures.
Therefore, the task cannot set a vari abl es val ue to the return code fr om a
procedur e cal l .
PROC name
BEGIN
.
.
.
END
Procedure defi ni ti on statement
Body of procedure, decl arati ons, and statements
PROC name (type name1 [,type name2])
BEGIN
.
.
END
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Program Files
FactoryLink ECS / Core Tasks Configuration Guide / 233
9
M
a
t
h

a
n
d

L
o
g
i
c
Do not confuse procedure defi ni ti ons wi th procedure decl arati ons whi ch are
forward references to pr ocedures defi ned l ater in the same fi l e or i n a di ffer ent
fil e.
Arguments
ArgumentsArguments are val ues passed to a procedure for i t to use i n i ts
computati ons; arguments are i nput-onl y parameters.
Decl are arguments by pl aci ng thei r types and names i n the procedure defi ni ti on
statement, as shown i n the exampl e above. Local and gl obal vari abl e names and
tag names can be used. The data type of the argument i s the same as that of the
ori gi nal vari abl e or database el ement (SHORT, LONG, FLOAT, STRI NG).
Math and Logi c copi es the val ues used as arguments so the procedure modi fi es
the copi es, not the ori gi nal val ues of the vari abl es or el ements. For exampl e, i f the
tag name of a database el ement is used as an argument, the task copi es the val ue
of that el ement and sends i t to the procedure as the argument. The ori gi nal val ue
of the database el ement i s not affected. Val ues modi fi ed as arguments cannot be
passed back to the cal l i ng procedure.
An array cannot be used as an argument to a procedure, but an array el ement
can.
PROC pgm1(short non_tagnm but CALL pgm1(tag1)
I n thi s exampl e, the val ue of the di gi tal el ement tag1 i s copi ed i nto the procedur e
vari abl e non_tagnm and converted to a short data type. I nsi de the procedure,
operati ons on non_tagnm do not affect the val ue of tag1. However, because
FactoryLi nk real -ti me el ements are gl obal , at the end of the procedure, tag1 can
be assi gned the val ue of non_tagnm.
The decl arati on secti on of a procedur e defi ni ti on is opti onal . Any of the
decl arati ons can be made i n thi s secti on. Remember the two pr evi ousl y stated
rul es:
Any vari abl es decl ared wi thi n the procedure are by defi ni ti on l ocal vari abl es
and cannot be r eferenced outsi de of the procedure.
Decl arati ons must come before any statements.
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Program Files
234 / FactoryLink ECS / Core Tasks Configuration Guide

Calling SequenceFor Math and Logi c to i nvoke a procedure, you must speci fy
a procedure cal l usi ng one of the fol l owi ng i nterchangeabl e for ms:
where the keyword CALL i s opti onal .
{CALL} proc_name[(type1 arg1 [, type2 arg2...])] or
{CALL} proc_name(type1 arg1 [, type2 arg2...])
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Running Programs as Interpreted Programs
FactoryLink ECS / Core Tasks Configuration Guide / 235
9
M
a
t
h

a
n
d

L
o
g
i
c
RUNNI NG PROGRAMS AS INTERPRETED PROGRAMS
To run as interpr eted those pr ograms that have I nterpreted entered i n the Mode
fi el d of the Math and Logi c Tri gger s I nfor mati on panel , start the appl i cati on by
typi ng the FLRUN command at the system pr ompt.
Math and Logi c begi ns executi ng i nterpreted progr ams by l oadi ng them into
memor y. After l oadi ng and val i dati ng the pr ogr ams, Math and Logi c wai ts for
changes to the tr i gger el ements i n the real -ti me database associ ated wi th the
procedures in the program. When a tri gger el ement i s set to 1 (ON), the task
executes the program associ ated wi th that tr i gger .
Each ti me an i nterpreted pr ogram i s executed, Math and Logi c fi rst reads, or
i nterprets, the i nstructi ons wi thi n the program to determi ne the acti ons to
perform, then i t executes those acti ons.
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
236 / FactoryLink ECS / Core Tasks Configuration Guide

TECHNICAL NOTES
Calling Procedures and Functions
Two types of routi nes can be cal l ed fr om wi thi n an expressi on:
Devel oper-defi ned l ocal procedures
Li brary functi ons
Local Procedures
Cal l s to l ocal procedures, wi th or wi thout arguments, are normal l y made usi ng
one of the for ms i n the char t bel ow:
Procedure names can be up to 16 characters, must conform to the nami ng rul es for
vari abl es, and can be fol l owed by a set of parentheses contai ni ng the functi ons
input parameters (arguments), i f any are requi red.
To be compati bl e wi th al l operati ng systems, the mai n procedure for each .PRG
fi l e shoul d have a name of up to 8 characters.
Table 9-1
Syntax Purpose
f( ) or f To pass no arguments
f(arg1) To pass arg1
f(arg1, ar g2) To pass arg1 and arg2
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 237
9
M
a
t
h

a
n
d

L
o
g
i
c
Library Functions
A number of speci al i zed procedures, known as functi ons, ar e predefi ned by, or
bui l t i nto, Math and Logi c. Functi ons bui l t i nto Math and Logi c are known as
l i brary functi ons. Expressi ons can incl ude cal l s to l i brary functi ons. The l i brary
functi ons suppli ed wi th Math and Logi c are grouped i nto fi ve categori es:
Mathemati cal
Di rectory/Path Control
Stri ng Mani pul ati on
Programmi ng Routi nes
Mi scel l aneous Routi nes
The functi ons wi thi n each category are descri bed i n the fol l owi ng secti ons.
I ncl uded i n each functi ons descri pti on i s a sampl e format of the functi on and an
exampl e of i ts use.
Functi ons can vary among di fferent operati ng systems. Refer to your operati ng
systems documentati on for i nformati on about speci fi c functi ons for a par ti cul ar
operati ng system.
Table 9-2 Mathematical Functions
Function: Sample Format: Description:
abs
Example:
Therefore:
x = abs(y)
x = abs(-5)
x = 5
Returns absol ute val ue
cos
Example:
Therefore:
x = cos(y)
x = cos(.4)
x = 0.921061
Returns the cosi ne of y. Speci fy y i n
radi ans.
exp
Example:
Therefore:
x = exp(y)
x = exp(4)
x = 54.59815
Returns ey
log
Example:
Therefore:
x = l og(y)
x = l og(100)
x = 2
Returns the l og base 10 of y
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
238 / FactoryLink ECS / Core Tasks Configuration Guide

loge
Example:
Therefore:
x = l oge(y)
x = l oge(1)
x = 0
Returns the natural l og of y
pow
Example:
Therefore:
x = y pow (z)
= 2 pow (3)
x = 8
Returns y to the zth power
rnd
Example:
One possi bl e
resul t:
x = rnd
x = rnd
x = 32750
Returns a pseudo-random posi ti ve integer
wi thi n the range 0 to 32767
Note: 32765 represents onl y one of many possi bl e resul ts fr om thi s cal l made to
the pseudo-randomi zer. Thi s functi on cannot be seeded, as can a more
sophi sti cated randomi zi ng functi on, and therefore i t tends to generate the same
sequence of integers each ti me i t i s run. No routi ne can choose trul y random
numbers. Probabi l i ty functi ons are a mai n component of these l i brary routi nes,
whi ch are heavi l y dependent on the handl i ng of the routi ne by the parti cul ar
operati ng system. Pure random numbers are normal l y not needed, but we
r ecommend you i nvesti gate wri ti ng a custom randomi zer functi on, seeded
di fferentl y each ti me the functi on i s cal l ed. I t i s beyond the scope of thi s
document to di scuss the uses and characteri sti cs of randomi zi ng functi ons, but
many texts provi de a poi nt-of-r efer ence. Thi s functi on, however , i s servi ceabl e for
the devel oper who wants to speci fy a di fferent number for a sort or poi nter each
ti me the routi ne i s entered, such as, start at a di fferent bel t each ti me red cars
ar e sought on the conveyor s. I f randomness is necessar y, contact Customer
Suppor t.
sin
Exampl e:
Therefore:
x = si n(y)
x = si n(1.5)
x = 0.9974951
Returns the si ne of y. Speci fy y i n
radi ans.
sqr
Example:
Therefore:
x = sqr (y)
x= sqr(144)
x = 12
Returns the square r oot of y
Table 9-2 Mathematical Functions (Continued)
Function: Sample Format: Description:
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 239
9
M
a
t
h

a
n
d

L
o
g
i
c
Directory/Path Control Functions
Di rectory and path control functi ons are uni que to each operati ng system.
tan
Example:
Therefore:
x = tan(y)
x = tan (.785)
x = 1
Returns the tangent of y. y i s speci fi ed i n
radi ans
Table 9-3 String Manipulation Functions
Function: Sample Format: Description:
alltrim
Exampl e:
Therefore:
stri ng = al l tri m(stri ng)
msgvar =
al l tri m(SMI TH )
msgvar = SMI TH
Returns string wi th l eadi ng and
trai l i ng bl anks tri mmed
asc
Example:
Therefore:
x = asc(stri ng)
x = asc (TEN)
x = 84 (84 i s the ASCI I
code for T.)
Returns the ASCI I val ue of the fi rst
character i n string
chr
Example:
Therefore:
stri ng = chr(var)
msgvar = chr(66)
msgvar = B (66 i s the
ASCI I code for B.)
Returns equi val ent character of an
ASCI I code
instr
Example:
Therefore:
x = i nstr(str1, str2)
x = i nstr(ABCDE ,B)
x = 2
Returns the offset i nto str1 of the
occur rence of str2
len
Example:
Therefore:
x = l en (stri ng)
x = l en(MI AMI ,
FLORI DA)
x = 13
Returns the l ength of string, not
i ncl uding the termi nator
Table 9-2 Mathematical Functions (Continued)
Function: Sample Format: Description:
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
240 / FactoryLink ECS / Core Tasks Configuration Guide

lower
Example:
Therefore:
stri ng = l ower (stri ng)
msgvar = l ower (NOT)
msgvar = not
Returns string conver ted to l ower case
ltrim
Example:
Therefore:
str i ng = l tri m (stri ng)
msgvar = l tr i m
(SMI TH)
msgvar = SMI TH
Returns string wi th l eadi ng bl anks
tr i mmed
substr
Example:
Therefore:
stri ng=substr (str i ng,
offset, l en)
msgvar =
substr(ABCDE, 3, 2)
msgvar = CD
Returns a stri ng of len l ength or l ess
begi nni ng wi th the offset char acter
fr om the begi nni ng of string. The offset
to the fi rst character i n string i s 1.
trim
Example:
Therefore:
stri ng = tri m(stri ng)
msgvar =
tr i m(SMI TH)
msgvar = SMI TH
Returns string wi th trai l i ng bl anks
tr i mmed
upper
Example:
Therefore:
stri ng = upper(stri ng)
msgvar = upper (not)
msgvar = NOT
Returns the i nput, string, conver ted to
upper case
Table 9-3 String Manipulation Functions (Continued)
Function: Sample Format: Description:
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 241
9
M
a
t
h

a
n
d

L
o
g
i
c
For Windows NT and Windows 95
Table 9-4 Directory/Path Control Functions
Function: Sample Format: Description:
getdir
stri ng = getdi r(drive) Returns the cur rent path of specified
drive.
dri ve = 0
dri ve = 1
dri ve = 2
and so on.
current dri ve
a:
b:
Example:
stri ng = getdi r(1)
Therefore:
stri ng = a:
getdrive
dri ve = getdri ve Returns current di sk number.
dri ve = 1
dri ve = 2
and so on.
a:
b:
Example:
dri ve = getdri ve
Therefore:
dri ve = 2 (i f current dri ve i s dri ve b)
setdir
status = setdi r(dri ve,
path)
Returns zero for success. Sets new
current dri ve/di r ector y.
dri ve = 0
dri ve = 1
dri ve = 2
and so on.
current dri ve
a:
b:
Example:
status = setdi r(1, a:\test)
Therefore:
status = 0 (i f current dri ve/di rectory successful l y set to a:\ test)
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
242 / FactoryLink ECS / Core Tasks Configuration Guide

setdrive
stat = setdri ve(dri ve) Returns zer o for success. Sets new
current dr i ve.
dri ve = 1
dri ve = 2
and so on.
a:
b:
Example:
stat = setdri ve(1)
Therefore:
stat = 0 (i f current dr i ve successful l y set to dri ve a)
Table 9-4 Directory/Path Control Functions (Continued)
Function: Sample Format: Description:
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 243
9
M
a
t
h

a
n
d

L
o
g
i
c
For OS/2
Table 9-5 Directory/Path Control Functions
Function: Sample Format: Description:
getdir stri ng = getdi r(dri ve) Returns the cur rent path of speci fi ed
dri ve.
dri ve = 0
dri ve = 1
dri ve = 2
and so on.
current dri ve
a:
b:
Exampl e: stri ng = getdi r(1)
Therefore: stri ng = a:\
getdrive dri ve = getdri ve Returns current di sk number.
dri ve = 1
dri ve = 2
and so on.
a:
b:
Exampl e: dri ve = getdri ve
Therefore: dri ve = 2 (i f current dri ve i s dri ve b)
setdir status =
setdi r(dri ve,path)
Returns zero for success. Sets new
current dri ve/di r ector y.
dri ve = 0
dri ve = 1
dri ve = 2
and so on.
current dri ve
a:
b:
Exampl e: status = setdi r(1, a:\test)
Therefore: status = 0 (i f current dri ve/di rectory successful l y set to a:\ test
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
244 / FactoryLink ECS / Core Tasks Configuration Guide

For UNIX
Programming Routines
The chart bel ow l i sts pr ogrammi ng routi nes al phabeti cal l y.
setdrive stat = setdri ve(dri ve) Returns zer o for success. Sets new
current dr i ve.
dri ve = 1
dri ve = 2
and so on.
a:
b:
Exampl e: stat = setdri ve(1)
Therefore: stat = 0 (i f current dr i ve successful l y set to dri ve a)
Table 9-6
Function: Sample Format: Description:
setdir
Example:
Therefore:
status = setdi r(*, path)
status = setdi r(*,/test)
status = 0 (i f cur r ent
di r ector y successful l y
set to /test)
Returns zer o for success. Sets new
current di rectory.
Table 9-5 Directory/Path Control Functions (Continued)
Function: Sample Format: Description:
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 245
9
M
a
t
h

a
n
d

L
o
g
i
c
TRACE is not supported i n the compi l ed mode of Math and Logi c.
Table 9-7 Programming Routines
Syntax: Description:
EXIT(status) Exi t the program and set the program
return status.
CALL procname([p1...]) Cal l a procedure. The keyword CALL i s
not requi red. (Refer to Procedur e
Cal l s on page 226 i n Chapter 8, Math
and Logi c Syntax. )
INPUT stri ng_prompt, var1, var2... Accept i nput fr om keyboar d. The fi r st
fi el d entered i s pl aced i n var1. The
fi rst comma entered begi ns second
fi el d, whi ch i s pl aced i n the var2, and
so on.
LOCK Lock the database. No other task can
access the database whi l e i t i s l ocked.
A LOCK statement del i mi ts a bl ock of
code to be executed i n cri ti cal mode;
that i s, wi thout i nter fer ence fr om other
FactoryLi nk tasks runni ng on the
system. For each LOCK statement,
ther e MUST be an UNLOCK
statement.
UNLOCK Unl ock the database, al l owi ng other
tasks to access i t. Must be is sued for
ever y LOCK.
I f time-consuming code is included
between LOCK and UNLOCK
statements, performance may be
affected, because no other tasks can
access the database while it remains
locked.
PRINT Row and l i ne:, row1, l i ne Send each li sted pri nt parameter
(vari abl e) to the di spl ay, converti ng to
ASCI I , i f necessary.
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
246 / FactoryLink ECS / Core Tasks Configuration Guide

Miscellaneous Routines
The retur n code fr om the operati ng system i s pl aced i n the vari abl e represented
here by x to check whether the requested system command was compl eted wi thout
errors. I f there wer e no errors, the functi on returns 0; other wise, at l east one er r or
on the request occurr ed.
TRACE expr
TRACE will not be supported in future
add-on products.
Whi l e expr r emai ns true, each l i ne
assi gnment, and the procedures exi t
poi nt are pri nted as they run.
Table 9-8 Miscellaneous Routines
Function: Sample Format: Description:
argcnt
Example:
Therefore:
x = argcnt
x = argcnt
x = 3 (i f the number of
program arguments i s
3)
Returns the number of program
arguments.
getarg
Example:
x = getar g(ar gnbr )
x = getarg(2)
x = TEST (i f the second
argument is the
di r ector y name, which
is TEST)
Returns the speci fi ed program
argument.
system
Example:
Result:
x = system
(system command)
x = system(copy
c:\\autoexec.bat
b:\\bat)
#OS/2 system cal l
x = 0 (i f the copy
request was successful )
Al l ows system cal l s. The command is
formatted as a stri ng. Returns success
(0) of fai l ure (1) of operati on.
Table 9-7 Programming Routines (Continued)
Syntax: Description:
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 247
9
M
a
t
h

a
n
d

L
o
g
i
c
To transmi t one backsl ash (\ ) character , type two backsl ashes. Doubl i ng the
character causes the system to recogni ze i t as a l i teral character.
System command represents a cal l made to the operati ng system. Thi s mi ght be a
si mpl e di recti ve such as DI R C:, or i t mi ght be compl ex, such as a request to
execute a batch fi l e to request val ues or i nputs fr om the user ( @GETI D) or to
request another operati ng system shel l (DOSSHELL). Arguments to the
SYSTEM functi on are operati ng system-dependent.
For Windows NT and Windows 95
Under Mi crosoft Wi ndows, the SYSTEM functi on i s asynchronous; that i s, the
SYSTEM functi on returns i mmedi atel y. The operati ng system command runs i n
paral l el to Math and Logi c. I f the command i s started, the return val ue of the
SYSTEM functi on i s 0 (zero); otherwi se, the return val ue i s -1.
Note that usi ng thi s featur e makes procedures non-por tabl e wi thout manual
conversi on of the system cal l s to those appropri ate in the tar get system.
For OS\2
The SYSTEM functi on sends the speci fi ed operati ng system command to the
operati ng system and begi ns a subprocess that passes the request to a DCL
Command Li ne I nterpreter (CLI ). The Run-Ti me Manager screen for the
parti cul ar domai n i n whi ch Math and Logi c i s runni ng displ ays the output the
CLI produces whi l e processi ng the request. Encl ose the desi red system command
i n doubl e quotes.
To obtai n di rectory l i sti ngs of fi l es i n the current (acti ve) dri ve/path, use:
SYSTEM(dir)
OS/2 returns a status code, wi th 1 indi cati ng success and any non-zer o val ue
i ndi cati ng fai l ure. Vi r tual l y any system command val i d fr om the nor mal OS/2
prompt i s val i d when sent through the SYSTEM functi on.
Usi ng thi s featur e makes procedures non-por tabl e wi thout manual conversi on of
the system cal l s to those appropri ate i n the tar get system.
For UNIX
The SYSTEM functi on sends the speci fi ed operati ng system command to the
operati ng system and spawns a subprocess that passes the request to a DCL
Command Li ne I nterpr eter (CLI ). The Run-Ti me Manager screen for the
parti cul ar domai n i n whi ch Math and Logi c i s runni ng displ ays the output the
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
248 / FactoryLink ECS / Core Tasks Configuration Guide

CLI produces whi l e processi ng the request. Encl ose the desi red system command
i n doubl e quotes.
To obtai n di rectory li sti ngs of fi l es in the current (acti ve) dri ve/path, use:
SYSTEM(ls)
UNI X returns a status code wi th 1 i ndi cati ng status and any non-zer o val ue
indi cati ng fai l ure. Vi rtual l y any system command val i d from the normal UNI X
prompt i s val i d when sent through the SYSTEM functi on.
Note that usi ng thi s feature makes procedures non-portabl e wi thout manual
conversi on of the system cal l s to those appropr i ate i n the tar get system.
Calling Functions that Operate on Tag IDs (CML Only)
Math and Logi c provi des a functi on that l ooks up tag names and retri eves thei r
tag I Ds so devel opers can cal l and use functi ons that operate on tag I Ds and not
tag names. Thi s functi on i s:
int fl_tagname_to_id(TAG*tp, int num, char*tagname,...);
where
TAG*tp is a poi nter to a devel oper -suppl i ed tag ar ray to be fi l l ed i n wi th
tag I Ds
int num is the number of tag names to l ook up.
char* is one or mor e char acter poi nters to val i d tag names.
Thi s functi on returns a code indi cati ng ei ther GOOD or ERROR. I t is desi gned for
devel opers who i ntegrate C source code i nto thei r Math and Logi c programs and i s
avai l abl e through the CML run-ti me l i brary.
By usi ng fl _tagname_to_i d() i nsi de CML C code bl ocks, devel opers can l ook up one
or mor e tag names and fi l l i n a devel oper-suppl i ed tag ar r ay wi th the tag I D for
each tag name. Devel opers can then use these Tag I Ds wi th the FactoryLi nk PAK
functi ons, and any other functi on that oper ates on the tag I D i nstead of the tag
name, just as the Math and Logi c grammar does.
fl _tagname_to_i d() i s a vari abl e argument functi on l i ke pri nt. The devel oper can
r etri eve as many val i d tag I Ds as tag arr ay has r oom for .
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
FactoryLink ECS / Core Tasks Configuration Guide / 249
9
M
a
t
h

a
n
d

L
o
g
i
c
The fol l owi ng exampl e shows how to use fl _tagname_to_i d():
I n thi s exampl e, the functi on r etr i eves the tag I Ds for the two real -ti me database
el ements TI ME and DATE and pl aces thei r I Ds i nto the tag ar r ay named l i st.
.
.
cbegin
void myfunc()
{
TAG list[2]
fl_tagname_to_id(list, 2, TIME, DATE);
.
.
}
cend
MATH AND LOGIC PROCEDURES AND FUNCTIONS
Technical Notes
250 / FactoryLink ECS / Core Tasks Configuration Guide

FactoryLink ECS / Core Tasks Configuration Guide / 251

10
M
a
t
h

a
n
d

L
o
g
i
c
Chapter 10
Compi l ed Math and
L ogi c
The FactoryLi nk Math and Logi c task executes user wri tten procedures, i .e.,
scri pts that coordi nate objecti ves and other FactoryLi nk tasks. These procedures
can be wr i tten so, at r un ti me, they ar e tri gger ed by responses to changes i n the
RTDB or they can be executed di rectl y fr om wi thi n other Math and Logi c
procedures.
Math and Logi c i s a task that incl udes i ntegrati ng several components. These
work i n the fol l owi ng rel ati onship.
COMPILED MATH AND LOGIC
252 / FactoryLink ECS / Core Tasks Configuration Guide

Pre-FactoryLink Run Mode Setup


1. System Confi gurati on Panel Setup
2. Confi gurati on of FactoryLi nk Tabl e
A. Vari abl es Tabl e
B. Tri ggers Tab
C. Procedures [user constructed l ogi c]
IF in Interpreted Mode: IF in Compiled Mode:
appl i cati on i s ready to run processi ng procedures for runni ng
and FactoryLi nk appli cati on programs must be created:
starts. 1.PARSECML [produci ng C code]
2. CCCML [compili ng and l i nki ng
generated code]
3. Executabl es for domai ns ready
for runni ng [cuser.exe and
cshared.exe],
then FactoryLi nk appl i cati on starts.
Procedures Operating at Run Time
FactoryLi nk tasks are runni ng
Tri ggers are turni ng on and off
Procedure l ogi c i s runni ng in ei ther I ML or CML or Both
Orderly FactoryLink Shutdown
COMPILED MATH AND LOGIC
System Configuration Panel Setup Under IML/CML
FactoryLink ECS / Core Tasks Configuration Guide / 253
10
M
a
t
h

a
n
d

L
o
g
i
c
SYSTEM CONFIGURATION PANEL SETUP UNDER IML/CML
When you use I ML or CML, you must al ways determi ne the correct task setti ng i n
the System Confi gurati on Panel . The defaul t setti ng for the Math and Logi c task
i s to run i n I ML mode. To run Math and Logi c i n Compi l ed mode, the task name
must be changed to CML and the executabl e fi l e fi el d must be set to bi n/cml . You
may choose to run both I ML and CML tasks i n the same domai n. I f thi s i s the
case, you must add the second task. The best way to do thi s is to copy the l ast l i ne
i n the system confi gurati on panel and paste i t in bel ow the li ne just copi ed. You
can then change the fl ags, task name, descri pti on, and increment the i ndex of al l
array el ements start_tri gger through the displ ay_descri pti on. Make sure you
change the executabl e fi l e to bi n/i ml or bi n/cml , whi chever i s appl i cabl e.
COMPILED MATH AND LOGIC
Makefiles
254 / FactoryLink ECS / Core Tasks Configuration Guide

MAKEFI LES
A makefi l e i s a fi l e contai ni ng al l the i nformati on needed by the CCCML uti l i ty to
compi l e the .C fi l es produced by PARSECML and create an executabl e for the
current domai n. The name of the makefi l e used by CCCML i s CML.MAK, and i s
uni que for each operati ng system.
The CML.MAK fi l e, l ocated i n the /FLINK/CML di rector y, contai ns the fol l owi ng
i nformati on to create the fi nal executabl e fi l e:
Name of the C compil er to use for a gi ven operati ng system
Command-l i ne swi tches to be used when compi l i ng
Name of the operati ng systems object l i nker
Li nker command-l i ne swi tches
References to the FactoryLi nk l i brari es to be l i nked
References to the devel oper-suppli ed l i brari es to be l i nked
Editing CML.MAK
As an ai d for advanced users, CML provi des a method for edi ti ng the CML.MAK
fi l e. You can change the compi l er and l i nker opti ons, speci fy command-l i ne
swi tches, and speci fy whi ch object fi l es and l i brari es to l i nk, gi vi ng you the
fl exi bi l i ty to cr eate a makefi l e uni que to an appl i cati on for a gi ven domai n.
CML provi des two opti ons on the Mai n Menu for edi ti ng CML.MAK:
Math and Logic System Makefile
Math and Logic Domain Makefile
Math and Logic System Makefile
Any changes made to thi s fi l e are gl obal ; they appl y to al l appl i cati ons on the
system. To edi t CML.MAK:
1 Choose Math and Logi c System Makefi l e fr om the Mai n Menu to di spl ay a text
edi tor contai ni ng the CML.MAK fi l e from the /FLI NK/CML di rectory.
2 Edi t the fi l e as requi red.
3 Save and exi t the fi l e.
COMPILED MATH AND LOGIC
Makefiles
FactoryLink ECS / Core Tasks Configuration Guide / 255
10
M
a
t
h

a
n
d

L
o
g
i
c
Math and Logic Domain Makefile
The fi rst ti me you choose Math and Logi c Domai n Makefi l e from the Mai n Menu,
an empty text edi tor i s di splayed because a domai n-speci fi c makefi l e does not
exi st. You can create one usi ng the master makefil e CML.MAK i n the /FLINK/CML
di r ector y as a model . To cr eate a domai n-speci fi c makefi l e:
1 Copy CML.MAK fr om the /FLINK/CML di rectory to ei ther:
/FLAPP/USER/CML di r ector y for the user domai n
/FLAPP/SHARED/CML di r ector y for the shared domai n
2 Open the Mai n Menu and ensure the current domai n sel ected i n the
Confi gurati on Manager Sel ecti on box matches the domai n of the makefi l e you are
creati ng.
3 Choose Math and Logi c Domai n Makefi l e fr om the Mai n Menu to displ ay a text
edi tor contai ni ng the domai n-speci fi c makefi l e CML.MAK copi ed i n Step 1.
4 Edi t the fi l e as requi red.
Any defi ni ti ons i n the domai n-speci fi c makefi l e i n the appli cati on di rectory
overri de the defi ni ti ons i n the master makefi l e i n /FLINK/CML di rectory.
5 Save and exi t the fi l e.
COMPILED MATH AND LOGIC
The CML Process
256 / FactoryLink ECS / Core Tasks Configuration Guide

THE CML PROCESS


When you have compl eted confi guri ng the three tabl es, Vari abl es Tabl e, Tri ggers
Tabl e, and Procedures Tabl e, you have created the processi ng procedures for
runni ng programs i n CML. The fol l owi ng di scusses the process i nvol ved i n
produci ng an executabl e fi l e for the gi ven domai n fr om the .PRG fi l es.
CML i s made up of several FL uti l i ti es al ong wi th a thi rd-party ANSI C l anguage
compi l er worki ng together at run ti me to gener ate ANSI C code fr om the *.pr g
fi l es you created. Thi s C code i s then compil ed and li nked to produce an executabl e
for each domai n confi gured to run in CML.
Thi s process begi ns when you create the *.pr g fi l es i n confi gurati on manager wi th
the procedure edi tor. At run ti me or fr om runni ng FL uti l i ti es, the *.pr g fi l es are
parsed [parsecml -Nuser -V2 -CJ] whi ch produces C code fr om the procedure fi l es.
The compil er i s then cal l ed to produce the associ ated object fi l es. Thi s i s fol l owed
by the l i nker cal l ed to l i nk the objects together to gener ate the executabl e for the
gi ven domai n.
Thi s occurs i n both the SHARED and the USER domai ns. The associ ated
executabl es are
/{FLAPP}/USER/CML/CUSER.EXE for the USER domai n
/{FLAPP}/SHARED/CML/CSHARED.EXE for the SHARED domai n
COMPILED MATH AND LOGIC
Generation of CML Executables
FactoryLink ECS / Core Tasks Configuration Guide / 257
10
M
a
t
h

a
n
d

L
o
g
i
c
GENERATION OF CML EXECUTABLES
The executabl es generated are
{FLAPP}/SHARED/CML/CSHARED.EXE
{FLAPP}/USER/CML/CI SER.EXE
1. Val i dati on
The fi rst step i n the process i s savi ng the procedure wi th the FactoryLi nk
procedure edi tor. When you save, the grammar syntax of the procedure i s
checked by the math val idati on uti l i ty. Al ways make sure al l procedures
val i date and al l l i nes are l ess than 80 characters i n l ength. Other wi se, your
resul ts wil l be unpredi ctabl e.
a. The val idati on routi ne ei ther accepts the source as i t has been i nput or i t
hi ghl i ghts i t i n red. You must correct al l grammar syntax before proceedi ng
wi th the devel opi ng of the process of generati ng C code.
2. Generati on of C code
The PARSECML uti l i ty used to generate C code i s
{parsecml { [-NDOMAI N] [-V[0-5]] [-c] di scussi on to fol l ow.}
The procedure i s then parsed and the I ML code i s read and converted i nto
ANSI C code. The uti l i ty that parses the i ml grammar and produces ANSI C
code i s PARSECML.exe. Thi s may recei ve several di fferent arguments
(di scussed l ater) when cal l ed.
a. The I ML gr ammar syntax that you have entered and the edi tor has
val i dated is now processed by the parser.
b. CML gener ates one or mor e fi l es that li st the tri ggered procedures. These
fi l es are named cml proc*.c where * i s an i nteger 0 through 9. The fi l es each
contai n 512 decl arati ons of tri ggered procedures. I f the si ze of the appli cati on
war r ants, then you may have several fi l es of the format, cml proc0.c,
cml pr oc1.c, and so forth.
c. Al l the gl obal data decl ared i n the procedure is processed and put i n the fi l e
gl vars.c and gl vars.h. These two fi l es are created by the CML task. The fi l e
gl vars.h al so hol ds functi on prototypes for user-defi ned functi ons or
procedures. The fi l e gl vars.c al so contai ns a functi on defi ni ti on: long
fl_ftol(double). Thi s functi on i s requi red i n conversi ons of fl oati ng-poi nt val ues
to a l ong integer val ue. When type casti ng a fl oati ng-poi nt to a l ong, a cal l i s
COMPILED MATH AND LOGIC
Generation of CML Executables
258 / FactoryLink ECS / Core Tasks Configuration Guide

made to a compi l er speci fi c functi on to convert the compi l ers i nternal stor age
format of fl oati ng-poi nt val ues to a l ong i nteger val ue. Thi s functi on i s uni que
to each compi l er manufacturer and they may name the conversi on functi on
di fferentl y.
I nsi de the CML l i brary, you need to perfor m fl oati ng-poi nt to l ong conversi ons.
To be abl e to suppor t the MSC 6.0 and I BM C/2 compi l ers for FactoryLi nk for
OS/2, we have created the functi on long fl_ftol(double) and pl aced i t i n the fi l e
gl vars.c. I n the CML l i brary, we cal l thi s functi on onl y when casti ng
fl oati ng-poi nts to l ongs. Thi s resul ts i n compi l er i ndependence.
Remember: gl obal vari abl es are user-defi ned vari abl es that are decl ared
outsi de the body of any procedure. Al l gl obal data i s pl aced i n gl vars.c.
d. Al l the FactoryLi nk tags used in the procedures that are al so i n the
FactoryLi nk (RTDB) Real -Ti me DataBase are l i sted i n the fi l e named tags*.bi n
and is created by the CML task. These fi l es ar e named i n si mi l ar fashi on as the
cml pr oc*.c fi l es. Each fi l e can contai n 500 tags. When the 500 tag li mi t is
reached, cl ose the current tags*.bi n fi l e and start the next one, i .e., tags0.bi n,
tags1.bi n, and so for th. These fil es ar e of bi nar y for mat. You can vi ew the
contents usi ng a hex edi tor (DOS debug). The tags*.bi n fil es contai n a li sti ng of
the tag segment and offset i n theFactoryLi nk RTDB,FactoryLi nk type i n
i nteger for mat and the di mensi on of ar r ay i f the tag i s an arr ay. CML
references thi s i nformati on at run ti me by l ooki ng thi s informati on up and not
havi ng to cal cul ate i t. Thi s reduces the CML overhead and makes for a ver y
effi ci ent process.
e. The pure C code that li es between the CBEGI N ...CEND keywords wi l l not
be parsed. I t wi l l be transl ated di rectl y to the generated C fi l e. The l ocati on in
the fi l e wi l l be preserved.
f. The par secml executabl e can be r un fr om the command l i ne. Thi s i s an
excel l ent debug tool to assur e yoursel f that the associ ated PRG fi l es have the
cor r ect syntax.
I f the FLAPP envi ronment vari abl e i s set, you may execute parsecml wi th no
ar guments.
I f you want control in executi ng parsecml , you can cal l i t wi th the fol l owing
ar guments.
COMPILED MATH AND LOGIC
Generation of CML Executables
FactoryLink ECS / Core Tasks Configuration Guide / 259
10
M
a
t
h

a
n
d

L
o
g
i
c
parsecml [ [-V[1-5]] [-Nuser] [-C] ]
Syntax of arguments:
- V[1-5] Thi s speci fi es the verbose l evel bui l t i nto the parsed C code
that FL produces. The di fferent l evel s do the fol l owi ng:
Usage: -V2 or -V5, etc.
Verbose Level Acti on
1 pri nts out fi l e names as they are parsed
2 pri nts out funcs/pr oc names as they are parsed
3 pl aces pri ntf()s i n each functi on to show entry
and exi t of that functi on
4 pl aces pri ntf()s i n each functi on to di spl ay each
l i ne as i t executes. Al so pri nts out the recei ved
val ues of procedures to the displ ay when they
are cal l ed.
5 Displ ays the l exemes of the functi ons as they are
parsed
-NDOMAI N Thi s argument speci fi es domai n FactoryLi nk
uti l i ty:
Usage:-Nuser or -Nshared
-C Thi s argument speci fi es that you want a cl ean
rebuild of al l the *.c fi l es generated. Thi s i s the
same as del eti ng al l the fi l e in the
{FLAPP}/user/cml , or {FLAPP}/shared/cml di rectori es. {
COMPILED MATH AND LOGIC
Generation of CML Executables
260 / FactoryLink ECS / Core Tasks Configuration Guide

The use of the verbose l evel s -V3 and above can cause the li nker er r or , DGROUP
Exceeds 64K. Thi s i s because of the l ar ge number of stri ngs inser ted i n the
pri ntf(...) statements. Pl ease li mi t the use of -V3 and above to debug use onl y.
g. The fol l owi ng i s the output from the command li ne when runni ng:
[E:\FLNEW\USER\CML]parsecml -V2 -Nuser -C
creati ng tag defi ni ti on fi l e: e:\FLNEW\user\cml \tags0.bi n
processi ng fil e: e:\FLNEW\user\cml \test.c
procedur e: test
[E:\FLNEW\USER\CM]
The fol l owi ng i s the output fr om: parsecml -V5 -Nuser -C
[E:\FLNEW\USER\CML]parsecml -V5 -Nuser -C
creating tag definition file: e:\FLNEW\user\cml\tags0.bin
processing file: e:\FLNEW\user\cml\test.c
procedure: test
(279)T_PROC :test
(277)T_BEGIN :00000000
(260)T_EQ :llocvar
(290)T_INT :00000000
(311)T_DOT :llocvar = 0
(318)T_PRINT :00000000
(293)T_STRING :You have entered the body of PROC
test.prg\n
(311)T_DOT :PRINT You have entered the body of PROC
COMPILED MATH AND LOGIC
Generation of CML Executables
FactoryLink ECS / Core Tasks Configuration Guide / 261
10
M
a
t
h

a
n
d

L
o
g
i
c
test.prg\n
(276)T_WHILE :00000000
(320)T_LVAR :LLOCVAR
(290)T_INT :00000003
(259)T_LE :00000000
(277)T_BEGIN :00000000
(311)T_DOT :WHILE llocvar <=3
(318)T_PRINT :00000000
(293)T_STRING :INSIDE THE WHILE LOOP\n
(311)T_DOT :PRINT INSIDE THE WHILE LOOP\n
(260)T_EQ :llocvar
(320)T_LVAR :llocvar
(290)T_INT :00000001
(269)T_ADD :00000000
(311)T_DOT :llocvar = llocvar + 1
(278)T_END :00000000
(311)T_DOT :WEND
(365)T_CCODE :printf(FactoryLink is the Best\n);
(365)T_CCODE :for(i = INITVAL; I<=UPBOUND; i+=INCREMENT) {
(365)T_CCODE :/*i,INITVAL, UPBOUND, INCREMENT, are defined
and declared in test.h
(365)T_CCODE :Body of for loop..., must be careful of
referencing
(365)T_CCODE :factorylink tags in CBEGIN ...CEND, block,
must assign the tag to a local
(365)T_CCODE :outside of block and then process the local
and then assign value back
(365)T_CCODE :to tag outside of the CBEGIN ... CEND bloc.






COMPILED MATH AND LOGIC
Generation of CML Executables
262 / FactoryLink ECS / Core Tasks Configuration Guide

(365)T_CCODE :*/
(365)T_CCODE :printf(inside the for loop\n);
(365)T_CCODE :}
(365)T_CCODE :
(311)T_DOT :
(278)T_END :00000000
( 0)T_BADTOK :00000000
[E:\FLNEW\USER\CML]
3. Descri pti on of the fi l es generated by parsecml
The fol l owi ng test.c i s generated by parsecml -V3 -NUSER -C
/*File:------------test.c---------------*/
#include <stdio.h>
#include <stdlib.h>
#include <flib.h>
#include <math.h>
#include <string.h>
#include <cml.h>
#include glvars.h
#include <test.h>
void test( void)
{
long llocvar;
char strlocvar[MAXMSG];
short slocvar
double flocvar;
COMPILED MATH AND LOGIC
Generation of CML Executables
FactoryLink ECS / Core Tasks Configuration Guide / 263
10
M
a
t
h

a
n
d

L
o
g
i
c
memset( &llocvar, 0, sizeof( llocvar ) );
memset( strlocvar, 0, sizeof( strlocvar ) );
memset( &slocvar, 0, sizeof( slocvar ) );
memset( &flocvar, 0, sizeof( flocvar ) );
Procname = test
printf(\nCML: Entering procedure: test\n);
cirstack();
/* PRINT INSIDE THE WHILE LOOP\N */
cirstack();
pushstr( INSIDE THE WHILE LOOP\N);
doprint(pop());
/* llocvar = llocvar + 1 */
puchlong( llocvar);
pushint( 1 );
doadd();
llocvar = poplong();
}
/*WEND*/
printf(FactoryLink is the best\n);
for(i = INITVAL; i <= UPBOUND; i += INCREMENT) {
/*I, INITVAL, UPBOUND, INCREMENT, are defined and
declared in test.h
COMPILED MATH AND LOGIC
Generation of CML Executables
264 / FactoryLink ECS / Core Tasks Configuration Guide

Body of for loop..., must be careful of referencing


factorylink tags in CBEGIN ...CEND block, must assign the
tag to a local outside of block and then process the local
and then assign value back to tag outside of the CBEGIN
... ECEND block.
*/
printf(Inside the for loop\n)
}
printf(CML: Leaving procedure: test\n)>
}
4. Uti l i ty that l i nks the associ ated object fi l es to produce the executabl e
Usage: cccml [-NDOMAIN]
5. The next process that happens to the generated ANSI C code i s to be l i nked
wi th the other fi l es and necessary li brari es to produce the domai n executabl e
fi l e {FLAPP}/SHARED/CML/CSHARED.EXE or
{FLAPP}USER/CML/CUSER.EXE. The l i nki ng i s done by a cal l to the uti l i ty
cccml .exe. Thi s functi on is gi ven a l i st of the object modul es to be li nked to
produce the executabl e. The l i st of objects i s i n the fi l e, cml .l nk.
Fil e: cml .l nk
/NOE/ST:16384/SE:512test +
syscp++
cfunk +
cbwtags +
gl vars +
CMLPROC0
e:\FLNEW\user\cml \cuser.exe
cml .map
E:\FLOS2431\l i b\fl i b.l i b +
e:\FLOS2431\l i b\cml .li b +
COMPILED MATH AND LOGIC
Generation of CML Executables
FactoryLink ECS / Core Tasks Configuration Guide / 265
10
M
a
t
h

a
n
d

L
o
g
i
c
E:\FLOS2431\cml \cml .def
Thi s fi l e, cml .l nk, i s the fi l e passed to the l i nker. I t tel l s the l i nker what fi l es and
l i brari es need to be l i nked together to produce the desi red executabl e: cuser .exe or
cshared.exe.
6. Uti l i ty mkcml.exe
Thi s uti l i ty encompasses al l of the uti l i ti es that compri se the generati on of C
code. Usual l y you wi l l cal l mkcml i nstead of separatel y cal l i ng al l of the other
steps. Thi s uti l i ty cal l s ctgen to make sure the i ml .ct i s up to date, then i t cal l s
parsecml to parse the code, and fi nal l y i t cal l s cccml to l i nk the associ ated fi l es
and produce an executabl e. Remember that arguments are not case sensi ti ve.
The syntax of ml cml i s as fol l ows.
COMPILED MATH AND LOGIC
Generation of CML Executables
266 / FactoryLink ECS / Core Tasks Configuration Guide

mkcml [ [-V[1-5] ] [-NDOMAIN] [-C] ]


Syntax of ar guments:
- V[1-5] Thi s speci fi es the verbose l evel bui l t into the parsed C code
that FL produces. The di ffer ent l evel s do the fol l owi ng:
Usage: -V2 or -V5, etc.
Verbose Level Acti on
1 pri nts out fi l e names as they are parsed
2 pri nts out funcs/pr oc names as they are parsed
3 pl aces pri ntf()s i n each functi on to show entr y
and exi t of that functi on
4 pl aces pri ntf()s i n each functi on to di spl ay each
l i ne as i t executes. Al so pri nts out the recei ved
val ues of procedures to the di spl ay when they
ar e cal l ed.
5 Di spl ays the l exemes of the functi ons as they are
parsed
-NDOMAI N Thi s argument speci fi es domai n FactoryLi nk
uti l i ty:
Usage:-Nuser or -Nshared
-C Thi s argument speci fi es that you want a cl ean
rebui l d of al l the *.c fil es generated. Thi s is the
same as del eti ng al l the fil e i n the
{FLAPP}/user/cml , or {FLAPP}/shared/cml di rectori es. {
COMPILED MATH AND LOGIC
Generation of CML Executables
FactoryLink ECS / Core Tasks Configuration Guide / 267
10
M
a
t
h

a
n
d

L
o
g
i
c
The fol l owi ng is the output of runni ng mkcml -V2 -Nuser -C:
creating tag definition file: D:\CMLDOC\ZIP\FLAPP\user\cml\tags0.bin
processing file: D:\CMLDOC\ZIP\FLAPP\user\cml\test.c
procedure: test
processing file: D:\CMLDOC\ZIP\FLAPP\user\cml\syscp.c
procedure: syscp
processing file: D:\CMLDOC\ZIP\FLAPP\user\cml\cfunk.c
procedure: cfunk
processing file: D:\CMLDOC\ZIP\FLAPP\user\cml\cbwtags.c
procedure: cbwtags
test.c
syscp.c
cfunk.c
cbwtags.c
glvars.c
Building Compiled Math and Logic task for application
D:\CMLDOC\ZIP\FLAPP
at domain: user
Compiling: cl -DOS2 -Au -Od -Zp -G2s -nologo -c -ID:\FLOS2431\inc
test.c
Compiling: cl -DOS2 -Au -Od -Zp -G2s -nologo -c -ID:\FLOS2431\inc
syscp.c
Compiling: cl -DOS2 -Au -Od -Zp -G2s -nologo -c -ID:\FLOS2431\inc
cfunk.c
Compiling: cl -DOS2 -Au -Od -Zp -G2s -nologo -c -ID:\FLOS2431\inc
cbwtags.c
Compiling: cl -DOS2 -Au -Od -Zp -G2s -nologo -c -ID:\FLOS2431\inc
glvars
Compiling: cl -DOCCMLPROC0.C
COMPILED MATH AND LOGIC
Generation of CML Executables
268 / FactoryLink ECS / Core Tasks Configuration Guide

Microsoft (R) Segmented-Executable Linker Version 5.10


Copyright (C) Microsoft Corp 1984-1990. All rights reserved.
Object Modules [.OBJ]: /NOE/ST:16384/SE:512 test +
Object Modules [.OBJ]: syscp +
Object Modules [.OBJ]: cfunk +
Object Modules [.OBJ]: cbwtags +
Object Modules [.OBJ]: glvars +
Object Modules [.OBJ]: CMLPROC0
Run File [test.exe]: D:\CMLDOC\ZIP\FLAPP\user\cml\cuser.exe
List File [NUL.MAP]: cml.map
Libraries [.LIB]: D;\FLOS2431\lib\flib.lib +
Libraries [.LIB]: D;\FLOS2431\lib\cml.lib +
Definitions File [NUL.DEF]: D:\FLOS2431\cml\cml.def;
S2 -Au -Od -Zp -G2s -nologo -c -ID:\FLOS2431\inc CMLPROC0.c
Linking: link @cml.lnk
Executing: D:\FLOS2431\bin\ctgen.exe -diml.ctg -AD:\CMLDOC\ZIP\FLAPP
-v
Switching to domain: user
Updating Compiled Math and Logic Task for Domain: user
Executing: D:\FLOS2431\bin\parsecml.exe -AD:\CMLDOC\ZIP\FLAPP -nuser
-v2 -c
Executing: D:\FLOS2431\bin\cccml.exe -AD:\CMLDOC\ZIP\FLAPP -nuser -v2
-c
The executi on of fl run wi l l cal l the uti l i ty mkcml for you. We r ecommend runni ng
mkcml befor e runni ng fl run. I n thi s way, al l errors are cl earl y seen and the
appl i cati on does not start up unti l you are sure that al l Math and Logi c i s
syntacti cal l y correct.

Part VI I
Scaling & Deadbanding
Core Tasks Confi gurati on Gui de
FactoryLink ECS / Core Tasks Configuration Guide / 271
Table of Contents
Scal i ng & Deadbandi ng

11 Scaling & Deadbanding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273


Pri nci pl es of Operati on . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Defi ni ng Scal i ng and Deadbandi ng Operati ons. . . . . . . . . . . . . . . . . . . . . . 276
Scaling & Deadbanding in this book
Scaling & Deadbanding in the Core Tasks Con-
figuration Guide
272 / FactoryLink ECS / Core Tasks Configuration Guide

Scaling & Deadbanding


11
S
c
a
l
i
n
g

a
n
d

D
e
a
d
b
a
n
d
i
n
g
FactoryLink ECS / Core Tasks Configuration Guide / 273

Chapter 11
Scal i ng &
Deadbandi ng
The Scal i ng and Deadbandi ng task (SCALE.EXE) i s used to convert, or scal e,
i ncomi ng raw data to a di ffer ent val ue range and to i ndi cate a dead or
non-recal cul ati ng band around a scal ed val ue.
The l i near scal i ng featur e of the task i s used to convert or scal e the i ncomi ng raw
data to a di fferent val ue range. Many val ues read from a pr ogrammabl e l ogi c
control l er (PLC) are i n uni ts other than those the user wi shes to displ ay,
mani pul ate and/or archi ve. Use of the scal i ng task el i mi nates the need to process
data through an i ntermedi ate routi ng mechani sm and the need to wri te code to
per for m the scal i ng functi on when the scal i ng i s li near. The scal i ng task, i f gi ven
ranges for the incomi ng and desi red data val ues, can deri ve the necessary
conversi on factor and/or offset and perform the l i near scal i ng cal cul ati ons
automati cal l y usi ng the for mul a:
mx + b = y
where x i s the r aw val ue, m i s the mul ti pli er , b i s a constant and y i s the resul t.
The Deadbandi ng task i s used to indi cate a band, or area, around a val ue smal l
enough to be consi dered i nsi gni fi cant. I n thi s case, the new val ue is stored and a
new deadband recal cul ated, but the new val ue i s not wr i tten to the pr ogr am
database. Si nce FactoryLi nk tasks process val ues upon every change,
deadbandi ng provi des a means of savi ng processi ng ti me and i mpr ovi ng system
effi ci ency. Note that the deadbanding por ti on of the functi on cannot be
i mpl emented wi thout confi guri ng the scal i ng por ti on of the functi on.
Refer to the Application Editor Guide for mor e i nformati on on how the Scal i ng
and Deadbanding featur e wor ks i n the Appl i cati on Edi tor.
SCALING & DEADBANDING
Principles of Operation
274 / FactoryLink ECS / Core Tasks Configuration Guide

PRINCIPLES OF OPERATION
Scal i ng i s onl y avai l abl e i n the SHARED domai n. The scal i ng functi on onl y
appl i es for tags wi th an anal og, l ongana or fl oat data type.
Scal i ng i s confi gured usi ng a pai r of r anges: one for r aw val ues and one for scal ed
val ues. These ranges can be speci fi ed as constants or tags. I f one or more of the
range tags i s changed, the scal i ng formul a i s adjusted accordi ngl y.
When a val ue is wri tten to a r aw val ue tag, i ts rel ated scal ed val ue tag is updated
accordi ngl y. When a val ue i s wri tten to a scal ed val ue tag, i ts r aw val ue tag i s
updated accordi ngl y. The former is cal l ed a r aw-to-scal ed conversi on. The l atter is
cal l ed a scal ed-to-r aw conversi on.
Pri or to changi ng a range tag, r aw val ue tag or scal ed val ue tag, the functi on
shoul d be di sabl ed usi ng the Scal i ng Lock Tag. When the Scal i ng Lock Tag has a
non-zer o val ue, changes made to the tag ar e not propagated to thei r rel ated
members. After the changes to that functi on have been made and the functi on has
been re-enabl ed, the current r aw val ue i s scal ed and wr i tten to the scal ed val ue
tag. Any changes to the ranges are appl i ed to the scal ed val ue as wel l .
Deadbandi ng, whi ch appli es to r aw-to-scal ed conversi on but not to scal ed-to-r aw
conversi on, may be speci fi ed i n one of two ways: as an absol ute (ABS) number of
Engi neeri ng Uni ts (EUs) or as a percentage (PCT) of the scal ed range. Duri ng
r aw-to-scal ed conversi on, a newl y cal cul ated scal ed val ue that does not exceed the
deadband wi l l not be wri tten to the database. I f deadbanding i s bei ng appli ed to a
tag associ ated wi th scal i ng rather than a speci fi c al pha-numeri c r ange, then
deadbandi ng shoul d be speci fi ed by a percentage of a range r ather than as an
absol ute val ue. I f the deadband vari ance for a scal ed tag i s speci fi ed as an
absol ute val ue, then no deadbanding i s appli ed to the associ ated r aw tag.
Note
I f Scal i ng and Deadbanding i s confi gured from the Appl i cati on
Edi tor, the system automati cal l y assi gns defaul t tag names for
r aw and scal ed val ues (even i f entered as a constant), deadbandi ng
and scal i ng l ock functi ons. However , i f Scal i ng and Deadbandi ng i s
confi gured fr om wi thi n the Confi gurati on Manager, onl y those tags
speci fi ed by the desi gner ar e created.
SCALING & DEADBANDING
Principles of Operation
FactoryLink ECS / Core Tasks Configuration Guide / 275
11
S
c
a
l
i
n
g

a
n
d

D
e
a
d
b
a
n
d
i
n
g
For thi s exampl e, assume the temperature of the l i qui d i n a tank i s bei ng
moni tored. The tank temperature probe records raw (i ncomi ng) data on a Cel si us
scal e. The operators moni tori ng the temper atur e ar e mor e fami l i ar wi th the
Fahrenhei t scal e and wish to have the data di spl ayed on that scal e.
The temperature never fal l s bel ow fr eezi ng or above the boi l i ng poi nt.
SCALING & DEADBANDING
Defining Scaling and Deadbanding Operations
276 / FactoryLink ECS / Core Tasks Configuration Guide

DEFINING SCALING AND DEADBANDING OPERATI ONS


1 To open Scal i ng & Deadbandi ng, open the Confi gurati on Manager Mai n Menu
and ensure the current domai n sel ected i s SHARED i n the Confi gurati on
Manager Domai n Sel ecti on box.
2 Doubl e-cl i ck Scal i ng and Deadbandi ng fr om the Confi gurati on Manager Mai n
Menu to open the Scal i ng and Deadbandi ng tabl e.
3 Enter the fol l owi ng i nformati on for each scal i ng or deadbanding operati on.
Scaled Tag Enter the name of the tag to whi ch scal ed val ues wi l l be wr i tten.
I n thi s exampl e, the tag is named tank_temp_f (for tank
temperature i n Fahrenhei t scal e)
Raw Tag The tag for the fi el d fr om whi ch r aw val ues ar e to be read. I n thi s
exampl e, the tag is named tank_temp.
Minimum Raw
Value
The l owest val ue for r aw data. Ei ther a constant val ue or a tag
can be speci fi ed i n thi s fi el d. For thi s exampl e, raw data i s bei ng
read on the Cel si us scal e. Because the temperature wil l never
drop bel ow freezi ng, thi s means a mi ni mum r aw val ue of 0
degrees on the Cel si us scal e.
Maximum Raw
Value
The hi ghest val ue for r aw data. Ei ther a constant val ue or a tag
can be speci fi ed i n thi s fi el d. For thi s exampl e, raw data i s bei ng
read on the Cel si us scal e. The temperature wi l l never ri se above
boi l i ng or a maxi mum raw val ue of 100 degrees on the Cel si us
scal e.
SCALING & DEADBANDING
Defining Scaling and Deadbanding Operations
FactoryLink ECS / Core Tasks Configuration Guide / 277
11
S
c
a
l
i
n
g

a
n
d

D
e
a
d
b
a
n
d
i
n
g
Minimum Eng. Unit The l owest val ue for scal ed data. Ei ther a constant val ue or a tag
can be speci fi ed i n thi s fi el d. For thi s exampl e, scal ed data i s
bei ng converted to a Fahrenhei t scal e. The temperature wi l l
never drop bel ow freezi ng or a mi ni mum engi neeri ng uni t val ue
of 32 degrees on the Fahrenhei t scal e.
Maximum Eng.
Unit
The hi ghest val ue for scal ed data. Ei ther a constant val ue or a tag
can be speci fi ed i n thi s fi el d. For thi s exampl e, r aw data i s bei ng
read on the Fahrenhei t scal e. The temperature wi l l never ri se
above boi l i ng or a maxi mum engi neeri ng uni t val ue of 212
degrees on the Cel si us scal e.
Deadband Value The amount, i n ei ther absol ute val ue or percent of total val ue
that, when appl i ed, creates a range on ei ther si de of the val ue i n
whi ch the recal cul ated val ue does not have to be wri tten to the
database. For thi s exampl e, temperature changes of l ess than 2%
i n a shor t peri od of ti me are not of concer n for thi s process. Thi s
woul d be refl ected i n a deadband val ue of 2 wi th PCT chosen for
the Deadband Abs./Pct. fi el d.
I f a tag name i s speci fi ed for the deadband val ue rather than an
i nteger, no deadbandi ng occurs unti l a val ue i s wri tten to the
speci fi ed tag fr om the database.
SCALING & DEADBANDING
Defining Scaling and Deadbanding Operations
278 / FactoryLink ECS / Core Tasks Configuration Guide

Deadband
Abs./Pct.
Enter Absol ute or Percentage to i ndi cate i f the deadband val ue
speci fi ed i s an absol ute number of engi neeri ng uni ts (EUs) or a
percentage of the scal ed val ue range. For thi s exampl e, a
deadband val ue of 2 per cent (PCT) has been sel ected.
Equi val entl y, si nce 2% of 180% Fahrenhei t is 3.6 degrees, you
coul d speci fy an absol ute (ABS) deadband of 3.6.
Scaling Lock Tag Use thi s fi el d to temporari l y di sabl e the scal i ng featur e for the
scal ed tag. When the Scal i ng Lock Tag has a non-zer o val ue,
changes made to the tag are not propagated to thei r rel ated
members. After the changes to that functi on have been made and
the functi on has been re-enabl ed, the current r aw val ue is scal ed
and wr i tten to the scal ed val ue tag. I n thi s exampl e, i f the
i ncomi ng tank_temp data needed to be di sabl ed temporari l y in
order to al ter the temperature range, a scal i ng l ock tag named
disabl_temp coul d be speci fi ed. Thi s tag woul d have the functi on of
di sabl i ng the tank_temp tag. Once tank_temp has been changed,
the user woul d need to come back to thi s tabl e and r emove
disabl_temp fr om the Scaling Lock Tag fi el d.
4 Cli ck on Enter to save the data when you have compl eted enteri ng al l the
i nformati on on thi s panel . I f you have entered the names of any tags not al ready
defi ned, the Tag Definition di al og i s di spl ayed.

You might also like