Sunteți pe pagina 1din 512

TriStation 1131

Libraries Reference

TriStation 1131 Developers Workbench


Versions 4.0 and Later
Assembly Number 9700098-010
November 2010

Information in this document is subject to change without notice. Companies, names and data used in
examples herein are fictitious unless otherwise noted. No part of this document may be reproduced or
transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express
written permission of Invensys Systems, Inc.
20032010 by Invensys Systems, Inc. All rights reserved.
Invensys, the Invensys logo, Triconex, Tricon, Trident, and TriStation are trademarks of Invensys plc, its
subsidiaries and affiliates. All other brands may be trademarks of their respective owners.

Document Number 9720098-010


Printed in the United States of America.

Contents

Preface

ix
Summary of Sections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Related Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Product and Training Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
Technical Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . x
We Welcome Your Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

Chapter 1

Introduction

How to Use This Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2


Name and Brief Description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Parameters and Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Description and Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Runtime Errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Application Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Sample Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

Chapter 2

Functions and Data Types

ABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
ACOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
ADD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
AIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
AIN_BP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
AIN_BP12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
AIN_HR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
ALARM_DEVIATION_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
ALARM_DEVIATION_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
ALARM_LEVEL_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
ALARM_LEVEL_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
ALARM_ROC_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
ALARM_ROC_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
ALARM_TRIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
AND. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
AOUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
AOUT_BP12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
ARRAY32_BOOL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
ARRAY32_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
ARRAY32_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
ASIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
ATAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
BLINK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
BLINK_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
BLINK_R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
BOOL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

TriStation 1131 Libraries Reference

iv

Contents

BOOL_TO_DWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
BYPASS_BOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
BYPASS_DINT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
BYPASS_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
CEIL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
CHK_ERR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
CLR_ERR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
CONCAT_DT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
COS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
CSCHED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
CSCHED_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
CSCHED_R. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
CTD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
CTU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
CTUD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
DATE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
DINT_TO_DWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
DINT_TO_INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
DINT_TO_LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
DINT_TO_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
DIV. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
DT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
DT_TO_DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
DT_TO_TOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
DWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
DWORD_TO_BOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
DWORD_TO_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
EQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
EXP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
EXPFLTR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
EXPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
F_TRIG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
FLOOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
GASDETR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
GATDIS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
GATENB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
GE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
GetDelta_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
GetDelta_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
GetDeltaT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
GetTimer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
GT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
INFINITY_LREAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
INFINITY_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
INT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
INT_TO_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
INT_TO_LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
INT_TO_REAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
INTGTOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
INTGTOR_R. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
IsFinite_LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
IsFinite_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
IsNan_LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

TriStation 1131 Libraries Reference

Contents

IsNan_REAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
LE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
LEADLAG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
LEADLAG_R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
LIMIT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
LINEMNTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
LN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
LOG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
LOOPDETR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
LREAL_TO_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
LREAL_TO_INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
LREAL_TO_REAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
LT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
MAX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
MBCTRL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
MBREAD_BOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
MBREAD_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
MBREAD_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
MBREAD_REAL_TRD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
MBWRITE_BOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
MBWRITE_DINT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
MBWRITE_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
MBWRITE_REAL_TRD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
MEDSEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
MIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
MINUS_INFINITY_LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
MINUS_INFINITY_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
MOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
MOVE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
MUL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
MUX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
NAN_LREAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
NAN_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
NE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
NUMBITS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
NUMBITS_DWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
OVDDISABLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
OVDENABLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
PACK16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
PACK32. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
PAGE_EJECT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
PERDEV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
PID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
PID_R. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
POLY4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
POLY5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
PRINT_BOOL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
PRINT_CDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
PRINT_CRLF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
PRINT_CTOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
PRINT_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244

TriStation 1131 Libraries Reference

vi

Contents

PRINT_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
PRINT_STRING. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
PRNTR_FLUSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
R_TRIG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
REAL_TO_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
REAL_TO_INT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
REAL_TO_LREAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
ReportBadParam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
ROL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
ROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
RS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
RTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
SCALE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
SEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
SHL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
SHR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
SIN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
SOECLR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
SOESTAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
SOESTOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
SOESTRT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
SQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
STRING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
SUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
SYS_AI32_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
SYS_AO04_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
SYS_APP_HALT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
SYS_CLEAR_FLTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
SYS_CM_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
SYS_CRITICAL_IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
SYS_DI16_AI16_STATUS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
SYS_DI32_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
SYS_DO16_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
SYS_HRDI32_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
SYS_IO_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
SYS_IOP_STATUS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
SYS_MP_EXT_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
SYS_MP_RESET_PORTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
SYS_MP_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
SYS_OVD_INHIBIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
SYS_PI06_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
SYS_RO32_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
SYS_SDO16_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
SYS_SERIAL_PORT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
SYS_SET_APP_LOCK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
SYS_SET_PROG_ALARM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
SYS_SET_REMOTE_WRT_ENBL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338
SYS_SHUTDOWN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
SYS_SYSTEM_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
SYS_VOTE_MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
TAN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
TCJ_CONV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348

TriStation 1131 Libraries Reference

Contents

vii

TCK_CONV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
TDD_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
TDD_R. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
TDE_I. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
TDE_R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
TIME_TO_SECS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
TIME_TO_SECS_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360
TIMEADJ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
TIMESET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
TMR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
TMR_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
TMR_R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
TOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
TOF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
TOGGLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
TON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
TP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
TP_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
TP_R. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
TR_64_POINT_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
TR_CALENDAR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
TR_CHASSIS_STATUS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
TR_CLEAR_FLTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
TR_CRITICAL_IO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
TR_MP_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
TR_PEER_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
TR_POINT_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
TR_PORT_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
TR_PROGRAM_STATUS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
TR_SCAN_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
TR_SHUTDOWN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
TR_SLOT_STATUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
TR_URCV_BOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
TR_URCV_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
TR_URCV_DINT_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
TR_URCV_REAL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
TR_URCV_REAL_32. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
TR_USEND_BOOL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
TR_USEND_DINT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
TR_USEND_DINT_32. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
TR_USEND_REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
TR_USEND_REAL_32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
TR_VOTE_MODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
TRUNC_LREAL_TO_DINT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
TRUNC_LREAL_TO_INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
TRUNC_REAL_TO_DINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
TRUNC_REAL_TO_INT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
TSCHED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
TSCHED_I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
TSCHED_R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
UNPACK16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
UNPACK32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
X_OF_N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451

TriStation 1131 Libraries Reference

viii

Contents

XOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453

Appendix A Modbus Protocol

455

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
Message Response Time. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Determining Message Response Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Modbus Functions and Scan Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Modbus Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Communication Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Function Names and Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Modbus Message Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
Sample Query and Response Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Modbus Message Lengths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Modbus Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Read Coil Status Function (Function Code 01) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Read Input Status (Function Code 02) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Read Holding Registers (Function Code 03) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
Read Input Registers (Function Code 04) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Force Single Coil (Function Code 05) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Preset Single Register (Function Code 06) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Read Exception Status (Function Code 07) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Loop-Back Diagnostic Test (Function Code 08) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Force Multiple Coils (Function Code 15) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
Preset Multiple Registers (Function Code 16) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
Transmission Errors and Exception Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Transmission Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Exception Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Exception Responses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Exception Response Codes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479

Appendix B Peer-to-Peer Parameters

481

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
Parameters of Send Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Parameters of Receive Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Peer-to-Peer Runtime Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488

Index

TriStation 1131 Libraries Reference

491

Preface

The Triconex libraries include IEC-compliant functions and function blocks which are part of the
TriStation 1131 Developers Workbench software.
This reference guide provides detailed descriptions of each of the functions and function blocks in the
libraries. The functions and function blocks described herein can be used in applications created with
TriStation 1131 versions 4.0 and later.

Note

For detailed information about the libraries released with each version of TriStation 1131, refer to
the Product Release Notice for TriStation 1131, available on the Invensys Global Customer Support
(GCS) Web site.

Summary of Sections

Chapter 1, IntroductionExplains how the functions and function blocks are described.

Chapter 2, Functions and Data TypesDescribes the parameters, return values, runtime error
flags, and usage constraints for each function and function block.

Appendix A, Modbus ProtocolProvides information about Modbus protocol including


Modbus message formats and error codes.

Appendix B, Peer-to-Peer ParametersProvides detailed information about the Peer-to-Peer


input and output parameters, and runtime errors.

Related Documents

TriStation 1131 Developers Guide

Safety Considerations Guides for Tricon, Trident, and Tri-GP Systems

Product Release Notice for TriStation 1131

TriStation 1131 Libraries Reference

Preface

Product and Training Information


To obtain information about Invensys products and in-house and on-site training, see the Invensys Web
site or contact your regional customer center.

Web Site
http://www.iom.invensys.com

Technical Support
Customers in the U.S. and Canada can obtain technical support from the Invensys Global Customer
Support (GCS) center at the numbers below. International customers should contact their regional
support center.

Requests for support are prioritized as follows:

Emergency requests are given the highest priority

Requests from participants with a support agreement and customers with purchase
order or charge card authorization are given next priority

All other requests are handled on a time-available basis

If you require emergency or immediate response and do not have a support agreement, you
may incur a charge. Please have a purchase order or credit card available for billing.
Telephone
Toll-free number
Toll number

866-746-6477, or
508-549-2424 (outside U.S.)

Fax
Toll number

508-549-4999

Web Site
http://support.ips.invensys.com/ (registration required)

E-mail
iom.support@invensys.com

TriStation 1131 Libraries Reference

Preface

xi

We Welcome Your Comments


To help us improve future versions of Triconex documentation, we want to know about any
corrections, clarifications, or further information you would find useful. When you contact us,
please include the following information:

The title and version of the guide you are referring to

A brief description of the content you are referring to (for example, step-by-step
instructions that are incorrect, information that requires clarification or more details,
missing information that you would find helpful)

Your suggestions for correcting or improving the documentation

The version of the Triconex hardware or software you are using

Your name, company name, job title, phone number, and e-mail address

Send e-mail to us at:


triconextechpubs@invensys.com
Please keep in mind that this e-mail address is only for documentation feedback. If you have a
technical problem or question, please contact the Invensys Global Customer Support (GCS)
center. See Technical Support on page x for contact information.
Or, you can write to us at:
Attn: Technical Publications Triconex
Invensys
15345 Barranca Parkway
Irvine, CA 92618
USA
Thank you for your feedback.

TriStation 1131 Libraries Reference

xii

Preface

TriStation 1131 Libraries Reference

1
Introduction

How to Use This Reference

Sample Projects

TriStation 1131 Libraries Reference

Chapter 1

Introduction

How to Use This Reference


This section explains how the library elements (functions, function blocks, and data types) are described
in this reference. For more information on programming with IEC functions and function blocks, see
Programming Industrial Control Systems Using IEC 1131-3, by R.W. Lewis, London: Short Run Press Ltd.,
1998.
Topics include:

Name and Brief Description on page 2

Syntax on page 2

Parameters and Return Values on page 2

Description and Example on page 3

Runtime Errors on page 3

Application Notes on page 4

Library on page 6

Name and Brief Description


The name and a brief description introduces each function and function block. This is an example:

BOOL_TO_DWORD
Converts a Boolean (BOOL) value to a DWORD value.

Syntax
The syntax is depicted in Structured Text (ST) language. This is an example:

Syntax
w := BOOL_TO_DWORD(b);

Parameters and Return Values


This section describes parameters and return values.

Input Parameters
A table of input parameters shows the name, data type, and description of each input parameter that is
passed to the function or function block. This is an example:

Table 1

Input Parameters

Name

Data Type

Description

BOOL

The Boolean value to be converted.

TriStation 1131 Libraries Reference

Output Parameters
A table of output parameters shows the name, data type, and description of each function block output.
This is an example:

Table 2

Output Parameters

Name

Data Type

Description

CO

BOOL

True if CLR_ERR executes successfully.

Return Value
A table shows the data type and description of the value returned by the function. This is an example:

Table 3

Return Value

Data Type

Description

DWORD

The value of b converted to a DWORD value.

Description and Example


The description and example include a detailed description and short example of how to use the function
or function block. This is an example:

Description
The CEIL function returns the next higher integer greater than or equal to x.

Example
VAR
x : REAL
END_VAR;
x := ceil(6.04 );

(* result is 7.0 *)

Runtime Errors
The Runtime Errors section includes the conditions, return values, and error flags returned if a runtime
error occurs. This is an example:

Runtime Errors
Condition

Return Value

Error Flags

If k is less than -32768

32768

BADCONV, ERROR

If k is greater than 32767

+32767

BADCONV, ERROR

TriStation 1131 Libraries Reference

Chapter 1

Introduction

Application Notes
The Application Notes section indicates how the function, function block, or data type can be used. These
properties are indicated:

Application Type on page 4

Function Block Usage on page 5

CEM Enabled on page 6

Application Type
The Application Type indicates whether a function, function block, or data type can be used in a safety
program or control program. The purpose of this designation is to reduce the interaction between safety
programs and control programs running on the same controller.
Each element (program, function, function block, or data type) is specified as a safety element or a control
(non-safety) element:

A safety element can be used in a safety element or a control (non-safety) element.

A control (non-safety) element can only be used in a control (non-safety) element.

A safety element must be made up entirely of other safety elements. A control (non-safety) element can
use a safety element or a control element.
Attempting to use a non-safety element in a safety element results in one of these errors:
WF0050: Element is not a safety element (indicated by Red X).
WF0051: Safety element uses non-safety element.
Application Type

Used in a Safety
Element

Used in a Control (NonSafety) Element

Safety element

OK

OK

Control (non-safety) element

WF0050 or WF0051

OK

TriStation 1131 Libraries Reference

Function Block Usage


The Usage section includes information about how a function block should be used in a TriStation 1131
application. To display the properties, right-click a function block, click Properties, then click the Usage
tab.

Usage includes these options:


Option

Description

Exactly Once

Each function block instance should be executed exactly once per scan.

Only Once

Each function block instance should be executed only once per scan, but does not need to
be executed every scan.

Space Saver

Each function block instance can be executed more than once per scan to reduce memory
usage and increase performance. See Using a Space Saver Function Block on page 6.

Internal State

Each function block instance may have an internal state which is remembered from one
execution to the next and from one scan to the next. There are no restricitons on usage of a
function block labeled internal state; that is, you can execute the function block instance
more than once per scan, or you can skip scans.

TriStation 1131 Libraries Reference

Chapter 1

Introduction

Using a Space Saver Function Block


1

Declare only one instance of the function block and use that same instance throughout your
program. On a function block diagram, just use the same instance name repeatedly.

To prevent mistakes, connect a value to every function block input. If you forget to connect an
input, then you must search for a previous execution of the function block to see the input value
because the function block remembers the input value from one execution to the next if the input
is not connected.

Do not use the function block instance more than once in a networkthe result is a WG0014
warning because the diagram could be ambiguous.

Note

If a function block is not a space saver, then using the same function block instance more than
once on a function block diagram results in a WF0031 warningwhereas there is no such
warning for a space saver.

CEM Enabled
A CEM Enabled function or function block can be used in the CEM matrix as indicated by one of these
statements:

Can be used in CEM Cause cells.

Can be used in CEM Cause and Effect cells.

Can be used in CEM Cause, Effect, and Intersection cells.

Can be used in CEM Effect cells.

Can be used in CEM Cause and Intersection cells.

Can be used in CEM Intersection cells.

Library
The Library section identifies the libraries that the function or function block is included in. TriStation
1131 includes these libraries:

Standard Library (STDLIB) complies with the IEC 61131-3 standard

Standard Sheet Library (STDSHEET) for all Triconex controllers (used only for selecting a sheet
template in a new function block diagram)

Triconex Library (TCXLIB) for all Triconex controllers

Tricon Library (TR1LIB or Tx1Lib) for Tricon controllers

Trident Library (TRDLIB) for Trident and Tri-GP controllers

Alarms Library (ALARMS) for all Triconex controllers (first released with TriStation 4.7.0)

TriStation 1131 Libraries Reference

Sample Projects

Sample Projects
Several of the functions or function blocks described in this reference are used in the sample projects
provided with TriStation 1131. These sample projects provide examples for how to use the selected
function or function block.
Starting with TriStation 1131 v4.7.0, sample projects are found in the following locations on the PC where
you installed TriStation 1131 (where x.x.x is the TriStation 1131 version number):

Windows XP and Windows Server 2003: C:\Documents and Settings\All


Users\Application Data\Triconex\TriStation 1131 x.x.x\Projects

Windows 7 and Windows Server 2008 R2: C:\Program Data\Triconex\TriStation


1131 x.x.x\Projects

Note

Older versions of TriStation 1131 (v4.6 or earlier) may have installed the sample projects in a
different location. If you cannot locate the sample projects in the above directories, simply search
your hard drive for the name of the sample project you are looking for.

TriStation 1131 Libraries Reference

Chapter 1

Introduction

TriStation 1131 Libraries Reference

2
Functions and Data Types

This section describes the functions, function blocks, and data types included in TriStation 1131 Libraries.

TriStation 1131 Libraries Reference

10

Chapter 2

Functions and Data Types

ABS
Calculates the absolute value of a number.

Syntax
k := ABS(m)

Table 4

Input Parameters

Name

Data Type

Description

ANY_NUM

A number.

Table 5

Return Value

Data Type

Description

ANY_NUM

The absolute value of m.

Description
The ABS function returns the absolute value of a number. The absolute value is the magnitude that is,
the value with the sign removed.

Example
VAR k : DINT;
END_VAR
k := ABS( 1234 );
k := ABS( 1234 );

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

(* result is 1234 *)
(* result is 1234 *)

ACOS

11

ACOS
Calculates the principal arc cosine of a real number.

Syntax
y := ACOS( x )

Table 6

Input Parameters

Name

Data Type

Description

ANY_REAL

A real number between 1.0 and 1.0 whose arc cosine is to be


calculated.

Table 7

Return Value

Data Type

Description

ANY_REAL

The arc cosine of x in radians from 0.0 to 3.14159.

Description
The ACOS function calculates the principal arc cosine of a real number. The result is in radians from 0.0
to 3.14159.

Example
VAR y : REAL; END_VAR
y := ACOS( 1.0 );
y := ACOS( 1.0 );

(* result is 0.0
*)
(* result is 3.14159 *)

Runtime Errors
Condition

Return Value

Error Flags

If x is not a number or the absolute value of x


is greater than 1.0.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

12

Chapter 2

Functions and Data Types

ADD
Calculates the sum of two operands.

Description
ADD can be used as an operator or as a function.

ADD Operator
The add operator (+) is used in Structured Text to calculate the sum of two operands. The operations that
can be performed are shown in this table.
Parameter
Data Type

Result Data
Type

Return Value

Calculates the sum of two numeric


values.

ANY_NUM

ANY_NUM

The sum of the operands.

Calculates the sum of two time


periods.

TIME

TIME

The sum of the operands.

Adds a time operand to a date and


time operand.

DT + TIME

DT

The date and time operand plus the


time operand.

Adds a time operand to a time of


day operand.

TOD + TIME

TOD

The time-of-day operand plus the time


operand.

Operation

ADD Function
In the graphical languages, the ADD extensible function is used instead of the add operator. Extensible
functions can operate on up to 50 input parameters. The operations that can be performed using the ADD
extensible function are shown in this table.
Parameter
Data Type

Return Value
Data Type

Return Value

Calculates the sum of from 1 to 50


numeric inputs.

ANY_NUM

ANY_NUM

The sum of the inputs.

Calculates the sum of two time inputs.

TIME

TIME

The sum of the inputs.

Adds a time input to a date and time


input.

DT + TIME

DT

The date and time input plus the


time input.

Adds a time input to a time of day


input.

TOD + TIME

TOD

The time-of-day input plus the


time input.

Operation

TriStation 1131 Libraries Reference

ADD

13

Example
Calculate the Sum of Numeric Values
VAR m : DINT; END_VAR
m := 10 + 1564;
m := 10 + 1564 + 32761 + 512;

(* result is 1574 *)
(* result is 33823 *)

Calculate the Sum of Two Times


VAR t : TIME; END_VAR
t := T#11d22h33m + T#3h10m;

(* result is T#12d1h43m *)

Add a Time to a Date and Time


VAR d : DT;
END_VAR
d := DT#2002-01-27-08:00:00 + T#3h30m45s;

(* result is DT#2002-01-27-11:30:45 *)

Add a Time to a Time of Day


VAR t : TOD; END_VAR
t := TOD#08:00:00 + T#3h30m45s;

(* result is TOD#11:30:45 *)

Runtime Errors
Condition

Return Value

Error Flags

If the result is infinite

INF

OVERFLOW, ERROR

If an operand is not a number (NAN)

NAN

OVERFLOW, ERROR

If the date and time is out of range

Invalid date

BADPARAM, ERROR

If the time is out of range

Invalid time

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

14

Chapter 2

Functions and Data Types

AIN
Converts an analog input to a real number.

Syntax
y := AIN( MX,

Table 8

IN,

MN )

Input Parameters

Name

Data Type

Description

MX

REAL

The upper limit of the return value.

IN

DINT

The value to be converted to engineering units.

MN

REAL

The lower limit of the return value.

Table 9

Return Value

Data Type

Description

REAL

The value of IN converted to engineering units.

Description
The AIN function converts an analog input to a real number. The range of IN is 819 to 4095, which
corresponds to 4 to 20 milliamps or 1 to 5 volts. The return value is a real number (in engineering units)
scaled to the range from MN to MX. MN is the value returned when the input corresponds to 4 milliamps
or 1 volt, or is less than 819. MX is the value returned when the input corresponds to 20 milliamps or
5 volts, or is greater than or equal to 4095.

Example
VAR
y :=
y :=
y :=

y : REAL; END_VAR
AIN( 100.0, 4095, 0.0 );
AIN( 100.0, 2457, 0.0 );
AIN( 100.0, 819,
0.0 );

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

(* result is 100.0 *)
(* result is 50.0 *)
(* result is
0.0 *)

AIN_BP

15

AIN_BP
Converts a differential bipolar analog input to a real number.

Syntax
y := AIN_BP( MX,

Table 10

IN,

MN )

Input Parameters

Name

Data Type

Description

MX

REAL

The upper limit of the return value.

IN

DINT

The value to be converted to engineering units.

MN

REAL

The lower limit of the return value.

Table 11

Return Value

Data Type

Description

REAL

The value of IN converted to engineering units.

Description
The AIN_BP function converts a differential bipolar analog input to a real number. The range of IN is 16383 to 16383, which corresponds to -20 to 20 milliamps or -5 to 5 volts. The return value is a real number
(in engineering units) scaled to the range from MN to MX. MN is the value returned when the input
corresponds to -20 milliamps or -5 volts, or is less than -16383. MX is the value returned when the input
corresponds to 20 milliamps or 5 volts, or is greater than or equal to 16383. The scaling equation
implemented in this function is equal to
IN
LO------------------- MX MN + MN
HI LO

where HI= 16383 and LO= -16383.

Example
VAR
y :=
y :=
y :=

y : REAL; END_VAR
AIN_BP( 100.0, 16383, 0.0 );
AIN_BP( 100.0, 0, 0.0 );
AIN_BP( 100.0, -16383,
0.0 );

(* result is 100.0 *)
(* result is 50.0 *)
(* result is
0.0 *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

16

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)
This function was added to the library in v1.31 of TCXLIB, first released with TriStation 1131 v4.1.419.

TriStation 1131 Libraries Reference

AIN_BP12

17

AIN_BP12
Converts a 12-bit differential bipolar analog input to a real number.

Syntax
y := AIN_BP12( MX,

Table 12

IN,

MN )

Input Parameters

Name

Data Type

Description

MX

REAL

The upper limit of the return value.

IN

DINT

The value to be converted to engineering units.

MN

REAL

The lower limit of the return value.

Table 13

Return Value

Data Type

Description

REAL

The value of IN converted to engineering units.

Description
The AIN_BP12 function converts a 12-bit differential bipolar analog input to a real number. The typical
range of IN is -4095 to 4095. The return value is a real number (in engineering units) scaled to the range
from MN to MX. MN is the value returned when the input is -4095. MX is the value returned when the
input is +4095. AIN_BP12 clamps the analog input to the range of -4095 to +4095. The scaling equation
implemented in this function is approximately equivalent to
IN
LO------------------- MX MN + MN
HI LO

where HI= 4095 and LO= -4095.


Engineering
Units

MX
-4095
+4095

Machine
Count

MN

TriStation 1131 Libraries Reference

18

Chapter 2

Functions and Data Types

Example
The BPAO module (model 3807) provides a 12-bit bipolar analog input that measures the voltage across
the load coil. Input value -4095 corresponds to -10 volts. Input value +4095 corresponds to +10 volts. The
following example function call converts the input to a voltage:

VAR y : REAL; in : DINT;


y := AIN_BP12( +10.0, in,
in

-4095

-10.0

0.0

+4095

+10.0

END_VAR
-10.0 );

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)
This function was added to the library in v1.32 of TCXLIB, first released with TriStation 1131 v4.3.

TriStation 1131 Libraries Reference

AIN_HR

19

AIN_HR
Converts a high-resolution analog input to a real number.

Syntax
y := AIN_HR( MX,

Table 14

IN,

MN )

Input Parameters

Name

Data Type

Description

MX

REAL

The upper limit of the return value.

IN

DINT

The value to be converted to engineering units.

MN

REAL

The lower limit of the return value.

Table 15

Return Value

Data Type

Description

REAL

The value of IN converted to engineering units.

Description
The AIN_HR function converts a high-resolution analog input to a real number. The range of IN is 3276
to 16383, which corresponds to 4 to 20 milliamps or 1 to 5 volts. The return value is a real number (in
engineering units) scaled to the range from MN to MX. MN is the value returned when the input
corresponds to 4 milliamps or 1 volt, or is less than 3276. MX is the value returned when the input
corresponds to 20 milliamps or 5 volts, or is greater than or equal to 16383. The scaling equation
implemented in this function is equal to
IN
LO------------------- MX MN + MN
HI LO

where HI= 16383 and LO= 3276.

Example
VAR
y :=
y :=
y :=

y : REAL; END_VAR
AIN_HR( 100.0, 16383, 0.0 );
AIN_HR( 100.0, 9829, 0.0 );
AIN_HR( 100.0, 3276,
0.0 );

(* result is 100.0 *)
(* result is 50.0 *)
(* result is
0.0 *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

20

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)
This function was added to the library in v1.31 of TCXLIB, first released with TriStation 1131 v4.1.419.

TriStation 1131 Libraries Reference

ALARM_DEVIATION_DINT

21

ALARM_DEVIATION_DINT
Generates deviation alarms for DINT tagnames.

Syntax
My_DevAlm(SOURCE:=Tagname_2_DevByp.VALUE, BYPASS:=Tagname_2_DevByp.BYPASSED,
SETPOINT:=55, ACK_REQUEST:=Tagname_1, DISABLE_REQUEST:=Tagname_4,
AUTOMATIC_RESET:=Tagname_3, MANUAL_RESET_REQUEST:=Tagname_6, DEADBAND:=2,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=400,
HIGH_LIMIT:=5, HIGH_SEVERITY:=300, LOW_LIMIT:=-5, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=10, LOW_LOW_SEVERITY:=100);

Table 16

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which deviation alarm will be generated. May


be connected to a tagname, or to the output of
BYPASS_DINT.

SETPOINT

DINT

Value from which the deviation alarm will be generated.

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_DINT function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_DINT function block along with
ALARM_DEVIATION_DINT. The output of
BYPASS_DINT (VALUE) should be connected to the
SOURCE input of ALARM_DEVIATION_DINT.
Additionally, BYPASS_REQ on BYPASS_DINT
should be true. Simply setting BYPASS to true will
not bypass the alarm. You must use BYPASS_DINT
to bypass the value, while
ALARM_DEVIATION_DINTs BYPASS input also
should be true so that you obtain the correct alarm
status.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator


to acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUEST

BOOL

If true, the ringback alarm is reset.

DEADBAND

DINT

Specifies the difference between the alarm limit and the input
value before an alarm goes inactive.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

TriStation 1131 Libraries Reference

22

Chapter 2

Functions and Data Types

Table 16

Input Parameters (continued)

Name

Data Type

Description

HIGH_HIGH_LIMIT

DINT

Specifies the High High alarm limit for the SOURCE.


When SOURCE is greater than SETPOINT +
HIGH_HIGH_LIMIT, then HIGH_HIGH_ACTIVE becomes
true, and subsequently, the output parameter ACTIVE
becomes true.

HIGH_HIGH_SEVERITY

DINT

Specifies the severity for the High High limit.

HIGH_LIMIT

DINT

Specifies the High alarm limit for the SOURCE.


When SOURCE is greater than SETPOINT + HIGH_LIMIT,
then HIGH_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

HIGH_SEVERITY

DINT

LOW_LIMIT

DINT

Specifies the severity for the High limit.


Specifies the Low alarm limit for the SOURCE.
When SOURCE is less than SETPOINT - LOW_LIMIT, then
LOW_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

LOW_SEVERITY

DINT

LOW_LOW_LIMIT

DINT

Specifies the severity for the Low limit.


Specifies the Low Low alarm limit for the SOURCE.
When SOURCE is less than SETPOINT - LOW_LOW_LIMIT,
then LOW_LOW_ACTIVE becomes true, and subsequently,
the output parameter ACTIVE becomes true.

LOW_LOW_SEVERITY

DINT

Specifies the severity for the Low Low limit.

SOURCE_ID

DINT

Reserved for future use.

Table 17

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

HIGH_HIGH_ACTIVE

BOOL

If true, a High High alarm is active.

HIGH_ACTIVE

BOOL

If true, a High alarm is active.

LOW_ACTIVE

BOOL

If true, a Low alarm is active.

LOW_LOW_ACTIVE

BOOL

If true, a Low Low alarm is active.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

TriStation 1131 Libraries Reference

ALARM_DEVIATION_DINT

Table 17

23

Output Parameters (continued)

Name

Data Type

Description

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
LOLO_LVL_ACTIVE (16#00000011)
LOLO_LVL_ACKED (16#00000012)
LO_LVL_ACTIVE (16#00000021)
LO_LVL_ACKED (16#00000022)
HI_LVL_ACTIVE (16#00000031)
HI_LVL_ACKED (16#00000032)
HIHI_LVL_ACTIVE (16#00000041)
HIHI_LVL_ACKED (16#00000042)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_DEVIATION_DINT function generates deviation alarms (Low Low, Low, High, High
High) for DINT tagnames.
Deviation alarms are commonly used to report an excess deviation between a process values desired
setpoint level, and the actual measured level. They typically relate to instruments (for example, a
temperature meter). A deviation alarm becomes active when the deviation exceeds or drops below a
defined limit.
For example, assume the setpoint has been set to 10, the High limit is set to 2, and the Low limit is set to
-1. If the process value drops below 9, the Low deviation alarm is generated. If the process value goes
above 12, the High deviation alarm is generated. If the setpoint is changed to 11, the new deviation values
will be 10 and 13, respectively.
The input parameter SOURCE is the process value being measured.
The DEADBAND input parameter specifies the difference between the alarm limit and the input value
that will cause an alarm to go inactive. For example, assume the following limit settings:

Setpoint = 40

HIGH_HIGH_LIMIT = 10

HIGH_LIMIT = 5

LOW_LIMIT = 4

LOW_LOW_LIMIT = 6

DEADBAND = 2

The High High alarm will go inactive if SOURCE is less than 48. The High alarm will go inactive if
SOURCE is less than 43. The Low alarm will go active if SOURCE is greater than 38. The Low Low alarm
will go inactive if SOURCE is greater than 36.

TriStation 1131 Libraries Reference

24

Chapter 2

Functions and Data Types

The TIME_DELAY input parameter specifies how long before an alarm will go active once the alarm
condition is detected. For example, if TIME_DELAY is configured as 5 seconds, and the High alarm is set
for 100, once the value exceeds 100, ALARM_DEVIATION_DINT will wait 5 seconds before generating
the High alarm. Use of the TIME_DELAY parameter can help prevent nuisance alarms that may be
generated due to process noise.

Example
VAR My_Deviation_Alarm: DEVIATION_ALARM_DINT; END_VAR
VAR_EXTERNAL My_Tagname: DINT;
Tagname2:BOOL;Tagname3:BOOL; Tagname4:BOOL; Tagname5:BOOL;Tagname6:BOOL;
END_VAR
My_Deviation_Alarm (SOURCE:=My_Tagname, BYPASS:=Tagname2,
SETPOINT:=55, ACK_REQUEST:=Tagname3, DISABLE_REQUEST:=Tagname4,
AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6, DEADBAND:=2,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=4,
HIGH_LIMIT:=5, HIGH_SEVERITY:=3, LOW_LIMIT:=5, LOW_SEVERITY:=2, LOW_LOW_LIMIT:=
10, LOW_LOW_SEVERITY:=1
);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

ALARM_DEVIATION_REAL

25

ALARM_DEVIATION_REAL
Generates deviation alarms for REAL tagnames.

Syntax
My_DevAlm(SOURCE:=Tagname_2_DevByp.VALUE, BYPASS:=Tagname_2_DevByp.BYPASSED,
SETPOINT:=55, ACK_REQUEST:=Tagname_1, DISABLE_REQUEST:=Tagname_4,
AUTOMATIC_RESET:=Tagname_3, MANUAL_RESET_REQUEST:=Tagname_6DEAD, BAND:=2.0,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10.0, HIGH_HIGH_SEVERITY:=400,
HIGH_LIMIT:=5.0, HIGH_SEVERITY:=300, LOW_LIMIT:=-5.0, LOW_SEVERITY:=200,
LOW_LOW_LIMIT:=-10.0, LOW_LOW_SEVERITY:=100);

Table 18

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which deviation alarm will be generated. May


be connected to a tagname, or to the output of
BYPASS_REAL.

SETPOINT

DINT

Value from which the deviation alarm will be generated.

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_REAL function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_REAL function block along with
ALARM_DEVIATION_REAL. The output of
BYPASS_REAL (VALUE) should be connected to the
SOURCE input of ALARM_DEVIATION_REAL.
Additionally, BYPASS_REQ on BYPASS_REAL
should be true. Simply setting BYPASS to true will
not bypass the alarm. You must use BYPASS_REAL
to bypass the value, while
ALARM_DEVIATION_REALs BYPASS input also
should be true so that you obtain the correct alarm
status.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator


to acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUEST

BOOL

If true, the ringback alarm is reset.

DEADBAND

DINT

Specifies the difference between the alarm limit and the input
value before an alarm goes inactive.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

TriStation 1131 Libraries Reference

26

Chapter 2

Functions and Data Types

Table 18

Input Parameters (continued)

Name

Data Type

Description

HIGH_HIGH_LIMIT

DINT

Specifies the High High alarm limit for the SOURCE.


When SOURCE is greater than SETPOINT +
HIGH_HIGH_LIMIT, then HIGH_HIGH_ACTIVE becomes
true, and subsequently, the output parameter ACTIVE
becomes true.

HIGH_HIGH_SEVERITY

DINT

Specifies the severity for the High High limit.

HIGH_LIMIT

DINT

Specifies the High alarm limit for the SOURCE.


When SOURCE is greater than SETPOINT + HIGH_LIMIT,
then HIGH_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

HIGH_SEVERITY

DINT

LOW_LIMIT

DINT

Specifies the severity for the High limit.


Specifies the Low alarm limit for the SOURCE.
When SOURCE is less than SETPOINT - LOW_LIMIT, then
LOW_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

LOW_SEVERITY

DINT

LOW_LOW_LIMIT

DINT

Specifies the severity for the Low limit.


Specifies the Low Low alarm limit for the SOURCE.
When SOURCE is less than SETPOINT - LOW_LOW_LIMIT,
then LOW_LOW_ACTIVE becomes true, and subsequently,
the output parameter ACTIVE becomes true.

LOW_LOW_SEVERITY

DINT

Specifies the severity for the Low Low limit.

SOURCE_ID

DINT

Reserved for future use.

Table 19

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

HIGH_HIGH_ACTIVE

BOOL

If true, a High High alarm is active.

HIGH_ACTIVE

BOOL

If true, a High alarm is active.

LOW_ACTIVE

BOOL

If true, a Low alarm is active.

LOW_LOW_ACTIVE

BOOL

If true, a Low Low alarm is active.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

TriStation 1131 Libraries Reference

ALARM_DEVIATION_REAL

Table 19

27

Output Parameters (continued)

Name

Data Type

Description

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
LOLO_LVL_ACTIVE (16#00000011)
LOLO_LVL_ACKED (16#00000012)
LO_LVL_ACTIVE (16#00000021)
LO_LVL_ACKED (16#00000022)
HI_LVL_ACTIVE (16#00000031)
HI_LVL_ACKED (16#00000032)
HIHI_LVL_ACTIVE (16#00000041)
HIHI_LVL_ACKED (16#00000042)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_DEVIATION_REAL function generates deviation alarms (Low Low, Low, High, High
High) for REAL tagnames.
Deviation alarms are commonly used to report an excess deviation between a process values desired
setpoint level, and the actual measured level. They typically relate to instruments (for example, a
temperature meter). A deviation alarm becomes active when the deviation exceeds or drops below a
defined limit.
For example, assume the setpoint has been set to 10, the High limit is set to 2, and the Low limit is set to
-1. If the process value drops below 9, the Low deviation alarm is generated. If the process value goes
above 12, the High deviation alarm is generated. If the setpoint is changed to 11, the new deviation values
will be 10 and 13, respectively.
The input parameter SOURCE is the process value being measured.
The DEADBAND input parameter specifies the difference between the alarm limit and the input value
that will cause an alarm to go inactive. For example, assume the following limit settings:

Setpoint = 40

HIGH_HIGH_LIMIT = 10

HIGH_LIMIT = 5

LOW_LIMIT = 4

LOW_LOW_LIMIT = 6

DEADBAND = 2

The High High alarm will go inactive if SOURCE is less than 48. The High alarm will go inactive if
SOURCE is less than 43. The Low alarm will go active if SOURCE is greater than 38. The Low Low alarm
will go inactive if SOURCE is greater than 36.

TriStation 1131 Libraries Reference

28

Chapter 2

Functions and Data Types

The TIMEDELAY input parameter specifies how long before an alarm will go active once the alarm
condition is detected. For example, if TIMEDELAY is configured as 5 seconds, and the High alarm is set
for 100, once the value exceeds 100, ALARM_DEVIATION_REAL will wait 5 seconds before generating
the High alarm. Use of the TIMEDELAY parameter can help prevent nuisance alarms that may be
generated due to process noise.

Example
VAR My_Deviation_Alarm: ALARM_DEVIATION_REAL; END_VAR
VAR_EXTERNAL My_Tagname: REAL;
Tagname2:BOOL;Tagname3:BOOL; Tagname4:BOOL; Tagname5:BOOL;Tagname6:BOOL;
END_VAR
My_Deviation_Alarm (SOURCE:=My_Tagname, BYPASS:=Tagname2,
SETPOINT:=55, ACK_REQUEST:=Tagname3, DISABLE_REQUEST:=Tagname4,
AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6, DEADBAND:=2,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=4,
HIGH_LIMIT:=5, HIGH_SEVERITY:=3, LOW_LIMIT:=5, LOW_SEVERITY:=2, LOW_LOW_LIMIT:=
10, LOW_LOW_SEVERITY:=1
);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

ALARM_LEVEL_DINT

29

ALARM_LEVEL_DINT
Generates level alarms for DINT tagnames.

Syntax
My_LvlAlm(SOURCE:=Tagname_2_LvByp.VALUE, BYPASS:=Tagname_2_LvByp.BYPASSED,
ACK_REQUEST:=Tagname_1, DISABLE_REQUEST:=Tagname_5, AUTOMATIC_RESET:=Tagname_3,
MANUAL_RESET_REQUEST:=Tagname_6, DEADBAND:=5, TIME_DELAY:=T#10ms, RINGBACK:=TRUE,
HIGH_HIGH_LIMIT:=90, HIGH_HIGH_SEVERITY:=400, HIGH_LIMIT:=80, HIGH_SEVERITY:=300,
LOW_LIMIT:=20, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=10, LOW_LOW_SEVERITY:=100);

Table 20

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which level alarm will be generated. May be


connected to a tagname, or to the output of BYPASS_DINT.

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_DINT function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_DINT function block along with
ALARM_LEVEL_DINT. The output of
BYPASS_DINT (VALUE) should be connected to the
SOURCE input of ALARM_LEVEL_DINT.
Additionally, BYPASS_REQ on BYPASS_DINT
should be true. Simply setting BYPASS to true will
not bypass the alarm. You must use BYPASS_DINT
to bypass the value, while ALARM_LEVEL_DINTs
BYPASS input also should be true so that you obtain
the correct alarm status.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator


to acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUEST

BOOL

If true, the ringback alarm is reset.

DEADBAND

DINT

Specifies the difference between the alarm limit and the input
value before an alarm goes inactive.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

HIGH_HIGH_LIMIT

DINT

Specifies the High High alarm limit for the SOURCE.


When SOURCE is greater than HIGH_HIGH_LIMIT, then
HIGH_HIGH_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

HIGH_HIGH_SEVERITY

DINT

Specifies the severity for the High High limit.

TriStation 1131 Libraries Reference

30

Chapter 2

Functions and Data Types

Table 20

Input Parameters (continued)

Name

Data Type

Description

HIGH_LIMIT

DINT

Specifies the High alarm limit for the SOURCE.


When SOURCE is greater than HIGH_LIMIT, then
HIGH_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

HIGH_SEVERITY

DINT

LOW_LIMIT

DINT

Specifies the severity for the High limit.


Specifies the Low alarm limit for the SOURCE.
When SOURCE is less than LOW_LIMIT, then
LOW_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

LOW_SEVERITY

DINT

LOW_LOW_LIMIT

DINT

Specifies the severity for the Low limit.


Specifies the Low Low alarm limit for the SOURCE.
When SOURCE is less than LOW_LOW_LIMIT, then
LOW_LOW_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

LOW_LOW_SEVERITY

DINT

Specifies the severity for the Low Low limit.

SOURCE_ID

DINT

Reserved for future use.

Table 21

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

HIGH_HIGH_ACTIVE

BOOL

If true, a High High alarm is active.

HIGH_ACTIVE

BOOL

If true, a High alarm is active.

LOW_ACTIVE

BOOL

If true, a Low alarm is active.

LOW_LOW_ACTIVE

BOOL

If true, a Low Low alarm is active.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

TriStation 1131 Libraries Reference

ALARM_LEVEL_DINT

Table 21

31

Output Parameters (continued)

Name

Data Type

Description

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
LOLO_LVL_ACTIVE (16#00000011)
LOLO_LVL_ACKED (16#00000012)
LO_LVL_ACTIVE (16#00000021)
LO_LVL_ACKED (16#00000022)
HI_LVL_ACTIVE (16#00000031)
HI_LVL_ACKED (16#00000032)
HIHI_LVL_ACTIVE (16#00000041)
HIHI_LVL_ACKED (16#00000042)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_LEVEL_DINT function generates level alarms (Low Low, Low, High, High High) for DINT
tagnames.
Level alarms are commonly used to report when a limit is exceeded. They typically relate to instruments
(for example, a temperature meter). A level alarm becomes active when the observed value is above a
high limit, or below a low limit.
The input parameter SOURCE is the process value being measured.
The DEADBAND input parameter specifies the difference between the alarm limit and the input value
that will cause an alarm to go inactive. For example, if a High alarm is set for 100, and the DEADBAND
is set to 10, the alarm will go active at 100, and inactive at 90. If a Low alarm is set for 100, it will go active
at 100, and inactive at 110.
The TIME_DELAY input parameter specifies how long before an alarm will go active once the alarm
condition is detected. For example, if TIME_DELAY is configured as 5 seconds, and the High alarm is set
for 100, once the value exceeds 100, ALARM_LEVEL_DINT will wait 5 seconds before generating the
High alarm. Use of the TIME_DELAY parameter can help prevent nuisance alarms that may be generated
due to process noise.

Example
VAR My_Level_Alarm: ALARM_LEVEL_DINT; END_VAR
VAR_EXTERNAL My_Tagname: DINT; Tagname2:BOOL; Tagname3:BOOL; Tagname4:BOOL;
Tagname5:BOOL; Tagname6:BOOL;
END_VAR
My_Level_Alarm (SOURCE:=My_Tagname, BYPASS:=Tagname2, ACK_REQUEST:=Tagname3,
DISABLE_REQUEST:=Tagname4, AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6,
DEADBAND:=2, TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=100,
HIGH_HIGH_SEVERITY:=4, HIGH_LIMIT:=80, HIGH_SEVERITY:=3, LOW_LIMIT:=20,
LOW_SEVERITY:=2, LOW_LOW_LIMIT:=10, LOW_LOW_SEVERITY:=1

TriStation 1131 Libraries Reference

32

Chapter 2

Functions and Data Types

);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

ALARM_LEVEL_REAL

33

ALARM_LEVEL_REAL
Generates level alarms for REAL tagnames.

Syntax
My_LvlAlm(SOURCE:=Tagname_2_LvByp.VALUE, BYPASS:=Tagname_2_LvByp.BYPASSED,
ACK_REQUEST:=Tagname_1, DISABLE_REQUEST:=Tagname_5, AUTOMATIC_RESET:=Tagname_3,
MANUAL_RESET_REQUEST:=Tagname_6, DEADBAND:=5.0, TIME_DELAY:=T#10ms, RINGBACK:=TRUE,
HIGH_HIGH_LIMIT:=90.0, HIGH_HIGH_SEVERITY:=400, HIGH_LIMIT:=80.0, HIGH_SEVERITY:=300,
LOW_LIMIT:=20.0, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=10.0, LOW_LOW_SEVERITY:=100);

Table 22

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which level alarm will be generated. May be


connected to a tagname, or to the output of BYPASS_REAL.

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_REAL function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_REAL function block along with
ALARM_LEVEL_REAL. The output of
BYPASS_REAL (VALUE) should be connected to the
SOURCE input of ALARM_LEVEL_REAL.
Additionally, BYPASS_REQ on BYPASS_REAL
should be true. Simply setting BYPASS to true will
not bypass the alarm. You must use BYPASS_REAL
to bypass the value, while ALARM_LEVEL_REALs
BYPASS input also should be true so that you obtain
the correct alarm status.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator


to acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUEST

BOOL

If true, the ringback alarm is reset.

DEADBAND

DINT

Specifies the difference between the alarm limit and the input
value before an alarm goes inactive.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

HIGH_HIGH_LIMIT

DINT

Specifies the High High alarm limit for the SOURCE.


When SOURCE is greater than HIGH_HIGH_LIMIT, then
HIGH_HIGH_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

HIGH_HIGH_SEVERITY

DINT

Specifies the severity for the High High limit.

TriStation 1131 Libraries Reference

34

Chapter 2

Functions and Data Types

Table 22

Input Parameters (continued)

Name

Data Type

HIGH_LIMIT

DINT

Description
Specifies the High alarm limit for the SOURCE.
When SOURCE is greater than HIGH_LIMIT, then
HIGH_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

HIGH_SEVERITY

DINT

LOW_LIMIT

DINT

Specifies the severity for the High limit.


Specifies the Low alarm limit for the SOURCE.
When SOURCE is less than LOW_LIMIT, then
LOW_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

LOW_SEVERITY

DINT

LOW_LOW_LIMIT

DINT

Specifies the severity for the Low limit.


Specifies the Low Low alarm limit for the SOURCE.
When SOURCE is less than LOW_LOW_LIMIT, then
LOW_LOW_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

LOW_LOW_SEVERITY

DINT

Specifies the severity for the Low Low limit.

SOURCE_ID

DINT

Reserved for future use.

Table 23

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

HIGH_HIGH_ACTIVE

BOOL

If true, a High High alarm is active.

HIGH_ACTIVE

BOOL

If true, a High alarm is active.

LOW_ACTIVE

BOOL

If true, a Low alarm is active.

LOW_LOW_ACTIVE

BOOL

If true, a Low Low alarm is active.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

TriStation 1131 Libraries Reference

ALARM_LEVEL_REAL

Table 23

35

Output Parameters (continued)

Name

Data Type

Description

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
LOLO_LVL_ACTIVE (16#00000011)
LOLO_LVL_ACKED (16#00000012)
LO_LVL_ACTIVE (16#00000021)
LO_LVL_ACKED (16#00000022)
HI_LVL_ACTIVE (16#00000031)
HI_LVL_ACKED (16#00000032)
HIHI_LVL_ACTIVE (16#00000041)
HIHI_LVL_ACKED (16#00000042)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_LEVEL_REAL function generates level alarms (Low Low, Low, High, High High) for REAL
tagnames.
Level alarms are commonly used to report when a limit is exceeded. They typically relate to instruments
(for example, a temperature meter). A level alarm becomes active when the observed value is above a
high limit, or below a low limit.
The input parameter SOURCE is the process value being measured.
The DEADBAND input parameter specifies the difference between the alarm limit and the input value
that will cause an alarm to go inactive. For example, if a High alarm is set for 100, and the DEADBAND
is set to 10, the alarm will go active at 100, and inactive at 90. If a Low alarm is set for 100, it will go active
at 100, and inactive at 110.
The TIME_DELAY input parameter specifies how long before an alarm will go active once the alarm
condition is detected. For example, if TIME_DELAY is configured as 5 seconds, and the High alarm is set
for 100, once the value exceeds 100, ALARM_LEVEL_REAL will wait 5 seconds before generating the
High alarm. Use of the TIME_DELAY parameter can help prevent nuisance alarms that may be generated
due to process noise.

Example
VAR My_Level_Alarm: ALARM_LEVEL_DINT; END_VAR
VAR_EXTERNAL My_Tagname: DINT; Tagname2:BOOL; Tagname3:BOOL; Tagname4:BOOL;
Tagname5:BOOL; Tagname6:BOOL;
END_VAR
My_Level_Alarm (SOURCE:=My_Tagname, BYPASS:=Tagname2, ACK_REQUEST:=Tagname3,
DISABLE_REQUEST:=Tagname4, AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6,
DEADBAND:=2, TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=100,
HIGH_HIGH_SEVERITY:=4, HIGH_LIMIT:=80, HIGH_SEVERITY:=3, LOW_LIMIT:=20,
LOW_SEVERITY:=2, LOW_LOW_LIMIT:=10, LOW_LOW_SEVERITY:=1

TriStation 1131 Libraries Reference

36

Chapter 2

Functions and Data Types

);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

ALARM_ROC_DINT

37

ALARM_ROC_DINT
Generates rate of change alarms for DINT tagnames.

Syntax
My_ROCAlm(SOURCE:=Tagname_2_ROCByp.VALUE, BYPASS:=Tagname_2_ROCByp.BYPASSED,
RATE_OF_CHANGE:=T#5s, ACK_REQUEST:=Tagname_1, DISABLE_REQUEST:=Tagname_5,
AUTOMATIC_RESET:=Tagname_3, MANUAL_RESET_REQUEST:=Tagname_6, DEADBAND:=2,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=6, HIGH_HIGH_SEVERITY:=400,
HIGH_LIMIT:=3, HIGH_SEVERITY:=300, LOW_LIMIT:=3, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=6,
LOW_LOW_SEVERITY:=100);

Table 24

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which a rate of change alarm will be


generated. May be connected to a tagname, or to the output
of BYPASS_DINT.

RATEOFCHANGE

DINT

The rate of change in SOURCE, measured in units of time


(seconds, minutes, or hours).

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_DINT function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_DINT function block along with
ALARM_ROC_DINT. The output of BYPASS_DINT
(VALUE) should be connected to the SOURCE input
of ALARM_ROC_DINT. Additionally,
BYPASS_REQ on BYPASS_DINT should be true.
Simply setting BYPASS to true will not bypass the
alarm. You must use BYPASS_DINT to bypass the
value, while ALARM_ROC_DINTs BYPASS input
also should be true so that you obtain the correct
alarm status.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator


to acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUEST

BOOL

If true, the ringback alarm is reset.

DEADBAND

DINT

Specifies the difference between the alarm limit and the input
value before an alarm goes inactive.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

HIGH_HIGH_LIMIT

DINT

Specifies the High High alarm limit for the SOURCE.


When SOURCE is greater than HIGH_HIGH_LIMIT, then
HIGH_HIGH_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

TriStation 1131 Libraries Reference

38

Chapter 2

Functions and Data Types

Table 24

Input Parameters (continued)

Name

Data Type

Description

HIGH_HIGH_SEVERITY

DINT

Specifies the severity for the High High limit.

HIGH_LIMIT

DINT

Specifies the High alarm limit for the SOURCE.


When SOURCE is greater than HIGH_LIMIT, then
HIGH_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

HIGH_SEVERITY

DINT

Specifies the severity for the High limit.

LOW_LIMIT

DINT

Specifies the Low alarm limit for the SOURCE.


When SOURCE is less than LOW_LIMIT, then
LOW_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

LOW_SEVERITY

DINT

Specifies the severity for the Low limit.

LOW_LOW_LIMIT

DINT

Specifies the Low Low alarm limit for the SOURCE.


When SOURCE is less than LOW_LOW_LIMIT, then
LOW_LOW_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

LOW_LOW_SEVERITY

DINT

Specifies the severity for the Low Low limit.

SOURCE_ID

DINT

Reserved for future use.

Table 25

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

HIGH_HIGH_ACTIVE

BOOL

If true, a High High alarm is active.

HIGH_ACTIVE

BOOL

If true, a High alarm is active.

LOW_ACTIVE

BOOL

If true, a Low alarm is active.

LOW_LOW_ACTIVE

BOOL

If true, a Low Low alarm is active.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

TriStation 1131 Libraries Reference

ALARM_ROC_DINT

Table 25

39

Output Parameters (continued)

Name

Data Type

Description

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
LOLO_LVL_ACTIVE (16#00000011)
LOLO_LVL_ACKED (16#00000012)
LO_LVL_ACTIVE (16#00000021)
LO_LVL_ACKED (16#00000022)
HI_LVL_ACTIVE (16#00000031)
HI_LVL_ACKED (16#00000032)
HIHI_LVL_ACTIVE (16#00000041)
HIHI_LVL_ACKED (16#00000042)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_ROC_DINT function generates rate of change alarms for DINT tagnames.
Rate of change alarms are commonly used to report an unusual change or lack of change in a measured
value, relative to the speed at which the value has changed. They typically relate to instruments (for
example, a temperature meter). A rate of change alarm becomes active when the rate at which the value
changes exceeds or drops below a defined limit.
The rate of change is measured in units of time (such as seconds, minutes, or hours). For example, a tank
may have a High limit for the rate of change of its level (measured in meters) of 4 meters/minute. If the
tank level changes at a rate greater than 4 meters/minute, then a High alarm is generated.
The input parameter SOURCE is the process value being measured.
The DEADBAND input parameter specifies the difference between the alarm limit and the input value
that will cause an alarm to go inactive. For example, if a High alarm is set for 100, and the DEADBAND
is set to 10, the alarm will go active at 100, and inactive at 90. If a Low alarm is set for 100, it will go active
at 100, and inactive at 110.
The TIME_DELAY input parameter specifies how long before an alarm will go active once the alarm
condition is detected. For example, if TIME_DELAY is configured as 5 seconds, and the High alarm is set
for 100, once the value exceeds 100, ALARM_ROC_DINT will wait 5 seconds before generating the High
alarm. Use of the TIME_DELAY parameter can help prevent nuisance alarms that may be generated due
to process noise.

Example
VAR My_RateOfChange_Alarm: ALARM_ROC_DINT; END_VAR
VAR My_BYPASS_DINT:BYPASS_DINT; END_VAR
VAR_EXTERNAL My_Tagname: DINT; Tagname2:BOOL; Tagname3:BOOL; Tagname4:BOOL;
Tagname5:BOOL; Tagname6:BOOL;
END_VAR

TriStation 1131 Libraries Reference

40

Chapter 2

Functions and Data Types

My_BYPASS_DINT(TAG_VALUE:=My_Tagname, BYPASS_VALUE:=55, BYPASS_REQ:=Tagname4);


My_RateOfChange_Alarm (SOURCE:=My_BYPASS_DINT.value, BYPASS:=Tagname4,
RATE_OF_CHANGE:=time#1m, ACK_REQUEST:=Tagname3, DISABLE_REQUEST:=Tagname4,
AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6, DEADBAND:=2,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=40,
HIGH_LIMIT:=5, HIGH_SEVERITY:=300, LOW_LIMIT:=5, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=10,
LOW_LOW_SEVERITY:=100
);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

ALARM_ROC_REAL

41

ALARM_ROC_REAL
Generates reate of change alarms for REAL tagnames.

Syntax
My_ROCAlm(SOURCE:=Tagname_2_ROCByp.VALUE, BYPASS:=Tagname_2_ROCByp.BYPASSED,
RATE_OF_CHANGE:=T#5s, ACK_REQUEST:=Tagname_1, DISABLE_REQUEST:=Tagname_5,
AUTOMATIC_RESET:=Tagname_3, MANUAL_RESET_REQUEST:=Tagname_6, DEADBAND:=2.0,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=6.0, HIGH_HIGH_SEVERITY:=400,
HIGH_LIMIT:=3.0, HIGH_SEVERITY:=300, LOW_LIMIT:=3.0, LOW_SEVERITY:=200,
LOW_LOW_LIMIT:=6.0, LOW_LOW_SEVERITY:=100);

Table 26

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which a rate of change alarm will be


generated. May be connected to a tagname, or to the output
of BYPASS_REAL.

RATEOFCHANGE

DINT

The rate of change in SOURCE, measured in units of time


(seconds, minutes, or hours).

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_REAL function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_REAL function block along with
ALARM_ROC_REAL. The output of BYPASS_REAL
(VALUE) should be connected to the SOURCE input
of ALARM_ROC_REAL. Additionally,
BYPASS_REQ on BYPASS_REAL should be true.
Simply setting BYPASS to true will not bypass the
alarm. You must use BYPASS_REAL to bypass the
value, while ALARM_ROC_REALs BYPASS input
also should be true so that you obtain the correct
alarm status.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator


to acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUE
ST

BOOL

If true, the ringback alarm is reset.

DEADBAND

DINT

Specifies the difference between the alarm limit and the input
value before an alarm goes inactive.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

TriStation 1131 Libraries Reference

42

Chapter 2

Functions and Data Types

Table 26

Input Parameters (continued)

Name

Data Type

HIGH_HIGH_LIMIT

DINT

Description
Specifies the High High alarm limit for the SOURCE.
When SOURCE is greater than HIGH_HIGH_LIMIT, then
HIGH_HIGH_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

HIGH_HIGH_SEVERITY

DINT

Specifies the severity for the High High limit.

HIGH_LIMIT

DINT

Specifies the High alarm limit for the SOURCE.


When SOURCE is greater than HIGH_LIMIT, then
HIGH_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

HIGH_SEVERITY

DINT

LOW_LIMIT

DINT

Specifies the severity for the High limit.


Specifies the Low alarm limit for the SOURCE.
When SOURCE is less than LOW_LIMIT, then
LOW_ACTIVE becomes true, and subsequently, the output
parameter ACTIVE becomes true.

LOW_SEVERITY

DINT

LOW_LOW_LIMIT

DINT

Specifies the severity for the Low limit.


Specifies the Low Low alarm limit for the SOURCE.
When SOURCE is less than LOW_LOW_LIMIT, then
LOW_LOW_ACTIVE becomes true, and subsequently, the
output parameter ACTIVE becomes true.

LOW_LOW_SEVERITY

DINT

Specifies the severity for the Low Low limit.

SOURCE_ID

DINT

Reserved for future use.

Table 27

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

HIGH_HIGH_ACTIVE

BOOL

If true, a High High alarm is active.

HIGH_ACTIVE

BOOL

If true, a High alarm is active.

LOW_ACTIVE

BOOL

If true, a Low alarm is active.

LOW_LOW_ACTIVE

BOOL

If true, a Low Low alarm is active.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

TriStation 1131 Libraries Reference

ALARM_ROC_REAL

Table 27

43

Output Parameters (continued)

Name

Data Type

Description

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
LOLO_LVL_ACTIVE (16#00000011)
LOLO_LVL_ACKED (16#00000012)
LO_LVL_ACTIVE (16#00000021)
LO_LVL_ACKED (16#00000022)
HI_LVL_ACTIVE (16#00000031)
HI_LVL_ACKED (16#00000032)
HIHI_LVL_ACTIVE (16#00000041)
HIHI_LVL_ACKED (16#00000042)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_ROC_REAL function generates rate of change alarms for REAL tagnames.
Rate of change alarms are commonly used to report an unusual change or lack of change in a measured
value, relative to the speed at which the value has changed. They typically relate to instruments (for
example, a temperature meter). A rate of change alarm becomes active when the rate at which the value
changes exceeds or drops below a defined limit.
The rate of change is measured in units of time (such as seconds, minutes, or hours). For example, a tank
may have a High limit for the rate of change of its level (measured in meters) of 4 meters/minute. If the
tank level changes at a rate greater than 4 meters/minute, then a High alarm is generated.
The input parameter SOURCE is the process value being measured.
The DEADBAND input parameter specifies the difference between the alarm limit and the input value
that will cause an alarm to go inactive. For example, if a High alarm is set for 100, and the DEADBAND
is set to 10, the alarm will go active at 100, and inactive at 90. If a Low alarm is set for 100, it will go active
at 100, and inactive at 110.
The TIME_DELAY input parameter specifies how long before an alarm will go active once the alarm
condition is detected. For example, if TIME_DELAY is configured as 5 seconds, and the High alarm is set
for 100, once the value exceeds 100, ALARM_ROC_REAL will wait 5 seconds before generating the High
alarm. Use of the TIME_DELAY parameter can help prevent nuisance alarms that may be generated due
to process noise.

Example
VAR My_RateOfChange_Alarm: ALARM_ROC_REAL; END_VAR
VAR My_BYPASS_REAL:BYPASS_REAL; END_VAR
VAR_EXTERNAL My_Tagname:REAL; Tagname2:BOOL; Tagname3:BOOL; Tagname4:BOOL;
Tagname5:BOOL; Tagname6:BOOL;
END_VAR

TriStation 1131 Libraries Reference

44

Chapter 2

Functions and Data Types

My_BYPASS_REAL(TAG_VALUE:=My_Tagname, BYPASS_VALUE:=55, BYPASS_REQ:=Tagname4);


My_RateOfChange_Alarm (SOURCE:=My_BYPASS_REAL.value, BYPASS:=Tagname4,
RATE_OF_CHANGE:=time#1m, ACK_REQUEST:=Tagname3, DISABLE_REQUEST:=Tagname4,
AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6, DEADBAND:=2,
TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=40,
HIGH_LIMIT:=5, HIGH_SEVERITY:=300, LOW_LIMIT:=5, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=10,
LOW_LOW_SEVERITY:=100
);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

ALARM_TRIP

45

ALARM_TRIP
Generates trip alarms for BOOL tagnames.

Syntax
My_TripAlarm(SOURCE:=Tagname_1_TRIPByp.VALUE, BYPASS:=Tagname_1_TRIPByp.BYPASSED,
ACK_REQUEST:=Tagname_3, DISABLE_REQUEST:=Tagname_5, AUTOMATIC_RESET:=Tagname_4,
MANUAL_RESET_REQUEST:=Tagname_6, TIME_DELAY:=T#200ms, RINGBACK:=TRUE, SEVERITY:=200,
NORMAL_STATE:=FALSE);

Table 28

Input Parameters

Name

Data Type

Description

SOURCE

DINT

Input value for which trip alarm will be generated. May be


connected to a tagname, or to the output of BYPASS_BOOL.

BYPASS

BOOL

If true, the source has been bypassed with the


BYPASS_VALUE (from the BYPASS_BOOL function block).
Note:

SOURCE = BYPASS_VALUE only when you use the


BYPASS_BOOL function block along with
ALARM_TRIP. The output of BYPASS_BOOL
(VALUE) should be connected to the SOURCE input
of ALARM_TRIP. Additionally, BYPASS_REQ on
BYPASS_BOOL should be true. Simply setting
BYPASS to true will not bypass the alarm. You must
use BYPASS_BOOL to bypass the value, while
ALARM_TRIPs BYPASS input also should be true so
that you obtain the correct alarm status.

NORMAL_STATE

BOOL

Specifies the healthy state of a point. If the value of SOURCE


changes its state, and the current state is not equal to
NORMAL_STATE, then a trip alarm is generated.

ACK_REQUEST

BOOL

If true, acknowledge request is sent, requesting the operator to


acknowledge the alarm generated by this function block.

DISABLE_REQUEST

BOOL

If true, alarms will not be generated (all alarms disabled).

AUTOMATIC_RESET

BOOL

If true, when the generated alarm returns to normal, it is


acknowledged automatically.

MANUAL_RESET_REQUEST

BOOL

If true, the ringback alarm is reset.

RINGBACK

BOOL

If true, generates a ringback alarm when any previously


generated alarm returns to normal.

TIME_DELAY

TIME

Specifies the time delay for an alarm to go active upon


detection of an alarm condition.

SEVERITY

DINT

Specifies the severity for the alarm.

SOURCE_ID

DINT

Reserved for future use.

TriStation 1131 Libraries Reference

46

Chapter 2

Functions and Data Types

Table 29

Output Parameters

Name

Data Type

Description

ACTIVE

BOOL

If true, an alarm is active. If false, there are no active alarms.

ACKNOWLEDGED

BOOL

If true, the active alarm has been acknowledged.

ACK_TIME

DT

The last time when an active alarm was acknowledged.

ACTIVE_TIME

DT

The last time the alarm was active.

INACTIVE_TIME

DT

The last time the alarm was inactive.

ALARM_STATE

DINT

The current alarm status. Possible values are:


NORMAL (16#00000000)
TRIP_ACTIVE (16#00000051)
TRIP_ACKED (16#00000052)
ALARM_RINGBACK (16#00000003)
ALARM_DISABLED (16#00000004)
ALARM_BYPASSED(16#000000XX)
where XX can be any of the above alarm states

Description
The ALARM_TRIP function generates a trip alarm when there is a mismatch between the current state
and the normal state for a BOOL tagname.
Trip alarms are intended to represent an equipment trip condition. A trip alarm is generated when the
monitored piece of equipment experiences an abnormal fault (such as a motor shutting down due to an
overload condition).
The input parameter SOURCE is the process value being monitored. The input parameter
NORMAL_STATE indicates which of the possible input values indicates the normal condition of the
equipment being monitored. When the value of the tagname referenced by the SOURCE parameter is not
equal to the value of NORMAL_STATE, then the trip alarm is generated.
The TIME_DELAY input parameter specifies how long before the trip alarm will go active once the alarm
condition is detected. For example, if TIME_DELAY is configured as 5 seconds, and the
NORMAL_STATE is set for True, once the state changes to False, ALARM_TRIP will wait 5 seconds
before generating the trip alarm. Use of the TIME_DELAY parameter can help prevent nuisance alarms
that may be generated due to process noise.

Example
VAR My_TripAlarm:ALARM_TRIP ; END_VAR
VAR_EXTERNAL My_Tagname: BOOL ; END_VAR
MY_TripAlarm(SOURCE:=My_Tagname,
BYPASS:=False(or any BOOL tag), ACK_REQUEST:=False(or any BOOL tag),
DISABLE_REQUEST:=False(or any BOOL tag), AUTOMATIC_RESET:=false(or any BOOL tag),
MANUAL_RESET_REQUEST:=true(or any BOOL tag), TIME_DELAY:=T#10ms(or any TIME tag),
RINGBACK:=TRUE(or any BOOL tag), SEVERITY:=200(or any DINT tag),
NORMAL_STATE:=FALSE);

Runtime Errors
None.

TriStation 1131 Libraries Reference

ALARM_TRIP

47

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was first released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

48

Chapter 2

Functions and Data Types

AND
Performs a logical AND of two or more Boolean operands or a bitwise AND of two or more bit-strings.

Syntax
b := b1 AND b2 AND ... AND bn ;

Table 30

Input Parameters

Name

Data Type

Description

b1...bn

ANY_BIT

Operands

Table 31

Return Value

Data Type

Description

ANY_BIT

b1 AND b2 AND ... AND bn

Description
In graphical languages, the AND function returns the logical AND of Boolean operands or the bitwise
AND of bit-strings. In Structured Text, the AND operator is used instead of the AND function.
The maximum number of function inputs is 50.
All operands must be the same type as the return value, either all BOOL or all DWORD.
If the operand type is BOOL, then the result is true if all operands are true. The result is false if any
operand is false.

Table 32

Logical AND

b1

b2

b1 OR b2

FALSE

FALSE

FALSE

FALSE

TRUE

FALSE

TRUE

FALSE

FALSE

TRUE

TRUE

TRUE

If the operand type is DWORD, then the result is the bitwise AND of all the operands. In other words, the
value in each bit position of the result is the AND of all the values in the same bit position.

Table 33

Bitwise AND

w1

w2

w1 AND w2

2#0011

2#0101

2#0001

TriStation 1131 Libraries Reference

AND

49

Example
Using Boolean Operands
VAR b, b1:=TRUE, b2:=FALSE, b3:=TRUE : BOOL; END_VAR
b := b1 AND b2 AND b3;
(* result is FALSE *)
b := b1 AND b3;
(* result is TRUE *)

Using Bit-String Parameters


VAR w, w1, w2, w3 : DWORD; END_VAR
w1 :=
2#00000000000000000000000000000111
w2 :=
2#00000000000000000000000000000011
w3 :=
2#00000000000000000000000000000101
w := w1 AND w2 AND w3; (* 2#00000000000000000000000000000001
w := w1 AND w3;
(* 2#00000000000000000000000000000101

;
;
;
*)
*)

Note that on the Controller Panel, you will see the example values in hex. The hex values of the operands
are w1=16#00000007, w2=16#00000003, w3=16#00000005, and the hex values of the results are
16#00000001 and 16#00000005.

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

50

Chapter 2

Functions and Data Types

AOUT
Converts a real number to an analog output.

Syntax
k := AOUT( MX,

Table 34

IN,

MN )

Input Parameters

Name

Data Type

Description

MX

REAL

The value of IN required to drive 20 mA or 5 V in the field.

IN

REAL

The value to be converted to an analog output.

MN

REAL

The value of IN required to drive 4 mA or 1 V in the field.

Table 35

Return Value

Data Type

Description

DINT

The value of IN converted to machine counts.

Description
The AOUT function converts a real number to an analog output (in machine counts) that is typically in
the range of 819 to 4095. MN is the input value required to drive 4 milliamps or 1 volt in the field. MX is
the input value required to drive 20 milliamps or 5 volts in the field. AOUT does not clamp the analog
output to the range of 819 to 4095.

Example
VAR
k :=
k :=
k :=

k : DINT; END_VAR
AOUT( 100.0, 100.0, 0.0 );
AOUT( 100.0, 50.0, 0.0 );
AOUT( 100.0,
0.0, 0.0 );

(* result is 4095 *)
(* result is 2457 *)
(* result is 819 *)

Runtime Errors
Condition

Return Value

Error Flags

If MX is less than or equal to MN.

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

AOUT_BP12

51

AOUT_BP12
Converts a real number to a 12-bit differential bipolar analog output.

Syntax
y := AOUT_BP12( MX,

Table 36

IN,

MN )

Input Parameters

Name

Data Type

Description

MX

REAL

The engineering unit value for the maximum machine count of


+4095.

IN

REAL

The value to be converted to an analog output.

MN

REAL

The engineering unit value for the minimum machine count of 4095.

Table 37

Return Value

Data Type

Description

DINT

The value of IN converted to machine counts.

Description
The AOUT_BP12 function converts a real number to a 12-bit differential bipolar analog output (in
machine counts). When the input equals MN, the return value is -4095. When the input equals MX, the
return value is +4095. AOUT_BP12 does not clamp the analog output to the range of -4095 to +4095. The
scaling equation implemented in this function is approximately equivalent to
IN MN------------------------ HI LO + LO
MX MN

where HI= 4095 and LO= -4095.


Machine
Count

+4095

MN
MX

Engineering
Units

-4095

TriStation 1131 Libraries Reference

52

Chapter 2

Functions and Data Types

Example
The BPAO module (model 3807) provides a 12-bit bipolar analog output that ranges from -60ma to
+60ma. An input value of -60ma corresponds to a machine count of -4095. An input value of +60ma
corresponds to a machine count of +4095. The following example function call converts the current (in
ma) to machine count:

VAR y : DINT; in : REAL; END_VAR


y := AOUT_BP12( +60.0, in, -60.0 );
in

-60.0

-4095

0.0

+60.0

+4095

Runtime Errors
None

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)
This function was added to the library in v1.32 of TCXLIB, first released with TriStation 1131 v4.3.

TriStation 1131 Libraries Reference

ARRAY32_BOOL

53

ARRAY32_BOOL
Stores an array of 32 Boolean values.

Syntax
ARRAY32_BOOL(READ:=b1, WRITE:=b2, INDEX:=k, IN:=b3)

Table 38

Input Parameters

Name

Data Type

Description

READ

BOOL

Enables reading from the selected array element.

WRITE

BOOL

Enables writing to the selected array element.

INDEX

DINT

Selects an array element from 1 to 32.

IN

BOOL

Specifies the value to be used.

Table 39

Output Parameters

Name

Data Type

Description

CO

BOOL

The control output.

OUT

BOOL

The data output.

Description
The ARRAY32_BOOL function block stores an array of 32 Boolean values. The INDEX input selects one
of the 32 array elements. If WRITE is true, then the data input value IN is copied to the selected array
element. If READ is true, then the value in the selected array element is copied to OUT.
This table shows the outputs for a combination of inputs.
READ

WRITE

INDEX

CO

OUT

Notes

True

False

In-range

True

Value in the selected


array element

False

True

In-range

True

False

Writes IN to selected array element.

True

True

In-range

True

Value in the selected


array element

Writes IN to selected array element.

True

Out-of-range

False

False

Sets BADPARAM, clears ENO.

True

Out-of-range

False

False

Sets BADPARAM, clears ENO.

False

False

False

False

No operation.

a. This symbol ( ) means the true or false value is ignored.

TriStation 1131 Libraries Reference

54

Chapter 2

Functions and Data Types

Example
Write a value to array element 23
VAR MY_ARRAY : ARRAY32_BOOL; END_VAR;
MY_ARRAY(READ:=FALSE, WRITE:=TRUE, INDEX:=23, IN:=TRUE);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is FALSE *)

Read a value from array element 23


VAR MY_ARRAY : ARRAY32_BOOL; END_VAR;
MY_ARRAY(READ:=TRUE, WRITE:=FALSE, INDEX:=23, IN:=FALSE);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is TRUE *)

Write then read a value from array element 23


VAR MY_ARRAY : ARRAY32_BOOL; END_VAR;
MY_ARRAY(READ:=TRUE, WRITE:=TRUE, INDEX:=23, IN:=FALSE);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is FALSE *)

Runtime Errors
Condition

Return Value

Error Flags

If INDEX is out-of-range (less than 1 or greater than 32).

OUT is false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Internal State: a single instance can be executed more than once per scan. However, you should
be aware of the internal states that are used from one scan to the next.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

ARRAY32_DINT

55

ARRAY32_DINT
Stores an array of 32 integers.

Syntax
ARRAY32_DINT(READ:=b1, WRITE:=b2, INDEX:=k, IN:=b3)

Table 40

Input Parameters

Name

Data Type

Description

READ

BOOL

Enables reading from the selected array element.

WRITE

BOOL

Enables writing to the selected array element.

INDEX

DINT

Selects an array element from 1 to 32.

IN

DINT

Specifies the value to be used.

Table 41

Output Parameters

Name

Data Type

Description

CO

BOOL

The control output.

OUT

DINT

The data output.

Description
The ARRAY32_DINT function block stores an array of 32 integers. The INDEX input selects one of the 32
array elements. If WRITE is true, then the data input value IN is copied to the selected array element. If
READ is true, then the value in the selected array element is copied to OUT. This table shows the outputs
for a combination of inputs.
READ

WRITE

INDEX

CO

OUT

Notes

True

False

In-range

True

Value in the selected


array element

False

True

In-range

True

Writes IN to selected array element.

True

True

In-range

True

Value in the selected


array element

Writes IN to selected array element.

True

Out-of-range

False

Sets BADPARAM, clears ENO.

True

Out-of-range

False

Sets BADPARAM, clears ENO.

False

False

False

No operation.

a. This symbol ( ) means the true or false state is ignored.

TriStation 1131 Libraries Reference

56

Chapter 2

Functions and Data Types

Example
Write a value to array element 23
VAR MY_ARRAY : ARRAY32_DINT; END_VAR;
MY_ARRAY(READ:=FALSE, WRITE:=TRUE, INDEX:=23, IN:=1234);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is 0 *)

Read a value from array element 23


VAR MY_ARRAY : ARRAY32_DINT; END_VAR;
MY_ARRAY(READ:=TRUE, WRITE:=FALSE, INDEX:=23, IN:=0);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is 1234 *)

Write then read a value from array element 23


VAR MY_ARRAY : ARRAY32_DINT; END_VAR;
MY_ARRAY(READ:=TRUE, WRITE:=TRUE, INDEX:=23, IN:=5678);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is 5678 *)

Runtime Errors
Condition

Return Value

Error Flags

If INDEX is out-of-range (less than 1 or greater than 32).

OUT is 0

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Internal State: a single instance can be executed more than once per scan. However, you should
be aware of the internal states that are used from one scan to the next.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

ARRAY32_REAL

57

ARRAY32_REAL
Stores an array of 32 real numbers.

Syntax
ARRAY32_REAL(READ:=b1, WRITE:=b2, INDEX:=k, IN:=b3)

Table 42

Input Parameters

Name

Data Type

Description

READ

BOOL

Enables reading from the selected array element.

WRITE

BOOL

Enables writing to the selected array element.

INDEX

DINT

Selects an array element from 1 to 32.

IN

REAL

Specifies the value to be used.

Table 43

Output Parameters

Name

Data Type

Description

CO

BOOL

The control output.

OUT

REAL

The data output.

Description
The ARRAY32_REAL function block stores an array of 32 real numbers. The INDEX input selects one of
the 32 array elements. If WRITE is true, then the data input value IN is copied to the selected array
element. If READ is true, then the value in the selected array element is copied to OUT.
This table shows the outputs for a combination of inputs.
READ

WRITE

INDEX

CO

OUT

Notes

True

False

In-range

True

Value in the selected


array element

False

True

In-range

True

Writes IN to selected array element.

True

True

In-range

True

Value in the selected


array element

Writes IN to selected array element.

True

Out-of-range

False

Sets BADPARAM, clears ENO.

True

Out-of-range

False

Sets BADPARAM, clears ENO.

False

False

False

No operation.

a. This symbol ( ) means the true or false state is ignored.

TriStation 1131 Libraries Reference

58

Chapter 2

Functions and Data Types

Example
Write a value to array element 23
VAR MY_ARRAY : ARRAY32_DINT; END_VAR;
MY_ARRAY(READ:=FALSE, WRITE:=TRUE, INDEX:=23, IN:=1234);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is 0 *)

Read a value from array element 23


VAR MY_ARRAY : ARRAY32_DINT; END_VAR;
MY_ARRAY(READ:=TRUE, WRITE:=FALSE, INDEX:=23, IN:=0);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is 1234 *)

Write then read a value from array element 23


VAR MY_ARRAY : ARRAY32_DINT; END_VAR;
MY_ARRAY(READ:=TRUE, WRITE:=TRUE, INDEX:=23, IN:=5678);
(* Result: MY_ARRAY.CO is TRUE; MY_ARRAY.OUT is 5678 *)

Runtime Errors
Condition

Return Value

Error Flag

If INDEX is out-of-range (less than 1 or greater than 32).

OUT is 0

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Internal State: a single instance can be executed more than once per scan. However, you should
be aware of the internal states that are used from one scan to the next.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

ASIN

59

ASIN
Calculates the principal arc sine of a real number.

Syntax
Y := ASIN( x )

Table 44

Input Parameters

Name

Data Type

Description

ANY_REAL

The real number between 1.0 and 1.0 whose arc sine is to be calculated.

Table 45

Return Value

Data Type

Description

ANY_REAL

The arc sine of x in radians from 1.5708 to +1.5708.

Description
The ASIN function calculates the principal arc sine of a real number. The result is in radians from 1.5708
to +1.5708.

Example
VAR y : REAL; ND VAR
y := ASIN( 1.0 );
y := ASIN( 1.0 );

(* result is +1.5708 *)
(* result is 1.5708 *)

Runtime Errors
Condition

Return Values

Error Flags

If X is not a number or the absolute value of x is greater than 1.0.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

60

Chapter 2

Functions and Data Types

ATAN
Calculates the principal arc tangent of a real number.

Syntax
Y := ATAN( x )

Table 46

Input Parameters

Name

Data Type

Description

ANY_REAL

Any real number.

Table 47

Return Value

Data Type

Description

ANY_REAL

The arc tangent of x in radians from 1.5708 to +1.5708.

Description
The ATAN function calculates the principal arc tangent of a real number. The result is in radians from
1.5708 to +1.5708.

Example
VAR
y :=
y :=
y :=
y :=

y : REAL; END_VAR
ATAN(
1.0 );
ATAN( 1.0 );
ATAN( 10.0 );
ATAN( 10.0 );

(*
(*
(*
(*

result
result
result
result

is
is
is
is

+0.785398
0.785398
+1.47113
1.47113

*)
*)
*)
*)

Runtime Errors
Condition

Return Value

Error Flags

If X is not a number.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

BLINK

61

BLINK
Generates a pulse output.

Syntax
BLINK(IN:=b1, RESET:=b2, T_ON:=t1, T_OFF:=t2)

Table 48

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables blinking.

RESET

BOOL

Resets the output Q to false.

T_ON

TIME

Generates a pulse output on-time in microseconds.

T_OFF

TIME

Generates a pulse output off-time in microseconds.

Table 49

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

Description
The BLINK function block generates a pulse output intended to repeatedly turn an indicator on and off.
The IN input enables blinking. The RESET input resets the Q output to false and initiates the pulse-off
period. T_ON specifies how long the pulse is on; T_OFF specifies how long the pulse is off.

Example
This example blinks an alarm indicator at a rate of 1 second on and 500 milliseconds off.
VAR_OUTPUT
INDICATOR : BOOL; END_VAR
VAR BLINK_ALARM : BLINK; END_VAR
BLINK_ALARM(IN:=TRUE,RESET:=FALSE,T_ON:=t#1s,T_OFF:=t#500ms);
INDICATOR := BLINK_ALARM.Q ;

TriStation 1131 Libraries Reference

62

Chapter 2

Functions and Data Types

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

BLINK_I

63

BLINK_I
Generates a pulse output.

Syntax
BLINK_I(IN:=b1, RESET:=b2, T_ON:=t1, T_OFF:=t2)

Table 50

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables blinking.

RESET

BOOL

Resets the output Q to false.

T_ON

DINT

Generates a pulse output on-time in milliseconds.

T_OFF

DINT

Generates a pulse output off-time in milliseconds.

Table 51

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

Description
The BLINK_I function block generates a pulse output intended to repeatedly turn an indicator on and off.
The IN input enables blinking. The RESET input resets the Q output to false and initiates the pulse-off
period. T_ON specifies how long the pulse is on; T_OFF specifies how long the pulse is off.

Example
This example blinks an alarm indicator at a rate of one second on and one-half second off.
VAR_OUTPUT
INDICATOR : BOOL; END_VAR
VAR
BLINK_ALARM : BLINK_I; END_VAR
BLINK_ALARM(IN:=TRUE,RESET:=FALSE,T_ON:=t#1s,T_OFF:=t#500ms);
INDICATOR := BLINK_ALARM.Q ;

TriStation 1131 Libraries Reference

64

Chapter 2

Functions and Data Types

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

BLINK_R

65

BLINK_R
Generates a pulse output.

Syntax
BLINK_R(IN:=b1, RESET:=b2, T_ON:=t1, T_OFF:=t2)

Table 52

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables blinking.

RESET

BOOL

Resets the output Q to false.

T_ON

REAL

Generates a pulse output on-time in seconds.

T_OFF

REAL

Generates a pulse output off-time in seconds.

Table 53

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

Description
The BLINK_R function block generates a pulse output intended to repeatedly turn an indicator on and
off. The IN input enables blinking. The RESET input resets the Q output to false and initiates the pulseoff period. T_ON specifies how long the pulse is on; T_OFF specifies how long the pulse is off.

Example
This example blinks an alarm indicator at a rate of one second on and one-half second off.
VAR_OUTPUT
INDICATOR : BOOL; END_VAR
VAR
BLINK_ALARM : BLINK_I; END_VAR
BLINK_ALARM(IN:=TRUE,RESET:=FALSE,T_ON:=t#1s,T_OFF:=t#500ms);
INDICATOR := BLINK_ALARM.Q ;

TriStation 1131 Libraries Reference

66

Chapter 2

Functions and Data Types

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

BOOL

67

BOOL
A BOOL data type is one bit in length and has two possible values: false (0) or true (1).
Attribute

Description

Keyword/type

BOOL

Description

Boolean

Size

1 bit

Default value

False (0)

Lower limit

False (0)

Upper limit

True (1)

Result if intermediate value is less than lower limit

N/A

Result if upper limit is less than intermediate value

Intermediate Value MOD 2

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

68

Chapter 2

Functions and Data Types

BOOL_TO_DWORD
Converts a Boolean (BOOL) value to a DWORD value.

Syntax
w := BOOL_TO_DWORD(b);

Table 54

Input Parameters

Name

Data Type

Description

BOOL

The Boolean value to be converted.

Table 55

Return Value

Name

Data Type

Description

DWORD

DWORD

The value of b converted to a DWORD value.

Description
The BOOL_TO_DWORD function converts a Boolean (BOOL) value to a DWORD value.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
b :=
w :=
b :=
w :=

b : BOOL;
w : DWORD;
TRUE;
BOOL_TO_DWORD( b );
FALSE;
BOOL_TO_DWORD( b );

END_VAR;

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

(* result is 16#0001 *)
(* result is 16#0000 *)

BYPASS_BOOL

69

BYPASS_BOOL
Bypasses an alarm generated from a BOOL alarm function block.

Syntax
Tagname_2_LvByp(TAG_VALUE:=Tagname_2, BYPASS_VALUE:=TRUE, BYPASS_REQ:=Tagname_4);

Table 56

Input Parameters

Name

Data Type

Description

BYPASS_REQ

BOOL

If true, the output VALUE is BYPASS_VALUE. If false, the


output VALUE is TAG_VALUE.

BYPASS_VALUE

BOOL

The value to be bypassed if BYPASS_REQ is true.

TAG_VALUE

BOOL

The value of a BOOL tagname.

Table 57

Output Parameters

Name

Data Type

Description

VALUE

BOOL

The output value.

BYPASSED

BOOL

True if input BYPASS_REQ is true. Otherwise, false.

Description
The BYPASS_BOOL function can be used to bypass an alarm that is generated from a BOOL alarm
function block (ALARM_TRIP).
If the input parameter BYPASS_REQ is true, the source value (TAG_VALUE) will be bypassed and the
output parameter VALUE will have the same value as BYPASS_VALUE. The output parameter VALUE
should be connected to the SOURCE input parameter of a BOOL alarm function block. Additionally,
BYPASS_REQ should be true.
Simply setting the BOOL alarm function blocks BYPASS input to true will not bypass the alarm. You
must use BYPASS_BOOL to bypass the value, while the BOOL alarm function blocks BYPASS input also
should be true so that you obtain the correct alarm status.

Example
VAR My_BYPASS_BOOL:BYPASS_BOOL; END_VAR
VAR My_Trip_Alarm: ALARM_TRIP; END_VAR
VAR_EXTERNAL
My_SourceTagname: BOOL;
My_BypassTagname: BOOL;
END_VAR
My_BYPASS_BOOL(TAG_VALUE:=My_SourceTagname, BYPASS_VALUE:=TRUE,
BYPASS_REQ:=My_BypassTagname);
My_Trip_Alarm (SOURCE:=My_BYPASS_BOOL.value, BYPASS:=My_BypassTagname,
ACK_REQUEST:=False, DISABLE_REQUEST:=False, AUTOMATIC_RESET:=False,
MANUAL_RESET_REQUEST:=True, TIME_DELAY:=T#10ms, RINGBACK:=FALSE, SEVERITY:=200,
NORMAL_STATE:=True);

TriStation 1131 Libraries Reference

70

Chapter 2

Functions and Data Types

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was initially released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

BYPASS_DINT

71

BYPASS_DINT
Bypasses an alarm generated from a DINT alarm function block.

Syntax
Tagname_2_LvByp(TAG_VALUE:=Tagname_2, BYPASS_VALUE:=55, BYPASS_REQ:=Tagname_4);

Table 58

Input Parameters

Name

Data Type

Description

BYPASS_REQ

BOOL

If true, the output VALUE is BYPASS_VALUE. If false, the


output VALUE is TAG_VALUE.

BYPASS_VALUE

DINT

The value to be bypassed if BYPASS_REQ is true.

TAG_VALUE

DINT

The value of a DINT tagname.

Table 59

Output Parameters

Name

Data Type

Description

VALUE

DINT

The output value.

BYPASSED

BOOL

True if input BYPASS_REQ is true. Otherwise, false.

Description
The BYPASS_DINT function can be used to bypass an alarm that is generated from a DINT alarm
function block (ALARM_LEVEL_DINT, ALARM_DEVIATION_DINT, or ALARM_ROC_DINT).
If the input parameter BYPASS_REQ is true, the source value (TAG_VALUE) will be bypassed and the
output parameter VALUE will have the same value as BYPASS_VALUE. The output parameter VALUE
should be connected to the SOURCE input parameter of a DINT alarm function block. Additionally,
BYPASS_REQ should be true.
Simply setting the DINT alarm function blocks BYPASS input to true will not bypass the alarm. You must
use BYPASS_DINT to bypass the value, while the DINT alarm function blocks BYPASS input also should
be true so that you obtain the correct alarm status.

Example
The following example bypasses a deviation alarm SOURCE input with the configured bypass value (55)
when BYPASS_REQ is True (Tagname4).
VAR My_Deviation_Alarm: ALARM_DEVIATION_DINT; END_VAR
VAR My_BYPASS_DINT:BYPASS_DINT; END_VAR
VAR_EXTERNAL
My_Tagname: DINT;
Tagname2:BOOL;Tagname3:BOOL; Tagname4:BOOL; Tagname5:BOOL;Tagname6:BOOL;
END_VAR
My_BYPASS_DINT(TAG_VALUE:=My_Tagname, BYPASS_VALUE:=55, BYPASS_REQ:=Tagname4);
My_Deviation_Alarm (SOURCE:=My_BYPASS_DINT.value, BYPASS:=Tagname4,
SETPOINT:=55, ACK_REQUEST:=Tagname3, DISABLE_REQUEST:=Tagname4,

TriStation 1131 Libraries Reference

72

Chapter 2

Functions and Data Types

AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6, DEADBAND:=2,


TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=400,
HIGH_LIMIT:=5, HIGH_SEVERITY:=300, LOW_LIMIT:=5, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=
10, LOW_LOW_SEVERITY:=100
);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was initially released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

BYPASS_REAL

73

BYPASS_REAL
Bypasses an alarm generated from a REAL alarm function block.

Syntax
Tagname_2_LvByp(TAG_VALUE:=Tagname_2, BYPASS_VALUE:=55.25, BYPASS_REQ:=Tagname_4);

Table 60

Input Parameters

Name

Data Type

Description

BYPASS_REQ

BOOL

If true, the output VALUE is BYPASS_VALUE. If false, the


output VALUE is TAG_VALUE.

BYPASS_VALUE

REAL

The value to be bypassed if BYPASS_REQ is true.

TAG_VALUE

REAL

The value of a REAL tagname.

Table 61

Output Parameters

Name

Data Type

Description

VALUE

REAL

The output value.

BYPASSED

BOOL

True if input BYPASS_REQ is true. Otherwise, false.

Description
The BYPASS_REAL function can be used to bypass an alarm that is generated from a REAL alarm
function block (ALARM_LEVEL_REAL, ALARM_DEVIATION_REAL, or ALARM_ROC_REAL).
If the input parameter BYPASS_REQ is true, the source value (TAG_VALUE) will be bypassed and the
output parameter VALUE will have the same value as BYPASS_VALUE. The output parameter VALUE
should be connected to the SOURCE input parameter of a REAL alarm function block. Additionally,
BYPASS_REQ should be true.
Simply setting the REAL alarm function blocks BYPASS input to true will not bypass the alarm. You
must use BYPASS_REAL to bypass the value, while the REAL alarm function blocks BYPASS input also
should be true so that you obtain the correct alarm status.

Example
The following example bypasses a deviation alarm SOURCE input with the configured bypass value (55)
when BYPASS_REQ is True (Tagname4).
VAR My_Deviation_Alarm: ALARM_DEVIATION_REAL; END_VAR
VAR My_BYPASS_REAL:BYPASS_REAL; END_VAR
VAR_EXTERNAL
My_Tagname: REAL;
Tagname2:BOOL;Tagname3:BOOL; Tagname4:BOOL; Tagname5:BOOL;Tagname6:BOOL;
END_VAR
My_BYPASS_REAL(TAG_VALUE:=My_Tagname, BYPASS_VALUE:=55, BYPASS_REQ:=Tagname4);
My_Deviation_Alarm (SOURCE:=My_BYPASS_REAL.value, BYPASS:=Tagname4,
SETPOINT:=55, ACK_REQUEST:=Tagname3, DISABLE_REQUEST:=Tagname4,

TriStation 1131 Libraries Reference

74

Chapter 2

Functions and Data Types

AUTOMATIC_RESET:=Tagname5, MANUAL_RESET_REQUEST:=Tagname6, DEADBAND:=2,


TIME_DELAY:=T#5ms, RINGBACK:=TRUE, HIGH_HIGH_LIMIT:=10, HIGH_HIGH_SEVERITY:=400,
HIGH_LIMIT:=5, HIGH_SEVERITY:=300, LOW_LIMIT:=5, LOW_SEVERITY:=200, LOW_LOW_LIMIT:=
10, LOW_LOW_SEVERITY:=100
);

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Process Alarm Library (ALARMS)
This library was initially released with TriStation 1131 v4.7.0, but can be used with all TriStation 1131 versions.

TriStation 1131 Libraries Reference

CEIL

75

CEIL
Returns the next higher integer.

Syntax
y := CEIL( x )

Table 62

Input Parameters

Name

Data Type

Description

ANY_REAL

The operand.

Table 63

Return Value

Data Type

Description

ANY_REAL

The next higher integer greater than or equal to x.

Description
The CEIL function returns the next higher integer greater than or equal to x.

Example
VAR
x : REAL
END_VAR;
x := ceil(6.04 );

(* result is 7.0 *)

Runtime Errors
Condition

Return Value

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

76

Chapter 2

Functions and Data Types

CHK_ERR
Checks for runtime errors.

Syntax
CHK_ERR( CI:=TRUE )

Table 64

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables CHK_ERR.

Table 65

Output Parameters

Name

Data Type

Description

CO

BOOL

True if CHK_ERR executes successfully.

ERROR

BOOL

True if any of the following outputs (except UNDERFLOW) are true.

DIVBYZERO

BOOL

Divide by zero.

OVERFLOW

BOOL

Floating-point overflow.

UNDERFLOW

BOOL

Floating-point underflow.

BADPARAM

BOOL

Bad parameter.

BADCONV

BOOL

Type conversion error.

STRLEN

BOOL

String length error.

RANGE

BOOL

Subrange bound error.

ARRAYERR

BOOL

Array index error.

INTERNALERR

BOOL

Internal error.

OTHER

BOOL

Other error.

Description
The CHK_ERR function block reads the runtime error flags.
When an error is detected while building or compiling a program, the error is considered a build error or
a compile error. When an error is detected while the program is running in an emulator or controller, the
error is considered a runtime error.
There are four mechanisms for detection, reporting, and handling of runtime errors.

A function can return an error number or Boolean value indicating success or failure or type of
error. See the Return Value section for a function to see the error codes for that function.

A function block can output an error number or Boolean value indicating success or failure or
type of error. See the Output Parameters section for a function block to see the error codes for
the function block.

A function or operator can reset ENO to false, indicating a runtime error. ENO is the variable
specified by IEC1131-3 for handling errors. In typical usage, a caller sets ENO to true before
calling the function. If the function detects a runtime error, the function resets ENO to false.

TriStation 1131 Libraries Reference

CHK_ERR

77

After calling the function, the caller tests ENO. For example, the caller can continue normal
operation if ENO is true, or handle the error if ENO is false. Note that the value of ENO is
undefined after calling a function block. See the Runtime Errors section for a function to
determine when the function resets ENO.

A function, function block, or operator can set runtime error flags. The caller can use the
CHK_ERR function block to read the runtime error flags. The caller can use the Triconex
(TCXLIB) function block to reset the runtime error flags to false. The runtime error flags are
automatically reset to false at the start of each scan. See the Runtime Errors section for a function
to see which runtime error flags can be set by the function.

This table shows the runtime error flags and the effect on ENO for each runtime error condition.
Condition

Runtime error flags,


CHK_ERR outputs

Reset ENO

Divide by zero

ERROR, DIVBYZERO

Yes

Floating point overflow

ERROR, OVERFLOW

Yes

Floating point underflow

UNDERFLOW

No

Bad parameter

ERROR, BADPARAM

Yes

Type conversion error

ERROR, BADCONV

Yes

String length error

ERROR, STRLEN

Yes

Subrange bound error

ERROR, RANGE

Yes

Array index error

ERROR, ARRAYERR

Yes

Internal error

ERROR, INTERNALERR

Yes

Other error

ERROR, OTHER

Yes

Note

When the ERROR flag is true, it indicates a design flaw in the application that should be
corrected. For example, you should never have a divide by zero error because the program
should check the divisor before doing the division. To find such errors, a good practice is to add
a CHK_ERR function block at the end of the last program and set an alarm if the ERROR output
is true.

Divide by zero is detected by the divide operator / , the MOD operator, the DIV function, and the MOD
function when the divisor is zero.
Floating point overflow is detected by floating point arithmetic when the result is infinity, that is, when
the result is out of range.
Floating point underflow is detected by the exponential operator ** , the EXP function, and the Standard
(STDLIB) function. Underflow occurs when the result is very close to zero. Since underflow is not an
error, an underflow condition does not set the ERROR flag and does not reset ENO to false.
Bad parameter is detected by library functions and user-defined functions when a parameter is not in the
specified range. A user-defined function can use the ReportBadParam function to report a bad parameter
error.
A type conversion error is detected by a conversion function ( like REAL_TO_DINT ) when the converted
result is out-of-range.
A string length error is detected when a string is too long, that is, too many characters.

TriStation 1131 Libraries Reference

78

Chapter 2

Functions and Data Types

A subrange bound error is detected when a result is out-of-range, that is, not in the specified subrange. If
the subrange data type feature is not implemented, then the RANGE flag is always false (reserved for
future use).
An array index error is detected when an array index is out-of-boundsthe index bounds are specified
in the declaration of each array. By default, if the ARRAYERR flag is true at the end of the last program,
the control program traps and the main processors reset to the safe state. To avoid a trap, use the Triconex
(TCXLIB) function block to clear the ARRAYERR flag at the end of the last program.
An internal error is an error in the implementation code, that is, not a user programming error. An
example is an error in an interface between a compiler and a library, or between a library and an operation
system. Such errors may occur during development of Triconex software, but should never occur in
released software. In most recent releases, such errors result in a trap and reset the main processors to the
safe state. In other words, the INTERNALERR flag is always false when a user program reads it.
The OTHER error flag is reserved for future use.

Example
For runtime error examples, see one of these sample projects:

Exmodbus.pt2 (Tricon controllers)

Tdmodbus.pt2 (Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

These examples, MY_FUNCTION and MY_PROGRAM, illustrate how to report a runtime error, how to
stop execution using ENO, and how to read the runtime error flags using the CHK_ERR function block.
FUNCTION MY_FUNCTION : DINT
VAR_INPUT
k : DINT ;
END_VAR
VAR
unused : BOOL ;
END_VAR
MY_FUNCTION := 0 ;
IF k < 0 THEN
(*
* The following statement
* sets the ERROR flag to true,
* sets the BADPARAM flag to true,
* and resets ENO to false.
*)
unused := ReportBadParam(0) ;
ELSE
MY_FUNCTION := k ;
END_IF ;
END_FUNCTION

PROGRAM MY_PROGRAM
VAR
FLAGS : CHK_ERR ;
n : DINT ;
END_VAR
FLAGS() ;

TriStation 1131 Libraries Reference

CHK_ERR

79

(* FLAGS.ERROR is false and FLAGS.BADPARAM is false. *)


ENO := true ;
IF ENO THEN
n := MY_FUNCTION( 1 ) ;
(* ENO is still true because the parameter was OK. *)
END_IF ;
IF ENO THEN
n := MY_FUNCTION( -1 ) ;
(* ENO is now false because MY_FUNCTION detected a runtime error. *)
END_IF ;
IF ENO THEN
(* The following statement is not executed because ENO is false. *)
n := n + 1 ;
END_IF ;
FLAGS() ;
(* FLAGS.ERROR is true and FLAGS.BADPARAM is true. *)
END_PROGRAM

Runtime Errors
NoneCHK_ERR reads, but does not change, the runtime error flags.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

80

Chapter 2

Functions and Data Types

CLR_ERR
Clears the runtime errors read by the CHK_ERR function block.

Syntax
CLR_ERR( CI:=TRUE )

Table 66

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables CHK_ERR.

Table 67

Output Parameters

Name

Data Type

Description

CO

BOOL

True if CLR_ERR executes successfully.

Description
The CLR_ERR function block clears the runtime errors read by the CHK_ERR function block.

Example
In this example, the program checks for runtime errors in the middle and end of the program. CLR_ERR
clears the errors after each error check.
PROGRAM CLR_ERR_EXAMPLE
VAR
CHECK_ERRORS : CHK_ERR;
CLEAR_ERRORS : CLR_ERR;
ERRORS_A, ERRORS_B : BOOL;
END_VAR
(*
:
CHECK_ERRORS( CI := TRUE );
IF (CHECK_ERRORS.ERROR = TRUE ) THEN ERRORS_A
CLEAR_ERRORS( CI := TRUE );
:
(* More
:
IF (CHECK_ERRORS.ERROR = TRUE ) THEN ERRORS_B
CLEAR_ERRORS( CI := TRUE );
END_PROGRAM

Runtime Errors
None.

TriStation 1131 Libraries Reference

Program code *)

:= TRUE; END_IF;

program code *)
:= TRUE; END_IF;

CLR_ERR

81

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

82

Chapter 2

Functions and Data Types

CONCAT_DT
Concatenates date and time-of-day values.

Syntax
datetime := CONCAT_DT( d, t )

Table 68

Input Parameters

Name

Data Type

Description

DATE

The date.

TOD

The time of day.

Table 69

Return Value

Data Type

Description

DT

The concatenation of d and t represented as date and time values.

Description
The CONCAT_DT function concatenates a date with a time of day and returns a date-and-time value.

Example
VAR
d : DATE; t : TOD; datetime : DT;
END_VAR
d := D#2002-01-01;
t := TOD#10:32:12;
datetime := CONCAT_DT( d, t ); (*result is DT#2002-01-01-10:32:12*)

Runtime Errors
Conditions

Return Values

Error Flags

If d or t is out of range.

d+t

BADPARAM, ERROR

If the result is out of range.

Invalid date

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

COS

83

COS
Calculates the cosine of an angle.

Syntax
y := COS( x ) ;

Table 70

Input Parameters

Name

Data Type

Description

ANY_REAL

The angle in radians.

Table 71

Return Value

Data Type

Description

ANY_REAL

The cosine of x.

Description
The COS function returns the cosine of an angle given in radians. The result is in the range 1 to 1.

Example
VAR
y : REAL;
END_VAR
y := COS( 3.14159 );

{* result is

-1.0 *)

Runtime Errors
Condition

Return Value

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If the absolute value of x is greater than 2**63

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

84

Chapter 2

Functions and Data Types

CSCHED
Schedules the execution of selected program logic after a specified number of scans.

Syntax
CSCHED( CI:=b1, NSCANS:=m1, NOFFSET:=m2 )

Table 72

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables CSCHED.

NSCANS

DINT

The number of scans between settings of the Q output.

NOFFSET

DINT

The number of scans before the Q output is set to true for the first
time.

Table 73

Output Parameters

Name

Data Type

Description

CO

BOOL

True if CSCHED executes successfully.

BOOL

True if the specified number of scans occur. Q holds true for one
scan, then returns to false.

ACTUAL

TIME

The elapsed time from the last setting of the Q output.

Description
The CSCHED function block is used to schedule the execution of selected program logic after a specified
number of scans occur. Output Q is true after the specified number of scans occur and holds true for one
scan. By testing the output Q, sections of the control program can execute periodically. This function
block must be invoked exactly once per scan. Otherwise, the scan count is incorrect.

Example
This example causes selected statements to be executed every 100 scans after the first 500 scans.
VAR
EXEC_LOGIC : CSCHED;
END_VAR
EXEC_LOGIC(CI := TRUE, NSCANS := 100, NOFFSET := 500 );
IF ( EXEC_LOGIC.Q = TRUE ) THEN
(* execute these statements *)
END_IF

Runtime Errors
None.

TriStation 1131 Libraries Reference

CSCHED

85

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

86

Chapter 2

Functions and Data Types

CSCHED_I
Schedules the execution of selected program logic after a specified number of scans.

Syntax
CSCHED_I( CI:=b1, NSCANS:=m1, NOFFSET:=m2 )

Table 74

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables CSCHED_I.

NSCANS

DINT

The number of scans between settings of the Q output.

NOFFSET

DINT

The number of scans before the Q output is set to true for the first time.

Table 75

Output Parameters

Name

Data Type

Description

CO

BOOL

True if CSCHED_I executes successfully.

BOOL

True if the specified number of scans have occurred. Q holds true for one scan, then
returns to false.

ACTUAL

DINT

The elapsed time in milliseconds from the last setting of the Q output.

Description
The CSCHED_I function block is used to schedule the execution of selected program logic after a
specified number of scans occur. Output Q is true after the specified number of scans occur and holds true
for one scan. By testing the output Q, sections of the control program can execute periodically. This
function block must be invoked exactly once per scan. Otherwise, the scan count is incorrect.

Note

CSCHED_I differs from CSCHED in that the ACTUAL elapsed time is represented in
milliseconds and is a DINT data type.

Example
This example causes selected statements to be executed every 100 scans after the first 500 scans.
VAR
EXEC_LOGIC : CSCHED_I;
END_VAR
EXEC_LOGIC(CI := TRUE, NSCANS := 100, NOFFSET := 500 );
IF ( EXEC_LOGIC.Q = TRUE ) THEN
(* execute these statements *)
END_IF

Runtime Errors
None.

TriStation 1131 Libraries Reference

CSCHED_I

87

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

88

Chapter 2

Functions and Data Types

CSCHED_R
Schedules the execution of selected program logic after a specified number of scans.

Table 76

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables CSCHED_R.

NSCANS

DINT

The number of scans between settings of the Q output.

NOFFSET

DINT

The number of scans before the Q output is set to true for the first time.

Table 77

Output Parameters

Name

Data Type

Description

CO

BOOL

True if CSCHED_R executes successfully.

BOOL

True if the specified number of scans occur. Q holds true for one scan, then returns
to false.

ACTUAL

REAL

The elapsed time in seconds from the last setting of the Q output.

Description
The CSCHED_R function block is used to schedule the execution of selected program logic after a
specified number of scans occur. Output Q is true after the specified number of scans occur and holds true
for one scan. By testing the output Q, sections of the control program can execute periodically. This
function block must be invoked exactly once per scan. Otherwise, the scan count is incorrect.

Note

CSCHED_R differs from CSCHED in that the ACTUAL elapsed time is represented in seconds
and is a REAL data type.

Example
This example causes selected statements to be executed every 100 scans after the first 500 scans.
VAR
EXEC_LOGIC : CSCHED_R;
END_VAR
EXEC_LOGIC(CI := TRUE, NSCANS := 100, NOFFSET := 500 );
IF ( EXEC_LOGIC.Q = TRUE ) THEN
(* execute these statements *)
END_IF

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)
TriStation 1131 Libraries Reference

CTD

89

CTD
Down counter. Signals when a value reaches zero while counting down from a preset value (PV).

Syntax
CTD( CD:=b1, LD:=b2, PV:=m )

Table 78

Input Parameters

Name

Data Type

Description

CD

BOOL

Enables counting down.

LD

BOOL

Loads the PV.

PV

INT

Defines the threshold at which the countdown


begins.

Table 79

Output Parameters

Name

Data Type

Description

BOOL

True when CV is less than or equal to zero.

CV

INT

The current value of the counter.

Description
The CTD function block decrements a value and signals when it reaches zero or less. Setting the LD input
to true causes the counter's current value to be initialized by the PV. While the input CD is true, the CV
decrements by one each time CTD is executed. The countdown stops when CV reaches 32768. Output Q
is true when CV is less than or equal to zero.

Example
This example counts down from 500 to zero. When zero is reached, the counter is reset and the
countdown is repeated.
VAR
COUNTDOWN : CTD;
RESET : BOOL := TRUE;
END_VAR;
COUNTDOWN( CD := TRUE, LD := RESET, PV := 500 );
RESET := COUNTDOWN.Q;

Runtime Errors
None.

TriStation 1131 Libraries Reference

90

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause and Effect cells.

IEC 1131-3 specifies that the CTD function block counts down the number of rising-edge
triggers detected at the CD input. In the Triconex implementation, the CD input is not a risingedge trigger. The countdown progresses as long as the CD input remains true.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

CTU

91

CTU
Up counter. Signals when a count reaches a preset value (PV).

Syntax
CTU( CU:=b1, R:=b2, PV:=m )

Table 80

Input Parameters

Name

Data Type

Description

CU

BOOL

Enables counting up.

BOOL

Resets the current value (CV) to zero.

PV

INT

Defines the threshold at which output Q


changes to True.

Table 81

Output Parameters

Name

Data Type

Description

BOOL

True when CV is greater than or equal to PV.

CV

INT

The current value of the counter.

Description
The CTU function block increments a value and signals when it reaches the value specified by the PV
input. Setting the R input to true resets the CV to zero. While the input CU is true, the CV increments by
one each time CTU is executed. The count up stops when CV reaches 32,767. Output Q is true when CV
is greater than or equal to PV.

Example
This example counts up from zero to 500. When 500 is reached, the counter is reset and the count-up
from zero is repeated.
VAR
COUNTUP : CTU;
RESET : BOOL := TRUE;
END_VAR;
COUNTUP( CU := TRUE, R := RESET, PV := 500 );
RESET := COUNTUP.Q;

Runtime Errors
None.

TriStation 1131 Libraries Reference

92

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause and Effect cells.

IEC 1131-3 specifies that the CTU function block count up the number of rising-edge triggers
detected at the CU input. In the Triconex implementation, the CU input is not a rising-edge
trigger. The count-up progresses as long as the CU input remains true.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

CTUD

93

CTUD
Up-down counter. Signals when a count reaches either zero or a preset value (PV).

Syntax
CTUD( CU:=b1, CD:=b2, R:=b3, LD:=b4, PV:=m )

Table 82

Input Parameters

Name

Data Type

Description

CU

BOOL

Enables counting up if CD is false.

CD

BOOL

Enables counting down if CU is false.

BOOL

Resets the current value (CV) to zero.

LD

BOOL

Is set to true to load the PV.

PV

INT

Defines the threshold at which output QU


changes to True.

Table 83

Output Parameters

Name

Data Type

Description

QU

BOOL

True when CV is greater than or equal to PV.

QD

BOOL

True when CV is less than or equal to zero.

CV

INT

The current value of the counter.

Description
The CTUD function block increments and decrements a value, and signals when it counts down to zero
or counts up to the value specified by the PV input. Setting the R input to true resets the CV to zero.
Setting the LD input to true causes the counter's CV to be initialized by the PV. When the input CU is true
and CD is false, the CV increments by one each time CTU is executed. When the input CD is true and CU
is false, the CV decrements by one each time CTU is executed. The count up stops when CV reaches 32767;
the count down stops when CV reaches 32768. Output QU is true when CV is greater than or equal to
PV. Output QD is true when CV is less than or equal to zero.

TriStation 1131 Libraries Reference

94

Chapter 2

Functions and Data Types

Example
This example counts up from zero to 500. When 500 is reached, the counter counts back down to zero.
VAR
COUNT : CTUD;
COUNTUP, RESET : BOOL := TRUE;
COUNTDN, BOOL := FALSE;
END_VAR;
COUNT( CU:=COUNTUP, CD:= COUNTDN, R:=RESET, LD:=FALSE, PV:=500 );
RESET := FALSE;
IF ( COUNT.QU = TRUE ) THEN
COUNTUP := FALSE;
COUNTDN := TRUE;
ELSIF ( COUNT.QD = TRUE ) THEN
COUNTUP := TRUE;
COUNTDN := FALSE;
END_IF

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause and Effect cells.

IEC 1131-3 specifies that the CTUD function block count up the number of rising-edge triggers
detected at the CU input and count down the number of rising-edge triggers detected at the CD
input. In the Triconex implementation, these inputs are not rising-edge triggers. The CU and CD
inputs enable counting up and counting down.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

DATE

95

DATE
A DATE data type refers to a specific date expressed as the year, month, and day.
Attribute

Description

Keyword/type

DATE

Description

Date

Size

64 bits

Syntax

D#CCYY-MM-DD

Default value

D#1970-01-01

Lower limit

D#1970-01-01

Upper limit

D#2029-12-31

Result if intermediate value is less than lower limit

Invalid date

Result if upper limit is less than intermediate value

Invalid date

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

96

Chapter 2

Functions and Data Types

DINT
A DINT data type is a double integer, 32 bits in length.
Attribute

Description

Keyword/type

DINT

Description

Double integer

Size

32 bits

Default value

Lower limit

2**31

Upper limit

2**311

Result if intermediate valuea is less than lower limit

2**31 or V modulo 2**32

Result if upper limit is less than intermediate valuea

2**311 or V modulo 2**32

a. If the intermediate conversion value is out of range (for example, when converting LREAL to DINT), the return
value is the smallest or greatest double integer.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

DINT_TO_DWORD

97

DINT_TO_DWORD
Converts a 32-bit integer to a DWORD value.

Syntax
w := DINT_TO_DWORD(k);

Table 84

Input Parameters

Name

Data Type

Description

DINT

The 32-bit integer to be converted.

Table 85

Return Value

Data Type

Description

DWORD

The value of k converted to a DWORD value.

Description
The DINT_TO_DWORD function converts a 32-bit integer to a DWORD value.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR

k : DINT;

w : DWORD;

END_VAR;

k := 256;
w := DINT_TO_DWORD( k );

(* result is 16#0100 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

98

Chapter 2

Functions and Data Types

DINT_TO_INT
Converts a 32-bit integer to a 16-bit integer.

Syntax
m := DINT_TO_INT(k);

Table 86

Input Parameters

Name

Data Type

Description

DINT

The 32-bit integer to be converted.

Table 87

Return Value

Data Type

Description

INT

The value of k converted to a 16-bit integer.

Description
The DINT_TO_INT function converts a 32-bit integer to a 16-bit integer.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; m : INT;
k := 1234;
m := DINT_TO_INT( k );

END_VAR;
(* result is 1234 *)

Runtime Errors
Condition

Return Value

Error Flags

If k is less than -32768

32768

BADCONV, ERROR

If k is greater than 32767

+32767

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

DINT_TO_LREAL

99

DINT_TO_LREAL
Converts a 32-bit integer to a 64-bit long real number.

Syntax
x := DINT_TO_LREAL(k);

Table 88

Input Parameters

Name

Data Type

Description

DINT

The 32-bit integer to be converted.

Table 89

Return Value

Data Type

Description

LREAL

The value of k converted to a 64-bit long real number.

Description
The DINT_TO_LREAL function converts a 32-bit integer to a 64-bit long real number.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : LREAL;
k := 1234;
x := DINT_TO_LREAL( k );

END_VAR;
(* result is 1234.0 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

100

Chapter 2

Functions and Data Types

DINT_TO_REAL
Converts a 32-bit integer to a 32-bit real number.

Syntax
x := DINT_TO_REAL( k );

Table 90

Input Parameters

Name

Data Type

Description

DINT

The 32-bit integer to be converted.

Table 91

Return Value

Data Type

Description

REAL

The value of k converted to a 32-bit real number.

Description
The DINT_TO_REAL function converts a 32-bit integer to a 32-bit real number.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : REAL;
k := 1234;
x := DINT_TO_REAL( k );

END_VAR;

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

(* result is 1234.0 *)

DIV 101

DIV
Divides two numbers.

Syntax
z := x / y ;

Description
The DIV function divides two numbers and can be used as an operator or as a function.
The operations that can be performed are shown in this table.

Table 92

DIV Operations

Operation

Numerator
Data Type

Denominator
Data Type

Result
Data Type

Divide a number by a number.

ANY_NUMa

ANY_NUM1

ANY_NUM

Divide a time by a number.

TIME

ANY_NUM

TIME

a. The numerator, denominator and quotient must the same numerical data type.

Example
Divide Two Numbers
VAR x : DINT;
VAR
x = 100 / 10;

END_VAR
(* result is 10 *)

Divide a Time by a Number


VAR t : TIME; END_VAR
t : = T#12d12h12m / 12;

(* result is T#1d1h1m0s0.0ms *)

Function Block Diagram

TriStation 1131 Libraries Reference

102

Chapter 2

Functions and Data Types

Runtime Errors
Conditions

Return Values

Error Flags

If the numerator or the denominator is not a number.

NAN

BADPARAM, ERROR

If the denominator is 0.0 and numerator is negative.

INF

DIVBYZERO, ERROR

If the denominator is 0.0 and numerator is zero.

NAN

DIVBYZERO, ERROR

If the denominator is 0.0 and numerator is positive.

+INF

DIVBYZERO, ERROR

If the integer denominator is zero.

DIVBYZERO, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

DT

103

DT
A DT data type represents a date and time of day. To specify the time of day, you can use fractions (FFF)
of a second. Values are stored internally in microseconds and displayed in the TriStation 1131 Controller
Panel in milliseconds.
A DT data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

DT

Description

Date and time of day

Size

64 bits

Syntax

DT#CCYY-MM-DD-HH:MM:SS
or
DT#CCYY-MM-DD-HH:MM:SS.FFF
or
DATE_AND_TIME#CCYY-MM-DD-HH:MM:SS

Default value

DT#1970-01-01-00:00:00

Lower limit

DT#1970-01-01-00:00:00

Upper limit

DT#2029-12-31-23:59:59.999

Result if intermediate value is less than lower limit

Invalid date

Result if upper limit is less than intermediate value

Invalid date

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

104

Chapter 2

Functions and Data Types

DT_TO_DATE
Extracts the date from a date and time value.

Syntax
d := DT_TO_DATE(dtm);

Table 93

Input Parameters

Name

Data Type

Description

dtm

DT

The date and time from which to extract the date.

Table 94

Return Value

Name

Data Type

Description

OUT

DATE

The date extracted from dtm.

Description
The DT_TO_DATE function extracts the date from the date portion of a DT data type value.

Example
VAR d : DATE; END_VAR
d := DT_TO_DATE( DT#2002-02-06-06:28:15 );

(* result is DATE#2002-02-06 *)

Runtime Errors
Condition

Return Value

Error Flags

If dtm is out of range.

Invalid date

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

DT_TO_TOD

105

DT_TO_TOD
Extracts the time of day from a date and time value.

Syntax
t := DT_TO_TOD(dtm);

Table 95

Input Parameters

Name

Data Type

Description

dtm

DT

The date and time from which to extract the time of day.

Table 96

Return Value

Data Type

Description

TOD

The time of day extracted from dtm.

Description
The DT_TO_TOD function extracts the time of day portion of a TD data type value.

Example
VAR t: TOD; END_VAR
t := DT_TO_TOD( DT#2002-02-06-06:28:15 );

(* result is TOD#06:28:15 *)

Runtime Errors
Condition

Return Value

Error Flags

If dtm is out of range.

Invalid time

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

106

Chapter 2

Functions and Data Types

DWORD
A DWORD data type is a double word, 32 bits in length. The result is always in the range from 0 to
16#FFFFFFFF. If the intermediate value is out of range, then the result is the least-significant 32 bits of the
intermediate value. For example, if you shift 16#FFFFFFFF to the left once, the intermediate value is
16#1FFFFFFFE and the result is 16#FFFFFFFE.
A DWORD data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

DWORD

Description

Double word

Size

32 bits

Default value

Lower limit

Upper limit

16#FFFFFFFF

Result if intermediate value is less than lower limit

N/A

Result if upper limit is less than intermediate value

V and 16#FFFFFFFF

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

DWORD_TO_BOOL

107

DWORD_TO_BOOL
Converts a DWORD value to a Boolean (BOOL) value.

Syntax
b := DWORD_TO_BOOL(w)

Table 97

Input Parameters

Name

Data Type

Description

IN

DWORD

The DWORD value to be converted.

Table 98

Return Value

Name

Data Type

Description

OUT

BOOL

The value of IN converted to a Boolean value.

Description
The DWORD_TO_BOOL function converts a DWORD value to a Boolean (BOOL) value. The return value
equals the value of the least significant bit of the DWORD.

Example
VAR b : BOOL; END_VAR
b := DWORD_TO_BOOL(16#00000001);
b := DWORD_TO_BOOL(16#00000002);

(* result is TRUE (1)


(* result is FALSE (0)

*)
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

108

Chapter 2

Functions and Data Types

DWORD_TO_DINT
Converts a DWORD value to a DINT value (32-bit signed integer).

Syntax
k := DWORD_TO_DINT(w)

Table 99

Parameter

Name

Data Type

Description

DWORD

The DWORD value to be converted.

Table 100

Return Value

Data Type

Description

DINT

The value of w converted to a 32-bit integer.

Description
The DWORD_TO_DINT function converts a DWORD value to a DINT value (32-bit signed integer).

Example
VAR k : DINT; END_VAR
k := DWORD_TO_DINT( 16#000000FF );

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

(* result is 255 *)

EQ

109

EQ
Compares two operands for equality.

Syntax
b :=

x = y;

Table 101

Input Parameters

Name

Data Type

Description

ANY

First operand.

ANY

Second operand.

Table 102

Return Value

Data Type

Description

BOOL

True if x is equal to y.

Description
The EQ function is used in graphical languages to determine if two operands are equal. In Structured
Text, the = operator is used to determine equality. The result is true if the operands are equal; otherwise
the result is false.
The operands can be any data type, but both operands must be the same data type. For type REAL or
LREAL, if either operand is not a number (NAN), the result is undefined.

Example
Structured Text
VAR b : BOOL; END_VAR
b := 10 = 11;
b := 11 = 11;
b := 'abcd' = 'abcd';

(* result is FALSE *)
(* result is TRUE *)
(* result is TRUE *)

Function Block Diagram

Runtime Errors
None.

TriStation 1131 Libraries Reference

110

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

EXP

111

EXP
Calculates the natural exponential for a real number.

Syntax
x := EXP(y)

Table 103

Input Parameters

Name

Data Type

Description

ANY_REAL

The operand.

Table 104

Return Value

Data Type

Description

ANY_REAL

The natural exponential ey.

Description
The EXP function calculates the natural exponential for a real number. EXP returns e raised to the power
specified by the real number parameter. The constant e is 2.71828182845904, the base for natural
logarithms.

Example
VAR
x :=
x :=
x :=

x : REAL; END_VAR
EXP(1.0);
EXP(2.0);
EXP(3.0);

(* result is 2.71828 *)
(* result is 7.38906 *)
(* result is 20.0855 *)

Runtime Errors
Conditions

Return Values

Error Flags

If y is not a number.

NAN

BADPARAM, ERROR

If the result is too large.

+INF

BADPARAM, ERROR

If the result underflows.

0.0

UNDERFLOW

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.
Underflow occurs when the result is very close to zero. Since underflow is not an error, an underflow
condition does not set the ERROR flag and does not reset ENO to false.

TriStation 1131 Libraries Reference

112

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

EXPFLTR

113

EXPFLTR
Provides an exponential filter to smooth a noisy input data value.

Syntax
MYFILTER(CI:=b1, RESET:=b2, INPUT:=x1, FACTOR:=x2, IOUTPUT:=x3);
y := MYFILTER.IOUTPUT;

Table 105

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables smoothing.

RESET

BOOL

Resets the output to the initial value supplied by IOUTPUT.

INPUT

REAL

The raw unfiltered input value.

FACTOR

REAL

The smoothing factor is greater than or equal to 0.0 and less than or equal to1.0.

IOUTPUT

REAL

The initial output value.

Table 106

Output Parameters

Name

Data Type

Description

CO

BOOL

True if EXPFLTR executes successfully.

OUTPUT

REAL

The smoothed output value.

Description
The EXPFLTR function block provides an exponential filter to smooth a noisy input data value.

Example
The following example has a constantly changing input that is being filtered by a factor of 0.5. On the
graph, the gray line is RAWVALUE and the black line is MYFILTER.OUTPUT.
VAR MYFILTER : EXPFLTR; END_VAR
MYFILTER
CI:=TRUE,RESET:=INITFLTR,INPUT:=RAWVALUE,FACTOR:=REAL#0.5,IOUTPUT:= REAL#2.0);
FILTER_VALUE := MYFILTER.OUTPUT;

TriStation 1131 Libraries Reference

114

Chapter 2

Functions and Data Types

Runtime Errors
Conditions

Return Values

Error Flag

If FACTOR is less than 0.0.

CO=false,

BADPARAM, ERROR

OUTPUT=No change
If FACTOR is greater then 1.0.

CO=false,

BADPARAM, ERROR

OUTPUT=INPUT

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

EXPT

115

EXPT
Raises a value to a specified power.

Syntax
z := x ** y;

Table 107

Input Parameters

Name

Data Type

Description

ANY_REAL

The value of the variable whose power is to be raised.

ANY_NUM

The exponent.

Table 108

Return Value

Data Type

Description

ANY_REAL

x to the y power, xy.

Description
The EXPT function raises a value to a specified power. EXPT is used in graphical languages to raise a real
value to a power specified by an exponent. In Structured Text, the ** operator is used for exponentiation.
Both the value to be raised and the return value must be the same data type (REAL or LREAL). The
exponent may be a REAL, LREAL, DINT, or INT data type.

Example
Structured Text
VAR z : REAL; END_VAR
z := 10.0 ** 2;

(* result is 100.0 *)

Function Block Diagram

TriStation 1131 Libraries Reference

116

Chapter 2

Functions and Data Types

Runtime Errors
Conditions

Return Values

Error Flag

If x or y is not a number.

NAN

BADPARAM, ERROR

If x = 1.#INF and y is not an integer.

NAN

BADPARAM, ERROR

If x = 1.#INF and y = +1.#INF.

NAN

BADPARAM, ERROR

If y = 1.#INF and x is less than or equal to 1.0 and less than 0.0.

NAN

BADPARAM, ERROR

If y = +1.#INF and x is less than or equal to 1.0.

NAN

BADPARAM, ERROR

If x is less than 0.0 and y is not an integer.

NAN

BADPARAM, ERROR

If x = 1.#INF and y is greater than 0.0 and is an odd integer.

INF

None

If x = 1.#INF and y is greater than 0.0 and is an even integer.

+INF

None

If x = +1.#INF and y is greater than 0.0.

+INF

None

If y = -1.#INF and x is greater than or equal to 0.0 and less than


1.0.

+INF

None

If y = +1.#INF and x is greater than 1.0.

+INF

None

If x = 0.0 and y is less than 1.0.

+INF

None

If x = 1.#INF and y is not an integer.

0.0

None

If x = +1.#INF and y is less than 0.0.

0.0

None

If y = 1.#INF and x is less than -1.0.

0.0

None

If x = 1.#INF and x is greater than 1.0.

0.0

None

If y = +1.#INF and x is greater than 1.0 and is less than 1.0.

0.0

None

If the absolute value of x ** y is less than 2.2E-308

0.0

UNDERFLOW

If x = 1.#INF and y = 0.0.

1.0

None

If x = +1.#INF and y = 0.0.

1.0

None

If y = 1.#INF and x = 1.0.

1.0

None

If y = +1.#INF and x = 1.0.

1.0

None

Upon detection of a runtime error condition, the function returns the value and sets the error flag
indicated in the runtime error table above, sets the ERROR status flag, and resets ENO to false. For more
about error flags and runtime errors, see the CHK_ERR function block.
Underflow occurs when the result is very close to zero. Since underflow is not an error, an underflow
condition does not set the ERROR flag and does not reset ENO to false.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

F_TRIG

117

F_TRIG
Triggers on the falling edge of the CLK input.

Syntax
F_TRIG(CLK:=b)

Table 109

Input Parameters

Name

Data Type

Description

CLK

BOOL

The value being monitored.

Table 110

Output Parameters

Data Type

Description

BOOL

The detector output.

Description
The F_TRIG function block detects a change in state of the CLK input from true to false. When the change
is detected, the Q output is set to true for one function block execution.

Example
This examples maintains a count of the number of times unit power has been lost.
VAR POWER_OK, POWER_FAILED : BOOL; END_VAR
VAR POWER_FAIL_COUNT : DINT; END_VAR
VAR POWER_MONITOR : F_TRIG; END_VAR
POWER_MONITOR( CLK:=POWER_OK );
IF ( POWER_MONITOR.Q = TRUE ) THEN POWER_FAIL_COUNT := POWER_FAIL_COUNT + 1;
END_IF;

Runtime Errors
None.

TriStation 1131 Libraries Reference

118

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

FLOOR 119

FLOOR
Truncates a real number to an integer.

Syntax
y := FLOOR( x );

Table 111

Input Parameters

Name

Data Type

Description

ANY_REAL

The operand.

Table 112

Return Value

Data Type

Description

ANY_REAL

The integer part of x.

Description
The FLOOR function truncates a real number to the largest integer that is less than or equal to x. In other
words, the function drops the fraction from the number.

Example
VAR y : REAL; END_VAR
y := FLOOR( 23.45986 );

(* result is 23.0 *)

Runtime Errors
Condition

Return Value

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

120

Chapter 2

Functions and Data Types

GASDETR
Processes analog inputs from a gas detector and generates alarms.

Syntax
MY_GASDETR(CI:=b1, INPUT:=n1, INHIBIT:=b2, RESET:=b3, OPFLIM:=n2, SHFLIM:=n3,
CALBLIM:=n4, OVRFLIM:=n5, GDMAXAV:=n6, GDMINAV:=n7, GDMAXEU:=x1, GDMINEU:=x2,
GHIALIM:=x3, GLOALIM:=x4 );
y := MY_GASDETR.OUTPUT;

Table 113

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables GASDETR.

INPUT

DINT

The gas detector analog input value.

INHIBIT

BOOL

Inhibits setting of alarms.

RESET

BOOL

Resets all alarms.

OPFLIM

DINT

The gas detector open-circuit fault limit.

SHFLIM

DINT

The gas detector short-circuit fault limit.

CALBLIM

DINT

The gas detector calibration limit.

OVRFLIM

DINT

The gas detector over-range fault limit.

GDMAXAV

DINT

The gas detector maximum analog input value.

GDMINAV

DINT

The gas detector minimum analog input value.

GDMAXEU

REAL

The gas detector maximum engineering value

GDMINEU

REAL

The gas detector minimum engineering value.

GHIALIM

REAL

The gas detector high-gas alarm limit.

GLOALIM

REAL

The gas detector low-gas alarm limit.

Table 114

Output Parameters

Name

Data Type

Description

CO

BOOL

True if GASDETR executes successfully.

GDVALUE

REAL

The gas concentration.

HIALARM

BOOL

The gas detector high-gas alarm.

LOALARM

BOOL

The gas detector low-gas alarm.

OPALARM

BOOL

The gas detector open-circuit fault alarm.

SHALARM

BOOL

The gas detector short-circuit fault alarm.

CLALARM

BOOL

The gas detector calibration alarm.

ORALARM

BOOL

The gas detector over-range alarm.

HISTAT

BOOL

The gas detector high-gas status.

TriStation 1131 Libraries Reference

GASDETR

Table 114

121

Output Parameters (continued)

Name

Data Type

Description

LOSTAT

BOOL

The gas detector low-gas status.

OPSTAT

BOOL

The gas detector open-circuit fault status.

SHSTAT

BOOL

The gas detector short-circuit fault status.

CLSTAT

BOOL

The gas detector calibration status.

ORSTAT

BOOL

The gas detector over range status.

OUTPUT

DWORD

The gas detector status word.

Description
The GASDETR function block processes analog inputs from a gas detector and generates alarms by
computing the gas concentration GDVALUE in engineering units and the low-gas and high-gas status of
the detector.
GASDETR also monitors the analog inputs and sets these status indicators:

Short-circuit fault

Open-circuit fault

Over-range fault

Detector in calibration

GASDETR generates alarms from the status values. However, alarms can be inhibited by setting the
alarm INHIBIT input, while the status indicators are unaffected by the alarm INHIBIT input.
All alarm outputs are latched after they are set, until reset by the RESET input. The function packs all the
status, alarm, inhibit, and reset bits into the OUTPUT variable.
Parameters include the limits that are used to check for these faults and limits:

Open-circuit faults

Short-circuit faults

Over-range faults

Calibration status

Low-gas alarm limit

High-gas alarm limit

The minimum and maximum analog input and engineering values are also provided so that GASDETR
can convert an analog input into a gas concentration. RESET clears the alarms even when CI is false.
RESET clears the alarms before executing the other operations. If RESET and CI are both false, no
operation occurs.

Runtime Errors
None.

TriStation 1131 Libraries Reference

122

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

GATDIS 123

GATDIS
Disables remote writes to aliased variables in a Tricon controller.

Syntax
GATDIS(CI:=b)

Table 115

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables GATDIS.

Table 116

Output Parameters

Name

Data Type

Description

CO

BOOL

True if GATDIS execute successfully.

Description
In a Tricon controller, the GATDIS function block disables remote writes for all ranges of read/write
aliased variables that were previously enabled by Tricon (TX1LIB), thereby restricting write operations
by external hosts. GATDIS must be executed after the Tricon (TX1LIB) function. For more information,
see Tricon (TX1LIB) on page 123.

Example
VAR GATE_IS_DISABLED : BOOL ; END_VAR
VAR DISABLED_GATE : GATDIS ; END_VAR
DISABLE_GATE(TRUE);
GATE_IS_DISABLED = GATDIS.CO ;

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Tricon (TX1LIB)

TriStation 1131 Libraries Reference

124

Chapter 2

Functions and Data Types

GATENB
Enables remote writes to aliased variables in a Tricon controller.

Syntax
GATENB(CI:=b,DRWFRST:=k1,DRWLAST:=k2,IRWFRST:=k3,IRWLAST:=k4,RRWFRST:=k5,KRWLAST:=k6

Table 117

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables GATENB.

DRWFRST

DINT

The starting alias number for memory discrete (BOOL) read/write range.

DRWLAST

DINT

The ending alias number for memory discrete (BOOL) read/write range.

IRWFRST

DINT

The starting alias number for memory integer (DINT) read/write range.

IRWLAST

DINT

The ending alias number for memory integer (DINT) read/write range.

RRWFRST

DINT

The starting alias number for memory real read/write range.

RRWLAST

DINT

The ending alias number for memory real read/write range.

Table 118

Output Parameters

Name

Data Type

Description

CO

BOOL

True if GATENB executes successfully.

Description
In a Tricon controller, the GATENB function block opens a gate for external-host read/writes to a
specified range of Modbus aliased variables when the controller is operating in RUN mode.
In a safety shutdown application, the keyswitch is typically set to RUN mode for normal operation.
However, this mode does not support Modbus writes from external hosts. To solve this problem,
TriStation 1131 provides gated-access function blocks to programmatically enable and disable externalhost writes to a Tricon controller.
GATENB allows you to specify a range of aliases for each of these data types:

Discrete Read/Write

Integer Read/Write

Real Read/Write

You should use only one GATENB function block in a program. If you do not want to specify alias ranges
for certain data types, leave their starting and ending values at zero (the default).

TriStation 1131 Libraries Reference

GATENB

125

Example
This example opens a gate for external-host writes to selected Modbus read/write memory BOOL and
DINT variables.
VAR ENABLE_GATE : GATENB; END_VAR
ENABLE_GATE( CI:=TRUE,DRWFRST:=2001, DRWLAST:=2020,
IRWFRST:=40251,IRWLAST:=40258,
RRWFRST:=0,
RRWLAST:=0
);

Runtime Errors
Condition

Return Value

Error Flags

If a specified alias range is invalid

CO=false

None

If this is a second function block with the same specified alias range

CO=false

None

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Tricon (TX1LIB)

TriStation 1131 Libraries Reference

126

Chapter 2

Functions and Data Types

GE
Determines if one operand is greater than or equal to another operand.

Syntax
b :=

x >= y ;

Table 119

Input Parameters

Name

Data Type

Description

ANY_ NOTE1

First operand.

ANY_NOTE1

Second operand.

Table 120

Return Value

Data Type

Description

BOOL

True if x is greater than or equal to y.

Description
The GE function is used in graphical languages to determine if one operand is greater than or equal to
another operand. In Structured Text, the operator is used. The result is true if one operand is greater
than or equal to another operand; otherwise the result is false.
The operands can be any of these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
STRING
TIME
TOD

Both operands must be the same data type. For type REAL or LREAL data types, if either operand is not
a number (NAN), the result is undefined.

TriStation 1131 Libraries Reference

GE

127

Examples
Structured Text
VAR b : BOOL; END_VAR
b := 10 >= 11;
b := 11 >= 11;
b := 11 >= 10;
b := 'abce' >= 'abcd';

(*
(*
(*
(*

result
result
result
result

is
is
is
is

FALSE
TRUE
TRUE
TRUE

*)
*)
*)
*)

Function Block Diagram

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

128

Chapter 2

Functions and Data Types

GetDelta_DINT
Returns the scan period for the previous scan in milliseconds.

Syntax
t := GetDelta_DINT()

Table 121

Input Parameters

Name

Data Type

Description

None

None

None.

Table 122

Return Value

Data Type

Description

DINT

The scan period for the previous scan in milliseconds.

Description
The GetDelta_DINT function returns the scan period for the previous scan in milliseconds. The scan
period is measured from the start of the previous scan to the start of the current scan. GetDelta_DINT can
only be used in Structured Text programs because it has no input parameters, which are required in FBD,
LD, and CEMPLE programs.
GetDelta_DINT does not comply with the statement in IEC 1131-3 that invocation of a function with
the same arguments (input parameters) shall always yield the same value (output). GetDelta_DINT
yields the same value for every invocation within one scan, but yields different values for different scans.

Example
VAR t : DINT ; END_VAR
t := GetDelta_DINT();
(* Result is 100 if the measured scan period is 100 milliseconds. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

GetDelta_DINT

129

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

130

Chapter 2

Functions and Data Types

GetDelta_REAL
Returns the scan period for the previous scan in seconds.

Syntax
t := GetDelta_REAL()

Table 123

Input Parameters

Name

Data Type

Description

None

None

None.

Table 124

Return Value

Data Type

Description

REAL

The scan period for the previous scan in seconds.

Description
The GetDelta_REAL function returns the scan period for the previous scan in seconds. The scan period is
measured from the start of the previous scan to the start of the current scan. GetDelta_REAL can only be
used in Structured Text programs because it has no input parameters, which are required in FBD, LD, and
CEMPLE programs.
GetDelta_REAL does not comply with the statement in IEC 1131-3 that invocation of a function with
the same arguments (input parameters) shall always yield the same value (output). GetDelta_REAL
yields the same value for every invocation within one scan, but yields different values for different scans.

Example
VAR t : REAL ; END_VAR
t := GetDelta_REAL();
(* Result is 0.1 if the measured scan period is 100 milliseconds. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

GetDelta_REAL

131

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

132

Chapter 2

Functions and Data Types

GetDeltaT
Returns the scan period for the previous scan.

Syntax
t := GetDeltaT()

Table 125

Input Parameters

Name

Data Type

Description

None

None

None.

Table 126

Return Value

Data Type

Description

DINT

The scan period for the previous scan.

Description
The GetDeltaT function returns the scan period for the previous scan. The scan period is measured from
the start of the previous scan to the start of the current scan. GetDeltaT can only be used in Structured
Text programs because it has no input parameters, which are required in FBD, LD, and CEMPLE
programs.
GetDeltaT does not comply with the statement in IEC 1131-3 that invocation of a function with the
same arguments (input parameters) shall always yield the same value (output). GetDeltaT yields the
same value for every invocation within one scan, but yields different values for different scans.

Example
VAR t : TIME ; END_VAR
t := GetDeltaT();
(* Result is T#100ms if the measured scan period is 100 milliseconds. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

GetDeltaT

133

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

134

Chapter 2

Functions and Data Types

GetTimer
Returns a date and time value that can be used to calculate the elapsed time between two events.

Syntax
dt := GetTimer()

Table 127

Input Parameters

Name

Data Type

Description

None

None

None.

Table 128

Return Value

Data Type

Description

DT

The date and time.

Description
The GetTimer function returns a date and time value that can be used in conjunction with a previously
returned date and time value to calculate an elapsed time. GetTimer can only be used in Structured Text
programs because it has no input parameters, which are required in FBD, LD, and CEM programs.
The GetTimer function does not comply with the statement in IEC 61131-3 that: invocation of a
function with the same arguments (input parameters) shall always yield the same value (output). The
GetTimer function yields the same value for every invocation within one scan, but yields different values
on different scans. The return value always increases from one scan to the next.

Example
This example calculates the time between two events: Event1 and Event2.
VAR
Event1, Event2
T1, T2
ElapsedTime
END_VAR

: BOOL;
: DT;
: TIME;

IF Event1 then
T1 := GetTimer();
END_IF;
IF Event2 then
T2 := GetTimer();
ElapsedTime := T2 - T1;
END_IF;

Runtime Errors
None.

TriStation 1131 Libraries Reference

GetTimer

135

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

136

Chapter 2

Functions and Data Types

GT
Determines if two operands have a greater-than-or-equal-to relationship.

Syntax
b :=

x > y;

Table 129

Input Parameters

Name

Data Type

Description

ANY_ NOTE1

First operand.

ANY_ NOTE1

Second operand.

Table 130

Return Value

Data Type

Description

BOOL

True if x is greater than y.

Description
The GT function is used in graphical languages to determine if two operands have a greater-than-orequal-to relationship. In Structured Text, the >=operator is used. The result is true if the operands have
a greater-than-or-equal-to relationship; otherwise the result is false.
The operands can be any of these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
STRING
TIME
TOD

Both operands must be the same data type. For type REAL or LREAL data types, if either operand is not
a number (NAN), the result is undefined.

TriStation 1131 Libraries Reference

GT

137

Example
Structured Text
VAR b : BOOL; END_VAR
b := 10 >= 11;
b := 11 >= 10;
b := 'abce' >= 'abcd';

(* result is FALSE *)
(* result is TRUE *)
(* result is TRUE *)

Function Block Diagram

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

138

Chapter 2

Functions and Data Types

INFINITY_LREAL
Returns plus infinity.

Syntax
y := INFINITY_LREAL();

Table 131

Input Parameters

Name

Data Type

Description

NA

NA

No inputs.

Table 132

Return Value

Data Type

Description

LREAL

Plus infinity.

Description
The INFINITY_LREAL function returns plus infinity.

Example
VAR
y : LREAL ; END_VAR;
y := INFINITY_LREAL();
(* result is plus infinity *)
(* Note: on the controller panel, the value shown is 1.#INF *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

INFINITY_REAL

139

INFINITY_REAL
Returns plus infinity.

Syntax
y := INFINITY_REAL();

Table 133

Input Parameters

Name

Data Type

Description

NA

NA

No inputs.

Table 134

Return Value

Data Type

Description

REAL

Plus infinity.

Description
The INFINITY_REAL function returns plus infinity.

Example
VAR
y : REAL ; END_VAR;
y := INFINITY_REAL();
(* result is plus infinity *)
(* Note: on the controller panel, the value shown is 1.#INF *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

140

Chapter 2

Functions and Data Types

INT
An INT data type is an integer, 16 bits in length. Arithmetic operators ADD, SUB, and MUL are
implemented with 32-bit arithmetic and the container for INT is 32 bits. The ADD, SUB, and MUL
operations do not check the range of results and can have resultant values out of the specified range (
32768 and +32767). For example, using the SUB function to subtract 1 from -32768 results in 32769
(clearly out of range) without clearing ENO or reporting a BADPARAM error. However, an out-of-range
value does display Inv INT on the Controller Panel.
To verify that output values from these functions are within range, connect the output terminal to the
INT_TO_DINT function, which converts the integer output to double integer and does a range check for
the integer output.
An INT data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

INT

Description

Integer

Size

32 bits

Default value

Lower limit

2**15

Upper limit

2**151

Result if intermediate value is less than lower limit

InvINT

Result if upper limit is less than intermediate value

InvINT

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

INT_TO_DINT

141

INT_TO_DINT
Converts a 16-bit integer to a 32-bit integer.

Syntax
m := INT_TO_DINT(k);

Table 135

Input Parameters

Name

Data Type

Description

INT

The 16-bit integer to be converted.

Table 136

Return Value

Data Type

Description

DINT

The value of k converted to a 32-bit integer.

Description
The INT_TO_DINT function converts a 16-bit integer to a 32-bit integer.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : INT; m : DINT;
k := 1234;
m := INT_TO_DINT( k );

END_VAR;
(* result is 1234 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

142

Chapter 2

Functions and Data Types

INT_TO_LREAL
Converts a 16-bit integer to a 64-bit long real number.

Syntax
x := INT_TO_LREAL(k);

Table 137

Input Parameters

Name

Data Type

Description

INT

The 16-bit integer to be converted.

Table 138

Return Value

Data Type

Description

LREAL

The value of k converted to a 64-bit long real number.

Description
The INT_TO_LREAL function converts a 16-bit integer to a 64-bit long real number.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : INT; x : LREAL;
k := 1234;
x := INT_TO_LREAL( k );

END_VAR;

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

(* result is 1234.0 *)

INT_TO_REAL

143

INT_TO_REAL
Converts a 16-bit integer to a 32-bit real number.

Syntax
x := INT_TO_REAL(k);

Table 139

Input Parameters

Name

Data Type

Description

INT

The 16-bit integer to be converted.

Table 140

Return Value

Data Type

Description

REAL

The value of k converted to a 32-bit real number.

Description
The INT_TO_REAL function converts a 16-bit integer to a 32-bit real number.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : INT; x : REAL;
k := 1234;
x := INT_TO_REAL( k );

END_VAR;
(* result is 1234.0 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

144

Chapter 2

Functions and Data Types

INTGTOR
Integrates the INPUT parameter, ignoring noise-level values less than or equal to MINLVL.

Syntax
MY_INTGTOR(CI:=b1, RESET:=b2, INPUT:=x1, MINLVL:=x2, GAIN:=x3, DELTAT := GetDeltaT(),
IOUTPUT:=x4 );
y := MY_INTGTOR.OUTPUT ;

Table 141

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables INTGTOR.

RESET

BOOL

Copies IOUTPUT to OUTPUT.

INPUT

REAL

The input value.

MINLVL

REAL

Excludes inputs below this level from integration.

GAIN

REAL

The gain factor.

DELTAT

TIME

The time between INTGTOR executions.

IOUTPUT

REAL

The initial output value.

Table 142

Output Parameters

Name

Data Type

Description

CO

BOOL

True if INTGTOR executes successfully.

OUTPUT

REAL

The integrated output value.

Description
The INTGTOR function block integrates the INPUT parameter, ignoring noise-level values less than or
equal to MINLVL. The result is OUTPUT.
CI is the control input. CI enables evaluation. If CI is false, then the integration step is not executed. See
DELTAT herein for suggested scheduling alternatives. The default initial value of CI is true.
RESET initializes OUTPUT to the value of argument IOUTPUT. The default initial value is 0.0. If RESET
and CI are both false, no operation occurs.
INPUT is the input value to be integrated.
MINLVL is a lower limit for the input value. If the input value is below this lower limit, then the
integration step is skipped and the result OUTPUT does not change. The default lower limit is zero.
GAIN is a gain factor. The input value is multiplied by the gain factor.
DELTAT is the time between executions. To schedule execution using a CSCHED or TSCHED function
block, connect the DELTAT input to the ACTUAL output of the CSCHED or TSCHED function block, and
connect the CI input to the Q output of the CSCHED or TSCHED function block. To schedule execution
every scan, connect the DELTAT input to the ouput of a Triconex (TCXLIB) function, and set CI=true.
IOUTPUT is an optional initial output value. If the RESET input is true, then the function block copies
IOUTPUT to OUTPUT. The default initial value is zero.

TriStation 1131 Libraries Reference

INTGTOR

145

CO is the control ouput. CO follows CI. CO=true indicates that evaluation was enabled.
OUTPUT is the result, the integral of the input value. The result unit is the input unit multiplied by
seconds and multiplied by the gain factor. The equation for the integration step is:
OUTPUT := OUTPUT + GAIN * INPUT * TIME_TO_SECS_REAL(DELTAT) ;

Example
VAR MY_INTGTOR : INTGTOR ; END_VAR
VAR y : REAL ; END_VAR
MY_INTGTOR( INPUT:=1.0, GAIN:=1.0, DELTAT := GetDeltaT() ) ;
y := MY_INTGTOR.OUTPUT; (* if the scan period is always 0.16 seconds, then the result
for the first 3 scans is 0.16, 0.32, 0.48 *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

146

Chapter 2

Functions and Data Types

INTGTOR_R
Integrates the INPUT parameter, ignoring noise-level values less than or equal to MINLVL.

Syntax
MY_INTGTOR(CI:=b1, RESET:=b2, INPUT:=x1, MINLVL:=x2, GAIN:=x3, IOUTPUT:=x4 );
y := MY_INTGTOR.OUTPUT ;

Table 143

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables INTGTOR_R.

RESET

BOOL

Copies IOUTPUT to OUTPUT.

INPUT

REAL

The input value.

MINLVL

REAL

Excludes inputs below this level from integration.

GAIN

REAL

The gain factor.

IOUTPUT

REAL

The initial output value.

Table 144

Output Parameters

Name

Data Type

Description

CO

BOOL

True if INTGTOR_R executes successfully.

OUTPUT

REAL

Integrated output value.

Description
The INTGTOR_R function block integrates the INPUT parameter, ignoring noise-level values less than or
equal to MINLVL. The result is OUTPUT.
INTGTOR_R is smaller and faster than INTGTOR, but does not provide the scheduling alternatives of
INTGTOR, which means INTGTOR_R must be executed and enabled every scan.
CI is the control input. CI enables evaluation. If CI is false, then the integration step is not executed. The
default initial value of CI is true.
RESET initializes OUTPUT to the value of argument IOUTPUT. The default initial value is 0.0. If RESET
and CI are both false, no operation occurs.
INPUT is the input value to be integrated.
MINLVL is a lower limit for the input value. If the input value is below this lower limit, then the
integration step is skipped and the result OUTPUT does not change. The default lower limit is zero.
GAIN is a gain factor. The input value is multiplied by the gain factor.
IOUTPUT is an optional initial output value. If the RESET input is true, then the function block copies
IOUTPUT to OUTPUT. The default initial value is zero.
CO is the control ouput. CO follows CI. CO=true indicates that evaluation was enabled.

TriStation 1131 Libraries Reference

INTGTOR_R 147

OUTPUT is the result, the integral of the input value. The result unit is the input unit multiplied by
seconds and multiplied by the gain factor. The equation for the integration step is:
OUTPUT := OUTPUT + GAIN * INPUT * GetDelta_REAL() ;

Example
VAR MY_INTGTOR : INTGTOR_R ; END_VAR
VAR y : REAL ; END_VAR
MY_INTGTOR( INPUT:=1.0, GAIN:=1.0 ) ;
y := MY_INTGTOR.OUTPUT; (* if the scan period is always 0.16 seconds, then the result
for the first 3 scans is 0.16, 0.32, 0.48 *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

148

Chapter 2

Functions and Data Types

IsFinite_LREAL
Returns true if a number is finite.

Syntax
b := IsFinite_LREAL( x );

Table 145

Input Parameters

Name

Data Type

Description

LREAL

A number

Table 146

Return Value

Data Type

Description

BOOL

True if x is finite.

Description
The IsFinite_LREAL function returns true if input x is a finite number; false if x is plus infinity, minus
infinity, or not a number (NAN).

Example
VAR
x :=
b :=
x :=
b :=

x : LREAL ; b : BOOL ;
0.0 ;
IsFinite_LREAL( x );
1.0 / x ;
IsFinite_LREAL( x );

END_VAR;
(* result is true *)
(* result is false *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

IsFinite_REAL

149

IsFinite_REAL
Returns true if a number is finite.

Syntax
b := IsFinite_REAL( x );

Table 147

Input Parameters

Name

Data Type

Description

REAL

A number

Table 148

Return Value

Data Type

Description

BOOL

True if x is finite.

Description
The IsFinite_REAL function returns true if input x is a finite number; false if x is plus infinity, minus
infinity, or not a number (NAN).

Example
VAR
x :=
b :=
x :=
b :=

x : REAL ; b : BOOL ;
0.0 ;
IsFinite_REAL( x );
1.0 / x ;
IsFinite_REAL( x );

END_VAR;
(* result is true *)
(* result is false *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

150

Chapter 2

Functions and Data Types

IsNan_LREAL
Returns true if the operand is not a number (NAN).

Syntax
b := IsNan_LREAL( x );

Table 149

Input Parameters

Name

Data Type

Description

LREAL

The operand

Table 150

Return Value

Data Type

Description

BOOL

True if x is not a number (NAN).

Description
The IsNan_LREAL function returns true if input x is a not a number (NAN); false if x is a finite number,
plus infinity, or minus infinity.

Example
VAR
x :=
b :=
x :=
b :=

x : LREAL ; b : BOOL ; END_VAR;


0.0 ;
IsNan_LREAL( x );
(* result is false *)
SQRT(-1.0) ;
IsNan_LREAL( x );
(* result is true *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

IsNan_REAL

151

IsNan_REAL
Returns true if the operand is not a number (NAN).

Syntax
b := IsNan_REAL( x );

Table 151

Input Parameters

Name

Data Type

Description

REAL

The operand

Table 152

Return Value

Data Type

Description

BOOL

True if x is not a number (NAN).

Description
The IsNan_REAL function returns true if input x is a not a number (NAN); false if x is a finite number,
plus infinity, or minus infinity.

Example
VAR
x :=
b :=
x :=
b :=

x : REAL ; b : BOOL ; END_VAR;


0.0 ;
IsNan_REAL( x );
(* result is false *)
SQRT(-1.0) ;
IsNan_REAL( x );
(* result is true *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

152

Chapter 2

Functions and Data Types

LE
Determines if one operand is less than or equal to another operand.

Syntax
b :=

x <= y ;

Table 153

Input Parameters

Name

Data Type

Description

ANY_ NOTE1

First operand.

ANY_ NOTE1

Second operand.

Table 154

Return Value

Data Type

Description

BOOL

True if x is less than or equal to y.

Description
The LE function is used in graphical languages to determine if one operand is greater than or equal to
another operand. In Structured Text, the <=operator is used. The result is true if one operand is less than
or equal to another operand; otherwise the result is false.
The operands can be any of these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
STRING
TIME
TOD

Both operands must be the same data type. For type REAL or LREAL data types, if either operand is not
a number (NAN), the result is undefined.

TriStation 1131 Libraries Reference

LE

153

Example
Structured Text
VAR b : BOOL; END_VAR
b := 10 <= 11;
b := 11 <= 11;
b := 11 <= 10;
b := 'abce' <= 'abcd';

(*
(*
(*
(*

result
result
result
result

is
is
is
is

TRUE *)
TRUE *)
FALSE *)
FALSE *)

Function Block Diagram

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

154

Chapter 2

Functions and Data Types

LEADLAG
Provides the normal lead-lag compensation commonly used in the process control industry.

Syntax
MY_LEADLAG(CI:=b1, IN:=x1, GAIN:=x2, TAU1:=x3, TAU2:=x4, AUTO_MAN:=b2,
DELTAT:=GetDeltaT() ) ;
y := MY_LEADLAG.OUT ;

Table 155

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables LEADLAG.

IN

REAL

The input value.

GAIN

REAL

The gain factor applied to input.

TAU1

REAL

The lead time constant in seconds.

TAU2

REAL

The lag time constant in seconds.

AUTO_MAN

BOOL

Controls auto/manual status of LEADLAG (auto =1, manual = 0).

DELTAT

TIME

The time between LEADLAG evaluations.

Table 156

Output Parameters

Name

Data Type

Description

CO

BOOL

True if LEADLAG executes successfully.

OUT

REAL

The output value.

Description
The LEADLAG function block provides the normal lead-lag compensation commonly used in the process
control industry. If input TAU1 is greater than input TAU2, then OUT is a lead. If TAU2 is greater than
TAU1, then OUT is a lag.
CI is the control input. CI enables evaluation. If CI is false, then the integration step is not executed. See
DELTAT herein for suggested scheduling alternatives. The default initial value of CI is true.
IN is the input value.
GAIN is a gain factor. The input value is multiplied by the gain factor.
TAU1 is the lead time constant in seconds.
TAU2 is the lag time constant in seconds.
AUTO_MAN controls whether the mode of operation is automatic (AUTO_MAN=1) or manual
(AUTO_MAN=0). In manual mode, the function block copies the input value times the gain to the output
value. In automatic mode, the function block calculates the output value as a function of input value,
previous input value, previous output value, gain, lead time constant, lag time constant, and time
between evaluations.

TriStation 1131 Libraries Reference

LEADLAG

155

DELTAT is the time between executions. To schedule execution using a CSCHED or TSCHED function
block, connect the DELTAT input to the ACTUAL output of the CSCHED or TSCHED function block, and
connect the CI input to the Q output of the CSCHED or TSCHED function block. To schedule execution
every scan, connect the DELTAT input to the ouput of a GetDeltaT function, and set CI=true.
CO is the control ouput. CO follows CI. CO=true indicates that evaluation was enabled.
OUT is the result. The result unit is the input unit multiplied by the gain factor.
If AUTO_MAN=0 then the equation for the output is:
OUT := GAIN * IN ;

If AUTO_MAN=1 then the equation for the output is:


OUT := (GAIN * (T1 * (IN - OLDX) + IN)
+ (T2 * OUT)) / (T2 + REAL#1.0) ;
where:
T1 is TAU1/DLT
T2 is TAU2/DLT
DLT is DELTAT converted to seconds
OLDX is the previous value of the input

Runtime Errors
None.

Application Notes

Can be used in Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

156

Chapter 2

Functions and Data Types

LEADLAG_R
Provides the normal lead-lag compensation commonly used in the process control industry.

Syntax
MY_LEADLAG_R(CI:=b1, IN:=x1, GAIN:=x2, TAU1:=x3, TAU2:=x4, AUTO_MAN:=b2 ) ;
y := MY_LEADLAG_R.OUT ;

Table 157

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables LEADLAG_R.

IN

REAL

The input value.

GAIN

REAL

The gain factor applied to input.

TAU1

REAL

The lead time constant in seconds.

TAU2

REAL

The lag time constant in seconds.

AUTO_MAN

BOOL

Controls auto/manual status of LEADLAG_R (auto =1, manual = 0).

Table 158

Output Parameters

Name

Data Type

Description

CO

BOOL

True if LEADLAG_R executes successfully.

OUT

REAL

The output value.

Description
The LEADLAG_R function block provides the normal lead-lag compensation commonly used in the
process control industry. If input TAU1 is greater than input TAU2, then OUT is a lead. If TAU2 is greater
than TAU1, then OUT is a lag.
LEADLAG_R is smaller and faster than LEADLAG, but does not provide the scheduling alternatives of
LEADLAG, which means LEADLAG_R must be executed and enabled every scan.
CI is the control input. CI enables evaluation. If CI is false, then no operation occurs. The default initial
value of CI is true.
IN is the input value.
GAIN is a gain factor. The input value is multiplied by the gain factor.
TAU1 is the lead time constant in seconds.
TAU2 is the lag time constant in seconds.
AUTO_MAN controls whether the mode of operation is automatic (AUTO_MAN=1) or manual
(AUTO_MAN=0). In manual mode, the function block copies the input value times the gain to the output
value. In automatic mode, the function block calculates the output value as a function of input value,
previous input value, previous output value, gain, lead time constant, lag time constant, and time
between evaluations.
CO is the control ouput. CO follows CI. CO=true indicates that evaluation was enabled.

TriStation 1131 Libraries Reference

LEADLAG_R

157

OUT is the result. The result unit is the input unit multiplied by the gain factor.
If AUTO_MAN=0 then the equation for the output is:
OUT := GAIN * IN ;

If AUTO_MAN=1 then the equation for the output is:


OUT := (GAIN * (T1 * (IN - OLDX) + IN)
+ (T2 * OUT)) / (T2 + REAL#1.0) ;
where:
T1 is TAU1/DLT
T2 is TAU2/DLT
DLT is DELTAT converted to seconds
OLDX is the previous value of the input

Runtime Errors
None.

Application Notes

Can be used in Control applications only.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

158

Chapter 2

Functions and Data Types

LIMIT
Returns a value between a minimum limit and a maximum limit.

Syntax
y := LIMIT( low, x, high ) ;

Table 159

Input Parameters

Name

Data Type

Description

MN

ANY_ NOTE1

The minimum limit.

IN

ANY_NOTE1

The input value.

MX

ANY_NOTE1

The maximum limit.

Table 160

Return Value

Data Type

Description

ANY_NOTE1

The output value.

Description
The LIMIT function returns a value between a minimum limit and a maximum limit.
If the input value is between the minimum limit and the maximum limit, then the return value equals the
input value. If the input value is less than or equal to the minimum limit, then the return value equals the
minimum limit. If the input value is greater than or equal to the maximum limit, then the return value
equals the maximum limit.
The LIMIT function can be used with these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
TIME
TOD

All operands must be the same data type as the data type for the return value. For data type REAL or
LREAL, if any operand is not a number (NAN), the result is NAN.

Note

STRING data types are not supported for this function.

TriStation 1131 Libraries Reference

LIMIT

159

Example
VAR x, y : REAL ; END_VAR
x := 5.0 ;
y := LIMIT( 10.0, x, 20.0 ) ;

(* result is 10.0 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

160

Chapter 2

Functions and Data Types

LINEMNTR
Monitors an analog current loop.

Syntax
MY_LINEMNTR_R(CI:=b1, INPUT:=n1, LNOPLIM:=n2, LNSHLIM:=n3, LMONLIM:=n4 ) ;
IS_ON := MY_LINEMNTR_R.OUTPUT ;
IS_SHORTED := MY_LINEMNTR_R.LNSHORT ;
IS_OPEN := MY_LINEMNTR_R.LNOPEN ;

Table 161

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables LINEMNTR.

INPUT

DINT

The analog input value.

LNOPLIM

DINT

The open-circuit fault limit.

LNSHLIM

DINT

The short-circuit fault limit.

LMONLIM

DINT

The contact input on limit.

Table 162

Output Parameters

Name

Data Type

Description

CO

BOOL

Control out.

OUTPUT

BOOL

The contact input status.

LNSHORT

BOOL

The short-circuit fault status.

LNOPEN

BOOL

The open-circuit fault status.

Description
The LINEMNTR function block monitors an input from an analog current loop.
First, the function block compares the analog input value with the open-circuit fault limit. If the analog
input value is less than or equal to the open-circuit fault limit, then there is not enough current flowing
in the current loop, which means there is an open circuit fault, and the function block sets ouput
LNOPEN=true.
If there is no open-circuit fault, then the function block compares the analog input value with the shortcircuit fault limit. If the analog input value is greater than or equal to the short-circuit fault limit, then
there is too much current flowing in the current loop, which means there is a short circuit fault, and the
function block sets output LNSHORT=true.
If there is neither an open-circuit fault nor a short-circuit fault, then the function block compares the
analog input value with the "contact input on" limit which is a current threshold that distinguishes data
0 from data 1. If the analog input value is greater than or equal to the "contact input on" limit, then the
function block sets OUTPUT=1; otherwise, OUTPUT=0.
CI is the control input. CI enables evaluation. If CI is false, then there is no operation. The default initial
value of CI is true.
INPUT is an analog input value that represents (for example, is proportional to) the monitored current.
TriStation 1131 Libraries Reference

LINEMNTR

161

LNOPLIM is the open-circuit fault limit. The circuit is open if INPUT is less than or equal to LNOPLIM.
LNSHLIM is the short-circuit fault limit. The circuit is shorted if INPUT is greater than or equal to
LNSHLIM.
LMONLIM is a threshold. The circuit is On, that is, OUTPUT=1, if there are no faults and INPUT is greater
than or equal to LMONLIM.
CO is the control ouput. CO follows CI. CO=true indicates that evaluation was enabled.
OUTPUT indicates whether the circuit is On. If there is no open-circuit and no short-circuit and INPUT
is greater than or equal to the threshold LMONLIM, then OUTPUT=1, indicating that the circuit is On. If
INPUT is less than the threshold LMONLIM or if there is an open-circuit or short-circuit, then OUPUT=0.
LNSHORT indicates a short-circuit fault. LNSHORT=true if INPUT is greater than or equal to LNSHLIM
and there is no open-circuit fault.
LNOPEN indicates an open-circuit fault. LNOPEN=true if INPUT is less than or equal to LNOPLIM.

Example
VAR MY_LINEMNTR : LINEMNTR ; END_VAR
VAR IS_ON, IS_SHORTED, IS_OPEN : BOOL
MY_LINEMNTR
(
LNOPLIM:=819,
LMONLIM:=2000,
LNSHLIM:=4000,
INPUT:=4010
);
IS_OPEN := MY_LINEMNTR.LNOPEN;
(*
IS_SHORTED := MY_LINEMNTR.LNSHORT; (*
IS_ON := MY_LINEMNTR.LNSHORT;
(*

; END_VAR

result is false *)
result is true *)
result is false *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

162

Chapter 2

Functions and Data Types

LN
Calculates the natural logarithm of a real number.

Syntax
y := LN( x );

Table 163

Input Parameters

Name

Data Type

Description

ANY_REAL

A real number.

Table 164

Return Value

Data Type

Description

ANY_REAL

The natural logarithm of x.

Description
The LN function calculates the natural logarithm of a real number.

Example
VAR y : REAL; END_VAR
y := LN( 1.0 );
y := LN( 2.718282 );

(* result is 0.0 *)
(* result is 1.0 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If x is negative or zero.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

LOG

163

LOG
Calculates the common (base-ten) logarithm of a real number.

Syntax
y := LOG( x );

Table 165

Input Parameters

Name

Data Type

Description

ANY_REAL

A real number.

Table 166

Return Value

Data Type

Description

ANY_REAL

The common logarithm of x.

Description
The LOG function calculates the common (base-ten) logarithm of a real number.

Example
VAR
y :=
y :=
y :=

y : REAL;
LOG(
1.0
LOG( 10.0
LOG( 100.0

END_VAR
);
);
);

(* result is 0.0 *)
(* result is 1.0 *)
(* result is 2.0 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If x is negative or zero.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

164

Chapter 2

Functions and Data Types

LOOPDETR
Processes an analog input from a detector or group of detectors in an analog current loop.

Syntax
MY_LOOPDETR(IN:=b1, INPUT:=n1, INHIBIT:=b2, RSTIN:=b3, OPFLIM:=n2, SHFLIM:=n3,
TRALIM:=n4, HITRIP:=b4, RSTTIME:=t1, DELTAT:=t2);

Table 167

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables LOOPDETR.

INPUT

DINT

The loop detector analog input value.

INHIBIT

BOOL

The inhibit loop detector alarms.

RSTIN

BOOL

The loop detector reset input.

OPFLIM

DINT

The loop detector open-circuit fault limit.

SHFLIM

DINT

The loop detector short-circuit fault limit.

TRALIM

DINT

The loop detector trip limit.

HITRIP

BOOL

The loop high trip alarm flag (high = 1, low = 0).

RSTTIME

TIME

The loop detector reset time.

DELTAT

TIME

The time between LOOPDETR evaluations.

Table 168

Output Parameters

Name

Data Type

Description

CO

BOOL

True if LOOPDETR executes successfully.

TRALARM

BOOL

The loop detector trip alarm.

OPALARM

BOOL

The loop detector open-circuit fault alarm.

SHALARM

BOOL

The loop detector short-circuit fault alarm.

RSTOUT

BOOL

The loop detector reset output.

TRSTAT

BOOL

The loop detector trip status

OPSTAT

BOOL

The loop detector open-circuit fault status

SHSTAT

BOOL

The loop detector short-circuit fault status.

RSTCNTR

TIME

The loop detector reset counter.

OUTPUT

BOOL

The loop detector status.

TriStation 1131 Libraries Reference

LOOPDETR 165

Description
The LOOPDETR function block processes an analog input from a detector or group of detectors in an
analog current loop.
If the INHIBIT input is not set, the alarm flags that correspond to the status flags are set. The setting of
the alarms can be inhibited by setting the INHIBIT input, but the status bits are unaffected. All alarms,
once set, are latched until reset by the RSTIN input.
The LOOPDETR function also supports an output RSTCNTR to provide an external reset that is required
by some detectors. When the RSTIN input is set, the RSTOUT output is set for RSTTIME milliseconds.
OUTPUT is set if any of the fault or trip status bits are set.
The HITRIP input controls the trip alarm limit TRALIM. If the HITRIP input is 1, then the trip alarm
occurs if the detector value is above the trip alarm limit. If the HITRIP input is 0, then the trip alarm occurs
if the detector value is below the trip alarm limit.
RSTIN clears the alarms even when CI is false. RSTIN clears the alarms before executing the other
operations. If RSTIN and CI are both false, no operation occurs.
In TriStation MSW, RSTIN was both an input and an output, and LOOPDETR cleared RSTIN when the
reset counter was less than or equal to zero. In TriStation 1131, RSTIN is an input, not an output, and
LOOPDETR does not write RSTIN. You must use RSTOUT, not RSTIN, to detect a counter less than or
equal to zero. An instance of LOOPDETR can be invoked no more than once per scan.
To execute each scan, connect the DELTAT input to the DELTAT output of a Triconex (TCXLIB)()
function.

Note

To schedule execution using a CSCHED or TSCHED function block, connect the DELTAT input
to the ACTUAL output of a CSCHED or TSCHED function block.

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

166

Chapter 2

Functions and Data Types

LREAL
An LREAL data type is 64 bits in length and has 15 decimal digits of precision. In TriStation 1131, the
LREAL data type follows the IEC-559 Standard floating-point format.
An LREAL data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

LREAL

Description

Long-real number

Size

64 bits

Default value

0.0

Most positive number

1.7976931348623158 e +308

Least positive number

4.9406564584124654 e 324

Least negative number

4.9406564584124654 e 324

Most negative number

1.7976931348623158 e +308

Result if intermediate value is less than lower limit

Infinity or HUGE

Result if upper limit is less than intermediate value

+Infinity or HUGE

Gradual Underflow for LREAL Data Types


In PCs and controllers, the floating-point implementation includes a standard feature called gradual
underflow that extends the range for an LREAL number and gradually changes the precision as values
approach zero.
This table compares the values obtained when gradual underflow is not present, to the values obtained
when it is present.
Without Gradual Underflow

With Gradual Underflow

The smallest positive number that can be stored in


an LREAL variable is:

The smallest positive number that can be stored in an


LREAL variable is:

21022 = 2.2250738585072014E308.

21074 = 4.9406564584124654E324.

The precision changes abruptly from 17 digits to 0


digits when the value changes from a number
greater than 21023 to a number less than 21023.

The precision changes gradually from 17 digits to 1 digit


as the value changes from
21023 to 21074.

The maximum relative error changes abruptly from


253 to 1 when the value changes from a number
greater than 21023 to a number less than 21023.

The maximum relative error changes gradually from 253


to 1 as the value changes from 21023 to 21074.

For values from 21075 to 21022, the maximum


absolute error equals the value.

For values from 21075 to 21022, the maximum absolute


error is a constant 21075.

TriStation 1131 Libraries Reference

LREAL

167

This table shows how the precision changes as LREAL numbers approach zero.
If |x| Is Greater Than:

Then the Precision Is Greater Than:

5.0E308

17 digits

5.0E309

16 digits

5.0E310

15 digits

5.0E322

3 digits

5.0E323

2 digits

5.0E324

1 digits

0.0

0 digits

Absolute error is the absolute value of x a, where x is the exact value and a is the actual value stored.
Relative error is the absolute value of (x a)/x, where x is the exact value and a is the actual value stored.
This table shows how gradual underflow affects absolute error and relative error as LREAL numbers
approach zero.
Range

Maximum Absolute
Error

Maximum Relative
Error

0 < |x| 21075

|x|

21075 < |x| 21022

21075

21075 / |x|

21022 |x| < 21024 2972

253 * |x|

253

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

168

Chapter 2

Functions and Data Types

LREAL_TO_DINT
Converts a 64-bit long real number to a 32-bit integer.

Syntax
k := LREAL_TO_DINT(x);

Table 169

Input Parameters

Name

Data Type

Description

LREAL

The 64-bit number to be converted.

Table 170

Return Value

Data Type

Description

DINT

The value of x converted to a 32-bit integer.

Description
The LREAL_TO_DINT function converts a 64-bit long real number to a 32-bit integer. The result is
rounded to the nearest integer.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : LREAL;
x := -123.6;
k := LREAL_TO_DINT( x );

END_VAR;
(* result is -124 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

2147483648

BADPARAM, ERROR

If x is less than -2147483648.5

2147483648

BADCONV, ERROR

If x is greater than or equal to +2147483647.5

+2147483647

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

LREAL_TO_DINT 169

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

170

Chapter 2

Functions and Data Types

LREAL_TO_INT
Converts a 64-bit long real number to a 16-bit integer.

Syntax
k := LREAL_TO_INT(x);

Table 171

Input Parameters

Name

Data Type

Description

LREAL

The 64-bit long real number to be converted.

Table 172

Return Value

Data Type

Description

INT

The value of x converted to a 16-bit integer.

Description
The LREAL_TO_INT function converts a 64-bit long real number to a 16-bit integer. The result is rounded
to the nearest integer.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : LREAL;
x := -123.6;
k := LREAL_TO_INT( x );

END_VAR;
(* result is -124 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

32768

BADPARAM, ERROR

If x is less than -32768.5

32768

BADCONV, ERROR

If x is greater than or equal to +32757.5

+32767

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

LREAL_TO_INT

171

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

172

Chapter 2

Functions and Data Types

LREAL_TO_REAL
Converts a 64-bit long real number to a 32-bit real number.

Syntax
y := LREAL_TO_REAL(x);

Table 173

Input Parameters

Name

Data Type

Description

LREAL

The 64-bit long real number to be converted.

Table 174

Return Value

Data Type

Description

REAL

The value of x converted to a 32-bit real number.

Description
The LREAL_TO_REAL function converts a 64-bit long real number to a 32-bit real number.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
x : LREAL
END_VAR;
VAR
y : REAL
END_VAR;
x := 6.25;
y = LREAL_TO_REAL(x);

(* result is 6.25 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If the result is out of range and negative.

INF

BADCONV, ERROR

If the result is out of range and positive.

+INF

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

LREAL_TO_REAL

173

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

174

Chapter 2

Functions and Data Types

LT
Determines if one operand is less than another operand.

Syntax
b :=

x < y ;

Table 175

Input Parameters

Name

Data Type

Description

ANY_ NOTE1

First operand

ANY_ NOTE1

Second operand

Table 176

Return Value

Data Type

Description

BOOL

True if x is less than y.

Description
The LT function is used in graphical languages to determine if one operand is less than another operand.
In Structured Text, the operator is used. The result is true if one operand is less than another operand;
otherwise the result is false.
The operands can be any of these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
STRING
TIME
TOD

Both operands must be the same data type. For type REAL or LREAL data types, if either operand is not
a number (NAN), the result is undefined.

TriStation 1131 Libraries Reference

LT

175

Example
Structured Text
VAR b : BOOL; END_VAR
b := 10 < 11;
b := 11 < 11;
b := 11 < 10;
b := 'abce' < 'abcd';

(*
(*
(*
(*

result
result
result
result

is
is
is
is

TRUE *)
FALSE *)
FALSE *)
FALSE *)

Function Block Diagram

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

176

Chapter 2

Functions and Data Types

MAX
Finds the maximum of the input values.

Syntax
M := MAX( I1, I2, ..., In ) ;

Table 177

Input Parameters

Name

Data Type

Description

I1

ANY_ NOTE1

Input value 1.

In

ANY_ NOTE1

Input value n.

Table 178

Return Value

Data Type

Description

ANY_NOTE1

The largest value of I1In.

Description
The MAX function returns the maximum of input values I1 ... In.
The maximum number of function inputs is 50.
The function can be used with these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
TIME
TOD

All operands must have the same data type as the return value. For data type REAL or LREAL, if any
operand is not a number (NAN), the result is NAN.

Note

STRING data types are not supported for this function.

TriStation 1131 Libraries Reference

MAX

177

Example
VAR y : REAL ; END_VAR
y := MAX( 10.0, 15.0, 20.0 ) ;

(* result is 20.0 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

178

Chapter 2

Functions and Data Types

MBCTRL
Sets time-out and retry values for a Modbus master port.

Syntax
MY_MBCTRL(CI:=b1, PORT:=n1, TIME_OUT:=n2, RETRIES:=n3 );

Table 179

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables MBCTRL.

PORT

DINT

The Modbus master port number.

TIME_OUT

DINT

The time, in seconds, to wait for a response from the slave during an MBREAD or
MBWRITE operation.Default is 3 seconds.
See the entries for the MBREAD functions (pages 180 188) and MBWRITE
functions (pages 191 198) for error codes.

RETRIES

Table 180

DINT

The number of retries for a failed inquiry. The default is zero.

Output Parameters

Name

Data Type

Description

CO

BOOL

True if MBCTRL executes successfully.

STATUS

DINT

Status:
0=

Idle, no operation.

100 = Bad parameter if PORT is less than 0.


105 = Bad parameter if TIME_OUT is less than 0 or RETRIES is less than 0.

Description
The MBCTRL function block sets time-out and retry values for a Modbus master port.
If CI = false, no operation occurs (no values are changed). If CI = true, the time-out is changed to
TIME_OUT and the number of retries is changed to RETRIES. To set the time-out or number of retries to
a value other than the default, execute the function block once with CI = true at the beginning of the first
scan.
For examples of using the MBCTRL function block, see one of these sample projects:

Exmodbus.pt2 (Tricon controllers)

Tdmodbus.pt2 (Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

TriStation 1131 Libraries Reference

MBCTRL

179

Example
VAR MY_MBCTRL : MBCTRL ; END_VAR
VAR bInitialized : BOOL ; END_VAR
(*
* Increase the port 1 time-out to 4 seconds
* and the number of retries to 3.
*)
MY_MBCTRL( CI:=not bInitialized, PORT:=1, TIME_OUT:=4, RETRIES:=3 ) ;
bInitialized := true ;

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

CO=false

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

180

Chapter 2

Functions and Data Types

MBREAD_BOOL
Reads Boolean values from a Modbus slave.

Syntax
MY_MBREAD_BOOL(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4 );

Table 181

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus read operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave (119999).

DINT

The number of values to read from slave (132).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

Table 182

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Read initiated (STATUS = 1 or 4).

NDR

BOOL

New data received (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

Status:
0=

Idle, no operation.

1=

Read initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received and new data received.

4=

Response received and new data received and next read initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port malfunctions or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.
203 = Modbus slave returned an Illegal Data Value response code.
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code.
213 = Modbus slaves response has a CRC error.

TriStation 1131 Libraries Reference

MBREAD_BOOL

Table 182
Name

181

Output Parameters (continued)


Data Type

Description
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.

D01

BOOL

Receive data 01.

D32

BOOL

Receive data 32.

Description
The MBREAD_BOOL function block reads Boolean values from a Modbus slave.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Example
For examples of using the MBREAD_BOOL function block, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes. Upon detection of a
runtime error condition, the function block returns the indicated values and sets the error flags to true.
For more information about error flags and runtime errors, see the CHK_ERR function block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

182

Chapter 2

Functions and Data Types

MBREAD_DINT
Reads integers from a Modbus slave.

Syntax
MY_MBREAD_DINT(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4 );

Table 183

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus read operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave (30001499999).

DINT

The number of values to read from slave (132).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

Table 184

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Read initiated (STATUS = 1 or 4).

NDR

BOOL

New data received (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

Status:
0=

Idle, no operation.

1=

Read initiated.

3=

Response received and new data received.

4=

Response received and new data received and next read initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port malfunctions or the port is not a odbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.
203 = Modbus slave returned an Illegal Data Value response code.
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code.
213 =Modbus slaves response has a CRC error.
214 = Modbus slaves response has an LRC error.
217 = Modbus slaves response function code does not match.
216 = Modbus slaves response has a length error.
219 = Response not received in specified time-out period.

TriStation 1131 Libraries Reference

MBREAD_DINT

Table 184

183

Output Parameters (continued)

Name

Data Type

Description

D01

DINT

Receive data 01.

D32

DINT

Receive data 32.

Description
The MBREAD_DINT function block reads integers from a Modbus slave. The type of the data output
(D01..D32) is DINT, which is a 32-bit integer. However, the corresponding data from the Modbus is only
16 bits. The 16-bit value from the Modbus slave is in the least significant 16 bits of the DINT, with zero in
the most significant 16 bits of the DINT.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Example
For examples of using the MBREAD_DINT function block, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

184

Chapter 2

Functions and Data Types

MBREAD_REAL
Reads real numbers from a Modbus slave.
The Modbus slave should be a Tricon controller. Use MBREAD_REAL_TRD if the Modbus slave is a
Trident or Tri-GP controller, or a non-Triconex device.

Syntax
MY_MBREAD_REAL(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4, SPECIAL:=b2 );

Table 185

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus read operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave. If SPECIAL = false, then the starting alias is the same
as the configured alias in the slave (if the slave is a Tricon controller).
ALIAS Ranges:
3200132120 = Input real, read only.
3300134000 = Memory real, read only.
4100142000 = Memory real, read/write.
If SPECIAL = true, then the starting alias is a special alias and must be an odd
number. If the slave is a Tricon controller, the configured alias in the slave is
mapped to two SPECIAL ALIASES.
SPECIAL ALIAS Ranges:
3400134240 = Input real, read only.
4400144240 = Input real, read only.
3500137000 = Memory real, read only.
4500147000 = Memory real, read only.
4200144000 = Memory real, read/write.

DINT

The number of values to read from slave (125).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

SPECIAL

BOOL

True if special aliases are used. For more information, see Description on page 185.

Table 186

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Read initiated (STATUS = 1 or 4).

NDR

BOOL

New data received (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to100.

TriStation 1131 Libraries Reference

MBREAD_REAL

Table 186

185

Output Parameters (continued)

Name

Data Type

STATUS

DINT

Description
Status:
0=

Idle, no operation.

1=

Read initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received and new data received.

4=

Response received and new data received and next read initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port malfunctions or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.
203 = Modbus slave returned an Illegal Data Value response code.
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code 213 =Modbus slaves
response has a CRC error.
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.
D01

REAL

Receive data 01.

D25

REAL

Receive data 25.

Description
The MBREAD_REAL function block reads real numbers from a Modbus slave.
The Modbus slave should be a Tricon controller. Use MBWRITE_REAL_TRD if the Modbus slave is a
Trident or Tri-GP controller, or a non-Triconex device.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Reading Real Values from a Tricon Controller


To read a real value from a Tricon controller, Triconex recommends setting SPECIAL=false (the default
value). The value of the ALIAS input is the same as the value configured in the slave controller. For
example, to read one real value from ALIAS 33002 in the slave, set ALIAS=33002 and N=1.

TriStation 1131 Libraries Reference

186

Chapter 2

Functions and Data Types

Reading Real Values from a Non-Triconex Device


You can use MBREAD_REAL to read a real value from a non-Triconex device if the alias you want to read
is a special alias. To read a real value from a non-Triconex device, set SPECIAL=true. The
MBREAD_REAL function block reads two 16-bit values from two consecutive aliases (ALIAS and
ALIAS+1) and concatenates the two values to form the first 32-bit real value (D01). The 16 most significant
bits are at ALIAS, and the 16 least significant bits are at ALIAS+1. The starting alias must be odd. For
example, to read a real value from SPECIAL ALIASES 35003 and 35004, set SPECIAL=true,
ALIAS=35003, and N=1.

Special Alias Mapping in Tricon Controllers


The Tricon controller provides special aliases for real variables. Each real variable is mapped into two
aliases to produce a 32-bit value. This table shows the mapping of real-variable aliases to the special
aliases.
Alias

Special Alias

Description

32001

3400134002 or 4400144002

Input real, read only.

32001

3400334004 or 4400344004

Input real, read only.

32120

3423934240 or 4423944240

Input real, read only.

33001

3500135002 or 4500145002

Memory real, read only.

33002

3500335004 or 4500345004

Memory real, read only.

34000

3699937000 or 4699947000

Memory real, read only.

41001

4200142002

Memory real, read/write.

41002

4200342004

Memory real, read/write.

4399944000

Memory real, read/write.

.
.

.
.

.
.
42000

Example
For examples of using the MBREAD_REAL function block, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

TriStation 1131 Libraries Reference

MBREAD_REAL

187

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

188

Chapter 2

Functions and Data Types

MBREAD_REAL_TRD
Reads real numbers from a Modbus slave.
The Modbus slave should be a Trident or Tri-GP controller, or a non-Triconex device. Use
MBREAD_REAL if the Modbus slave is a Tricon controller.

Syntax
MY_MBREAD_REAL_TRD(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4 );

Table 187

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus read operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave (3000149998).

DINT

The number of values to read from slave (125).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

Table 188

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Read initiated (STATUS = 1 or 4).

NDR

BOOL

New data received (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

Status:
0=

Idle, no operation.

1=

Read initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received and new data received.

4=

Response received and new data received and next read initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port malfunctions or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.
203 = Modbus slave returned an Illegal Data Value response code.
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code.

TriStation 1131 Libraries Reference

MBREAD_REAL_TRD

Table 188
Name

189

Output Parameters (continued)


Data Type

Description
213 = Modbus slaves response has a CRC error.
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.

D01

REAL

Receive data 01.

D25

REAL

Receive data 25.

Description
The MBREAD_REAL_TRD function block reads real numbers from a Modbus slave.
The Modbus slave should be a Trident or Tri-GP controller, or a non-Triconex device. Use
MBREAD_REAL if the Modbus slave is a Tricon controller.
The function block reads two 16-bit values from two consecutive aliases (ALIAS and ALIAS+1) and
concatenates the two values to form the first 32-bit REAL value (D01). The 16 most significant bits are at
ALIAS, and the 16 least significant bits are at ALIAS+1. For example, to read a REAL value from aliases
35003 and 35004, set ALIAS=35003, and N=1.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Example
For examples of using Modbus Read function blocks, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

190

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

MBWRITE_BOOL

191

MBWRITE_BOOL
Writes Boolean values to a Modbus slave.

Syntax
MY_MBWRITE_BOOL(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4, D01 := b2 );

Table 189

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus write operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave (19999).

DINT

The number of values to write (132).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

D01

BOOL

Send data 01.

D32

BOOL

Send data 32.

Table 190

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Write initiated (STATUS = 1 or 4).

ACK

BOOL

Write acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

Status:
0=

Idle, no operation.

1=

Write initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received.

4=

Response received and next write initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port is malfunctioning or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code

TriStation 1131 Libraries Reference

192

Chapter 2

Functions and Data Types

Table 190
Name

Output Parameters (continued)


Data Type

Description
203 = Modbus slave returned an Illegal Data Value response code
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code.
213 = Modbus slaves response has a CRC error.
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.

Description
The MBWRITE_BOOL function block writes Boolean values to a Modbus slave.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Example
For examples of using the MBWRITE_BOOL function block, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

MBWRITE_DINT

193

MBWRITE_DINT
Writes the least significant 16 bits of a DINT to a Modbus slave.

Syntax
MY_MBWRITE_DINT(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4, D01 := n5 );

Table 191

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus write operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave (4000149999).

DINT

The number of values to write (132).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

D01

DINT

Send data 01.

D32

DINT

Send data 32.

Table 192

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Write initiated (STATUS = 1 or 4).

ACK

BOOL

Write acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

Status:
0=

Idle, no operation.

1=

Write initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received.

4=

Response received and next write initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port is malfunctioning or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.

TriStation 1131 Libraries Reference

194

Chapter 2

Functions and Data Types

Table 192
Name

Output Parameters (continued)


Data Type

Description
203 = Modbus slave returned an Illegal Data Value response code.
204 = Modbus slave returned a Failure in Associated Device response code
206 = Modbus slave returned a Busy, Rejected Message code
213 = Modbus slaves response has a CRC error.
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.

Description
The MBWRITE_DINT function block writes the least significant 16 bits of a DINT to a Modbus slave.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Example
For examples of using the MBWRITE_DINT function block, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

MBWRITE_REAL

195

MBWRITE_REAL
Allows a Triconex Modbus master controller to write real numbers to a Trident or Tri-GP Modbus slave
controller, or to a non-Triconex device.

Syntax
MY_MBWRITE_REAL(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4, SPECIAL:=b2,
D01:=x1 );

Table 193

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus write operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave.


ALIAS Range:
4100142000 = Memory real, read/write.
Special ALIAS Range:
4200144000 = Memory real, read/write.

DINT

The number of values to write (125).

PORT

DINT

The Modbus master port number.

STATION

DINT

The slave station address (1247).

SPECIAL

BOOL

True if special aliases are used. For more information, see Special Alias Mapping in
Tricon Controller on page 197.

D01

REAL

Send data 01.

D25

REAL

Send data 25.

Table 194

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Write initiated (STATUS = 1 or 4).

ACK

BOOL

Write acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to100.

TriStation 1131 Libraries Reference

196

Chapter 2

Functions and Data Types

Table 194

Output Parameters (continued)

Name

Data Type

STATUS

DINT

Description
Status:
0=

Idle, no operation.

1=

Write initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received.

4=

Response received and next write initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port is malfunctioning or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.
203 = Modbus slave returned an Illegal Data Value response code.
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code.
213 = Modbus slaves response has a CRC error.
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.

Description
The MBWRITE_REAL function block writes real numbers to a Modbus slave.
The Modbus slave should be a Tricon controller. Use MBWRITE_REAL_TRD if the Modbus slave is a
Trident or Tri-GP controller, or a non-Triconex device.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Writing Real Values to a Tricon Controller


To write a real value to a Tricon controller, Triconex recommends setting SPECIAL=False (the default
value). The value of the ALIAS input is the same as the value configured in the slave controller. For
example, to write a real value to ALIAS 41002 in the slave, set ALIAS=41002 and N=1.

Writing Real Values to a Non-Triconex Device


You can use MBWRITE_REAL to write a real value to a non-Triconex device if the alias you want to write
is a special alias. To write a real value to a non-Triconex device, set SPECIAL=true. The function block
splits the first 32-bit real value (D01) into two 16-bit values and writes the values to two consecutive
ALIASES (ALIAS and ALIAS+1). The 16 most significant bits are at ALIAS, and the 16 least significant

TriStation 1131 Libraries Reference

MBWRITE_REAL

197

bits are at ALIAS+1. The starting ALIAS must be odd. For example, to write a real value to SPECIAL
ALIASES 42003 and 42004, set SPECIAL=true, ALIAS=42003, and N=1.

Special Alias Mapping in Tricon Controller


The Tricon controller provides special aliases for real variables. Each real variable is mapped into two
aliases to produce a 32-bit value. The following table shows the mapping of real-variable aliases to the
special aliases:
Alias

Special Alias

Description

41001

4200142002

Memory real, read/write.

41002

4200342004

Memory real, read/write.

42000

439994400

Memory real, read/write.

Example
For examples of using the MBWRITE_REAL function block, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

198

Chapter 2

Functions and Data Types

MBWRITE_REAL_TRD
Writes real numbers to a Modbus slave.
The Modbus slave should be a Trident or Tri-GP controller, or a non-Triconex device. Use
MBWRITE_REAL if the Modbus slave is a Tricon controller.

Syntax
MY_MBWRITE_REAL_TRD(ACTIVE:=b1, ALIAS:=n1, N:=n2, PORT:=n3, STATION:=n4, D01:=x1 );

Table 195

Input Parameters

Name

Data Type

Description

ACTIVE

BOOL

Requests a Modbus write operation when the internal status equals 0 or 3.

ALIAS

DINT

The starting alias of the slave.


ALIAS Range: 3000149998.

DINT

The number of values to write (125).

PORT

DINT

The port number.

STATION

DINT

The slave station address (1247).

D01

REAL

Send data 01.

D25

REAL

Send data 25.

Table 196

Output Parameters

Name

Data Type

Description

IDLE

BOOL

Idle (STATUS = 0).

BOOL

Write initiated (STATUS = 1 or 4).

ACK

BOOL

Write acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

TriStation 1131 Libraries Reference

MBWRITE_REAL_TRD

Table 196

199

Output Parameters (continued)

Name

Data Type

STATUS

DINT

Description
Status:
0=

Idle, no operation.

1=

Write initiated.

2=

Busy (waiting for response to previous operation).

3=

Response received.

4=

Response received and next write initiated.

100 = PORT is not a Modbus port.


101 = ALIAS in function is not a valid alias.
102 = N is not valid.
103 = Port is malfunctioning or the port is not a Modbus master port.
106 = Sequence error (conditional execution of Modbus function block).
201 = Modbus slave returned an Illegal Function response code.
202 = Modbus slave returned an Illegal Data Address response code.
204 = Modbus slave returned a Failure in Associated Device response code.
206 = Modbus slave returned a Busy, Rejected Message code.
213 = Modbus slaves response has a CRC error.
214 = Modbus slaves response has an LRC error.
216 = Modbus slaves response has a length error.
217 = Modbus slaves response function code does not match.
219 = Response not received in specified time-out period.

Description
The MBWRITE_REAL_TRD function block writes real numbers to a Modbus slave.
The Modbus slave should be a Trident or Tri-GP controller, or a non-Triconex device. Use
MBWRITE_REAL if the Modbus slave is a Tricon controller.
The function block splits the first 32-bit REAL value (D01) into two 16-bit values and writes the two 16bit values to two consecutive aliases (ALIAS and ALIAS+1). The 16 most significant bits are at ALIAS,
and the 16 least significant bits are at ALIAS+1. For example, to write a REAL value to aliases 42003 and
42004, set ALIAS=42003 and N=1.
On each scan, the sequence of Modbus function block calls must be the same, from the start of the first
program to the end of the last program. A change detected in the sequence of Modbus function blocks
causes error status 106.

Note

The number of Modbus reads and writes per scan is limited.

Example
For examples of using Modbus Write function blocks, see these sample projects:

Exmodbus.pt2 (For Tricon controllers)

Tdmodbus.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

TriStation 1131 Libraries Reference

200

Chapter 2

Functions and Data Types

Runtime Errors
Condition

Return Value

Error Flag

If STATUS is greater than or equal to 100

ERROR=true

None

See the description for the STATUS output for runtime error conditions and codes.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes
Can be used in Safety or Control applications.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

MEDSEL 201

MEDSEL
Returns the median of the input numbers.

Syntax
y := MEDSEL( x1, x2, ..., xn ) ;

Table 197

Input Parameters

Name

Data Type

Description

x1

ANY_REAL

Input value 1.

xn

ANY_REAL

Input value n.

Table 198

Return Value

Data Type

Description

ANY_REAL

The median value of x1...xn.

Description
The MEDSEL function returns the median of the input numbers. If the number of inputs is odd, the
median is the middle number. If the number of inputs is even, the median is the average of the two middle
numbers, which means half the numbers are greater than the median and half the numbers are smaller.
The maximum number of function inputs is 50.
All inputs must have the same data type as the return value. If any operand is not a number (NAN), the
result is NAN.

Example
VAR y : REAL ; END_VAR

y := MEDSEL( 15.0, 10.0, 20.0 ) ;


y := MEDSEL( 15.0, 10.0, 20.0, 30.0 ) ;

(* result is 15.0 *)
(* result is 17.5 *)

Runtime Errors
Table 199

Runtime Errors

Condition

Return Value

Error Flags

If an input is not a number.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

202

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

MIN

203

MIN
Find the minimum of the input values.

Syntax
M := MIN( I1, I2, ..., In ) ;

Table 200

Input Parameters

Name

Data Type

Description

I1

ANY_ NOTE1

Input value 1.

In

ANY_ NOTE1

Input value n.

Table 201

Return Value

Data Type

Description

ANY_NOTE1

The smallest value of I1...In.

Description
The MIN function returns the minimum of input values I1 ... In.
The maximum number of function inputs is 50.
The function can be used with these data types:
BOOL
DATE
DINT
DT
DWORD
INT
LREAL
REAL
TIME
TOD

All operands must have the same data type as the return value. For data type REAL or LREAL, if any
operand is not a number (NAN), the result is NAN.

Note

STRING data types are not supported for this function.

Example
VAR m : DINT ; END_VAR
m := MIN( 3, 1, 2 );

(* Result is 1 *)

TriStation 1131 Libraries Reference

204

Chapter 2

Functions and Data Types

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

MINUS_INFINITY_LREAL

205

MINUS_INFINITY_LREAL
Returns minus infinity.

Syntax
y := MINUS_INFINITY_LREAL();

Table 202

Input Parameters

Name

Data Type

Description

NA

NA

No inputs.

Table 203

Return Value

Data Type

Description

LREAL

Minus infinity.

Description
The MINUS_INFINITY_LREAL function returns minus infinity.

Example
VAR
y : LREAL ; END_VAR;
y := MINUS_INFINITY_LREAL();
(* result is minus infinity *)
(* Note: on the controller panel, the value shown is -1.#INF *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

206

Chapter 2

Functions and Data Types

MINUS_INFINITY_REAL
Returns minus infinity.

Syntax
y := MINUS_INFINITY_REAL();

Table 204

Input Parameters

Name

Data Type

Description

NA

NA

No inputs.

Table 205

Return Value

Data Type

Description

REAL

Minus infinity.

Description
The MINUS_INFINITY_REAL function returns minus infinity.

Example
VAR
y : REAL ; END_VAR;
y := MINUS_INFINITY_REAL();
(* result is minus infinity *)
(* Note: on the controller panel, the value shown is -1.#INF *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

MOD

207

MOD
Divides two integers and returns the remainder.

Syntax
i := j MOD k ;

Table 206

Input Parameters

Name

Data Type

Description

ANY_INT

First operand.

ANY_INT

Second operand.

Table 207

Return Value

Data Type

Description

ANY_INT

The remainder.

Description
The MOD (modulus) function divides one integer by another and returns the remainder.
Both operands must have the same data type as the return value.

Example
VAR i : DINT ; END_VAR
i := 5 MOD 3 ;

(* result is 2 *)

Runtime Errors
Condition

Return Value

Error Flags

If the divisor is equal to 0.

DIVBYZERO, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

208

Chapter 2

Functions and Data Types

MOVE
Assigns an input value to an output value.

Syntax
OUT := IN ;

Table 208

Input Parameters

Name

Data Type

Description

IN

ANY

The input value.

Table 209

Return Value

Data Type

Description

ANY

The value of IN.

Description
In a graphical language, the MOVE function assigns an input value to an output value.
In Structured Text, use an assignment statement instead of the MOVE function.

Example
VAR OUT : DINT ; END_VAR
OUT := 3 ;

(* move 3 to variable OUT *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

MUL

209

MUL
Multiplies two or more numbers, or multiplies a time by a number.

Syntax
P := I1 * I2 * ... * In ;
T2 := T1 * N ;

Multiplying Two or More Numbers


Table 210

Input Parameters

Name

Data Type

Description

I1

ANY_NUM

First operand.

In

ANY_NUM

Last operand.

Table 211

Return Value

Data Type

Description

ANY_NUM

The product.

Multiplying a Time by a Number


Table 212

Input Parameters

Name

Type

Description

T1

TIME

The time.

ANY_NUM

A number.

Table 213

Return Value

Data Type

Description

TIME

Product.

Description
In a graphical language, the MUL function multiplies two or more numbers, up to a maximum of 50, or
multiplies a time by a number.
In Structured Text, the multiply operator * multiplies two numbers or multiplies a time by a number.
The product of two or more numbers is a number. The data types of all the numbers must be the same.
The product of a time and a number is a time. The number can be any numeric data type.

TriStation 1131 Libraries Reference

210

Chapter 2

Functions and Data Types

Example
Calculate the product of three numbers
VAR p : DINT; END_VAR
p := 2 * 3 * 4 ;

(* result is 24 *)

Multiply time by a number


VAR t : TIME;
t := T#1s ;
t := t * 2 ;

END_VAR
(* result is T#2s *)

Runtime Errors
Condition

Return Value

Error Flags

If the result is infinite

INF

OVERFLOW, ERROR

If an operand is not a number (NAN)

NAN

OVERFLOW, ERROR

If the time is out of range

Invalid time

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

MUX

211

MUX
Selects a value from multiple inputs.

Syntax
v := MUX( K, I0, I1, ..., In-1 ) ;

Table 214

Input Parameters

Name

Data Type

Description

ANY_INT

The selector.

I0

ANY

Data value 0.

..

In-1

ANY

Data value n-1.

Table 215

Return Value

Data Type

Description

ANY

The selected data value.

Description
The MUX function selects a value from multiple inputs, depending on an input selector (K).
The maximum number of data values is 49.
Normally, the value of K should be from 0 to n-1, where n is the number of data inputs. In this case, the
function returns IK. If K is less than 0, the function returns I0. If K is greater than n-1, the function returns
In-1.
The data values can be any data type, but all data values must have the same data type as the return value.

Example
VAR v : REAL ; END_VAR
v := MUX( 2, 0.0, 1.0, 2.0, 3.0 )

(* result is 2.0 *)

Runtime Errors
Conditions

Return Values

Error Flags

If K is less than 0 [K can be from 0 to (n1)].

Input I0

BADPARAM, ERROR

If K is greater than the index number of the last input.

Last input In-1

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

212

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

NAN_LREAL

213

NAN_LREAL
Returns not a number (NAN).

Syntax
y := NAN_LREAL();

Table 216

Input Parameters

Name

Data Type

Description

NA

NA

No inputs.

Table 217

Return Value

Data Type

Description

LREAL

Not a number (NAN).

Description
The NAN_LREAL function returns not a number (NAN).

Example
VAR
y : LREAL ; END_VAR;
y := NAN_LREAL();
(* result is not a number NAN *)
(* Note: on the controller panel, the value shown is -1.#IND *)
(*
IND is an abbreviation for indefinite
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

214

Chapter 2

Functions and Data Types

NAN_REAL
Returns not a number (NAN).

Syntax
y := NAN_REAL();

Table 218

Input Parameters

Name

Data Type

Description

NA

NA

No inputs.

Table 219

Return Value

Data Type

Description

REAL

Not a number (NAN).

Description
The NAN_REAL function returns not a number (NAN).

Example
VAR
y : REAL ; END_VAR;
y := NAN_REAL();
(* result is not a number NAN *)
(* Note: on the controller panel, the value shown is -1.#IND *)
(*
IND is an abbreviation for indefinite
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

NE

215

NE
Compares two operands for inequality.

Syntax
b :=

x <> y;

Table 220

Input Parameters

Name

Data Type

Description

ANY

First operand

ANY

Second operand

Table 221

Return Value

Data Type

Description

BOOL

True if x is not equal to y.

Description
The NE function is used in graphical languages to determine if two operands are not equal. In Structured
Text, the <> operator is used to determine inequality. The result is true if the operands are not equal;
otherwise the result is false.
The operands can be any data type, but both operands must be the same data type. For type REAL or
LREAL, if either operand is not a number (NAN), the result is undefined.

Example
Structured Text
VAR b : BOOL; END_VAR
b := 10 <> 11;
b := 11 <> 11;
b := 'abcd' <> 'abcd';

(* result is TRUE *)
(* result is FALSE *)
(* result is FALSE *)

Function Block Diagram

Runtime Errors
None.

TriStation 1131 Libraries Reference

216

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

NOT

217

NOT
Performs a logical negation of a Boolean operand or a bitwise complement of a bit-string.

Syntax
v := not b ;

Table 222

Input Parameters

Name

Data Type

Description

ANY_BIT

Operand

Table 223

Return Value

Data Type

Description

ANY_BIT

NOT b

Description
In graphical languages, the NOT function returns the logical negation of a Boolean operand or the bitwise
complement of a bit-string. In Structured Text, the NOT operator is used instead of the NOT function.
If the operand type is BOOL, then the result is true if the operand if false, and the result is false if the
operand is true.

Table 224

logical NOT

NOT b

FALSE

TRUE

TRUE

FALSE

If the operand type is DWORD, then each bit of the DWORD is inverted. This means if the operand bit is
a 0, then the corresponding result bit is 1, and if the operand bit is a 1, then the corresponding result bit
is a 0.

Table 225

bitwise complement

Bit

Complement

The operand and the return value are the same data type, that is, they are both BOOL or both DWORD.

TriStation 1131 Libraries Reference

218

Chapter 2

Functions and Data Types

Example
Using Boolean Operands
VAR b, b1:=TRUE, b2:=FALSE : BOOL; END_VAR
b := NOT b1;
(* result is FALSE *)
b := NOT b2;
(* result is TRUE *)

Using Bit-String Operands


VAR w, w1 : DWORD; END_VAR
w1 :=
2#10101010101010101010101010101010 ;
w := NOT w1 ; (* result is 2#01010101010101010101010101010101 *)

Note that on the Controller Panel, you will see the example values in hex. The value of operand w1 is
16#AAAAAAAA, and the value of result w is 16#55555555.

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

NUMBITS

219

NUMBITS
Counts the number of Boolean parameters with value true.

Syntax
n := NUMBITS(b1, b2, ... , bn) ;

Table 226

Input Parameters

Name

Data Type

Description

b1...bn

BOOL

Boolean parameters

Table 227

Return Value

Data Type

Description

DINT

Number of true parameters.

Description
The NUMBITS function counts the number of parameters with value equal to true.
The maximum number of function inputs is 50.

Example
n := NUMBITS(TRUE, FALSE, TRUE, TRUE);

(* result is 3 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

220

Chapter 2

Functions and Data Types

NUMBITS_DWORD
Counts the number of 1-bits in a DWORD.

Syntax
n := NUMBITS_DWORD( w ) ;

Table 228

Input Parameters

Name

Data Type

Description

DWORD

A bit-string

Table 229

Return Value

Data Type

Description

DINT

The number of 1-bits in w.

Description
The NUMBITS_DWORD function counts the number of 1-bits in a DWORD.

Example
VAR n : DINT ; w : DWORD ; END_VAR
w := 2#00000000000000000000000011111111 ;
n := NUMBITS_DWORD( w );
(* result is 8 *)

Note that on the Controller Panel, you will see the example operand w displayed in hex: 16#000000FF.

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

OR 221

OR
Performs a logical OR of two or more Boolean operands or a bitwise OR of two or more bit-strings.

Syntax
b := b1 OR b2 OR ... OR bn ;

Table 230

Input Parameters

Name

Data Type

Description

b1...bn

ANY_BIT

Operands

Table 231

Return Value

Data Type

Description

ANY_BIT

b1 OR b2 OR ... OR bn

Description
In graphical languages, the OR function returns the logical OR of Boolean operands or the bitwise OR of
bit-strings. In Structured Text, the OR operator is used instead of the OR function.
The maximum number of function inputs is 50.
All operands must be the same type as the return value either all BOOL or all DWORD.
If the operand type is BOOL, then the result is true if any operand is true. The result is false if all operands
are false.

Table 232

logical OR

b1

b2

b1 OR b2

FALSE

FALSE

FALSE

FALSE

TRUE

TRUE

TRUE

FALSE

TRUE

TRUE

TRUE

TRUE

If the operand type is DWORD, then the result is the bitwise OR of all the operands. In other words, the
value in each bit position of the result is the inclusive OR of all the values in the same bit position.

Table 233

bitwise OR

w1

w2

w1 OR w2

2#0011

2#0101

2#0111

TriStation 1131 Libraries Reference

222

Chapter 2

Functions and Data Types

Example
Using Boolean Operands
VAR b, b1:=FALSE, b2:=FALSE, b3:=TRUE : BOOL; END_VAR
b := b1 OR b2 OR b3;
(* result is TRUE *)
b := b1 OR b2;
(* result is FALSE *)

Using Bit-String Operands


VAR w, w1, w2, w3 : DWORD; END_VAR
w1 :=
2#00000000000000000000000000000001
w2 :=
2#00000000000000000000000000000010
w3 :=
2#00000000000000000000000000000100
w := w1 OR w2 OR w3; (* 2#00000000000000000000000000000111
w := w1 OR w3;
(* 2#00000000000000000000000000000101

;
;
;
*)
*)

Note that on the Controller Panel, you will see the example values in hex. The hex values of the operands
are w1=16#00000001, w2=16#00000002, w3=16#00000004, and the hex values of the results are
16#00000007 and 16#00000005.

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

OVDDISABLE

223

OVDDISABLE
Disables output voter diagnostics (OVD) for a selected Digital Output (DO) Module.

Syntax
MY_OVDDISABLE( CI:=b1, CHASSIS:=n1, SLOT:=n2 ) ;

Table 234

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables OVDDISABLE.

CHASSIS

DINT

The chassis number (115).

SLOT

DINT

The physical slot number.

Table 235

Output Parameters

Name

Data Type

Description

CO

BOOL

True if OVDDISABLE executes successfully.

Description
The OVDDISABLE function block disables output voter diagnostics (OVD) for the Digital Output (DO)
Module selected by CHASSIS and SLOT.

Example
VAR MY_OVDDISABLE : OVDDISABLE ; END_VAR
(* Disable OVD for the module in chassis 9 slot 5. *)
MY_OVDDISABLE( CI:=true, CHASSIS:=9, SLOT:=5 ) ;

Runtime Errors
Condition

Return Value

Error Flags

The chassis or the slot is out of range.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

224

Chapter 2

Functions and Data Types

OVDENABLE
Enables output voter diagnostics (OVD) for a selected Digital Output (DO) Module.

Syntax
MY_OVDENABLE( CI:=b1, CHASSIS:=n1, SLOT:=n2 ) ;

Table 236

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables OVDENABLE.

CHASSIS

DINT

The chassis number (115).

SLOT

DINT

The physical slot number.

Table 237

Output Parameters

Name

Data Type

Description

CO

BOOL

True if OVDENABLE executes successfully.

Description
The OVDENABLE function block disables output voter diagnostics (OVD) for the Digital Output (DO)
Module selected by CHASSIS and SLOT.

Example
VAR MY_OVDENABLE : OVDENABLE ; END_VAR
(* Enable OVD for the module in chassis 9 slot 5. *)
MY_OVDENABLE( CI:=true, CHASSIS:=9, SLOT:=5 ) ;

Runtime Errors
Condition

Return Value

Error Flags

The chassis or the slot is out of range.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

PACK16

225

PACK16
Packs 16 bits into a DWORD.

Syntax
w := PACK16(IN01, IN02, ... , IN16) ;

Table 238

Input Parameters

Name

Data Type

Description

IN01

BOOL

Input bit 01 (least significant).

IN02

BOOL

Input bit 02.

IN03

BOOL

Input bit 03.

IN04

BOOL

Input bit 04.

INnn

BOOL

Input bit nn.

IN16

BOOL

Input bit 16 (most significant).

Table 239

Return Value

Data Type

Description

DWORD

The packed result

Description
The PACK16 function packs 16 bits into a DWORD. The 16 bits are packed into the least significant 16 bits
of a 32-bit DWORD. The values for the 16 bits are given in 16 Boolean parameters. The first parameter,
IN01, is packed into the least significant bit of the result.

Example
w := PACK16(0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0);
(* result is 2#00000000000000000000000000111100 *)
Note that the result displayed on the controller panel is in hex, i.e., 16#0000003C.

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

226

Chapter 2

Functions and Data Types

PACK32
Packs 32 bits into a DWORD.

Syntax
w := PACK32(IN01, IN02, ... , IN32) ;

Table 240

Input Parameters

Name

Data Type

Description

IN01

BOOL

Input bit 01 (least significant).

IN02

BOOL

Input bit 02.

IN03

BOOL

Input bit 03.

IN04

BOOL

Input bit 04.

INnn

BOOL

Input bit nn.

IN32

BOOL

Input bit 32 (most significant).

Table 241

Return Value

Data Type

Description

DWORD

The packed result

Description
The PACK32 function packs 32 bits into a DWORD. The values for the 32 bits are given in 32 Boolean
parameters. The first parameter, IN01, is packed into the least significant bit of the result.

Example
w := PACK32(0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ;
(* result is 2#00000000000000000000000000111100 *)
Note that the result displayed on the controller panel is in hex, i.e., 16#0000003C.

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

PAGE_EJECT 227

PAGE_EJECT
Ejects paper (feeds the form) to the top of the next page.

Syntax
MY_PAGE_EJECT( CI:=b1, PRINTER:=n1 ) ;

Table 242

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PAGE_EJECT.

PRINTER

DINT

Printer number.

Table 243

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PAGE_EJECT executes successfully.

Description
The PAGE_EJECT function block ejects paper (feeds the form) to the top of the next page.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers. For the Tricon controller, all values are validhowever, the function block prints to port 5 if
PRINTER=5, but prints to port 10 if PRINTER is any other number. For the Trident or Tri-GP controller,
the valid range is 1 through 10.
CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PAGE_EJECT : PAGE_EJECT ; END_VAR
(* Eject a page on printer 5. *)
MY_PAGE_EJECT( PRINTER:=5 ) ;

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.

TriStation 1131 Libraries Reference

228

Chapter 2

Functions and Data Types

Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

PERDEV

229

PERDEV
Computes percent deviation.

Syntax
b := PERDEV( NAME1, NAME2, SPAN, FRACTION );

Table 244

Input Parameters

Name

Data Type

Description

NAME1

REAL

The first argument.

NAME2

REAL

The second argument.

SPAN

REAL

The range used to calculate fraction.

FRACTION

REAL

The reference value.

Table 245

Return Value

Data Type

Description

BOOL

True if measured ratio less than or equal toFRACTION.

Description
The PERDEV function computes percent deviation. This function is used to measure a signal as a ratio,
regardless of the engineering units used. PERDEV computes the difference between the NAME1 and
NAME2 inputs, divides this difference by the SPAN, and then takes the absolute value of the result.
The result is a floating-point number between 0.0 and 1.0, which is then compared to the reference input
FRACTION. If the measured ratio is less than or equal to the reference fraction, the return value is true.
Otherwise, the return value is false.

Example
VAR b: BOOL ; END_VAR
b := PERDEV( 10.0, 30.0, 100.0, 0.5 ) ;
b := PERDEV( 10.0, 80.0, 100.0, 0.5 ) ;

(* result is TRUE *)
(* result is FALSE *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

230

Chapter 2

Functions and Data Types

PID
Performs the proportional integral derivative (PID) algorithm.

Syntax
MY_PID( SP:=x1, CV:=x2, CI:=b1, PV:=x3, AUTO_MAN:=b2, RATE:=x4, RESET:=x5, KPB:=x6,
MAXCV:=x7, MINCV:=x8, MAXRATE:=x9, DELTAT:=t1 ) ;

Table 246

VAR_IN_OUT Parameters

Name

Data Type

Description

SP

REAL

The set point.

CV

REAL

The control variable.

Table 247

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PID.

PV

REAL

The process variable.

AUTO_MAN

BOOL

Controls auto/manual state of PID (auto = 1, manual = 0).

RATE

REAL

The derivative time constant in seconds.

RESET

REAL

The integral time constant in seconds.

KPB

REAL

The proportional gain.

MAXCV

REAL

The maximum CV value.

MINCV

REAL

The minimum CV value.

MAXRATE

REAL

The maximum change of CV between evaluations.

DELTAT

TIME

The time between PID evaluations.

Table 248

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PID executes successfully.

Description
The PID function block performs the proportional integral derivative (PID) algorithm. PID provides for
anti-reset windup, bumpless transfer, and limitation of the maximum rate of change for the control
variable. Bumpless transfer is handled in the setpoint-tracking form. Neither the SP nor the PV argument
is limited in its dynamic range.
To impose limitations, use the LIMIT function prior to calling PID. The control variable CV is typically
scaled to range from 0 to 100 percent. KPB represents the proportional gain. For direct-acting control, PID
is programmed for KPB to be positive (that is to say, increasing the control variable causes an increasing
process variable).

TriStation 1131 Libraries Reference

PID

231

For reverse-acting control (increasing the control variable causes a decreasing process variable), KPB
should be negative. You should determine the value of KPB by making control changes and observing
the effect on the process variable being controlled. For example, if a 5 percent change in the control
variable causes a 150-unit change in the process variable, then the process gain is 150/5 or 30. KPB is
typically set near the reciprocal of the process gain.
The integral time constant RESET adjusts the integral action of the PID. If RESET is increased, the integral
action is decreased and the response is slower. If RESET is decreased, the integral action is increased and
the response is faster. To avoid excessive integral action, RESET should be set initially to a few seconds.
The derivative time constant RATE is used to provide damping of the control loop response. As RATE is
increased, the derivative action is increased and a damping action is applied to the response. Typically
RATE is set to a value of one second or less; in many cases, it can be set to zero.

Note

To schedule execution using a CSCHED or TSCHED function block, connect the DELTAT input
to the ACTUAL output of a CSCHED or TSCHED function block, and connect the CI input to the
Q output.

Runtime Errors
None.

Application Notes

Can be used in Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

232

Chapter 2

Functions and Data Types

PID_R
Performs the proportional integral derivative (PID) algorithm.

Syntax
MY_PID_R( SPIN:=x1, CVIN:=x2, CI:=b1, PV:=x3, AUTO_MAN:=b2, RATE:=x4, RESET:=x5,
KPB:=x6, MAXCV:=x7, MINCV:=x8, MAXRATE:=x9, DLT:=x10 ) ;
x1 := MY_PID_R.SPOUT ;
x2 := MY_PID_R.CVOUT ;

Table 249

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PID_R.

SPIN

REAL

The set point.

CVIN

REAL

The control variable.

PV

REAL

The process variable.

AUTO_MAN

BOOL

Controls auto/manual state of PID (auto = 1, manual = 0).

RATE

REAL

The derivative time constant (seconds).

RESET

REAL

The integral time constant (seconds).

KPB

REAL

The proportional gain.

MAXCV

REAL

The maximum CV value.

MINCV

REAL

The minimum CV value.

MAXRATE

REAL

The maximum change of CV between evaluations.

DLT

REAL

The execution interval in seconds.

Table 250

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PID_R executes successfully.

SPOUT

REAL

Set point out.

CVOUT

REAL

Control variable out.

Description
The PID_R function block performs the proportional integral derivative (PID) algorithm. PID provides
for anti-reset windup, bumpless transfer, and limitation of the maximum rate of change for the control
variable. Bumpless transfer is handled in the setpoint-tracking form.
Neither the SP nor the PV argument is limited in its dynamic range. To impose limitations, use the LIMIT
function prior to calling PID. The control variable CV is typically scaled to range from 0 to 100 percent.
KPB represents the proportional gain. For direct-acting control, PID is programmed for KPB to be positive
(that is, increasing the control variable causes an increasing process variable).
For reverse-acting control (increasing the control variable causes a decreasing process variable), KPB
should be negative. You should determine the value of KPB by making control changes and observing

TriStation 1131 Libraries Reference

PID_R

233

the effect on the process variable being controlled. For example, if a 5 percent change in the control
variable causes a 150-unit change in the process variable, then the process gain is 150/5 or 30. KPB is
typically set near the reciprocal of the process gain.
The integral time constant RESET adjusts the integral action of the PID. If RESET is increased, the integral
action is decreased and the response is slower. If RESET is decreased, the integral action is increased and
the response is faster. To avoid excessive integral action, initially you should set RESET to a few seconds.

Rate Parameter
The derivative time constant RATE is used to provide damping of the control loop response. As RATE is
increased, the derivative action is increased and a damping action is applied to the response. Typically
RATE is set to a value of one second or less; in many cases, it can be set to zero.

Runtime Errors
None.

Application Notes

Can be used in Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

234

Chapter 2

Functions and Data Types

POLY4
Returns the value of a polynomial with four coefficients.

Syntax
y := POLY4( X, C0, C1, C2, C3 ) ;

Table 251

Input Parameters

Name

Data Type

Description

LREAL

The input variable.

C0

LREAL

Coefficient 0.

C1

LREAL

Coefficient 1.

C2

LREAL

Coefficient 2.

C3

LREAL

Coefficient 3.

Table 252

Return Value

Data Type

Description

LREAL

The returned value (C0 + C1*X + C2*X*X + C3*X*X*X).

Description
The POLY4 function returns the value of a polynomial with four coefficients (C0 + C1*X + C2*X*X +
C3*X*X*X, where X is the variable and C0, C1, C2, C3 are the coefficients).

Example
VAR x, y, c0, c1, c2, c3 : LREAL ; END_VAR
x := 10.0 ;
c0 := 1.0 ;
c1 := 2.0 ;
c2 := 3.0 ;
c3 := 4.0 ;
y := POLY4(x, c0, c1, c2, c3) ;
(* result is 4321.0 );

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

POLY5

235

POLY5
Returns the value of a polynomial with five coefficients.

Syntax
y := POLY4( X, C0, C1, C2, C3, C4 ) ;

Table 253

Input Parameters

Name

Data Type

Description

LREAL

The input variable.

C0

LREAL

Coefficient 0.

C1

LREAL

Coefficient 1.

C2

LREAL

Coefficient 2.

C3

LREAL

Coefficient 3.

C4

LREAL

Coefficient 4.

Table 254

Return Value

Data Type

Description

LREAL

The returned value (C0 + C1*X + C2*X*X + C3*X*X*X + C4*X*X*X*X).

Description
The POLY5 function returns the value of a polynomial with five coefficients (C0 + C1*X + C2*X*X +
C3*X*X*X X + C4*X*X*X*X, where X is the variable and C0, C1, C2, C3, C4 are the coefficients).

Example
VAR x, y, c0, c1, c2, c3, c4 : LREAL ; END_VAR
x := 10.0 ;
c0 := 1.0 ;
c1 := 2.0 ;
c2 := 3.0 ;
c3 := 4.0 ;
c4 := 5.0 ;
y := POLY5(x, c0, c1, c2, c3, c4) ;
(* result is 54321.0 );

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

236

Chapter 2

Functions and Data Types

PRINT_BOOL
Prints a three-character field containing either Off or On.

Syntax
MY_PRINT_BOOL( CI:=b1, PRINTER:=n1, IN:=b2 ) ;

Table 255

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_BOOL.

PRINTER

DINT

Printer number.

IN

BOOL

The value to be printed.

Table 256

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_BOOL executes successfully.

Description
The PRINT_BOOL function block prints a three-character field containing either Off or On. (On is leftjustified in the field.) Prints Off if IN is false or 0. Prints On if IN is true or 1. When printed, each argument
is preceded by a blank space.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

IN is the Boolean value to be printed. If IN=false, then print "Off". If IN=true, then print "On ".
CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PRINT_BOOL : PRINT_BOOL ; END_VAR
(* Print "Off" on printer 5. *)
MY_PRINT_BOOL( PRINTER:=5, IN:=FALSE ) ;

TriStation 1131 Libraries Reference

PRINT_BOOL

237

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

238

Chapter 2

Functions and Data Types

PRINT_CDT
Prints the current date and time of day.

Syntax
MY_PRINT_CDT( CI:=b1, PRINTER:=n1 ) ;

Table 257

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_CDT.

PRINTER

DINT

Printer number.

Table 258

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_CDT executes successfully.

Description
The PRINT_CDT function block prints the current date and time of day in this format:
mm/dd/yy hh:mm:ss.msec
When printed, each argument is preceded by a blank space.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PRINT_CDT : PRINT_CDT ; END_VAR
(* Print current date and time on printer 5. *)
MY_PRINT_CDT( PRINTER:=5 ) ;

TriStation 1131 Libraries Reference

PRINT_CDT

239

Runtime Errors
Condition

Return Value

Error FlagS

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

240

Chapter 2

Functions and Data Types

PRINT_CRLF
Prints a new line (a carriage return and line feed).

Syntax
MY_PRINT_CRLF( CI:=b1, PRINTER:=n1 ) ;

Table 259

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_CRLF.

PRINTER

DINT

Printer number.

Table 260

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_CRLF executes successfully.

Description
The PRINT_CRLF function block prints a new line (a carriage return and line feed).
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PRINT_CRLF : PRINT_CRLF ; END_VAR
(* Print a carriage return and line feed on printer 5. *)
MY_PRINT_CRLF( PRINTER:=5 ) ;

TriStation 1131 Libraries Reference

PRINT_CRLF

241

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

242

Chapter 2

Functions and Data Types

PRINT_CTOD
Prints the current time of day.

Syntax
MY_PRINT_CTOD( CI:=b1, PRINTER:=n1 ) ;

Table 261

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_CTOD.

PRINTER

DINT

Printer number.

Table 262

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_CTOD executes successfully.

Description
The PRINT_CTOD function block prints the current time of day in this format:
hh:mm:ss.msec
When printed, each argument is preceded by a blank space.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PRINT_CTOD : PRINT_CTOD ; END_VAR
(* Print the current time of day on printer 5. *)
MY_PRINT_CTOD( PRINTER:=5 ) ;

TriStation 1131 Libraries Reference

PRINT_CTOD 243

Runtime Errors
Condition

Return Value

Error Flag

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

244

Chapter 2

Functions and Data Types

PRINT_DINT
Prints a double integer right-justified in an eight-character field.

Syntax
MY_PRINT_DINT( CI:=b1, PRINTER:=n1, IN:=n2 ) ;

Table 263

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_DINT.

PRINTER

DINT

Printer number.

IN

DINT

The value to be printed.

Table 264

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_DINT executes successfully.

Description
The PRINT_DINT function block prints a double integer right-justified in an eight-character field. If the
value is negative, the minus () sign immediately precedes the value. When printed, each argument is
preceded by a blank space.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

IN represents the integer value to be printed, right-justified in an eight-character field. If the value is
negative, the minus () sign immediately precedes the value. When printed, each argument is preceded
by a blank space.
CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

TriStation 1131 Libraries Reference

PRINT_DINT

245

Example
VAR MY_PRINT_DINT : PRINT_DINT ; END_VAR
(* Print "
999" on printer 5. *)
MY_PRINT_DINT( PRINTER:=5, IN:=999 ) ;

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

246

Chapter 2

Functions and Data Types

PRINT_REAL
Prints a real (floating-point) value right justified in an eight-character field.

Syntax
MY_PRINT_REAL( CI:=b1, PRINTER:=n1, IN:=x1, PRECISION:=n2 ) ;

Table 265

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_REAL.

PRINTER

DINT

Printer number.

IN

REAL

The value to be printed.

PRECISION

DINT

The number of fraction digits (0 ...... 7).

Table 266

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_REAL executes successfully.

Description
The PRINT_REAL function block prints a real (floating-point) value right justified in an eight-character
field. If the value is negative, a minus () sign immediately precedes the first printed digit. The
PRECISION argument specifies the number of decimal places. The default is 4 decimal places.
If a real number does not fit in the eight-character field, then significance to the right of the decimal point
is reduced. If this fails, then the number is printed in scientific notation. When printed, each argument is
preceded by a blank space.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

IN represents the real number to be printed, right-justified in an eight-character field. If the number is
negative, a minus () sign immediately precedes the first printed digit. The PRECISION argument
specifies the number of decimal places. The default is 4 decimal places.
CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

TriStation 1131 Libraries Reference

PRINT_REAL

247

Example
VAR MY_PRINT_REAL : PRINT_REAL ; END_VAR
(* Print "
1.0625" on printer 5. *)
MY_PRINT_REAL( PRINTER:=5, IN:=1.0625 ) ;

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

248

Chapter 2

Functions and Data Types

PRINT_STRING
Prints a string of text (not including quotation marks).

Syntax
MY_PRINT_STRING( CI:=b1, PRINTER:=n1, IN:=s1 ) ;

Table 267

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRINT_STRING.

PRINTER

DINT

Printer number.

IN

STRING

The value to be printed.

Table 268

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRINT_STRING executes successfully.

Description
The PRINT_STRING function block prints a string of text (not including quotation marks).
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

IN represents the string to be printed.


CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PRINT_STRING : PRINT_STRING ; END_VAR
(* Print "Now is the time." on printer 5. *)
MY_PRINT_BOOL( PRINTER:=5, IN:=Now is the time. ) ;

TriStation 1131 Libraries Reference

PRINT_STRING

249

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

250

Chapter 2

Functions and Data Types

PRNTR_FLUSH
Clears the print buffer for the specified printer without printing the contents of the buffer.

Syntax
MY_PRNTR_FLUSH( CI:=b1, PRINTER:=n1 ) ;

Table 269

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables PRNTR_FLUSH.

PRINTER

DINT

Printer number.

Table 270

Output Parameters

Name

Data Type

Description

CO

BOOL

True if PRNTR_FLUSH executes successfully.

Description
The PRNTR_FLUSH function block clears the print buffer for the specified printer without printing the
contents of the buffer.
CI is the control input. CI enables evaluation. If CI is true, then perform the print operation. If CI is false,
then do nothing. The default initial value of CI is true.
PRINTER is a number that identifies the printer or print server. The valid range is different for different
controllers.

For the Tricon controller, all values are valid, however, the function block prints to port 10 if
PRINTER=10, but prints to port 5 if PRINTER is any other number.

For the Trident v1.x controller, the valid range is 1 through 10.

For the Trident v2.x or Tri-GP controller, the PRINTER parameter must be 5 or 10. The Left and
Right CM ports cannot have the same PRINTER parameter.

CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_PRNTR_FLUSH : PRNTR_FLUSH ; END_VAR
(* Clear the print buffer for printer 5. *)
MY_PRNTR_FLUSH( PRINTER:=5 ) ;

TriStation 1131 Libraries Reference

PRNTR_FLUSH

251

Runtime Errors
Condition

Return Value

Error Flags

If PRINTER is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If the PRINTER parameter is invalid, then the function block aborts the print operation.
Note that this function block simply adds the print operation to a buffer and does not check the status of
the printer or print server. To read printer status (like printer ready, buffer overflow, bytes free, bytes
used), see SYS_CM_STATUS or TR_PORT_STATUS.

Application Notes

Can be used in Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

252

Chapter 2

Functions and Data Types

R_TRIG
Detects a rising edge.

Syntax
MY_R_TRIG( CLK:=b1 ) ;
b2 := MY_R_TRIG.Q ;

Table 271

Input Parameters

Name

Data Type

Description

CLK

BOOL

Clock.

Table 272

Output Parameters

Name

Data Type

Description

BOOL

True indicates rising edge detected.

Description
The R_TRIG function block sets the output Q on the rising edge of the CLK input. A rising edge is a
change from false to true (0 to 1). The output Q is true if the input CLK was false during the previous
evaluation but true during the current evaluation of the function block instance; otherwise, the output Q
is false.

Example
VAR CHECK_FOR_RISING_EDGE : R_TRIG ; END_VAR
VAR b : BOOL ; END_VAR

b := 0 ;
CHECK_FOR_RISING_EDGE(
b := 1 ;
CHECK_FOR_RISING_EDGE(
b := 1 ;
CHECK_FOR_RISING_EDGE(
b := 0 ;
CHECK_FOR_RISING_EDGE(

CLK:=b );
CLK:=b );
CLK:=b );
CLK:=b );

(* no rising edge *)
(* Q is FALSE *)
(*
(*
(*
(*
(*
(*

rising edge, 0 to 1 *)
Q is TRUE *)
no rising edge *)
Q is FALSE *)
no rising edge *)
Q is FALSE *)

(************ here is a bad example *********************)


b := 0 ;
(* no rising edge *)
b := 1 ;
(* rising edge, missed *)
b := 0 ;
(* no rising edge *)
CHECK_FOR_RISING_EDGE( CLK:=b );
(* Q is FALSE *)
(************ end of bad example *********************)

TriStation 1131 Libraries Reference

R_TRIG

253

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan. However, to prevent missing an edge, the instance should be executed
after every possible change in input value, which could be every scan or even more than once
per scan.

Can be used in CEM Cause and Effect cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

254

Chapter 2

Functions and Data Types

REAL
A REAL data type is 32 bits in length and has 6 decimal digits of precision. In TriStation 1131, the REAL
data type follows the IEC-559 Standard Floating-Point format.
Attribute

Description

Keyword/type

REAL

Description

Real number

Size

32 bits

Default value

0.0

Most positive number

3.402823466 e +38

Least positive number

1.401298464 e 45

Least negative number

1.401298464 e 45

Most negative number

3.402823466 e +38

Result if intermediate value is less than lower limit

Infinity or HUGE

Result if upper limit is less than intermediate value

+Infinity or HUGE

Gradual Underflow for REAL Data Types


In PCs and safety controllers, the floating-point implementation includes a standard feature called
gradual underflow. This feature extends the range of a REAL number and gradually changes the precision
as values approach zero.
This table compares the values obtained when gradual underflow is not present, to the values obtained
when it is present.
Without Gradual Underflow

With Underflow

The smallest positive number that can be stored in a


REAL variable is:

The smallest positive number that can be stored in a


REAL variable is:

2126 = 1.175494351E-38.
The precision changes abruptly from 7 digits to 0
digits when the value changes from a number greater
than 2127 to a number less than 2127.

2149 = 1.401298464E45.
The precision changes gradually from 7 digits to 1 digit
as the value changes from 2127 to 2149.
The maximum relative error changes gradually from 2
to 1 as the value changes from 2127 to
149
2 .

The maximum relative error changes abruptly from 2


24 to 1 when the value changes from a number greater
than 2127 to a number less than 2127.

24

For values from 2150 to 2126, the maximum absolute


error equals the value.

For values from 2150 to 2126, the maximum absolute


error is a constant 2150.

TriStation 1131 Libraries Reference

REAL

255

This table shows how the precision changes as numbers approach zero.
If |x| Is Greater Than:

Then the Precision Is


Greater Than:

1.5E39

7 digits

1.5E40

6 digits

1.5E41

5 digits

1.5E42

4 digits

1.5E43

3 digits

1.5E44

2 digits

1.5E45

1 digits

0.0

0 digits

Absolute error is the absolute value of x a, where x is the exact value and a is the actual value stored.
Relative error is the absolute value of (x a)/x, where x is the exact value and a is the actual value stored.
This table shows how gradual underflow affects absolute error and relative error as REAL numbers
approach zero.
Range

Maximum Absolute
Error

Maximum Relative
Error

0 < |x| 2150

|x|

2150 < |x| 2126

2150

2150 / |x|

2126 |x| < 2128 2103

224 * |x|

224

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

256

Chapter 2

Functions and Data Types

REAL_TO_DINT
Converts a 32-bit real number to a 32-bit integer.

Syntax
k := REAL_TO_DINT( x );

Table 273

Input Parameters

Name

Data Type

Description

REAL

The 32-bit number to be converted.

Table 274

Return Value

Data Type

Description

DINT

The value of x converted to a 32-bit integer.

Description
The REAL_TO_DINT function converts a 32-bit real number to a 32-bit integer. The result is rounded to
the nearest integer.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : REAL;
x := -123.6;
k := REAL_TO_DINT( x );

END_VAR;
(* result is -124 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

2147483648

BADPARAM, ERROR

If x is less than -2147483648.5

2147483648

BADCONV, ERROR

If x is greater than or equal to +2147483647.5

+2147483647

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

REAL_TO_DINT

257

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

258

Chapter 2

Functions and Data Types

REAL_TO_INT
Converts a 32-bit real number to a 16-bit integer.

Syntax
k := REAL_TO_INT( x );

Table 275

Input Parameters

Name

Data Type

Description

REAL

The 32-bit number to be converted.

Table 276

Return Value

Data Type

Description

INT

The value of x converted to a 16-bit integer.

Description
The REAL_TO_INT function converts a 32-bit real number to a 16-bit integer. The result is rounded to the
nearest integer.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : INT; x : REAL;
x := -123.6;
k := REAL_TO_INT( x );

END_VAR;
(* result is -124 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

32768

BADPARAM, ERROR

If x is less than -32768.5

32768

BADCONV, ERROR

If x is greater than or equal to +32757.5

+32767

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

REAL_TO_INT

259

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

260

Chapter 2

Functions and Data Types

REAL_TO_LREAL
Converts a 32-bit real number to a 64-bit long real number.

Syntax
y := REAL_TO_LREAL( x );

Table 277

Input Parameters

Name

Data Type

Description

REAL

The 32-bit number to be converted.

Table 278

Return Value

Data Type

Description

LREAL

The value of x converted to a 64-bit long real number.

Description
The REAL_TO_LREAL function converts a 32-bit real number to a 64-bit long real number.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
x : REAL
END_VAR;
VAR
y : LREAL
END_VAR;
x := 6.25;
y = REAL_TO_LREAL(x);

(* result is 6.25 *)

Runtime Errors
Condition

Return Value

Error Flags

If x is not a number

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

ReportBadParam

261

ReportBadParam
Reports a bad parameter error.

Syntax
b1 := ReportBadParam(I1) ;

Table 279

Input Parameters

Name

Data Type

Description

I1

INT

Not used.

Table 280

Return Value

Data Type

Description

BOOL

Not used, always false.

Description
The ReportBadParam function resets ENO and sets the BAD PARAM and ERROR status flags.
When a Triconex library function detects a bad parameter, the function typically resets ENO and sets the
BADPARAM status flag. A user-defined function can call ReportBadParam() to do the same thing.
A programmer can use ENO to isolate an error or to stop execution after detection of an error.
A programmer can use the status flags to read what errors have been detected. The CHK_ERR function
block reads the status flags.

Example
VAR NOT_USED, b1, b2 : BOOL ; STATUS : CHK_ERR ; END_VAR
ENO := true ;
NOT_USED := ReportBadParam(0) ;
b1 := ENO ;
(* result is false *)
STATUS() ;
b2 := STATUS.BADPARAM ;
(* result is true *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

262

Chapter 2

Functions and Data Types

ROL
Rotates left N bits, where N is the shift count.

Syntax
w := ROL( IN, N ) ;

Table 281

Input Parameters

Name

Data Type

Description

IN

ANY_BIT

Operand

ANY_INT

Shift count.

Table 282

Return Value

Data Type

Description

ANY_BIT

IN rotated left N bits

Description
The ROL function rotates left N bits, where N is the shift count. If N is negative, then rotating left N bits
is equivalent to rotating right N bits.

Example
VAR w1, w2, w3 : DWORD; END_VAR
w1 :=
16#12345678 ;
w2 := ROL( w1, 4) ; (* 16#23456781 *)
w3 := ROL( w1, -4) ; (* 16#81234567 *)
(*
* Remember that 1 hex digit is 4 bits,
* so shifting 4 bits is the same as shifting 1 hex digit.
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

ROR

263

ROR
Rotates right N bits, where N is the shift count.

Syntax
w := ROR( IN, N ) ;

Table 283

Input Parameters

Name

Data Type

Description

IN

ANY_BIT

Operand.

ANY_INT

Shift count.

Table 284

Return Value

Data Type

Description

ANY_BIT

IN rotated left N bits

Description
The ROR function rotates right N bits, where N is the shift count. If N is negative, then rotating right N
bits is equivalent to rotating left N bits.

Example
VAR w1, w2, w3 : DWORD; END_VAR
w1 :=
16#12345678 ;
w2 := ROR( w1, 4) ; (* 16#81234567 *)
w3 := ROR( w1, -4) ; (* 16#23456781 *)
(*
* Remember that 1 hex digit is 4 bits,
* so shifting 4 bits is the same as shifting 1 hex digit.
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

264

Chapter 2

Functions and Data Types

RS
RS is a bistable function block (reset dominant).

Syntax
RS( S:=b1, R1:=b2 ) ;
b3 := SR.Q1

Table 285

Input Parameters

Name

Data Type

Description

BOOL

Set.

R1

BOOL

Reset.

Table 286

Output Parameters

Name

Data Type

Description

Q1

BOOL

State

Description
The RS function block is a latch with the reset input dominant over the set input. The R1 input resets Q1
to false. The S input sets Q1 to true if R1 is false. If R1 is false and S is false, then Q1 does not change.

Table 287

Truth Table

R1

Q1

false

false

no change

false

true

false

true

false

true

true

true

false

Example
VAR MY_RS : RS ; END_VAR
MY_RS( S:=FALSE, R1:=TRUE
MY_RS( S:=FALSE, R1:=FALSE
MY_RS( S:=TRUE,
R1:=TRUE
MY_RS( S:=TRUE,
R1:=FALSE
MY_RS( S:=FALSE, R1:=FALSE

Runtime Errors
None.

TriStation 1131 Libraries Reference

);
);
);
);
);

(*
(*
(*
(*
(*

Q1
Q1
Q1
Q1
Q1

is
is
is
is
is

FALSE
FALSE
FALSE
TRUE
TRUE

*)
*)
*)
*)
*)

RS

265

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause and Effect cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

266

Chapter 2

Functions and Data Types

RTC
Provides a real-time clock.

Syntax
MY_RTC( IN:=b1, PDT:=dt1 ) ;

Table 288

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables RTC.

PDT

DT

Preset date and time.

Table 289

Output Parameters

Name

Data Type

Description

BOOL

Copy of IN.

CDT

DT

The current date and time.

Description
The RTC function block provides a real-time clock. Output CDT gives the current system date and time.
Output Q is a copy of input IN.
These are deviations from the IEC 61131-3 standard:

TriStation 1131 does not allow the program to set the system date and time, therefore RTC does
not use the PDT input.

TriStation 1131 names the enable input IN because the name EN has a special meaning for
functions (the standard conflicts with itself).

Output CDT is valid even when input IN is false.

Example
VAR MY_RTC : RTC ; END_VAR
MY_RTC() ;
(* Output CDT is the current date and time. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

SCALE

267

SCALE
Scales a value from one engineering unit to another.

Syntax
y := SCALE( INPUT, MAX1, MIN1, MAX2, MIN2 )

Table 290

Input Parameters

Name

Data Type

Description

INPUT

REAL

The input value.

MAX1

REAL

The maximum value in input units.

MIN1

REAL

The minimum value in input units.

MAX2

REAL

The maximum value in output units.

MIN2

REAL

The minimum value in output units.

Table 291

Return Value

Data Type

Description

REAL

The scaled output value.

Description
The Scale function scales a value from one engineering unit to another. The function returns the scaled
value.
The equation for the return value is:
SCALE := ((INPUT - MIN1)/(MAX1 - MIN1))* (MAX2 - MIN2) + MIN2 ;

Example
VAR y : REAL; END_VAR
y := SCALE( 8.0, 10.0, 5.0, 100.0, 50.0 );

(* result is 80.0 *)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

268

Chapter 2

Functions and Data Types

SEL
Selects one of two data values.

Syntax
v := SEL( G, IN0, IN1 ) ;

Table 292

Input Parameters

Name

Data Type

Description

BOOL

False selects IN0, true selects IN1.

IN0

ANY

First data value..

IN1

ANY

Second data value..

Table 293

Return Value

Data Type

Description

ANY

The output value.

Description
The SEL function selects one of two data values depending on an input selector (G). If G is false, the return
value is the first data value IN0. If G is true, the return value is the second data value IN1.
The data values can be any data type, but both data values must have the same data type as the return
value.

Example
v := SEL( G, IN0, IN1 ) ;

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

SHL

269

SHL
Shifts left N bits, where N is the shift count.

Syntax
w := SHL( IN, N ) ;

Table 294

Input Parameters

Name

Data Type

Description

IN

ANY_BIT

Operand

ANY_INT

Shift count.

Table 295

Return Value

Data Type

Description

ANY_BIT

IN shifted left N bits

Description
The SHL function shifts left N bits, where N is the shift count. If N is negative, then shifting left N bits is
equivalent to shifting right N bits. Bits shifted into an operand are zero. Bits shifted out of an operand
are lost. If the shift count is greater than or equal to the size of the operand, the result is zero.

Example
VAR w1, w2, w3 : DWORD; END_VAR
w1 :=
16#12345678 ;
w2 := SHL( w1, 4) ; (* 16#23456780 *)
w3 := SHL( w1, -4) ; (* 16#01234567 *)
(*
* Remember that 1 hex digit is 4 bits,
* so shifting 4 bits is the same as shifting 1 hex digit.
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

270

Chapter 2

Functions and Data Types

SHR
Shifts right N bits, where N is the shift count.

Syntax
w := SHR( IN, N ) ;

Table 296

Input Parameters

Name

Data Type

Description

IN

ANY_BIT

Operand

ANY_INT

Shift count

Table 297

Return Value

Data Type

Description

ANY_BIT

IN shifted right N bits

Description
The SHR function shifts right N bits, where N is the shift count. If N is negative, then shifting right N bits
is equivalent to shifting left N bits. Bits shifted into an operand are zero. Bits shifted out of an operand
are lost. If the shift count is greater than or equal to the size of the operand, then the result is zero.

Example
VAR w1, w2, w3 : DWORD; END_VAR
w1 :=
16#12345678 ;
w2 := SHR( w1, 4) ; (* 16#01234567 *)
w3 := SHR( w1, -4) ; (* 16#23456780 *)
(*
* Remember that 1 hex digit is 4 bits,
* so shifting 4 bits is the same as shifting 1 hex digit.
*)

Runtime Errors
None.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

SIN

271

SIN
Calculates the sine of an angle.

Syntax
y := SIN( x ) ;

Table 298

Input Parameters

Name

Data Type

Description

ANY_REAL

The angle, in radians.

Table 299

Return Value

Data Type

Description

ANY_REAL

The sine of x.

Description
The SIN function returns the sine of an angle given in radians. The result is in the range -1 to 1.

Example
VAR
y : REAL;
END_VAR
y := SIN( 1.570796 );

{* result is

1.0 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If the absolute value of x is greater than 2**63

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

272

Chapter 2

Functions and Data Types

SOECLR
Clears a sequence of events (SOE) block.

Syntax
MY_SOECLR( CI:=b1, BLOCK:=n1 ) ;

Table 300

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SOECLR.

BLOCK

DINT

The block number (116).

Table 301

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SOECLR executes successfully.

STAT

DINT

Status:
0 = The block is not started or not configured with data type and size.
1 = The block is collecting data.
2 = The block is stopped or cleared.
3 = The block is full.

Description
The SOECLR function block clears a sequence of events (SOE) block. SOECLR removes all entries from
the block and writes a SOECLR time stamp into the block. You must stop event collection (using
SOESTOP) before clearing the block.
If the SOECLR operation is successful, the output status is 2, indicating that the block is cleared. If the
event collection was not stopped before the SOECLR operation was attempted, the output status is 0, 1,
or 3.
If CI is false, no operation occurs (no output changes).

Example
For examples of using SOE function blocks, see these SOE sample projects:

ExSOE.pt2 (For Tricon controllers)

TdSOE.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

TriStation 1131 Libraries Reference

SOECLR 273

Runtime Errors
Condition

Return Value

Error Flags

If the block number is out of


range

CO=false,

BADPARAM, ERROR

STAT=0

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

274

Chapter 2

Functions and Data Types

SOESTAT
Returns status for a sequence of events (SOE) block.

Syntax
MY_SOESTAT( CI:=b1, BLOCK:=n1 ) ;

Table 302

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SOESTAT.

BLOCK

DINT

The block number (116).

Table 303

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SOESTAT executes successfully.

STAT

DINT

Status:
0 = The block is not started or not configured with data type and size.
1 = The block is collecting data.
2 = The block is stopped or cleared.
3 = The block is full.

FREE

DINT

The number of unused 8-byte entries in the block.

USED

DINT

The number of used 8-byte entries in the block.

Description
The SOESTAT function block returns status for a sequence of events (SOE) block, including the number
of 8-byte entries that are used, and the number of 8-byte entries that are free.
If CI is false, no operation occurs.

Example
For examples of using SOE function blocks, see these SOE sample projects:

ExSOE.pt2 (For Tricon controllers)

TdSOE.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

TriStation 1131 Libraries Reference

SOESTAT

275

Runtime Errors
Condition

Return Value

Error Flags

If the block number is out of range

CO=false,

BADPARAM, ERROR

STAT=0,
FREE=0,
USED=0

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

276

Chapter 2

Functions and Data Types

SOESTOP
Writes a time stamp into a sequence of events (SOE) block, and changes the state of the block from
collecting to stopped.

Syntax
MY_SOESTOP( CI:=b1, BLOCK:=n1 ) ;

Table 304

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SOESTOP.

BLOCK

DINT

The block number (116).

Table 305

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SOESTOP executes successfully.

STAT

DINT

Status:
0 = The block is not started or not configured with data type and size.
1 = The block is collecting data.
2 = The block is stopped or cleared.
3 = The block is full.

Description
The SOESTOP function block writes a time stamp into a sequence of events (SOE) block, and changes the
state of the block from collecting to stopped. Event collection stops until the next SOESTRT operation.
If the SOESTOP operation is successful, the output status is 2, indicating that the event collection is
stopped. If CI is false, no operation occurs (no output changes).

Example
For examples of using SOE function blocks, see these SOE sample projects:

ExSOE.pt2 (For Tricon controllers)

TdSOE.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If the block number is out of range

CO=false,

BADPARAM, ERROR

STAT=0

TriStation 1131 Libraries Reference

SOESTOP

277

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

278

Chapter 2

Functions and Data Types

SOESTRT
Starts sequence of events (SOE) collection for an SOE block.

Syntax
MY_SOESTRT( CI:=b1, BLOCK:=n1 ) ;

Table 306

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SOESTRT.

BLOCK

DINT

The block number (116).

Table 307

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SOESTRT executes successfully.

STAT

DINT

Status:
0 = The block is not started or not configured with data type and size.
1 = The block is collecting data.
2 = The block is stopped or cleared.
3 = The block is full.

Description
The SOESTRT function block starts sequence of events (SOE) collection for an SOE block. The Main
Processor writes an SOESTRT time stamp entry into the block and changes the state of the block from not
started or stopped to collecting. If the SOESTRT operation is successful, the output status is 1, indicating
that the block is collecting data.
If CI is false, no operation occurs (no output changes).
The SOESTRT function block must be executed for each SOE block you want to collect events from.

Note

The SOESTRT function block is executed once per scan, which means the resulting STAT output
is valid only for that scan.

Example
For examples of using SOE function blocks, see these SOE sample projects:

ExSOE.pt2 (For Tricon controllers)

TdSOE.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

TriStation 1131 Libraries Reference

SOESTRT

279

Runtime Errors
Condition

Return Value

Error Flags

If the block number is out of range

CO=false,

BADPARAM, ERROR

STAT=0

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library

Tricon (TR1LIB/TX1LIB)

Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

280

Chapter 2

Functions and Data Types

SQRT
Calculates the square root of a number.

Syntax
y := SQRT( x ) ;

Table 308

Input Parameters

Name

Data Type

Description

ANY_REAL

A real number.

Table 309

Return Value

Data Type

Description

ANY_REAL

The square root of x.

Description
The SQRT function returns the square root of a number.

Example
VAR
y : REAL;
END_VAR
y := SQRT( 4.0 );

{* result is 2.0 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If x less than or equal to zero.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

SR

281

SR
SR is a bistable function block (set dominant).

Syntax
SR( S1:=b1, R:=b2 ) ;
b3 := SR.Q1

Table 310

Input Parameters

Name

Data Type

Description

S1

BOOL

Set

BOOL

Reset

Table 311

Output Parameters

Name

Data Type

Description

Q1

BOOL

State

Description
The SR function block is a latch with the set input dominant over the reset input. The S1 input sets Q1 to
true. The R input resets Q1 to false if S1 is false. If S1 is false and R is false, then Q1 does not change.

Table 312

Truth Table

S1

Q1

false

false

no change

false

true

false

true

false

true

true

true

true

Example
VAR MY_SR : SR ; END_VAR
MY_SR( S1:=FALSE, R:=TRUE
MY_SR( S1:=FALSE, R:=FALSE
MY_SR( S1:=TRUE,
R:=TRUE
MY_SR( S1:=TRUE,
R:=FALSE
MY_SR( S1:=FALSE, R:=FALSE

);
);
);
);
);

(*
(*
(*
(*
(*

Q1
Q1
Q1
Q1
Q1

is
is
is
is
is

FALSE
FALSE
TRUE
TRUE
TRUE

*)
*)
*)
*)
*)

Runtime Errors
None.

TriStation 1131 Libraries Reference

282

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause and Effect cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

STRING

283

STRING
A STRING data type is an alphanumeric sequence, up to 132 characters in length, which is delimited by
single quotation marks ( ' ). The count of 132 characters does not include the null terminator or the single
quotation mark.
A STRING data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

STRING

Description

Character string

Size

136 bytes

Default Value

Empty string (two single quotation marks not


separated by any characters)

Lower limit

0 characters

Upper limit

132 characters

Result if intermediate value is less than lower limit

Truncated string

Result if upper limit is less than intermediate value

N/A

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

284

Chapter 2

Functions and Data Types

SUB
Calculates the difference between two operands.

Syntax for Subtracting a Number from Another Number


z := x - y ;

Table 313

Input Parameters

Name

Data Type

Description

ANY_NUM

Minuend

ANY_NUM

Subtrahend

Table 314

Return Value

Data Type

Description

ANY_NUM

The difference x - y

Syntax for Subtracting a Time from a Date and Time


d2 := d1 - t ;

Table 315

Input Parameters

Name

Data Type

Description

d1

DT

Minuend

TIME

Subtrahend

Table 316

Return Value

Data Type

Description

DT

The difference d1 - t

Syntax for Subtracting a Time from a Time


t3 := t1 - t2 ;

Table 317

Input Parameters

Name

Data Type

Description

t1

TIME

Minuend

t2

TIME

Subtrahend

Table 318

Return Value

Data Type

Description

TIME

The difference t1 - t2

TriStation 1131 Libraries Reference

SUB

285

Subtracting a Time from a Time of Day


tod2 := tod1 - t ;

Table 319

Input Parameters

Name

Data Type

Description

tod1

TIME OF DAY

Minuend

TIME

Subtrahend

Table 320

Return Value

Data Type

Description

TOD

The difference tod1 - t

Description
The subtract operator () is used in Structured Text to calculate the difference between two operands.
In the graphical languages, the SUB function is used instead of the subtract operator.
The subtract operator and SUB function:

Subtract a number from another number

Subtract a time from a date and time

Subtract a time from a time

Subtract a time from a time of day

Example
Subtract two numbers:
VAR m : DINT; END_VAR
m := 1564 - 10;

(* result is 1554 *)

Subtract a time from a date and time:


VAR d : DT;
END_VAR
d := DT#2002-01-27-08:00:00 - T#3h30m45s;

(* result is DT#2002-01-27-05:29:15 *)

Subtract a time from a time:


VAR t : TIME; END_VAR
t := T#11d22h33m - T#3h10m;

(* result is T#11d19h23m *)

Subtract a time from a time of day:


VAR tod1 : TOD; END_VAR
tod1 := TOD#08:00:00 - T#3h30m45s; (* result is TOD#04:29:15 *)

TriStation 1131 Libraries Reference

286

Chapter 2

Functions and Data Types

Runtime Errors
Condition

Return Value

Error Flags

If the result is infinite

INF

OVERFLOW, ERROR

If an operand is not a number (NAN)

NAN

OVERFLOW, ERROR

If the date and time is out of range

Invalid date

BADPARAM, ERROR

If the time is out of range

Invalid time

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

SYS_AI32_STATUS

287

SYS_AI32_STATUS
Gets the status of an Analog Input Module in a Trident or Tri-GP controller.

Syntax
MY_SYS_AI32_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 321

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_AI32_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 322

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_AI32_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel is operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected.

TriStation 1131 Libraries Reference

288

Chapter 2

Functions and Data Types

Table 322

Output Parameters (continued)

Name

Data Type

Description

NO_VOTER_FLTS

BOOL

No voter faults detected.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_AI32_STATUS function block gets the status of an Analog Input Module in a Trident or Tri-GP
controller.

Example
VAR MY_AI : SYS_AI32_STATUS ; END_VAR
VAR AI_ACTIVE : BOOL ; END_VAR
MY_AI( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
AI_ACTIVE := MY_AI.LEFT_ACTIVE OR MY_AI.RIGHT_ACTIVE ;
(*
* Result : AI_ACTIVE is TRUE if there is
* an active AI32 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_AO04_STATUS

289

SYS_AO04_STATUS
Gets the status of an Analog Output Module.

Syntax
MY_SYS_AO04_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 323

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_AO04_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 324

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_AO04_ST executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel are operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected on module.

NO_VOTER_FLTS

BOOL

No voter faults detected on module.

TriStation 1131 Libraries Reference

290

Chapter 2

Functions and Data Types

Table 324

Output Parameters (continued)

Name

Data Type

Description

FLD_OK01

BOOL

Field wiring for point 01 is OK .

FLD_OK02

BOOL

Field wiring for point 02 is OK .

FLD_OK03

BOOL

Field wiring for point 03 is OK .

FLD_OK04

BOOL

Field wiring for point 04 is OK .

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_AO04_STATUS function block gets the status of an Analog Output Module.

Example
VAR MY_AO : SYS_AO04_STATUS ; END_VAR
VAR AO_ACTIVE : BOOL ; END_VAR
MY_AO( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
AO_ACTIVE := MY_AO.LEFT_ACTIVE OR MY_AO.RIGHT_ACTIVE ;
(*
* Result : AO_ACTIVE is TRUE if there is
* an active AO04 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_APP_HALT

291

SYS_APP_HALT
Halts the application.

Syntax
n1 := SYS_APP_HALT( b1 ) ;

Table 325

Input Parameters

Name

Data Type

Description

APP_HALT

BOOL

True means halt the application; false means do not halt.

Table 326

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_APP_HALT function halts the application. Halting the application stops execution of the control
program at the end of the current scan and initializes the variables.
APP_HALT enables the function. If APP_HALT is true, then halt the application. If APP_HALT is false,
then do not halt.

Example
(* Halt the application. *)
VAR
n : DINT;
END_VAR
n := SYS_APP_HALT( TRUE );

{* result is 0 *)

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

292

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_CLEAR_FLTS 293

SYS_CLEAR_FLTS
Clear all faults in the system.

Syntax
n1 := SYS_CLEAR_FLTS( b1 ) ;

Table 327

Input Parameters

Name

Data Type

Description

CLEAR_FLTS

BOOL

True means clear faults; false means do not clear.

Table 328

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_CLEAR_FLTS clears all faults in the system.
Halting the application stops execution of the control program at the end of the current scan and
initializes the variables.
CLEAR_FLTS enables the function. If APP_HALT is true, then halt the application. If APP_HALT is false,
then do not halt.

Example
(* Clear system faults. *)
VAR
n : DINT;
END_VAR
n := SYS_CLEAR_FLTS( TRUE );

{* result is 0 *)

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

294

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_CM_STATUS

295

SYS_CM_STATUS
Gets the status of a Trident or Tri-GP Communication Module (CM).

Syntax
MY_SYS_CM_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 329

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_CM_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (2 or 3).

Table 330

Output Parameters

Name

Data Type

Description

CO

BOOL

True if executes SYS_CM_STATUS successfully.

NO_FLTS

BOOL

No faults on CM detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS

BOOL

The CM has no faults.

ACTIVE

BOOL

The CM is active.

INSTALLED

BOOL

The CM is installed.

LOCKED

BOOL

The CM is locked.

NET1_OK

BOOL

Net1 port is receiving messages.

NET2_OK

BOOL

Net2 port is receiving messages.

PRNTR_READY

BOOL

The print server is connected.

PRNTR_NO_OVRFLW

BOOL

No printer buffer overflow.

STATS_RESET_SERIAL_1

BOOL

The statistics were reset for serial port 1.

STATS_RESET_SERIAL_2

BOOL

The statistics were reset for serial port 2.

STATS_RESET_SERIAL_3

BOOL

The statistics were reset for serial port 3.

CM_TEMP

DINT

The current CM temperature.

MSGS_SERIAL_1

DINT

The number of messages received on serial port 1.

BRDCSTS_SERIAL_1

DINT

The number of broadcast messages received on serial port 1.

RSPNS_SERIAL_1

DINT

The number of responses sent on serial port 1.

BAD_MSGS_SERIAL_1

DINT

The number of bad messages received on serial port 1.

ELAPSED_SERIAL_1

DINT

The milliseconds since the last message was received on serial


port 1.

MSGS_SERIAL_2

DINT

The number of messages received on serial port 2.

TriStation 1131 Libraries Reference

296

Chapter 2

Functions and Data Types

Table 330

Output Parameters (continued)

Name

Data Type

Description

BRDCSTS_SERIAL_2

DINT

The number of broadcast messages received on serial port 2.

RSPNS_SERIAL_2

DINT

The number of responses sent on serial port 2.

BAD_MSGS_SERIAL_2

DINT

The number of bad messages received on serial port 2.

ELAPSED_SERIAL_2

DINT

The milliseconds since the last message was received on serial


port 2.

MSGS_SERIAL_3

DINT

The number of messages received on serial port 3.

BRDCSTS_SERIAL_3

DINT

The number of broadcast messages received on serial port 3.

RSPNS_SERIAL_3

DINT

The number of responses sent on serial port 3.

BAD_MSGS_SERIAL_3

DINT

The number of bad messages received on serial port 3.

ELAPSED_SERIAL_3

DINT

The milliseconds since the last message was received on serial


port 3.

PRNTR_BYTES_FREE

DINT

The printer buffer bytes free.

PRNTR_BYTES_USED

DINT

The printer buffer bytes used.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_CM_STATUS function block gets the status of a Communications Module. The status
information for serial ports only applies to ports used as Modbus slaves.

Example
VAR MY_CM : SYS_CM_STATUS ; END_VAR
VAR CM_ACTIVE : BOOL ; END_VAR
MY_CM( CI:=TRUE, IOP:=0, SLOT:=2 ) ;
CM_ACTIVE := MY_CM.ACTIVE ;
(*
* Result : CM_ACTIVE is TRUE if there is
* an active CM module in slot 2.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all outputs except ERROR_NUM to zero.

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

SYS_CM_STATUS

297

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

298

Chapter 2

Functions and Data Types

SYS_CRITICAL_IO
Accumulates the status of safety-critical I/O modules.

Syntax
MY_SYS_CRITICAL_IO( CI:=b1, RESET:=b2, IOP:=n1, SLOT:=n2, APP:=n3, RELAY_OK:=b3 ) ;

Table 331

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_CRITICAL_IO.

RESET

BOOL

Resets.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

APP

DINT

The application number (1-2).

RELAY_OK

BOOL

The relay is energized and not stuck.

Table 332

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_CRITICAL_IO executes successfully.

TMR

BOOL

Three channels are operating without faults on all critical I/O module.

GE_DUAL

BOOL

At least two channels are operating without faults on all critical I/O
module.

GE_SINGLE

BOOL

At least one channel is operating without faults on all critical I/O module.

NO_VOTER_FLTS

BOOL

No voter faults detected on critical modules.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_CRITICAL_IO function block accumulates the status of safety-critical I/O modules. For more
information, see the Safety Considerations Guide for your controller.

Instructions for Use


To initialize, invoke once with RESET := TRUE.
To complete initialization, invoke again with these input settings:

RESET := FALSE

CI := TRUE

TriStation 1131 Libraries Reference

SYS_CRITICAL_IO

APP := DE_ENERGIZED

RELAY_OK := false

299

To get the status of a safety-critical I/O module:

For each module, invoke specifying the input values:

IOP
SLOT
APP
RELAY_OK
For example, if IOP 1 SLOT 1 is a critical DO module with a relay, and SCIO is the function block
instance name:
SCIO( IOP:=1, SLOT:=1, APP:=RELAY,RELAY_OK:=RELAY1_OK );

Read the output values:

CO
TMR
GE_DUAL
GE_SINGLE

Example
For shutdown examples, see this sample project:

Note

TdTUV.pt2 (For Trident or Tri-GP controllers)


See Sample Projects on page 7 for information about where to find this project on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

300

Chapter 2

Functions and Data Types

SYS_DI16_AI16_STATUS
Gets the status of a combo AI/DI input module.

Syntax
MY_SYS_DI16_AI16_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 333

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_DI16_A16_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 334

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_DI16_A16_STATUS executes successfully.

TMR

BOOL

Three channels are operating without faults on all critical I/O


modules.

GE_DUAL

BOOL

At least two channels are operating without faults on all critical


I/O modules.

GE_SINGLE

BOOL

At least one channel is operating without faults on all critical


I/O modules.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

TriStation 1131 Libraries Reference

SYS_DI16_AI16_STATUS

Table 334

301

Output Parameters (continued)

Name

Data Type

Description

NO_FLD_FLTS

BOOL

No field faults detected.

NO_VOTER_FLTS

BOOL

No voter faults detected.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_DI16_A16_STATUS function block gets the status of a combo AI/DI input module.

Example
VAR MY_AIDI : SYS_DI16_AI16_STATUS
VAR AIDI_ACTIVE : BOOL ; END_VAR
MY_AIDI( CI:=TRUE, IOP:=1, SLOT:=5
AIDI_ACTIVE := MY_AIDI.LEFT_ACTIVE
(*
* Result : AIDI_ACTIVE is TRUE if
* an active AI/DI combo module in
*)

; END_VAR
) ;
OR MY_AIDI.RIGHT_ACTIVE ;
there is
slot 5.

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)
This function was added to the library in v1.114 of TRDLIB, first released with TriStation 1131 v4.3.

TriStation 1131 Libraries Reference

302

Chapter 2

Functions and Data Types

SYS_DI32_STATUS
Gets the status of a discrete input module.

Syntax
MY_SYS_DI32_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 335

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_DI32_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 336

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_DI32_STATUS executes successfully.

TMR

BOOL

Three channels are operating without faults on all critical I/O


module.

GE_DUAL

BOOL

At least two channels are operating without faults on all critical


I/O module.

GE_SINGLE

BOOL

At least one channel is operating without faults on all critical


I/O module.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

TriStation 1131 Libraries Reference

SYS_DI32_STATUS

Table 336

303

Output Parameters (continued)

Name

Data Type

Description

NO_FLD_FLTS

BOOL

No field faults detected (always truea).

NO_VOTER_FLTS

BOOL

No voter faults detected (always truea).

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

a. Because there are no field diagnostics or voter diagnostics for the DI32 module, the NO_FLD_FLTS and
NO_VOTER_FLTS outputs are always true after successfully reading the DI32 status.

Description
The SYS_DI32_STATUS function block gets the status of a discrete input module.

Example
VAR MY_DI : SYS_DI32_STATUS ; END_VAR
VAR DI_ACTIVE : BOOL ; END_VAR
MY_DI( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
DI_ACTIVE := MY_DI.LEFT_ACTIVE OR MY_DI.RIGHT_ACTIVE ;
(*
* Result : DI_ACTIVE is TRUE if there is
* an active DI32 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

304

Chapter 2

Functions and Data Types

SYS_DO16_STATUS
Gets the status of a discrete output module.

Syntax
MY_SYS_DO16_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 337

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_DO16_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 338

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_DO16_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel are operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected on module.

NO_VOTER_FLTS

BOOL

No voter faults detected on module.

TriStation 1131 Libraries Reference

SYS_DO16_STATUS

Table 338

305

Output Parameters (continued)

Name

Data Type

Description

OVD_RUNNING_01_16

DWORD

OVD points 0116 are OK.

FLD_OK_01_16

DWORD

Field points 0116 are OK.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_DO16_STATUS function block gets the status of a discrete output module.

Example
VAR MY_DO : SYS_DO16_STATUS ; END_VAR
VAR DO_ACTIVE : BOOL ; END_VAR
MY_DO( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
DO_ACTIVE := MY_DO.LEFT_ACTIVE OR MY_DO.RIGHT_ACTIVE ;
(*
* Result : DO_ACTIVE is TRUE if there is
* an active DO16 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

306

Chapter 2

Functions and Data Types

SYS_HRDI32_STATUS
Gets the status of a high resolution discrete input module.

Syntax
MY_SYS_HRDI32_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 339

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_HRDI32_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 340

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_HRDI32_STATUS executes successfully.

TMR

BOOL

Three channels are operating without faults on all critical I/O


module.

GE_DUAL

BOOL

At least two channels are operating without faults on all critical


I/O module.

GE_SINGLE

BOOL

At least one channel is operating without faults on all critical


I/O module.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

TriStation 1131 Libraries Reference

SYS_HRDI32_STATUS

Table 340

307

Output Parameters (continued)

Name

Data Type

Description

NO_FLD_FLTS

BOOL

No field faults detected (always truea).

NO_VOTER_FLTS

BOOL

No voter faults detected (always truea).

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

a. Because there are no field diagnostics or voter diagnostics for the HRDI32 module, the NO_FLD_FLTS and
NO_VOTER_FLTS outputs are always true after successfully reading the HRDI32 status.

Description
The SYS_HRDI32_STATUS function block gets the status of a high-resolution discrete input module.
CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_HRDI : SYS_HRDI32_STATUS ; END_VAR
VAR HRDI_ACTIVE : BOOL ; END_VAR
MY_HRDI( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
HRDI_ACTIVE := MY_HRDI.LEFT_ACTIVE OR MY_HRDI.RIGHT_ACTIVE ;
(*
* Result : HRDI_ACTIVE is TRUE if there is
* an active HRDI32 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

308

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)
This function was added to the library in v1.120 of TRDLIB, first released with TriStation 1131 v4.6.

TriStation 1131 Libraries Reference

SYS_IO_STATUS

309

SYS_IO_STATUS
Gets the status of an I/O module.

Syntax
MY_SYS_IO_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 341

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_IO_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 342

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_IO_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel are operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected on module.

NO_VOTER_FLTS

BOOL

No voter faults detected on module.

TriStation 1131 Libraries Reference

310

Chapter 2

Functions and Data Types

Table 342

Output Parameters (continued)

Name

Data Type

Description

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_IO_STATUS function block gets the status of an I/O module.

Example
VAR MY_IO : SYS_IO_STATUS ; END_VAR
VAR IO_ACTIVE : BOOL ; END_VAR
MY_IO( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
IO_ACTIVE := MY_IO.LEFT_ACTIVE OR MY_IO.RIGHT_ACTIVE ;
(*
* Result : IO_ACTIVE is TRUE if there is
* an active IO module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_IOP_STATUS

311

SYS_IOP_STATUS
Gets the status of a Trident or Tri-GP I/O Processor.

Syntax
MY_SYS_IOP_STATUS( CI:=b1, IOP:=n1 ) ;

Table 343

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_IOP_STATUS.

IOP

DINT

The I/O Processor (1).

Table 344

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_IOP_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel is operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

LOGIC_PWR1_OK

BOOL

Logic power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_MID

BOOL

The middle module has no faults.

ACTIVE_MID

BOOL

The middle module is active.

INSTALLED_MID

BOOL

The middle module is installeds

LOCKED_MID

BOOL

The middle module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

IO_TMR

BOOL

Three channels are operating without fatal faults detected on the


I/O string.

IO_GE_Dual

BOOL

At least two channels are operating without fatal faults detected


on the I/O string.

TriStation 1131 Libraries Reference

312

Chapter 2

Functions and Data Types

Table 344

Output Parameters (continued)

Name

Data Type

Description

IO_GE_Single

BOOL

At least one channel is operating without fatal faults detected on


the I/O string.

IO_NO_FLTS

BOOL

No faults on the I/O string detected.

IO_NO_ACTIVE_FLTS

BOOL

No faults on the active I/O module detected.

IO_NO_VOTER_FLTS

BOOL

No voter faults on the I/O string detected.

IO_NO_FLD_FLTS

BOOL

No field faults on the I/O string detected.

IO_LOGIC_PWR1_OK

BOOL

Logic power 1 is OK on I/O string.

IO_LOGIC_PWR2_OK

BOOL

Logic power 2 is OK on I/O string.

IO_FLD_PWR1_OK

BOOL

Field power 1 is OK on I/O string.

IO_FLD_PWR2_OK

BOOL

Field power 2 is OK on I/O string.

DISCRETE_POLL_TIME

DINT

The discrete poll time.

ANALOG_POLL_TIME

DINT

The analog poll time.

REAL_POLL_TIME

DINT

The real poll time.

STRUCTURE_POLL_TIME

DINT

The structure poll time.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_IOP_STATUS function block gets the status of an I/O Processor.

Example
VAR MY_IOP : SYS_IOP_STATUS ; END_VAR
VAR NO_IOP_FAULTS : BOOL ; END_VAR
MY_IOP( CI:=TRUE, IOP:=1 ) ;
NO_IOP_FAULTS := MY_IOP.NO_FLTS ;
(*
* Result : NO_IOP_FAULTS is TRUE if there are
* no failed modules detected on the IOP.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all outputs except ERROR_NUM to zero.

BADPARAM, ERROR

TriStation 1131 Libraries Reference

SYS_IOP_STATUS

313

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

314

Chapter 2

Functions and Data Types

SYS_MP_EXT_STATUS
Gets the extended status of a Trident or Tri-GP Main Processor Module.

Syntax
MY_SYS_MP_EXT_STATUS( CI:=b1 ) ;

Table 345

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_MP_STATUS.

Table 346

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_MP_STATUS executes successfully.

REQUESTED_SCAN_TIME

DINT

The requested scan time in milliseconds.

ACTUAL_SCAN_TIME

DINT

The actual scan time in milliseconds.

SURPLUS_SCAN_TIME

DINT

The surplus scan time in milliseconds.

SCAN_OVERRUNS

DINT

The number of scan overruns.

TEMP_LEFT

DINT

The temperature of the left MP in degrees Celsius.

TEMP_MID

DINT

The temperature of the middle MP in degrees Celsius.

TEMP_RIGHT

DINT

The temperature of the right MP in degrees Celsius.

POINTS_DISABLED

DINT

The number of disabled points.

APP_STATE

DINT

Application states:
0 =Running
1 =Halted
2 =Paused
3 =Trapped

MSGS_PORT_LEFT

DINT

The number of messages received on the left port.

BRDCSTS_PORT_LEFT

DINT

The number of broadcast messages received on the left port.

RSPNS_PORT_LEFT

DINT

The number of response messages sent on the left port.

BAD_MSGS_PORT_LEFT

DINT

The number of bad messages received on the left port.

ELAPSED_PORT_LEFT

DINT

The number of milliseconds since last message was received on


left port.

MSGS_PORT_MID

DINT

The number of messages received on the middle port.

BRDCSTS_PORT_MID

DINT

The number of broadcast messages received on the middle port.

RSPNS_PORT_MID

DINT

The number of response messages sent on the middle port.

BAD_MSGS_PORT_MID

DINT

The number of bad messages received on the middle port.

ELAPSED_PORT_MID

DINT

The number of milliseconds since last message was received on


middle port.

TriStation 1131 Libraries Reference

SYS_MP_EXT_STATUS

Table 346

315

Output Parameters (continued)

Name

Data Type

Description

MSGS_PORT_RIGHT

DINT

The number of messages received on the right port.

BRDCSTS_PORT_RIGHT

DINT

The number of broadcast messages received on the right port.

RSPNS_PORT_RIGHT

DINT

The number of response messages sent on the right port.

BAD_MSGS_PORT_RIGHT

DINT

The number of bad messages received on the right port.

ELAPSED_PORT_RIGHT

DINT

The number of milliseconds since last message was received on


right port.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_MP_EXT_STATUS function block gets the extended status of a Main Processor module. You
should use SYS_MP_STATUS when employing BOOL MP status variables and SYS_MP_EXT_STATUS
when using DINT MP status variables.

Example
VAR MY_MPX : SYS_MP_EXT_STATUS ; END_VAR
VAR DELTA : DINT ; END_VAR
MY_MPX( CI:=TRUE ) ;
DELTA := MY_MPX.ACTUAL_SCAN_TIME ;
(*
* Result : DELTA is the actual scan period in milliseconds.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all outputs except ERROR_NUM to zero.

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

316

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_MP_RESET_PORTS 317

SYS_MP_RESET_PORTS
Reset statistics for Modbus ports on the MP.

Syntax
n1 := SYS_MP_RESET_PORTS( RESET_PORT_LEFT, RESET_PORT_MID, RESET_PORT_RIGHT ) ;

Table 347

Input Parameters

Name

Data Type

Description

RESET_PORT_LEFT

BOOL

Reset statistics for the left Modbus port on the MP.

RESET_PORT_MID

BOOL

Reset statistics for the middle Modbus port on the MP.

RESET_PORT_RIGHT

BOOL

Reset statistics for the right Modbus port on the MP.

Table 348

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_MP_RESET_PORTS function block resets statistics for Modbus ports on the MP.
Each Boolean input controls one Modbus port on the main processor (MP). Calling the function with a
Boolean input true resets statistics for the corresponding Modbus port. If a Boolean input is false, then do
not reset statistics for the corresponding Modbus port.

Example
(* Reset statistics for the left port on the MP. *)
VAR
n : DINT;
END_VAR
n := SYS_MP_RESET_PORTS( TRUE, FALSE, FALSE );

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

318

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_MP_STATUS

319

SYS_MP_STATUS
Gets the status of the Trident or Tri-GP Main Processor Modules.

Syntax
MY_SYS_MP_STATUS( CI:=b1 ) ;

Table 349

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_MP_STATUS.

Table 350

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_MP_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults


detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults


detected.

NO_FLTS

BOOL

No failed modules detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

BATT_OK_LEFT

BOOL

The left module battery is OK.

NET_OK_LEFT

BOOL

The left port is receiving messages.

PASS_MID

BOOL

The middle module has no faults.

ACTIVE_MID

BOOL

The middle module is active.

INSTALLED_MID

BOOL

The middle module is installed.

LOCKED_MID

BOOL

The middle module is locked.

BATT_OK_MID

BOOL

The middle module battery is OK.

NET_OK_MID

BOOL

The middle port is receiving messages.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

BATT_OK_RIGHT

BOOL

The right module battery is OK.

TriStation 1131 Libraries Reference

320

Chapter 2

Functions and Data Types

Table 350

Output Parameters (continued)

Name

Data Type

Description

NET_OK_RIGHT

BOOL

The right port is receiving messages.

APP_LOCKED

BOOL

Application changes are locked out.

APP_RUNNING

BOOL

The application is running.

TEMP_OK

BOOL

MP temperature is OK.

SYSTEM_OK

BOOL

No faults in the controller detected.

LOGIC_PWR_OK

BOOL

System logic power supplies are OK.

FLD_PWR_OK

BOOL

System field power supplies are OK.

PROG_ALARM_ON

BOOL

The program alarm is on.

REMOTE_WRT_ENABLE

BOOL

Write from remote host is allowed.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_MP_STATUS function block gets the status of Trident or Tri-GP Main Processor modules. Use
the SYS_MP_STATUS function block with BOOL MP status variables and the SYS_MP_EXT_STATUS
function block with DINT MP status variables.

Example
VAR MY_MP : SYS_MP_STATUS ; END_VAR
VAR MP_TEMPERATURE_OK : BOOL ; END_VAR
MY_MP( CI:=TRUE ) ;
MP_TEMPERATURE_OK := MY_MP.TEMP_OK ;
(*
* Result : MP_TEMPERATURE_OK is TRUE if
* the MP temperature is OK.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

TriStation 1131 Libraries Reference

SYS_MP_STATUS

321

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

322

Chapter 2

Functions and Data Types

SYS_OVD_INHIBIT
Inhibits output voter diagnostics.

Syntax
n1 := SYS_OVD_INHIBIT( IOP, SLOT, IOVD_01_16 ) ;

Table 351

Input Parameters

Name

Data Type

Description

IOP

DINT

I/O Processor (1).

SLOT

DINT

Baseplate number (0-32).

IOVD_01_16

DWORD

Inhibit Output Voter Diagnostics points 01..16

Table 352

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_OVD_INHIBIT function block turns output voter diagnostic inhibits on or off.
When enabled, the Trident or Tri-GP DO or SDO module runs output voter diagnostics on each output
point. The application program can call SYS_OVD_INHIBIT to control the OVD inhibit for each point.
Each bit 01..16 of IOVD_01_16 controls the running of OVD for the corresponding point on the output
module. If the bit value is one, then inhibit diagnostics for that point. If the bit value is zero, then run the
diagnostics for that point.
Invoke SYS_DO16_STATUS or SYS_SDO16_STATUS to read whether OVD is running for each point.

WARNING

Points on the Trident or Tri-GP SDO module are configured for supervision in
TriStation 1131.
Using the SYS_OVD_INHIBIT function block to inhibit OVDs on an SDO point
overrides the TriStation 1131 supervisory configuration and results in loss of
supervision of that point.
See the TriStation 1131 Developers Guide for more information about configuring
the Trident or Tri-GP SDO module.

TriStation 1131 Libraries Reference

SYS_OVD_INHIBIT

323

Programming tip: the bit numbers in parameter IOVD_01_16 are the same as the bit numbers in the
PACK16 function, so if you prefer using separate Boolean inputs, you can use PACK16.
The format of IOVD_01_16 parameter is:
*
bit --> |32 ... 17|16 ... 01|
*
output point -->
|16 ... 01|
*
where the most significant bits 17..32 are not used.

Example
(* Inhibit voter diagnostic for chassis 1 slot 5 points 01 thru 06. *)
VAR
n : DINT;
END_VAR
n := SYS_OVD_INHIBIT( 1, 5, 2#00000000000000000000000000111111 );

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

324

Chapter 2

Functions and Data Types

SYS_PI06_STATUS
Gets the status of a Trident/Tri-GP Pulse Input or Enhanced Pulse Input Module.

Syntax
MY_SYS_PI06_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 353

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_PI06_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 354

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_PI06_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel is operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INPUT_STABLE_1

BOOL

The measured input for pulse input 1 or enhanced pulse input 1


is stable.

INPUT_STABLE_2

BOOL

The measured input for pulse input 2 or enhanced pulse input 2


is stable.

INPUT_STABLE_3

BOOL

The measured input for pulse input 3 or enhanced pulse input 3


is stable.

INPUT_STABLE_4

BOOL

The measured input for pulse input 4 or enhanced pulse input 4


is stable.

INPUT_STABLE_5

BOOL

The measured input for pulse input 5 or enhanced pulse input 5


is stable.

TriStation 1131 Libraries Reference

SYS_PI06_STATUS

Table 354

325

Output Parameters (continued)

Name

Data Type

Description

INPUT_STABLE_6

BOOL

The measured input for pulse input 6 or enhanced pulse input 6


is stable.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected.

NO_VOTER_FLTS

BOOL

No voter faults detected.

SIGNAL_PRESENT_1

BOOL

The frequency of pulse input 1 or enhanced pulse input 1 is >=


0.5 Hz.

SIGNAL_PRESENT_2

BOOL

The frequency of pulse input 2 or enhanced pulse input 2 is >=


0.5 Hz.

SIGNAL_PRESENT_3

BOOL

The frequency of pulse input 3 or enhanced pulse input 3 is >=


0.5 Hz.

SIGNAL_PRESENT_4

BOOL

The frequency of pulse input 4 or enhanced pulse input 4 is >=


0.5 Hz.

SIGNAL_PRESENT_5

BOOL

The frequency of pulse input 5 or enhanced pulse input 5 is >=


0.5 Hz.

SIGNAL_PRESENT_6

BOOL

The frequency of pulse input 6 or enhanced pulse input 6 is >=


0.5 Hz.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_PI06_STATUS function block gets the status of a Trident or Tri-GP Pulse Input or Enhanced
Pulse Input Module.

Example
VAR MY_PI : SYS_PI06_STATUS ; END_VAR
VAR PI_ACTIVE : BOOL ; END_VAR
MY_PI( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
PI_ACTIVE := MY_PI.LEFT_ACTIVE OR MY_PI.RIGHT_ACTIVE ;
(*
* Result : PI_ACTIVE is TRUE if there is an active PI06 module in slot 5.
*)

TriStation 1131 Libraries Reference

326

Chapter 2

Functions and Data Types

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_RO32_STATUS

327

SYS_RO32_STATUS
Gets the status of a Trident/Tri-GP Relay Output Module.

Syntax
MY_SYS_RO32_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 355

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_RO32_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 356

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_RO32_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel is operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected.

NO_VOTER_FLTS

BOOL

No voter faults detected.

TriStation 1131 Libraries Reference

328

Chapter 2

Functions and Data Types

Table 356

Output Parameters (continued)

Name

Data Type

Description

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_RO32_STATUS function block gets the the status of a Relay Output module.
If CI = false, then CO = false and no operation occurs (no output changes). If CI = true, then CO = true if
no errors occur (ERROR_NUM=0).

Example
VAR MY_RO : SYS_RO32_STATUS ; END_VAR
VAR RO_ACTIVE : BOOL ; END_VAR
MY_RO( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
RO_ACTIVE := MY_RO.LEFT_ACTIVE OR MY_RO.RIGHT_ACTIVE ;
(*
* Result : RO_ACTIVE is TRUE if there is
* an active RO32 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_SDO16_STATUS

329

SYS_SDO16_STATUS
Gets the status of a supervised discrete output module.

Syntax
MY_SYS_SDO16_STATUS( CI:=b1, IOP:=n1, SLOT:=n2 ) ;

Table 357

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_SDO16_STATUS.

IOP

DINT

The I/O Processor (1).

SLOT

DINT

The baseplate number (032).

Table 358

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_SDO16_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults detected.

GE_SINGLE

BOOL

At least one channel are operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

PASS_LEFT

BOOL

The left module has no faults.

ACTIVE_LEFT

BOOL

The left module is active.

INSTALLED_LEFT

BOOL

The left module is installed.

LOCKED_LEFT

BOOL

The left module is locked.

PASS_RIGHT

BOOL

The right module has no faults.

ACTIVE_RIGHT

BOOL

The right module is active.

INSTALLED_RIGHT

BOOL

The right module is installed.

LOCKED_RIGHT

BOOL

The right module is locked.

NO_FLD_ALARM_LEFT

BOOL

The left module field alarm indicator is off.

NO_FLD_ALARM_RIGHT

BOOL

The right module field alarm indicator is off.

FLD_PWR1_OK

BOOL

Field power 1 is OK.

FLD_PWR2_OK

BOOL

Field power 2 is OK.

NO_FLD_FLTS

BOOL

No field faults detected on module.

NO_VOTER_FLTS

BOOL

No voter faults detected on module.

TriStation 1131 Libraries Reference

330

Chapter 2

Functions and Data Types

Table 358

Output Parameters (continued)

Name

Data Type

Description

OVD_RUNNING_01_16

DWORD

OVD points 0116 are OK.

FLD_OK_01_16

DWORD

Field points 0116 are OK.

SPRVSD_ON_01_16

DWORD

Supervision status for points 01-16. TRUE: Supervision enabled.


FALSE: Supervision disabled.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_SDO16_STATUS function block gets the status of a supervised discrete output module.
CO is the control ouput. CO follows CI if no runtime error is detected. CO=true indicates that the function
block was enabled and executed successfully, with no runtime error. CO=false and CI=true indicates a
runtime error was detected. CO=false and CI=false indicates no operation.

Example
VAR MY_SDO : SYS_SDO16_STATUS ; END_VAR
VAR SDO_ACTIVE : BOOL ; END_VAR
MY_SDO( CI:=TRUE, IOP:=1, SLOT:=5 ) ;
SDO_ACTIVE := MY_SDO.LEFT_ACTIVE OR MY_SDO.RIGHT_ACTIVE ;
(*
* Result : SDO_ACTIVE is TRUE if there
* is an active SDO16 module in slot 5.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

SYS_SDO16_STATUS

331

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)
This function was added to the library in v1.120 of TRDLIB, first released with TriStation 1131 v4.6.

TriStation 1131 Libraries Reference

332

Chapter 2

Functions and Data Types

SYS_SERIAL_PORT
Resets statistics for one or more serial ports.

Syntax
MY_SYS_SERIAL_PORT( CI:=b1, IOP:=n1, RESET_STATS_SERIAL_1:=b2,
RESET_STATS_SERIAL_2:=b3, RESET_STATS_SERIAL_3:=b4 ) ;

Table 359

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_SERIAL_PORT.

IOP

DINT

I/O Processor (1).

SLOT

DINT

Baseplate number (2-3).

RESET_STATS_SERIAL_1

BOOL

Reset statistics for serial port 1.

RESET_STATS_SERIAL_2

BOOL

Reset statistics for serial port 2.

RESET_STATS_SERIAL_3

BOOL

Reset statistics for serial port 3.

Table 360

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_SERIAL_PORT executes successfully.

STATS_RESET_SERIAL_1

BOOL

Statististics were reset for serial port 1.

STATS_RESET_SERIAL_2

BOOL

Statististics were reset for serial port 2.

STATS_RESET_SERIAL_3

BOOL

Statististics were reset for serial port 3.

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_SERIAL_PORT function block resets statistics for one or more serial ports.
CI is a control input. If CI is false, then CO is false and there is no operation, which means that new
requests are ignored. If CI is true, then CO is false if there are errors (ERROR_NUM not zero). If CI is true,
then CO is true if there are no errors (ERROR_NUM = 0).
Each input RESET_STATS_SERIAL_n is a request to reset the statistics for port "n". The function block
latches the request until the port acknowledges the request, that is, until the transition of
STATS_RESET_SERIAL_n from false to true.
Each output STATS_RESET_SERIAL_n is true when the statistics are reset, false otherwise.

TriStation 1131 Libraries Reference

SYS_SERIAL_PORT

333

Invoke SYS_CM_STATUS to read statistics for each serial port. The statistics for serial port 1 are
MSGS_SERIAL_1, BRDCSTS_SERIAL_1, RSPNS_SERIAL_1, and BAD_MSGS_SERIAL_1, and similarly
for ports 2 and 3.

Example
(* Reset statistics for all three ports. *)
VAR MY_SYS_SERIAL_PORT : SYS_SERIAL_PORT;
END_VAR
MY_SYS_SERIAL_PORT( RESET_STATS_SERIAL_1:=TRUE, RESET_STATS_SERIAL_2:=TRUE,
RESET_STATS_SERIAL_3:=TRUE );

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

334

Chapter 2

Functions and Data Types

SYS_SET_APP_LOCK
Turns the application lock on or off.

Syntax
n1 := SYS_SET_APP_LOCK( b1 ) ;

Table 361

Input Parameters

Name

Data Type

Description

VALUE

BOOL

True means locked; false means unlocked.

Table 362

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_SET_APP_LOCK function turns the application lock on or off.
The application lock controls the TriStation 1131 permissions for performing application changes. When
locked, TriStation 1131 cannot download changes, download all, set variable values, or disable points on
a Trident or Tri-GP controller.

CAUTION

Once the application has been locked by setting SYS_SET_APP_LOCK to True,


the only way to unlock the application is to reseat all three MPs. Simply changing
the value to False will not unlock the application.
To be able to unlock the application without reseating the MPs, before locking
the application, you must configure a call to the SYS_SET_APP_LOCK function
that passes an externally controlled value to the function. The following are two
examples of how to use this technique:

Connect a switch to a DI input, and then connect the DI input to the


SYS_SET_APP_LOCK function.

Or, connect a Read/Write aliased variable to the SYS_SET_APP_LOCK


function and use Modbus to control the variable.

Invoke function block SYS_MP_STATUS to read APP_LOCKED.

Example
(* Lock the application. *)

TriStation 1131 Libraries Reference

SYS_SET_APP_LOCK

VAR
n : DINT;
END_VAR
n := SYS_SET_APP_LOCK( TRUE );

335

{* result is 0 *)

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

336

Chapter 2

Functions and Data Types

SYS_SET_PROG_ALARM
Turns the programmable alarm on or off.

Syntax
n1 := SYS_SET_PROG_ALARM( b1 ) ;

Table 363

Input Parameters

Name

Data Type

Description

VALUE

BOOL

True means alarm on; false means alarm off.

Table 364

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_SET_PROG_ALARM function turns the programmable alarm on or off.
The programmable alarm is a blue indicator lamp on the Trident or Tri-GP MP module.
Invoke function block SYS_MP_STATUS to read PROG_ALARM_ON.

Example
(* Turn the blue programmable alarm indicator on. *)
VAR
n : DINT;
END_VAR
n := SYS_SET_PROG_ALARM( TRUE );
{* result is 0 *)

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

SYS_SET_PROG_ALARM

337

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

338

Chapter 2

Functions and Data Types

SYS_SET_REMOTE_WRT_ENBL
Turns remote write enable on or off.

Syntax
n1 := SYS_SET_REMOTE_WRT_ENBL( b1 ) ;

Table 365

Input Parameters

Name

Data Type

Description

VALUE

BOOL

True means enable writes; false means disable writes.

Table 366

Return Value

Data Type

Description

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_SET_REMOTE_WRT_ENBL function turns remote write enable on or off. Remote write enable
controls permission for external hosts to write to an aliased variable on a Trident or Tri-GP controller.
Invoke function block SYS_MP_STATUS to read REMOTE_WRT_ENBL.

Example
(* Allow writes from remote hosts. *)
VAR
n : DINT;
END_VAR
n := SYS_SET_REMOTE_WRT_ENBL( TRUE );

{* result is 0 *)

Runtime Errors
Condition

Return Value

Error Flags

If error number is non-zero.

Error number

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

SYS_SET_REMOTE_WRT_ENBL

339

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

340

Chapter 2

Functions and Data Types

SYS_SHUTDOWN
Enables a system shutdown according to industry guidelines.

Syntax
MY_SYS_SHUTDOWN( CI:=b1, IO_CO:=b2, IO_TMR:=b3, IO_GE_DUAL:=b4, IO_GE_SINGLE:=b5,
IO_NO_VOTER_FAULTS:=b6, MAX_TIME_DUAL:=t1, MAX_TIME_SINGLE:=t2, MAX_SCAN_TIME:=t3 ) ;

Table 367

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_SHUTDOWN.

IO_CO

BOOL

True if SYS_SHUTDOWN executes successfully.

IO_TMR

BOOL

Three channels are operating without faults on every critical I/O


module.

IO_GE_DUAL

BOOL

At least two channels are operating without faults on every critical


I/O module.

IO_GE_SINGLE

BOOL

At least one channel is operating without faults on every critical I/O


module.

IO_NO_VOTER_FLTS

BOOL

No voter faults on critical modules detected.

IO_ERROR

DINT

Error number, not used.

MAX_TIME_DUAL

TIME

The maximum time permittedof continuous operation permitted


with two channels operating.

MAX_TIME_SINGLE

TIME

The maximum time of continuous operation permitted with one


channel operating.

MAX_SCAN_TIME

TIME

50% of the maximum response time.

Table 368

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_SHUTDOWN executes successfully.

OPERATING

BOOL

Shutdown if OPERATING is false.

TMR

BOOL

Three channels are operating without fatal faults detected.

DUAL

BOOL

At least two channels are operating without fatal faults


detected.

SINGL

BOOL

At least one channel is operating without fatal faults detected.

ZERO

BOOL

No channels are operating.

TIMER_RUNNING

BOOL

Shutdown timer is running

TIME_LEFT

TIME

Time remaining to shutdown

ALARM_PROGRAMMING_PE
RMITTED

BOOL

True if application changes are permitted

ALARM_REMOTE_ACCESS

BOOL

True if remote-host writes are enabled

TriStation 1131 Libraries Reference

SYS_SHUTDOWN

Table 368

341

Output Parameters (continued)

Name

Data Type

Description

ALARM_RESPONSE_TIME

BOOL

True if actual scan time MAX_SCAN_TIME

ALARM_DISABLED_POINTS

BOOL

True if one or more points are disabled

ERROR

DINT

Error Number:
0 =No error.
1 =Error in maximum time.
2 =IO function block error - IO_ERROR is non-zero.
3 =System status or MP status function block error.

Description
The SYS_SHUTDOWN function block enables a system shutdown according to industry guidelines. For
more information, see the Safety Considerations Guide for your controller.

Example
For shutdown examples, see this sample project:

Note

TdTUV.pt2 (For Trident or Tri-GP controllers)


See Sample Projects on page 7 for information about where to find this project on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If ERROR is non-zero

Set alarm outputs to true, reset the other BOOL


outputs to false, and reset TIME_LEFT to zero.

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If a programming error or configuration error occurs, then CO is false and the error number is non-zero.
For error numbers, see the description of the ERROR output.

Application Notes
Can be used in Safety or Control applications.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

342

Chapter 2

Functions and Data Types

SYS_SYSTEM_STATUS
Gets the status of an entire Trident or Tri-GP system, including Main Processors, I/O modules,
communication, power, and time.

Syntax
MY_SYS_SYSTEM_STATUS( CI:=b1 ) ;

Table 369

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_SYSTEM_STATUS.

Table 370

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_SYSTEM_STATUS executes successfully.

TMR

BOOL

Three channels are operating without fatal faults detected.

GE_DUAL

BOOL

At least two channels are operating without fatal faults


detected.

GE_SINGLE

BOOL

At least one channel is operating without fatal faults detected.

NO_FLTS

BOOL

No failed modules detected.

NO_ACTIVE_FLTS

BOOL

No faults on the active module detected.

LOGIC_PWR1_OK

BOOL

Logic Power 1 is OK.

LOGIC_PWR2_OK

BOOL

Logic Power 2 is OK.

POWER_UP

BOOL

The first scan after power up.

FIRST_SCAN

BOOL

The first scan.

COLD_START

BOOL

The first scan after initializing retentive variables.

PT_DISABLING_OFF

BOOL

Disabling points is not permitted.

MASTER_CLK

BOOL

The system owns the master clock.

LOCAL_TIME

BOOL

The system is using local time.

DAYLIGHT_TIME

BOOL

Daylight Savings Time is in effect.

DSBL_REMOTE_CHGS

BOOL

Remote changes to output disallowed.

IO_TMR

BOOL

Three channels are operating without fatal faults detected on


the I/O string.

IO_GE_Dual

BOOL

At least two channels are operating without fatal faults


detected on the I/O string.

IO_GE_Single

BOOL

At least one channel is operating without fatal faults detected


on the I/O string.

IO_NO_FLTS

BOOL

No faults on the I/O string detected.

IO_NO_ACTIVE_FLTS

BOOL

No faults on the active I/O module detected.

TriStation 1131 Libraries Reference

SYS_SYSTEM_STATUS 343

Table 370

Output Parameters (continued)

Name

Data Type

Description

IO_NO_VOTER_FLTS

BOOL

No voter faults on the I/O string detected.

IO_NO_FLD_FLTS

BOOL

No field faults on the I/O string detected.

FLD_PWR1_OK

BOOL

Field power supply 1 is OK.

FLD_PWR2_OK

BOOL

Field power supply 2 is OK.

NODE_OK_01_32

DWORD

Valid communication links (nodes 01 to 32).

NODE_OK_33_64

DWORD

Valid communication links (nodes 33 to 64).

NODE_REDUNDANT_01_32

DWORD

Redundant communication links (nodes 01 to 32).

NODE_REDUNDANT_33_64

DWORD

Redundant communication links (nodes 33 to 64).

YEAR

DINT

The year (for example, 1999).

MONTH

DINT

The month (112)

DAY

DINT

The day of the month (131)

HOUR

DINT

The hour (023)

MINUTE

DINT

The minute (059)

SECOND

DINT

The second (059)

MILLISECOND

DINT

The millisecond (0999)

MICROSECOND

DINT

The millisecond (0999)

RELATIVE_SECONDS

DINT

The relative seconds since January 1, 1970

DAY_OF_WEEK

DINT

The current day of the week (06, 0=Sunday)

APP_MAJOR_VRSN

DINT

The application major version

APP_MINOR_VRSN

DINT

The application minor version

APP_NAME

STRING

The application name

ERROR_NUM

DINT

Error Number:
0 =No error.
1 =The IOP is invalid.
2 =The slot is not valid.
3 =The module is not configured.
4 =The module is the wrong type.

Description
The SYS_SYSTEM_STATUS function block gets the status of an entire Trident or Tri-GP system,
including Main Processors, I/O modules, communication, power, and time.
If CI = false, then CO = false and no operation occurs (no output changes). If CI = true, then CO = true if
no errors occur (ERROR_NUM=0).

TriStation 1131 Libraries Reference

344

Chapter 2

Functions and Data Types

Each digit of the DWORD for the NODE_OK... parameters corresponds to four nodes in the given range
of the parameter. The following diagram illustrates which nodes each digit corresponds to:
NODE_OK_01_32 or NODE_REDUNDANT_01_32
Layout
Digit

32
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
09
08
07
06
05
04
03
02
01

Node Number

NODE_OK_33_64 or NODE_REDUNDANT_33_64
Layout
Digit

64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33

Node Number

For example, if the DWORD for NODE_OK_01_32 contains "5000," reading right to left indicates:
0 = 0000, Nodes 1-4 Not OK
0 = 0000, Nodes 5-8 Not OK
0 = 0000, Nodes 9-12 Not OK
5 = 0101, Nodes 13 and 15 OK, Nodes 14 and 16 Not OK

Example
VAR MY_SYS : SYS_SYSTEM_STATUS ; END_VAR
VAR NO_SYSTEM_FAULTS : BOOL ; END_VAR
MY_SYS( CI:=TRUE ) ;
NO_SYSTEM_FAULTS := MY_SYS.NO_FLTS ;
(*
* Result : NO_SYSTEM_FAULTS is TRUE if there are
* no failed modules detected in the system.
*)

Runtime Errors
Condition

Return Value

Error Flags

If ERROR_NUM is non-zero

Reset all outputs except ERROR_NUM to zero.

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

SYS_VOTE_MODE

345

SYS_VOTE_MODE
Converts redundancy status.

Syntax
MY_SYS_VOTE_MODE( CI:=b1, IN_TMR:=b2, GE_DUAL:=b3, GE_SINGLE:=b4 ) ;

Table 371

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables SYS_VOTE_MODE.

IN_TMR

BOOL

Three channels are operating.

GE_DUAL

BOOL

Two or more channels are operating.

GE_SINGLE

BOOL

One or more channels are operating.

Table 372

Output Parameters

Name

Data Type

Description

CO

BOOL

True if SYS_VOTE_MODE executes successfully.

TMR

BOOL

Three channels are operating.

DUAL

BOOL

Two channels are operating.

SINGLE

BOOL

One or more channels are operating.

ZERO

BOOL

No channel is operating.

Description
The SYS_VOTE_MODE function block converts redundancy status, as shown in this truth table.

Table 373

Truth Table

TMR

GE_DUAL

GE_SINGLE

TMR

DUAL

SINGL

ZERO

Othera

a. If an error in the inputs occurs, then CO is false, the mode outputs are
false, and the function block reports a bad parameter error
(BADPARAM).

Note

GE_ means greater than or equal to.

TriStation 1131 Libraries Reference

346

Chapter 2

Functions and Data Types

Example
For shutdown examples, see this sample project:

Note

TdTUV.pt2 (For Trident or Tri-GP controllers)


See Sample Projects on page 7 for information about where to find this project on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If the inputs do not match one of the first four


rows of the truth table

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Trident/Tri-GP (TRDLIB)

TriStation 1131 Libraries Reference

TAN

347

TAN
Calculates the tangent of an angle.

Syntax
y := TAN( x ) ;

Table 374

Input Parameters

Name

Data Type

Description

ANY_REAL

The angle, in radians.

Table 375

Return Value

Data Type

Description

ANY_REAL

The tangent of x.

Description
The TAN function returns the tangent of an angle given in radians.

Example
VAR
y : REAL;
END_VAR
y := TAN( 3.141593/4.0 );

{* result is

1.0 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number.

NAN

BADPARAM, ERROR

If the absolute value of x is greater than 2**63

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

348

Chapter 2

Functions and Data Types

TCJ_CONV
Converts a Type J thermocouple input into degrees Celsius and returns the result.

Syntax
y := TCJ_CONV( MC, CONVM, CONVB, COLDJNC ) ;

Table 376

Input Parameters

Name

Data Type

Description

MC

DINT

The machine count input from thermocouple wire to be converted (04095).

CONVM

REAL

The conversion from machine counts to millivolts (see the Thermocouple and
Amplifier specification sheets).

CONVB

REAL

The conversion bias from machine count to millivolts (see the Thermocouple and
Amplifier specification sheets).

COLDJNC

REAL

The cold-junction compensation temperature in degrees Celsius.

Table 377

Return Value

Data Type

Description

REAL

The temperature in degrees Celsius.

Description
The TCJ_CONV function converts a Type J thermocouple input into degrees Celsius and returns the
result.
First, a thermocouple input machine count (MC) from an Analog Input Module is converted to millivolts
using a bias and scale factor. Next, the millivolts are corrected by cold-junction compensation using a
quartic equation, which is a function of cold-junction temperature. Lastly, the temperature in degrees
Celsius is computed using a set of quartic equations, which are functions of the corrected millivolts.
Temperatures ranging from 200 C to 1200 C are supported for Type J thermocouples. The cold-junction
compensation temperature must be in the range from 20 C to 500 C.

WARNING
Note

The TCJ_CONV function should be used when thermocouple wiring is tied to an


Analog Input module through an amplifier. TCJ_CONV is not intended for use
with Thermocouple modules.

Conversion from millivolts to degrees Celsius is based on the Type J quartic equation
approximation done in four ranges. If the intermediate result is outside the calculable range, the
function returns either 10000 or 10000. For example, if coldJnc < 20 or result < 200, then return
10000; if coldJnc > 500 or result > 1200, then return +10000

Runtime Errors
None.

TriStation 1131 Libraries Reference

TCJ_CONV

349

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

350

Chapter 2

Functions and Data Types

TCK_CONV
Converts a Type K thermocouple input into degrees Celsius and returns the result.

Syntax
y := TCJ_CONV( MC, CONVM, CONVB, COLDJNC ) ;

Table 378

Input Parameters

Name

Data Type

Description

MC

DINT

The machine count input from thermocouple wire to be converted


(04095).

CONVM

REAL

The conversion from machine counts to millivolts (see the Thermocouple and
Amplifier specification sheets).

CONVB

REAL

The conversion bias from machine count to millivolts (see the Thermocouple and
Amplifier specification sheets).

COLDJNC

REAL

The cold-junction compensation temperature in degrees Celsius.

Table 379

Return Value

Data Type

Description

REAL

The temperature in degrees Celsius.

Description
The TCK_CONV function converts a Type K thermocouple input into degrees Celsius and returns the
result.
First, a thermocouple input machine count MC from an Analog Input Module is converted to millivolts
using a bias and scale factor. Next, the millivolts are corrected by cold-junction compensation, using a
quartic equation, which is a function of cold-junction temperature. Lastly, the temperature in degrees
Celsius is computed using a set of quartic equations, which are functions of the corrected millivolts.
Temperatures ranging from 200 C to 1370 C are supported for Type K thermocouples. The coldjunction compensation temperature must be in the range from 20 C to 500 C.

WARNING
Note

The TCK_CONV function should be used when thermocouple wiring is tied to


an Analog Input module through an amplifier. TCK_CONV is not intended for
use with Thermocouple modules.

Conversion from millivolts to degrees Celsius is based on the Type K quartic equation
approximation done in three ranges. If the intermediate result is outside the calculable range, the
function returns either 10000 or 10000. For example, if coldJnc < 20 or output < 200, then
output = 10000; if coldJnc > 500 or output > 1370, then output = +10000.

Runtime Errors
None.

TriStation 1131 Libraries Reference

TCK_CONV

351

Application Notes
Can be used in Safety or Control applications.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

352

Chapter 2

Functions and Data Types

TDD_I
Provides a time delay to de-energize.

Syntax
MY_TDD_I( I1:=b1, TGT:=n1 ) ;

Table 380

Input Parameters

Name

Data Type

Description

I1

BOOL

The input state.

TGT

DINT

The target delay time in integer milliseconds.

Table 381

Output Parameters

Name

Data Type

Description

Q1

BOOL

The output state.

Description
The TDD_I function block provides a time delay to de-energize. The delay time is given in integer
milliseconds. If the input is true, then the output is true. After the input changes to false, the output
remains true for the specified delay time, then the output changes to false.

Note

If TGT is within one scan period of 2147483647 milliseconds (25 days), then the time accumulator
can overflow to a negative value.

You must invoke an instance of TDD_I exactly once per scan.

Example
VAR MY_TDD_I : TDD_I ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TDD_I( I1:=b1, 10000 ) ;
b2 := MY_TDD_I.Q1 ;
(* result: The delay time is about 10 seconds from the falling edge of b1 to the falling
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TDD_R

353

TDD_R
Provides a time delay to de-energize.

Syntax
MY_TDD_R( I1:=b1, TGT:=x1 ) ;

Table 382

Input Parameters

Name

Data Type

Description

I1

BOOL

The input state.

TGT

REAL

The target delay time in real seconds.

Table 383

Output Parameters

Name

Data Type

Description

Q1

BOOL

The output state.

Description
The TDD_R function block provides a time delay to de-energize. The delay time is given in real seconds.
If the input is true, then the output is true. After the input changes to false, the output remains true for
the specified delay time, then the output changes to false.
You must invoke an instance of TDD_R exactly once per scan.

Note

The rounding error in the time accumulator increases with time until the accumulator eventually
stops. The rounding error in seconds is less than ACC ACC (50,000,000 T), where ACC is
the accumulated time in seconds and T is the scan period in seconds. The accumulator stops after
ACC > 16,000,000 T. For example, if the scan period is 20 milliseconds, then after one hour, the
rounding error is less than 13 seconds.

Example
VAR MY_TDD_R : TDD_R ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TDD_R( I1:=b1, 10.0 ) ;
b2 := MY_TDD_R.Q1 ;
(* result: The delay time is about 10 seconds from the falling edge of b1 to the falling
edge of b2. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

354

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TDE_I

355

TDE_I
Provides a time delay to energize.

Syntax
MY_TDE_I( I1:=b1, TGT:=n1 ) ;

Table 384

Input Parameters

Name

Data Type

Description

I1

BOOL

The input state.

TGT

DINT

The target delay time in integer milliseconds.

Table 385

Output Parameters

Name

Data Type

Description

Q1

BOOL

The output state.

Description
The TDE_I function block provides a time delay to energize. The delay time is given in integer
milliseconds. If the input is false, then the output is false. After the input changes to true, the output
remains false for the specified delay time, then the output changes to true.

Note

If TGT is within one scan period of 2147483647 milliseconds (25 days), then the time accumulator
can overflow to a negative value.

You must invoke an instance of TDE_I exactly once per scan.

Example
VAR MY_TDE_I : TDE_I ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TDE_I( I1:=b1, 10000 ) ;
b2 := MY_TDE_I.Q1 ;
(* result: The delay time is about 10 seconds from the rising edge of b1 to the rising
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

356

Chapter 2

Functions and Data Types

TDE_R
Provides a time delay to energize.

Syntax
MY_TDE_R( I1:=b1, TGT:=x1 ) ;

Table 386

Input Parameters

Name

Data Type

Description

I1

BOOL

The input state.

TGT

REAL

The target delay time in real seconds.

Table 387

Output Parameters

Name

Data Type

Description

Q1

BOOL

The output state.

Description
The TDE_R function block provides a time delay to energize. The delay time is given in real seconds. If
the input is false, then the output is false. After the input changes to true, the output remains false for the
specified delay time, then the output changes to true.
You must invoke an instance of TDE_R exactly once per scan.

Note

The rounding error in the time accumulator increases with time until the accumulator eventually
stops. The rounding error in seconds is less than ACC ACC (50,000,000 T), where ACC is
the accumulated time in seconds and T is the scan period in seconds. The accumulator stops after
ACC > 16,000,000 T. For example, if the scan period is 20 milliseconds, then after one hour, the
rounding error is less than 13 seconds.

Example
VAR MY_TDE_R : TDE_R ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TDE_R( I1:=b1, 10.0 ) ;
b2 := MY_TDE_R.Q1 ;
(* result: The delay time is about 10 seconds from the rising edge of b1 to the rising
edge of b2. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

TDE_R

357

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

358

Chapter 2

Functions and Data Types

TIME
A TIME data type refers to a period of time (duration) in days, hours, minutes, seconds, and milliseconds.
The range is 9999 years and the precision is 0.1 milliseconds.
A TIME data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

TIME

Description

Duration

Size

64 bits

Syntax

TIME#11d
or
TIME#22.2h
or
TIME#33.3m
or
TIME#44.4s
or
TIME#55.5ms
or
TIME#11d22h33m44s55.5ms
or
T#11d22h33m44s55.5ms
or
T#44.4s

Default value

TIME#0S

Lower limit

TIME#-3652134d

Upper limit

TIME#3652134d

Result if intermediate value is less than lower limit

Inv Time

Result if upper limit is less than intermediate value

Inv Time

Note

In TriStation 1131 v4.4 and later, the syntax of the TIME data type is not case-sensitive.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

TIME_TO_SECS 359

TIME_TO_SECS
Converts time to number of seconds.

Syntax
y := TIME_TO_SECS( t ) ;

Table 388

Input Parameters

Name

Data Type

Description

TIME

The time.

Table 389

Return Value

Data Type

Description

LREAL

The number of seconds.

Description
The TIME_TO_SECS function converts time to number of seconds.

Example
VAR t : TIME ; y : LREAL ; END_VAR
t := T#500ms ;
y := TIME_TO_SECS( t ) ;
(* result is 0.5 *)

Runtime Errors
Condition

Return Value

Error Flags

If t is out of range.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

360

Chapter 2

Functions and Data Types

TIME_TO_SECS_REAL
Converts time to number of seconds.

Syntax
y := TIME_TO_SECS_REAL( t ) ;

Table 390

Input Parameters

Name

Data Type

Description

TIME

The time.

Table 391

Return Value

Data Type

Description

REAL

The number of seconds.

Description
The TIME_TO_SECS_REAL function converts time to number of seconds.

Example
VAR t : TIME ; y : REAL ; END_VAR
t := T#500ms ;
y := TIME_TO_SECS( t ) ;
(* result is 0.5 *)

Runtime Errors
Condition

Return Value

Error Flags

If t is out of range.

NAN

BADPARAM, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TIMEADJ

361

TIMEADJ
Adjusts the calendar clock.

Syntax
MY_TIMEADJ( CI:=b1, MS:=n1 ) ;

Table 392

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TIMEADJ.

MS

DINT

The number of milliseconds, positive or negative, to adjust the clock.

Table 393

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TIMEADJ executes successfully.

Description
The TIMEADJ function block adjusts the calendar clock.
CI is the control input. Call the function block with CI=true to adjust the clock. Then change CI to false
for the next evaluation.

Note

You must clear CI to 0 (False) after adjusting the clock.

MS is the number of milliseconds, positive or negative, by which the clock should be adjusted.
CO is the control output. The function block sets CO to true after the clock is adjusted. CO is false if CI is
false or if an error is detected.

CAUTION

Triconex recommends using the TIMEADJ function block no more than once a
day. Using TIMEADJ more frequently can result in excessive time adjustments to
a network and may result in Main Processor re-education.

Example
(*
* Subtract 700 milliseconds from the clock.
*)
VAR MY_TIMEADJ : TIMEADJ ; END_VAR
VAR DO_ADJUST : BOOL ; END_VAR
MY_TIMEADJ( CI:=DO_ADJUST, MS:=-700 ) ;
DO_ADJUST := false ;

Runtime Errors
Condition

Return Value

Error Flags

If the adjusted time is before 00:00:00 on January 1, 1970 or after


23:59:59 on December 31, 2029

CO=false

BADPARAM, ERROR

TriStation 1131 Libraries Reference

362

Chapter 2

Functions and Data Types

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TIMESET

363

TIMESET
Sets the calendar clock.

Syntax
MY_TIMESET( CI:=b1, GMT:=n1, MS:=n2 ) ;

Table 394

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TIMESET.

GMT

DINT

The number of seconds elapsed since 00:00:00 Greenwich mean time, January 1, 1970.
GMT must be a positive number.

MS

DINT

The number of milliseconds (0999) past the time given in GMT.

Table 395

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TIMESET executes successfully.

Description
The TIMESET function block sets the calendar clock to the time given in GMT and MS.
CI is the control input. Call the function block with CI=true to set the calendar clock. Then change CI to
false for the next evaluation.

Note

You must clear CI to 0 (False) after adjusting the clock.

GMT is the Greenwich mean time given in number of seconds elapsed since 00:00:00 on January 1, 1970.
GMT must be a positive number.
MS is the number of milliseconds (0-999) past the time given in GMT.
CO is the control output. CO=true indicates that the time was successfully set. CO=false indicates that the
time was not set. CO is false if an error is detectedfor example, if MS is less than 0 or greater than 999.
As a general rule, do not set the time back to previous dates.

CAUTION

Triconex recommends using the TIMESET function no more than once a day.
Using TIMESET more frequently can result in excessive time adjustments to a
network and may result in Main Processor re-education. Tricon version 9
systems do not allow you to set the time to a date earlier than December 31, 1993.

TriStation 1131 Libraries Reference

364

Chapter 2

Functions and Data Types

Example
(*
* Set the time and date
* to 18:43:53 on February 24, 2003
* plus 160 milliseconds.
*)
VAR MY_TIMESET : TIMESET ; END_VAR
VAR SET_THE_TIME : BOOL ; END_VAR
MY_TIMESET( CI:=SET_THE_TIME, GMT:=1046112233, MS:=160 ) ;
SET_THE_TIME := false ;

Runtime Errors
Condition

Return Value

Error Flags

If GMT or MS is out of range

CO=false

BADPARAM, ERROR

The range of GMT is 0 <= GMT <= 1893455999 seconds, which represents 00:00:00 on January 1, 1970 to
23:59:59 on December 31, 2029.
The range of MS is 0 <= MS <= 999 milliseconds.
Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TMR

365

TMR
Provides a timer to replace the functionality of the TMR coil in TriStation MSW.

Syntax
MY_TMR( IN:=b1, RESET:=b2, PT:=t1, IT:=t2 ) ;

Table 396

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables TMR.

RESET

BOOL

Resets TMR.

PT

TIME

The preset time.

IT

TIME

The initial time.

Table 397

Output Parameters

Name

Data Type

Description

BOOL

The current state.

ET

TIME

The elapsed time accumulator.

Description
The TMR function block replaces the functionality of the TMR coil in TriStation MSW.
While the input IN is true, the timer increments the elapsed time accumulator until its value is greater
than or equal to the preset time (input PT). After the preset time is reached, the output Q remains true
until reset.
RESET clears Q and copies IT to ET.
Input IN adds the previous scan period to ET. If IN is true and ET is greater than or equal to PT, then the
function block copies PT to ET and sets Q. If IN is false, then ET holds its current value until reset
PT is the preset time which means the timer expires when ET is greater than or equal to PT.
IT is the initial time that is loaded into ET. The default initial value is T#0s.
Q indicates when the timer expires. Q is set to true when ET increases to PT or beyond. RESET clears Q.
ET is the elapsed time during which input IN is true.

TriStation 1131 Libraries Reference

366

Chapter 2

Functions and Data Types

Example
VAR MY_TMR : TMR ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TMR( IN:=b1, RESET:=NOT b1, PT:=T#10s ) ;
b2 := MY_TMR.Q ;
(* result: The delay time is about 10 seconds from the rising edge of b1 to the rising
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TMR_I

367

TMR_I
Provides a timer to replace the functionality of the TMR coil in TriStation MSW.

Syntax
MY_TMR_I( IN:=b1, RESET:=b2, PT:=n1 ) ;

Table 398

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables TMR_I.

RESET

BOOL

Resets TMR_I.

PT

DINT

The preset time in milliseconds.

Table 399

Output Parameters

Name

Data Type

Description

BOOL

The current state.

ET

DINT

The elapsed time accumulator in milliseconds.

Description
The TMR_I function block replaces the functionality of the TMR coil in TriStation MSW. It differs from
TMR in that the time is in milliseconds.
While the input IN is true, the timer increments the elapsed time accumulator until its value is greater
than or equal to the preset time (input PT). After the preset time is reached, the output Q remains true
until reset.
RESET clears Q and resets ET to 0.
Input IN adds the previous scan period to ET. If IN is true and ET is greater than or equal to PT, then the
function block copies PT to ET and sets Q. If IN is false, then ET holds its current value until reset
PT is the preset time in milliseconds which means the timer expires when ET is greater than or equal to
PT.
Q indicates when the timer expires. Q is set to true when ET increases to PT or beyond. RESET clears Q.
ET accumulates the elapsed time in milliseconds while input IN is true. ET starts at 0 milliseconds. While
input IN is true, the timer adds the previous scan period to ET until its value is greater than or equal to
PT. After the preset time is reached, the timer sets ET equal to PT.

Note

If PT is within one scan period of 2147483647 milliseconds (25 days), then the elapsed time
accumulator can overflow to a negative value.

You must invoke an instance of TMR_I exactly once per scan.

TriStation 1131 Libraries Reference

368

Chapter 2

Functions and Data Types

Example
VAR MY_TMR_I : TMR_I ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TMR_I( IN:=b1, RESET:=NOT b1, PT:=10000 ) ;
b2 := MY_TMR_I.Q ;
(* result: The delay time is about 10 seconds from the rising edge of b1 to the rising
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TMR_R

369

TMR_R
Provides a timer to replace the functionality of the TMR coil in TriStation MSW.

Syntax
MY_TMR_R( IN:=b1, RESET:=b2, PT:=x1 ) ;

Table 400

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables TMR_I.

RESET

BOOL

Resets TMR_I.

PT

REAL

The preset time in seconds.

Table 401

Output Parameters

Name

Data Type

Description

BOOL

The current state.

ET

REAL

The elapsed time accumulator in seconds.

Description
The TMR_R function block replaces the functionality of the TMR coil in TriStation MSW. It differs from
TMR in that the time is in seconds.
While the input IN is true, the timer increments the elapsed time accumulator until its value is greater
than or equal to the preset time (input PT). After the preset time is reached, the output Q remains true
until reset.
RESET clears Q and resets ET to 0.0.
Input IN adds the previous scan period to ET. If IN is true and ET is greater than or equal to PT, then the
function block copies PT to ET and sets Q. If IN is false, then ET holds its current value until reset
PT is the preset time in milliseconds which means the timer expires when ET is greater than or equal to
PT.
Q indicates when the timer expires. Q is set to true when ET increases to PT or beyond. RESET clears Q.
ET accumulates the elapsed time in seconds while input IN is true. ET starts at 0.0 seconds. While input
IN is true, the timer adds the previous scan period to ET until its value is greater than or equal to PT. After
the preset time is reached, the timer sets ET equal to PT.
You must invoke an instance of TMR_R exactly once per scan.

Note

The rounding error in the elapsed time accumulator increases with time until the accumulator
eventually stops. The rounding error in seconds is less than ET ET (50,000,000 T), where ET
is the elapsed time in seconds and T is the scan period in seconds. The elapsed time accumulator
stops after ET > 16,000,000 T. For example, if the scan period is 20 milliseconds, then after one
hour, the rounding error is less than 13 seconds.

TriStation 1131 Libraries Reference

370

Chapter 2

Functions and Data Types

Example
VAR MY_TMR_R : TMR_R ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TMR_R( IN:=b1, RESET:=NOT b1, PT:=10.0 ) ;
b2 := MY_TMR_R.Q ;
(* result: The delay time is about 10 seconds from the rising edge of b1 to the rising
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TOD

371

TOD
A TOD data type refers to a specific time of day expressed in hours, minutes, seconds, and fractions (FFF)
of a second. The precision is 0.001 seconds.
A TOD data type cannot be used as a program input or output.
Attribute

Description

Keyword/type

TOD

Description

Time of day

Size

64 bits

Syntax

TOD#HH:MM:SS
or
TOD#HH:MM:SS.FFF
or
TIME_OF_DAY#HH:MM:SS

Default value

TOD#00:00:00

Lower limit

TOD#00:00:00

Upper limit

TOD#23:59:59.999

Result if intermediate value is less than lower limit

V modulo 24 hours

Result if upper limit is less than intermediate value

V modulo 24 hours

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause, Effect, and Intersection cells.

TriStation 1131 Libraries Reference

372

Chapter 2

Functions and Data Types

TOF
Delays the falling edge of a pulse.

Syntax
MY_TOF( IN:=b1, PT:=t1 ) ;

Table 402

Input Parameters

Name

Data Type

Description

IN

BOOL

The input pulse.

PT

TIME

The pulse time.

Table 403

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

ET

TIME

The elapsed time.

Description
The TOF function block provides a delay of duration PT from the falling edge of input IN to the falling
edge of output Q.
IN is the input pulse. The falling edge of IN starts the timer. While IN is false, after a delay of duration
PT, the timer changes Q to false. If at any time the input IN changes to true, the timer resets, changing Q
to true and ET to zero.
PT gives the duration of the delay.
Q is the output pulse. Q is initially true. Q changes from true to false after the specified delay time. Q
changes from false to true when the input changes from false to true.

TriStation 1131 Libraries Reference

TOF

373

ET gives the elapsed time from the falling edge of IN, while IN is false and Q is true. While IN is false and
Q is false, ET is equal to PT. If IN is true, then ET is zero.

If input IN is true, then TOF sets output Q to true and the elapsed time to zero. If the width of input IN is
less than PT, then output Q does not change, but while IN is false, output ET still gives the elapsed time
since the falling edge of input IN.

If the initial value of input IN is false, then the timer does not start and Q remains false until input IN
changes to true.

TriStation 1131 Libraries Reference

374

Chapter 2

Functions and Data Types

Example
VAR MY_TOF : TOF ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TOF( IN:=b1, PT:=T#10s ) ;
b2 := MY_TOF.Q ;
(* result: The delay time is about 10 seconds from the falling edge of b1 to the falling
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TOGGLE

375

TOGGLE
Replaces the functionality of the TGL coil in TriStation MSW.

Syntax
MY_TOGGLE( IN:=b1, RESET:=b2 ) ;

Table 404

Input Parameters

Name

Data Type

Description

IN

BOOL

Enables TOGGLE.

RESET

BOOL

Resets TOGGLE.

Table 405

Output Parameters

Name

Data Type

Description

BOOL

The current state.

Description
The TOGGLE function block replaces the functionality of the TGL coil in TriStation MSW.
IN toggles Q if RESET is false. Toggle means to change the state, that is, from false to true or true to false.
RESET resets Q (to false).
Q is the output that toggles.

Table 406

Truth Table

IN

RESET

false

false

no change

false

true

false

true

false

not Q

true

true

false

Example
VAR MY_TOGGLE : TOGGLE ; END_VAR
MY_TOGGLE( IN:=FALSE, RESET:=TRUE
MY_TOGGLE( IN:=FALSE, RESET:=FALSE
MY_TOGGLE( IN:=TRUE,
RESET:=TRUE
MY_TOGGLE( IN:=TRUE,
RESET:=FALSE
MY_TOGGLE( IN:=FALSE, RESET:=FALSE
MY_TOGGLE( IN:=TRUE,
RESET:=FALSE

);
);
);
);
);
);

(*
(*
(*
(*
(*
(*

Q
Q
Q
Q
Q
Q

is
is
is
is
is
is

FALSE
FALSE
FALSE
TRUE
TRUE
FALSE

*)
*)
*)
*)
*)
*)

Runtime Errors
None.

TriStation 1131 Libraries Reference

376

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TON

377

TON
Delays the rising edge of a pulse.

Syntax
MY_TON( IN:=b1, PT:=t1 ) ;

Table 407

Input Parameters

Name

Data Type

Description

IN

BOOL

The input pulse.

PT

TIME

The pulse time.

Table 408

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

ET

TIME

The elapsed time.

Description
The TON function block provides a delay of duration PT from the rising edge of input IN to the rising
edge of output Q.
IN is the input pulse. The rising edge of IN starts the timer. While IN is true, after a delay of duration PT,
the timer changes Q to true. If at any time the input IN changes to false, the timer resets, changing Q to
false and ET to zero.
PT gives the duration of the delay.
Q is the output pulse. Q is initially false. Q changes from false to true after the specified delay time. Q
changes from true to false when the input changes from true to false.

Output ET (elapsed time) gives the time since the rising edge of input IN. The maximum value of ET is PT.

TriStation 1131 Libraries Reference

378

Chapter 2

Functions and Data Types

ET gives the elapsed time from the rising edge of IN, while IN is true and Q is false. While IN is true and
Q is true, ET is equal to PT. If IN is false, then ET is zero.

If the width of input IN is less than PT, then output Q does not change.

Example
VAR MY_TON : TON ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TON( IN:=b1, PT:=T#10s ) ;
b2 := MY_TON.Q ;
(* result: The delay time is about 10 seconds from the rising edge of b1 to the rising
edge of b2. *)

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TP

379

TP
Generates a timed pulse.

Syntax
MY_TP( IN:=b1, PT:=t1 ) ;

Table 409

Input Parameters

Name

Data Type

Description

IN

BOOL

The input pulse.

PT

TIME

The pulse time.

Table 410

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

ET

TIME

The elapsed time.

Description
The TP function block generates a pulse of duration PT starting on the rising edge of input IN.
IN is an input pulse. The rising edge of IN starts the timer, setting Q to true. While Q is true, the timer
ignores IN.
PT gives the requested duration of the pulse. When Q is true and ET is greater than or equal to PT, the
timer resets Q to false.
Q is the output pulse. The timer sets Q true on the rising edge of IN. Q remains true for time PT, and then
changes to false.
ET is the elapsed time from the rising edge of Q while Q is true. After the falling edge of Q, ET is equal to
PT while input IN remains true. ET is zero if IN and Q are both false.

Example
VAR MY_TP : TP ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TP( IN:=b1, PT:=T#10s ) ;
b2 := MY_TP.Q ;
(* The result b2 is a pulse of approximately 10 seconds following the rising edge of
b1. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

380

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Only Once: each instance should be executed only once per scan, but does not need to be
executed every scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TP_I

381

TP_I
Generates a timed pulse.

Syntax
MY_TP_I( IN:=b1, PT:=n1 ) ;

Table 411

Input Parameters

Name

Data Type

Description

IN

BOOL

The input pulse.

PT

DINT

The pulse time in milliseconds.

Table 412

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

Description
The TP_I function block generates a pulse of width PT milliseconds starting on the rising edge of input IN.
IN is an input pulse. The rising edge of IN starts the timer, setting Q to true. While Q is true, the timer
ignores IN.
PT gives the requested duration of the pulse in milliseconds. When Q is true and the pulse width is
greater than or equal to PT milliseconds, the timer resets Q to false.
Q is the output pulse. The timer sets Q true on the rising edge of IN. Q remains true for time PT
milliseconds, and then changes to false.

Note

If PT is within one scan period of 2147483647 milliseconds (25 days), then the time accumulator
can overflow to a negative value.

You must invoke an instance of TP_I exactly once per scan.

Example
VAR MY_TP_I : TP_I ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TP_I( IN:=b1, PT:=10000 ) ;
b2 := MY_TP_I.Q ;
(* The result b2 is a pulse of approximately 10 seconds following the rising edge of
b1. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

382

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TP_R

383

TP_R
Generates a timed pulse.

Syntax
MY_TP_R( IN:=b1, PT:=x1 ) ;

Table 413

Input Parameters

Name

Data Type

Description

IN

BOOL

The input pulse.

PT

REAL

The pulse time in seconds.

Table 414

Output Parameters

Name

Data Type

Description

BOOL

The output pulse.

Description
The TP_R function block generates a pulse of width PT seconds starting on the rising edge of input IN.
IN is an input pulse. The rising edge of IN starts the timer, setting Q to true. While Q is true, the timer
ignores IN.
PT gives the requested duration of the pulse in seconds. When Q is true and the pulse width is greater
than or equal to PT seconds, the timer resets Q to false.
Q is the output pulse. The timer sets Q true on the rising edge of IN. Q remains true for time PT seconds,
and then changes to false.
You must invoke an instance of TP_R exactly once per scan.

Note

The rounding error in the time accumulator increases with time until the accumulator eventually
stops. The rounding error in seconds is less than ACC ACC (50,000,000 T), where ACC is
the accumulated time in seconds and T is the scan period in seconds. The accumulator stops after
ACC > 16,000,000 T. For example, if the scan period is 20 milliseconds, then after one hour, the
rounding error is less than 13 seconds.

Example
VAR MY_TP_R : TP_R ; END_VAR
VAR b1, b2 : BOOL ; END_VAR
MY_TP_R( IN:=b1, PT:=10.0 ) ;
b2 := MY_TP_R.Q ;
(* The result b2 is a pulse of approximately 10 seconds following the rising edge of
b1. *)

Runtime Errors
None.

TriStation 1131 Libraries Reference

384

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Can be used in CEM Cause, Effect, and Intersection cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TR_64_POINT_STATUS

385

TR_64_POINT_STATUS
Gets point information, specifically LOAD/FUSE and diagnostic status for up to 64 points, from a Tricon
controller.

Syntax
MY_TR_64_POINT_STATUS( CI:=b1, CHASSIS:=n1, SLOT:=n2 ) ;

Table 415

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_64_POINT_STATUS.

CHASSIS

DINT

The chassis number.

SLOT

DINT

The physical slot number.

Table 416

Output Parameters

Name

Data Type

Description

CO

BOOL

False if the chassis or the slot is invalid.

FUSE_01_32

DWORD

The status of a point on a module (point 01 is least significant bit, point 32 is


most significant bit).
0 =Good point
1 =Bad point

FUSE_33_64

DWORD

The status of a point on a module (point 33 is least significant bit, point 64 is


most significant bit).

FAULT_01_32

DWORD

The diagnostic status of a point on a module (point 01 is least significant bit,


point 32 is most significant bit).
If an output module:
0 = Point passed output voter diagnostic (OVD) most significant bit.
1 = Point failed OVD.
If an input module:
0 =Point passed the compare test.
1 =Point failed the compare test.

FAULT_33_64

DWORD

The diagnostic status of a point on a module (point 33 is least significant bit,


point 64 is most significant bit).

Description
The TR_64_POINT_STATUS function block gets point information, specifically LOAD/FUSE and
diagnostic status for up to 64 points, from a Tricon controller.

TriStation 1131 Libraries Reference

386

Chapter 2

Functions and Data Types

Example
(* Get the status for chassis 1 slot 5. *)
VAR MY_TR_64_POINT_STATUS : TR_64_POINT_STATUS ; END_VAR
MY_TR_64_POINT_STATUS( CI:=TRUE, CHASSIS:=1, SLOT:=5 ) ;

Runtime Errors
Condition

Return Value

Error Flags

If the chassis or slot is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_CALENDAR

387

TR_CALENDAR
Gets calendar values from a Tricon controller.

Syntax
MY_TR_CALENDAR( CI:= b1 ) ;

Table 417

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_CALENDAR.

Table 418

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_CALENDAR executes successfully.

YEAR

DINT

The year (for example, 1998).

MONTH

DINT

The month (112).

DAY

DINT

The day of the month (131).

HOUR

DINT

The hour (023).

MINUTE

DINT

The minute (059).

SECOND

DINT

The second (059).

MILLISEC

DINT

The millisecond (0999).

WEEKDAY

DINT

The day of the week (06, 0=Sunday).

RELSEC

DINT

The seconds since Jan 01 1970 00:00:00.

Description
The TR_CALENDAR function block gets the date and time from a Tricon controller.

Example
(*
* Get the current day of the month.
*)
VAR NOW : TR_CALENDAR ; END_VAR
VAR TODAY : DINT ; END_VAR
NOW() ;
TODAY := NOW.DAY

Runtime Errors
None.

TriStation 1131 Libraries Reference

388

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_CHASSIS_STATUS

389

TR_CHASSIS_STATUS
Gets the chassis status from a Tricon controller.

Syntax
MY_TR_CHASSIS_STATUS( CI:=b1, CHASSIS:=n1 ) ;

Table 419

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_CHASSIS_STATUS.

CHASSIS

DINT

The chassis number.

Table 420

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_CHASSIS_STATUS executes successfully.

MAINTENANCE

BOOL

True if the chassis requires maintenance.

UPPERPOWER

BOOL

True if the upper power supply in the chassis has a fault.

LOWERPOWER

BOOL

True if the lower power supply in the chassis has a fault.

IOFAULT

BOOL

True if an active module in the chassis has a fault.

Description
The TR_CHASSIS_STATUS function block gets the chassis status from a Tricon controller.

Example
(* Get the status for chassis 3. *)
VAR MY_TR_CHASSIS_STATUS : TR_CHASSIS_STATUS ; END_VAR
MY_TR_CHASSIS_STATUS( CHASSIS:=3 ) ;

Runtime Errors
Condition

Return Value

Error Flags

If the chassis number is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

390

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_CLEAR_FLTS

391

TR_CLEAR_FLTS
Clears all faults in the system.

Syntax
ERROR_NUMBER := TR_CLEAR_FLTS( CLEAR_FLTS := TRUE );

Table 421

Input Parameters

Name

Data Type

Description

CLEAR_FLTS

BOOL

Clears fault alarms.

Table 422

Return Value

Data Type

Description

DINT

If zero, the function is successful.


If -1, the function is unsuccessful because the TSX version does not support this feature. Only
available with Tricon v10 and later systems.

Description
The TR_CLEAR_FLTS function clears all alarms from the system. If the input is true, all alarms are
cleared.

Example
(* Clear fault alarms. *)
VAR ERROR_NUMBER : DINT ; END_VAR
ERROR_NUMBER := TR_CLEAR_FLTS( CLEAR_FLTS := TRUE );

Runtime Errors
Condition

Return Value

Error Flags

If the system is not Tricon v10 or later, the function is not supported.

-1

BADPARAM

Upon detection of a runtime error, the function resets ENO and sets the BADPARAM status flag. For
more information about error flags and runtime errors, see the CHK_ERR function block.

Application Notes
Can be used in Safety or Control applications.

Library
Tricon (TX1LIB)
This function was added to the library in v1.62 of TX1LIB, first released with TriStation 1131 v4.1.419.

TriStation 1131 Libraries Reference

392

Chapter 2

Functions and Data Types

TR_CRITICAL_IO
Accumulates the status of safety-critical I/O modules in a Tricon controller.

Syntax
MY_TR_CRITICAL_IO( CI:=b1, INIT:=b2, CHASSIS:=n1, SLOT:=n2, APP:=n3, RELAY_OK:=b3 ) ;

Table 423

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_CRITICAL_IO.

INIT

BOOL

Initializes TR_CRITICAL_IO.

CHASSIS

DINT

The chassis number (115).

SLOT

DINT

The physical slot number.

APP

DINT

The application number (1-2).

RELAY_OK

BOOL

The relay is energized and not stuck.

Table 424

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_CRITICAL_IO executes successfully.

TMR

BOOL

Three channels are operating without fatal faults on critical I/O modules
detected.

GE_DUAL

BOOL

Two channels are operating without fatal faults on critical I/O modules
detected.

GE_SINGLE

BOOL

At least one channel is operating without faults on critical I/O modules


detected.

NO_VOTER_FLTS

BOOL

No voter faults on critical I/O modules detected.

ERROR

DINT

Error Number:
0 =No error.
1 The slot is not odd or not numbered 115.
2 =Invalid chassis or slot.
3 =The module is not configured.
5 =An invalid application number is used.
6 =Not initialized.

Description
The TR_CRITICAL_IO function block accumulates the status of all safety-critical I/O modules in a Tricon
controller. For more information, see the Safety Considerations Guide for Tricon Systems.

Instructions for Use


The following instructions for using the TR_CRITICAL_IO function block apply to the Structured Text
(ST) language.

TriStation 1131 Libraries Reference

TR_CRITICAL_IO

393

To obtain the accumulated status of critical I/O modules:


1

Initialize TR_CRITICAL_IO by invoking it once with INIT := TRUE.

To complete initialization, invoke TR_CRITICAL_IO again with these input settings:

INIT := FALSE

CI := TRUE

APP := DE_ENERGIZED

RELAY_OK := FALSE

To get the status of all safety-critical I/O modules, invoke each module by specifying these input
values:

CHASSIS

SLOT

APP

RELAY_OK

If CHASSIS 1 SLOT 1 is a critical DI module, and CHASSIS 1 SLOT 2 is a critical DO module with
a relay, then this example applies. SCIO is the function block instance name:
SCIO(CHASSIS:=1,SLOT:=1,APP:=DE-ENERGIZED,RELAY_OK:=FALSE);
SCIO(CHASSIS:=1,SLOT:=2,APP:=RELAY,RELAY_OK:=RELAY1_OK);

Read the output values:

CO

TMR

GE_DUAL

GE_SINGLE

NO_VOTER_FAULTS

The output values are an accumulation of the status of all critical I/O modules. For example, the
output called TMR is true if all of the critical modules in the system are in TMR mode.

Example
For shutdown examples, see this sample project:

Note

ExTUV.pt2 (For Tricon controllers)


See Sample Projects on page 7 for information about where to find this project on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If ERROR is non-zero

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

394

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_MP_STATUS

395

TR_MP_STATUS
Gets the status of the Main Processor.

Syntax
MY_TR_MP_STATUS( CI:=b1 ) ;

Table 425

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_MP_STATUS.

Table 426

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_MP_STATUS executes successfully.

MPMAIN

BOOL

At least one MP is out-of-sync or has failed.

MPBAD

BOOL

Two MPs are out-of-sync or have failed, or the controller is running in simplex
mode.

IOMAIN

BOOL

One of these conditions is true:


One channel of an I/O module is reporting a major or fatal error.
The communication to a channel of an I/O module has failed.
At least one MP is out-of-sync or has failed.

IOBAD

BOOL

One of these conditions is true:


A channel of a digital output module has an OVD error followed by a failure of
an MP.
A channel of a digital output module has an OVD error and a channel of the
same module has a bad module error.
Channel x of an I/O module has a bad module error and MP y has failed,
where x < > y.
Two MPs have failed and/or are out-of- sync.
Two channels of an I/O module have bad module errors.

Description
The TR_MP_STATUS function block gets the status of the Main Processor.

Example
(* Get the main processor status. *)
VAR MY_TR_MP_STATUS : TR_MP_STATUS ; END_VAR
MY_TR_MP_STATUS() ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

396

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_PEER_STATUS 397

TR_PEER_STATUS
Gets the Peer-to-Peer status of a node.

Syntax
MY_TR_PEER_STATUS( CI:=b1, NODE:=n1 ) ;

Table 427

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_PEER_STATUS.

NODE

DINT

The node number.

Table 428

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_PEER_STATUS executes successfully.

COMM_OK

BOOL

One path going to the specified node from this node is OK.

COMM_REDUNDANT

BOOL

Two paths going to the specified node from this node are OK.

Description
The TR_PEER_STATUS function block gets the Peer-to-Peer status of a node.

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If the node number is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

398

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_POINT_STATUS 399

TR_POINT_STATUS
Gets the status of a point from a Tricon controller.

Syntax
MY_TR_POINT_STATUS( CI:=b1, CHASSIS:=n1, SLOT:=n2, POINT:=n3 ) ;

Table 429

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_POINT_STATUS.

CHASSIS

DINT

The chassis number.

SLOT

DINT

The physical slot number.

POINT

DINT

The point number.

Table 430

Output Parameters

Name

Data Type

Description

CO

BOOL

False if chassis, slot, or point is invalid.

LOADFUSE

BOOL

The output point has a fault and the load/fuse indicator on the module is on.

FAULT

BOOL

The output point has an OVD failure or an input point has a compare error.

Description
The TR_POINT_STATUS function block gets the status of a point from a Tricon controller.

Example
(* Get the status for chassis 1 slot 5 point 7. *)
VAR MY_TR_POINT_STATUS : TR_POINT_STATUS ; END_VAR
MY_TR_POINT_STATUS( CI:=TRUE, CHASSIS:=1, SLOT:=5, POINT:=7 ) ;

Runtime Errors
Condition

Return Value

Error Flags

If the chassis, slot, or point is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

TriStation 1131 Libraries Reference

400

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_PORT_STATUS

401

TR_PORT_STATUS
Gets the status of a Tricon Communication Module (TCM), Network Communication Module (NCM), or
an Advanced Communication Module (ACM).

Syntax
MY_TR_PORT_STATUS( CI:=b1 ) ;

Table 431

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_PORT_STATUS.

Table 432

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_PORT_STATUS executes successfully.

ICM_P5_OVFL

BOOL

The printer on port 5 has a buffer overflow.

ICM_P10_OVFL

BOOL

The printer on port 10 has a buffer overflow.

ICM_P5_RDY

BOOL

The printer on port 5 is ready.

ICM_P10_RDY

BOOL

The printer on port 10 is ready.

NCM_NET1L_OK

BOOL

Port 1 of a communication module in the left slot is operational.

NCM_NET2L_OK

BOOL

Port 2 of a communication module in the left slot is operational.

NCM_NET1R_OK

BOOL

Port 1 of a communication module in the right slot is. operational.

NCM_NET2R_OK

BOOL

Port 2 of a communication module in the right slot is operational.

Description
The TR_PORT_STATUS function block gets the status of aTricon Communication Module (TCM),
Network Communication Module (NCM), or an Advanced Communication Module (ACM). The NET1
status is not used with the ACM. When there is more than one communication module installed, and both
are in the same type of slot (left or right), the corresponding status (NET1L/NET2L, and NET1R/NET2R,
respectively) are not defined.

Example
(* Get the port status. *)
VAR MY_TR_PORT_STATUS : TR_PORT_STATUS ; END_VAR
MY_TR_PORT_STATUS() ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

402

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_PROGRAM_STATUS

403

TR_PROGRAM_STATUS
Gets the status of a Tricon program.

Syntax
MY_TR_PROGRAM_STATUS( CI:=b1 ) ;

Table 433

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_PROGRAM_STATUS.

Table 434

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_PROGRAM_STATUS executes successfully.

MAJOR_VERSION

DINT

The major version number of a program.

MINOR_VERSION

DINT

The minor version number of a program.

WRITE_ENABLED

BOOL

True if write access from an external host is enabled for any


ALIAS.

DISABLE_NOT_ALLOWED

BOOL

True if a program does not allow disabling of points.

POINTS_DISABLED

DINT

The number of points currently disabled.

Description
The TR_PROGRAM_STATUS function block gets the status of a program.
When DISABLE_NOT_ALLOWED is false (0), a user can disable points, and a program instance calls a
function to store the value of an output point.
When DISABLE_NOT_ALLOWED is true (1), a user cannot disable points and the scan time is shorter
because a program instance stores the value of an output point without calling a function.

Example
(* Get the program status. *)
VAR MY_TR_PROGRAM_STATUS : TR_PROGRAM_STATUS ; END_VAR
MY_TR_PROGRAM_STATUS() ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

404

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_SCAN_STATUS

405

TR_SCAN_STATUS
Gets the status of a scan.

Syntax
MY_TR_SCAN_STATUS( CI:=b1 ) ;

Table 435

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_SCAN_STATUS.

Table 436

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_SCAN_STATUS executes successfully.

POWERUP

BOOL

The system has been powered up.

FIRSTSCAN

BOOL

The first scan of a program after a reset.

SCANREQUEST

DINT

The scan time, in milliseconds, set by the user.

SCANSURPLUS

DINT

The average surplus scan time for last 100 scans.

SCANDELTA

DINT

The measured scan time, in milliseconds, for the current scan.

DELTAT

TIME

The measured scan time for the current scan.

SCANOVERRUN

DINT

The average number of scan overruns for the last 100 scans.

KEYSWITCH

DINT

Setting:
0 =STOP
1 =PROGRAM
2 =RUN
3 =REMOTE

Description
The TR_SCAN_STATUS function block gets the status of a scan.

Example
(* Get the scan status. *)
VAR MY_TR_SCAN_STATUS : TR_SCAN_STATUS ; END_VAR
MY_TR_SCAN_STATUS() ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

406

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_SHUTDOWN

407

TR_SHUTDOWN
Enables a Tricon system shutdown according to industry guidelines.

Syntax
MY_TR_SHUTDOWN( CI:=b1, IO_CO:=b2, IO_TMR:=b3, IO_GE_DUAL:=b4, IO_GE_SINGLE:=b5,
IO_NO_VOTER_FLTS:=b6, IO_ERROR:=n1, MAX_TIME_DUAL:=t1, MAX_TIME_SINGLE:=t2,
MAX_SCAN_TIME:=t3 ) ;

Table 437

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_SHUTDOWN.

IO_CO

BOOL

True if TR_SHUTDOWN executes successfully.

IO_TMR

BOOL

Three channels are operating without fatal faults detected.

IO_GE_DUAL

BOOL

Two channels are operating without fatal faults detected.

IO_GE_SINGLE

BOOL

One channel is operating without fatal faults detected.

IO_NO_VOTER_FLTS

BOOL

No failed critical modules detected.

IO_ERROR

DINT

Zero = no error.
Non-zero = programming or configuration error.

MAX_TIME_DUAL

TIME

The maximum time of continuous operation in dual mode (two


channels operating).

MAX_TIME_SINGLE

TIME

The maximum time of continuous operation in single mode (one


channel operating).

MAX_SCAN_TIME

TIME

50% of the maximum response time.

Table 438

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_SHUTDOWN executes successfully.

OPERATING

BOOL

If false, shut down.

TMR

BOOL

Three channels are operating.

DUAL

BOOL

Two channels are operating.

SINGL

BOOL

One channel is operating.

ZERO

BOOL

No channels are operating.

TIMER_RUNNING

BOOL

The shutdown timer is running

TIME_LEFT

TIME

The time remaining to shutdown.

ALARM_PROGRAMMING_
PERMITTED

BOOL

True if application changes are permitted.

ALARM_REMOTE_ACCESS

BOOL

True if remote-host writes are enabled.

ALARM_RESPONSE_TIME

BOOL

True if actual scan time is greater than or equal to


MAX_SCAN_TIME.

TriStation 1131 Libraries Reference

408

Chapter 2

Functions and Data Types

Table 438

Output Parameters (continued)

Name

Data Type

Description

ALARM_DISABLED_POINT
S

BOOL

True if one or more points are disabled.

ERROR

DINT

Error Number:
0 No error.
1 =Error in maximum time.
2 =Error in I/O function block (IO_ERROR input is
non-zero).
3 =Error in status function block.

Description
The TR_SHUTDOWN function block enables a Tricon system shutdown according to industry
guidelines. For more information, see the Safety Considerations Guide for Tricon v9-v10 Systems.

Example
For shutdown examples, see this sample project:

Note

ExTUV.pt2 (For Tricon controllers)


See Sample Projects on page 7 for information about where to find this project on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If ERROR is non-zero

Set alarm outputs to true, reset the other BOOL


outputs to false, and reset TIME_LEFT to zero.

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.
If a programming error or configuration error occurs, then CO is false and the error number is non-zero.
For error numbers, see the description of the ERROR output.

Application Notes
Can be used in Safety or Control applications.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_SLOT_STATUS

409

TR_SLOT_STATUS
Gets the status of a Tricon controller slot.

Syntax
MY_TR_SLOT_STATUS( CI:=b1, CHASSIS:=n1, SLOT:=n2 ) ;

Table 439

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_SLOT_STATUS.

CHASSIS

DINT

The chassis number.

SLOT

DINT

The physical slot number.

Table 440

Output Parameters

Name

Data Type

Description

CO

BOOL

False if the chassis or the slot is invalid.

PASS

BOOL

I/O module is installed in the slot and the pass indicator is on.

FAIL

BOOL

An I/O module is installed in the slot and the fail indicator is on.

ACTIVE

BOOL

An I/O module is installed in the slot and the active indicator is on.

LOADFUSE

BOOL

An I/O module is installed in the slot and the load/fuse indicator is on.

INSTALLED

BOOL

An I/O module is installed and configured in the slot.

VOTER_FAULT

BOOL

An I/O module is installed in the slot and a point has a voter fault.

OVD_ENABLED

BOOL

An I/O module is installed in the slot and output voter diagnostics are
enabled.

NOGOOD

BOOL

The I/O module installed in the slot is operating in SINGLE mode for at
least one point. Please refer to the Safety Considerations Guide for Tricon v9v10 Systems for SINGLE mode SIL operation time guidelines.

Description
The TR_SLOT_STATUS function block gets the status of a Tricon controller slot.

Example
(* Get the status for chassis 1 slot 5. *)
VAR MY_TR_SLOT_STATUS : TR_SLOT_STATUS ; END_VAR
MY_TR_SLOT_STATUS( CI:=TRUE, CHASSIS:=1, SLOT:=5 ) ;

TriStation 1131 Libraries Reference

410

Chapter 2

Functions and Data Types

Runtime Errors
Condition

Return Value

Error Flags

If the chassis or slot is invalid.

CO=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_URCV_BOOL

411

TR_URCV_BOOL
Receives up to 20 data values from a matching TR_USEND_BOOL function block on another Triconex
controller.

Syntax
MY_TR_URCV_BOOL( CI:=b1, RECVID:=n1, SENDNODE:=n2, SENDID:=n3, N:=n4 ) ;

Table 441

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_URCV_BOOL.

RECVID

DINT

The unique identifier for a TR_URCV_BOOL function block (199).

SENDNODE

DINT

Specifies which node sends data to a TR_URCV_BOOL function block (163).

SENDID

DINT

The unique identifier for a matching TR_USEND_BOOL function block in a


sending controller (199).

DINT

The number of values to receive (120).

Table 442

Output Parameters

Name

Data Type

Description

NDR

BOOL

New data received.

ERROR

BOOL

True if STATUS is equal to or greater than 100.

STATUS

DINT

0=

Ready to receive data from sending controller.

1=

New data received, ready for processing.

102 = Invalid RECVID, SENDNODE, or SENDID input.


103 = Mismatched data type or number of values in SEND and RECV function calls.
105 = More than one RECV function has the same RECVID.
RD_01

BOOL

Receive data 01.

RD_20

BOOL

Receive data 20.

Description
The TR_URCV_BOOL function block receives up to 20 data values from a matching TR_USEND_BOOL
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

TriStation 1131 Libraries Reference

412

Chapter 2

Functions and Data Types

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_URCV_DINT

413

TR_URCV_DINT
Receives up to 20 data values from a matching TR_USEND_DINT function block on another Triconex
controller.

Syntax
MY_TR_URCV_DINT( CI:=b1, RECVID:=n1, SENDNODE:=n2, SENDID:=n3, N:=n4 ) ;

Table 443

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_URCV_DINT.

RECVID

DINT

The unique identifier for a TR_URCV_DINT function block (199).

SENDNODE

DINT

Specifies which node sends data to a TR_URCV_DINT function block (163).

SENDID

DINT

The unique identifier for a matching TR_USEND_DINT function block in a


sending controller (199).

DINT

The number of values to receive (120).

Table 444

Output Parameters

Name

Data Type

Description

NDR

BOOL

New data received.

ERROR

BOOL

True if STATUS is equal to or greater than 100.

STATUS

DINT

0=

Ready to receive data from sending controller.

1=

New data received, ready for processing.

102 = Invalid RECVID, SENDNODE, or SENDID input.


103 = Mismatched data type or number of values in SEND and RECV function calls.
105 = More than one RECV function has the same RECVID.
RD_01

DINT

Receive data 01.

RD_20

DINT

Receive data 20.

Description
The TR_URCV_DINT function block receives up to 20 data values from a matching TR_USEND_DINT
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

TriStation 1131 Libraries Reference

414

Chapter 2

Functions and Data Types

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_URCV_DINT_32

415

TR_URCV_DINT_32
Receives up to 32 data values from a matching TR_USEND_DINT_32 function block on another Triconex
controller.

Syntax
MY_TR_URCV_DINT_32( CI:=b1, RECVID:=n1, SENDNODE:=n2, SENDID:=n3, N:=n4 ) ;

Table 445

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_URCV_DINT_32.

RECVID

DINT

The unique identifier for a TR_URCV_DINT_32 function block (199).

SENDNODE

DINT

Specifies which node sends data to a TR_URCV_DINT_32 function block (163).

SENDID

DINT

The unique identifier for a matching TR_USEND_DINT_32 function block in a


sending controller (199).

DINT

The number of values to receive (132).

Table 446

Output Parameters

Name

Data Type

Description

NDR

BOOL

New data received.

ERROR

BOOL

True if STATUS is equal to or greater than 100.

STATUS

DINT

0=

Ready to receive data from sending controller.

1=

New data received, ready for processing.

102 = Invalid RECVID, SENDNODE, or SENDID input.


103 = Mismatched data type or number of values in SEND and RECV function calls.
105 = More than one RECV function has the same RECVID.
RD_01

DINT

Receive data 01.

RD_32

DINT

Receive data 32.

Description
The TR_URCV_DINT_32 function block receives up to 32 data values from a matching
TR_USEND_DINT_32 function block on another Triconex controller. For detailed descriptions of the
input and output parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

TriStation 1131 Libraries Reference

416

Chapter 2

Functions and Data Types

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_URCV_REAL

417

TR_URCV_REAL
Receives up to 20 data values from a matching TR_USEND_REAL function block on another Triconex
controller.

Syntax
MY_TR_URCV_REAL( CI:=b1, RECVID:=n1, SENDNODE:=n2, SENDID:=n3, N:=n4 ) ;

Table 447

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_URCV_REAL.

RECVID

DINT

The unique identifier for a TR_URCV_REAL function block (199).

SENDNODE

DINT

Specifies which node sends data to a TR_URCV_REAL function block (163).

SENDID

DINT

The unique identifier for a matching TR_USEND_REAL function block in a


sending controller (199).

DINT

The number of values to receive (120).

Table 448

Output Parameters

Name

Data Type

Description

NDR

BOOL

New data received.

ERROR

BOOL

True if STATUS is equal to or greater than 100.

STATUS

DINT

0=

Ready to receive data from sending controller.

1=

New data received, ready for processing.

102 = Invalid RECVID, SENDNODE, or SENDID input.


103 = Mismatched data type or number of values in SEND and RECV function calls.
105 = More than one RECV function has the same RECVID.
RD_01

REAL

Receive data 01.

RD_20

REAL

Receive data 20.

Description
The TR_URCV_REAL function block receives up to 20 data values from a matching TR_USEND_REAL
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

TriStation 1131 Libraries Reference

418

Chapter 2

Functions and Data Types

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_URCV_REAL_32

419

TR_URCV_REAL_32
Receives up to 32 data values from a matching TR_USEND_REAL_32 function block on another Triconex
controller.

Syntax
MY_TR_URCV_REAL_32( CI:=b1, RECVID:=n1, SENDNODE:=n2, SENDID:=n3, N:=n4 ) ;

Table 449

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_URCV_REAL_32.

RECVID

DINT

The unique identifier for a TR_URCV_REAL_32 function block (199).

SENDNODE

DINT

Specifies which node sends data to a TR_URCV_REAL_32 function block (163).

SENDID

DINT

The unique identifier for a matching TR_USEND_REAL_32 function block in a


sending controller (199).

DINT

The number of values to receive (132).

Table 450

Output Parameters

Name

Data Type

Description

NDR

BOOL

New data received.

ERROR

BOOL

True if STATUS is equal to or greater than 100.

STATUS

DINT

0=

Ready to receive data from sending controller.

1=

New data received, ready for processing.

102 = Invalid RECVID, SENDNODE, or SENDID input.


103 = Mismatched data type or number of values in SEND and RECV function calls.
105 = More than one RECV function has the same RECVID.
RD_01

REAL

Receive data 01.

RD_32

REAL

Receive data 32.

Description
The TR_URCV_REAL_32 function block receives up to 32 data values from a matching
TR_USEND_REAL_32 function block on another Triconex controller. For detailed descriptions of the
input and output parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

TriStation 1131 Libraries Reference

420

Chapter 2

Functions and Data Types

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_USEND_BOOL

421

TR_USEND_BOOL
Sends up to 20 data values to a matching TR_URCV_BOOL function block on another Triconex controller.

Syntax
MY_TR_USEND_BOOL( SENDFLG:=b1, SENDID:=n1, RECVNODE:=n2, RECVID:=n3, N:=n4, SD_01:=d1,
..., SD_20:=d20 ) ;

Table 451

Input Parameters

Name

Data Type

Description

SENDFLG

BOOL

Enables TR_USEND_BOOL.

SENDID

DINT

The unique identifier for a TR_USEND_BOOL function block (199).

RECVNODE

DINT

Specifies which controller node receives data from a TR_USEND_BOOL


function block (163).

RECVID

DINT

The unique identifier for a matching TR_URCV_BOOL function block in a


receiving controller (199).

DINT

The number of values to send (120).

SD_01

BOOL

Send data 01.

SD_20

BOOL

Send data 20.

Table 452

Output Parameters

Name

Data Type

Description

SENT

BOOL

Send initiated (STATUS = 1 or 4).

ACK

BOOL

Send acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

0=

Connected to a controller node, ready to SEND.

1=

SEND initiated with SENDFLG set to 1.

2=

SEND function is busy sending data.

3=

Last SEND completed (receiving node has received SEND data).

4=

SEND completed and new SEND initiated.

100 = Not connected to controller node.


101 = Last SEND failed (communication problem with receiving node).
102 = Invalid SENDID, RECVNODE, or RECVID input.
103 = Mismatched data type or number of values in SEND and RECV function calls.
104 = Number of values specified by input N is out of range.
105 = More than one SEND function has same SENDID.

TriStation 1131 Libraries Reference

422

Chapter 2

Functions and Data Types

Description
The TR_USEND_BOOL function block sends up to 20 data values to a matching TR_URCV_BOOL
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_USEND_DINT

423

TR_USEND_DINT
Sends up to 20 data values to a matching TR_URCV_DINT function block on another Triconex controller.

Syntax
MY_TR_USEND_DINT( SENDFLG:=b1, SENDID:=n1, RECVNODE:=n2, RECVID:=n3, N:=n4, SD_01:=d1,
..., SD_20:=d20 ) ;

Table 453

Input Parameters

Name

Data Type

Description

SENDFLG

BOOL

Enables TR_USEND_DINT.

SENDID

DINT

The unique identifier for a TR_USEND_DINT function block (199).

RECVNODE

DINT

Specifies which controller node receives data from a TR_USEND_DINT function


block (163).

RECVID

DINT

The unique identifier for a matching TR_URCV_DINT function block in a


receiving controller (199).

DINT

The number of values to send (120).

SD_01

DINT

Send data 01.

SD_20

DINT

Send data 20.

Table 454

Output Parameters

Name

Data Type

Description

SENT

BOOL

Send initiated (STATUS = 1 or 4).

ACK

BOOL

Send acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

0=

Connected to a controller node, ready to SEND.

1=

SEND initiated with SENDFLG set to 1.

2=

SENDFLGSEND function is busy sending data.

3=

Last SEND completed (receiving node has received SEND data).

4=

SEND completed and new SEND initiated.

100 = Not connected to controller node.


101 = Last SEND failed (communication problem with receiving node).
102 = Invalid SENDID, RECVNODE, or RECVID input.
103 = Mismatched data type or number of values in SEND and RECV function calls.
104 = Number of values specified by input N is out of range.
105 = More than one SEND function has same SENDID.

TriStation 1131 Libraries Reference

424

Chapter 2

Functions and Data Types

Description
The TR_USEND_DINT function block ends up to 20 data values to a matching TR_URCV_DINT function
block on another Triconex controller. For detailed descriptions of the input and output parameters, see
Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_USEND_DINT_32

425

TR_USEND_DINT_32
Sends up to 32 data values to a matching TR_URCV_DINT_32 function block on another Triconex
controller.

Syntax
MY_TR_USEND_DINT_32( SENDFLG:=b1, SENDID:=n1, RECVNODE:=n2, RECVID:=n3, N:=n4,
SD_01:=d1, ..., SD_32:=d32 ) ;

Table 455

Input Parameters

Name

Data Type

Description

SENDFLG

BOOL

Enables TR_USEND_DINT_32.

SENDID

DINT

The unique identifier for a TR_USEND_DINT_32 function block (199).

RECVNODE

DINT

Specifies which controller node receives data from a TR_USEND_DINT_32


function block (163).

RECVID

DINT

The unique identifier for a matching TR_URCV_DINT_32 function block in a


receiving controller (199).

DINT

The number of values to send (132).

SD_01

DINT

Send data 01.

SD_32

DINT

Send data 32.

Table 456

Output Parameters

Name

Data Type

Description

SENT

BOOL

Send initiated (STATUS = 1 or 4).

ACK

BOOL

Send acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

0=

Connected to a controller node, ready to SEND.

1=

SEND initiated with SENDFLG set to 1.

2=

SEND function is busy sending data.

3=

Last SEND completed (receiving node has received SEND data).

4=

SEND completed and new SEND initiated.

100 = Not connected to controller node.


101 = Last SEND failed (communication problem with receiving node).
102 = Invalid SENDID, RECVNODE, or RECVID input.
103 = Mismatched data type or number of values in SEND and RECV function calls.
104 = Number of values specified by input N is out of range.
105 = More than one SEND function has same SENDID.

TriStation 1131 Libraries Reference

426

Chapter 2

Functions and Data Types

Description
The TR_USEND_DINT_32 function block sends up to 32 data values to a matching TR_URCV_DINT_32
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_USEND_REAL

427

TR_USEND_REAL
Sends up to 20 data values to a matching TR_URCV_REAL function block on another Triconex controller.

Syntax
MY_TR_USEND_REAL( SENDFLG:=b1, SENDID:=n1, RECVNODE:=n2, RECVID:=n3, N:=n4, SD_01:=d1,
..., SD_20:=d20 ) ;

Table 457

Input Parameters

Name

Data Type

Description

SENDFLG

BOOL

Enables TR_USEND_REAL.

SENDID

DINT

The unique identifier for a TR_USEND_REAL function block (199).

RECVNODE

DINT

Specifies which controller node receives data from a TR_USEND_REAL function


block (163).

RECVID

DINT

The unique identifier for a matching TR_URCV_REAL function block in a


receiving controller (199).

DINT

The number of values to send (120).

SD_01

REAL

Send data 01.

SD_20

REAL

Send data 20.

Table 458

Output Parameters

Name

Data Type

Description

SENT

BOOL

Send initiated (STATUS = 1 or 4).

ACK

BOOL

Send acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

0=

Connected to a controller node, ready to SEND.

1=

SEND initiated with SENDFLG set to 1.

2=

SEND function is busy sending data.

3=

Last SEND completed (receiving node has received SEND data).

4=

SEND completed and new SEND initiated.

100 = Not connected to controller node.


101 = Last SEND failed (communication problem with receiving node).
102 = Invalid SENDID, RECVNODE, or RECVID input.
103 = Mismatched data type or number of values in SEND and RECV function calls.
104 = Number of values specified by input N is out of range.
105 = More than one SEND function has same SENDID.

TriStation 1131 Libraries Reference

428

Chapter 2

Functions and Data Types

Description
The TR_USEND_REAL function block sends up to 20 data values to a matching TR_URCV_REAL
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_USEND_REAL_32

429

TR_USEND_REAL_32
Sends up to 32 data values to a matching TR_URCV_REAL_32 function block on another Triconex
controller.

Syntax
MY_TR_USEND_REAL_32( SENDFLG:=b1, SENDID:=n1, RECVNODE:=n2, RECVID:=n3, N:=n4,
SD_01:=d1, ..., SD_32:=d32 ) ;

Table 459

Input Parameters

Name

Data Type

Description

SENDFLG

BOOL

Enables TR_USEND_REAL_32.

SENDID

DINT

The unique identifier for a TR_USEND_REAL_32 function block (1-99).

RECVNODE

DINT

Specifies which controller node receives data from a TR_USEND_REAL_32


function block (163).

RECVID

DINT

The unique identifier for a matching TR_URCV_REAL_32 function block in a


receiving controller (199).

DINT

The number of values to send (132).

SD_01

REAL

Send data 01.

SD_32

REAL

Send data 32.

Table 460

Output Parameters

Name

Data Type

Description

SENT

BOOL

Send initiated (STATUS = 1 or 4).

ACK

BOOL

Send acknowledged (STATUS = 3 or 4).

ERROR

BOOL

True if STATUS is greater than or equal to 100.

STATUS

DINT

0=

Connected to a controller node, ready to SEND.

1=

SEND initiated with SENDFLG set to 1.

2=

SEND function is busy sending data.

3=

Last SEND completed (receiving node has received SEND data).

4=

SEND completed and new SEND initiated.

100 = Not connected to controller node.


101 = Last SEND failed (communication problem with receiving node).
102 = Invalid SENDID, RECVNODE, or RECVID input.
103 = Mismatched data type or number of values in SEND and RECV function calls.
104 = Number of values specified by input N is out of range.
105 = More than one SEND function has same SENDID.

TriStation 1131 Libraries Reference

430

Chapter 2

Functions and Data Types

Description
The TR_USEND_REAL_32 function block sends up to 32 data values to a matching TR_URCV_REAL_32
function block on another Triconex controller. For detailed descriptions of the input and output
parameters, see Appendix B, Peer-to-Peer Parameters.
For information about setting the number of send and receive functions and determining data transfer
time, see the TriStation 1131 Developers Guide.

Example
For Peer-to-Peer examples, see these sample projects:

ExPeer.pt2 (For Tricon controllers)

TdPeer.pt2 (For Trident or Tri-GP controllers)

Note

See Sample Projects on page 7 for information about where to find these projects on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If STATUS is greater than or equal to 100.

ERROR=true

None

For error numbers, see the description for the STATUS output.

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TR_VOTE_MODE 431

TR_VOTE_MODE
Converts redundancy status.

Syntax
MY_TR_VOTE_MODE( CI:=b1, IN_TMR:=b2, GE_DUAL:=b3, GE_SINGLE:=b4 ) ;

Table 461

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TR_VOTE_MODE.

IN_TMR

BOOL

Three channels are operating.

GE_DUAL

BOOL

Two or more channels are operating.

GE_SINGLE

BOOL

One or more channels are operating.

Table 462

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TR_VOTE_MODE executes successfully.

TMR

BOOL

Three channels are operating.

DUAL

BOOL

Two or more channels are operating.

SINGL

BOOL

One or more channels are operating.

ZERO

BOOL

No channels are operating.

Description
The TR_VOTE_MODE function block converts redundancy status, as shown in this truth table.

Table 463

Truth Table

TMR

GE_DUAL

GE_SINGLE

TMR

DUAL

SINGL

ZERO

Othera

a. If an error in the inputs occurs, then CO is false, the mode outputs are
false, and the function block reports a bad parameter error
(BADPARAM).

Note

GE_ means greater than or equal to.

TriStation 1131 Libraries Reference

432

Chapter 2

Functions and Data Types

Example
For shutdown examples, see this sample project:

Note

ExTUV.pt2 (For Tricon controllers)


See Sample Projects on page 7 for information about where to find this project on the PC where
you installed TriStation 1131.

Runtime Errors
Condition

Return Value

Error Flags

If the inputs do not match one of the first four


rows of the truth table

Reset all BOOL outputs to false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Tricon (TR1LIB/TX1LIB)

TriStation 1131 Libraries Reference

TRUNC_LREAL_TO_DINT

433

TRUNC_LREAL_TO_DINT
Truncates a 64-bit long real number to a 32-bit integer.

Syntax
k := TRUNC_LREAL_TO_DINT(x);

Table 464

Input Parameters

Name

Data Type

Description

LREAL

A 64-bit long real number.

Table 465

Return Value

Data Type

Description

DINT

The integer part of x.

Description
The TRUNC_LREAL_TO_DINT function converts a 64-bit long real number to a 32-bit integer with
truncation instead of rounding, which means the fraction is dropped.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : LREAL;
END_VAR;
x := -123.6;
k := TRUNC_LREAL_TO_DINT( x );

(* result is -123 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number

2147483648

BADPARAM, ERROR

If x is minus infinity

2147483648

BADPARAM, ERROR

If x is plus infinity

+2147483647

BADPARAM, ERROR

If x <= -2147483649.0

2147483648

BADCONV, ERROR

If x >= +2147483648.0

+2147483647

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

434

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TRUNC_LREAL_TO_INT

435

TRUNC_LREAL_TO_INT
Truncates a 64-bit long real number to a 16-bit integer.

Syntax
k := TRUNC_LREAL_TO_INT(x);

Table 466

Input Parameters

Name

Data Type

Description

LREAL

A 64-bit long real number.

Table 467

Return Value

Data Type

Description

INT

The integer part of x.

Description
The TRUNC_LREAL_TO_INT function converts a 64-bit long real number to a 16-bit integer with
truncation instead of rounding, which means the fraction is dropped.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : INT; x : LREAL;
END_VAR;
x := -123.6;
k := TRUNC_LREAL_TO_INT( x );

(* result is -123 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number

32768

BADPARAM, ERROR

If x is minus infinity

32768

BADPARAM, ERROR

If x is plus infinity

+32767

BADPARAM, ERROR

If x <= -32769.0

32768

BADCONV, ERROR

If x >= +32768.0

+32767

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

436

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TRUNC_REAL_TO_DINT

437

TRUNC_REAL_TO_DINT
Truncates a 32-bit real number to a 32-bit integer.

Syntax
k := TRUNC_REAL_TO_DINT(x);

Table 468

Input Parameters

Name

Data Type

Description

REAL

A 32-bit real number.

Table 469

Return Value

Data Type

Description

DINT

The integer part of x.

Description
The TRUNC_REAL_TO_DINT function converts a 32-bit real number to a 32-bit integer with truncation
instead of rounding which means the fraction is dropped.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : DINT; x : REAL;
END_VAR;
x := -123.6;
k := TRUNC_REAL_TO_DINT( x );

(* result is -123 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number

2147483648

BADPARAM, ERROR

If x is minus infinity

2147483648

BADPARAM, ERROR

If x is plus infinity

+2147483647

BADPARAM, ERROR

If x <= -2147483649.0

2147483648

BADCONV, ERROR

If x >= +2147483648.0

+2147483647

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

438

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TRUNC_REAL_TO_INT

439

TRUNC_REAL_TO_INT
Truncates a 32-bit real number to a 16-bit integer.

Syntax
k := TRUNC_REAL_TO_INT(x);

Table 470

Input Parameters

Name

Data Type

Description

REAL

A 32-bit real number.

Table 471

Return Value

Data Type

Description

INT

The integer part of x.

Description
The TRUNC_REAL_TO_INT function converts a 32-bit real number to a 16-bit integer with truncation
instead of rounding, which means the fraction is dropped.

Note

IEC 1131-3 requires strict data type checking. It does not permit assigning the value of a variable
directly to a variable of a different data type. When it is necessary to use variables of different
data types, an explicit conversion must be made using a data type conversion function.

Example
VAR
k : INT; x : REAL;
END_VAR;
x := -123.6;
k := TRUNC_REAL_TO_INT( x );

(* result is -123 *)

Runtime Errors
Conditions

Return Values

Error Flags

If x is not a number

32768

BADPARAM, ERROR

If x is minus infinity

32768

BADPARAM, ERROR

If x is plus infinity

+32767

BADPARAM, ERROR

If x <= -32769.0

32768

BADCONV, ERROR

If x >= +32768.0

+32767

BADCONV, ERROR

Upon detection of a runtime error condition, the function returns the indicated value, sets the error flags
to true, and resets ENO to false. For more information about error flags and runtime errors, see the
CHK_ERR function block.

TriStation 1131 Libraries Reference

440

Chapter 2

Functions and Data Types

Application Notes
Can be used in Safety or Control applications.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

TSCHED 441

TSCHED
Schedules periodic execution.

Syntax
MY_TSCHED( CI:=b1, PERIOD:=t1, OFFSET:=t2 ) ;

Table 472

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TCSCHED.

PERIOD

TIME

The desired time period between settings of output Q.

OFFSET

TIME

Time offset before the first setting of output Q (0.0 OFFSET < PERIOD).

Table 473

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TCSCHED executes successfully.

BOOL

True for one scan each period.

ACTUAL

TIME

The measured time since last setting of output.

Description
The TCSCHED function block schedules execution with a specified time period. (The CSCHED function
block schedules execution after a specified number of scans.)
Output Q is true when the specified period of time has passed, holding true for one scan. Otherwise
output Q is false. By testing the output Q, you can cause sections of the control program to be executed
periodically.

Example
(*
* Increment N every 90 seconds.
*)
VAR MY_TSCHED : TSCHED ; END_VAR
VAR N : DINT ; END_VAR
MY_TSCHED( CI:=TRUE, PERIOD:=T#90s ) ;
if MY_TSCHED.Q then
N := N + 1 ;
end_if ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

442

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TSCHED_I

443

TSCHED_I
Schedules periodic execution.

Syntax
MY_TSCHED_I( CI:=b1, PERIOD:=n1, OFFSET:=n2 ) ;

Table 474

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TCSCHED_I.

PERIOD

DINT

The desired time period, in milliseconds, between settings of output Q.

OFFSET

DINT

Time offset, in milliseconds, before the first setting of output Q (0.0 is less than or
equal to OFFSET).

Table 475

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TCSCHED_I executes successfully.

BOOL

True for one scan each period.

ACTUAL

DINT

The measured time, in milliseconds, since last


setting of output Q.

Description
The TCSCHED_I function block schedules periodic execution with the time period given in integer
milliseconds.
The output Q is true when the specified period of time has passed, holding true for one scan. Otherwise
Q is false. By testing the output Q, you can cause sections of the control program to be executed in a
periodic manner.

Note

If PERIOD is within one scan period of 2147483647 milliseconds (25 days), then the time
accumulator can overflow to a negative value.

Example
(*
* Increment N every 90 seconds.
*)
VAR MY_TSCHED_I : TSCHED_I ; END_VAR
VAR N : DINT ; END_VAR
MY_TSCHED_I( CI:=TRUE, PERIOD:=90000 ) ;
if MY_TSCHED_I.Q then
N := N + 1 ;
end_if ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

444

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

TSCHED_R

445

TSCHED_R
Schedules periodic execution.

Syntax
MY_TSCHED_R( CI:=b1, PERIOD:=x1, OFFSET:=x2 ) ;

Table 476

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables TCSCHED_R

PERIOD

REAL

The desired time period, in seconds, between settings of output Q.

OFFSET

REAL

Time offset, in seconds, before the first setting of output Q


(0.0 is less than or equal to OFFSET).

Table 477

Output Parameters

Name

Data Type

Description

CO

BOOL

True if TCSCHED_R executes successfully.

BOOL

True for one scan each period.

ACTUAL

REAL

The measured time, in seconds, since last setting of output Q.

Description
The TCSCHED_R function block schedules periodic execution with the time period given in real seconds.
The output Q is true when the specified period of time has passed, holding true for one scan. Otherwise
Q is false. By testing the output Q, you can cause sections of the control program to be executed in a
periodic manner.

Note

The rounding error in the time accumulator increases with time until the accumulator eventually
stops. The rounding error in seconds is less than ACC ACC (50,000,000 T), where ACC is
the accumulated time in seconds and T is the scan period in seconds. The accumulator stops after
ACC > 16,000,000 T. For example, if the scan period is 20 milliseconds, then after one hour, the
rounding error is less than 13 seconds.

Example
(*
* Increment N every 90 seconds.
*)
VAR MY_TSCHED_R : TSCHED_R ; END_VAR
VAR N : DINT ; END_VAR
MY_TSCHED_R( CI:=TRUE, PERIOD:=90.0 ) ;
if MY_TSCHED_R.Q then
N := N + 1 ;
end_if ;

Runtime Errors
None.

TriStation 1131 Libraries Reference

446

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Exactly Once: each instance should be executed exactly once per scan.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

UNPACK16

447

UNPACK16
Unpacks a DWORD into 16 separate Boolean outputs.

Syntax
MY_UNPACK16( CI:=b1, INPUT:=w1 ) ;

Table 478

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables UNPACK16.

INPUT

DWORD

The input value.

Table 479

Output Parameters

Name

Data Type

Description

CO

BOOL

True if UNPACK16 executes successfully.

NZ

BOOL

Not zero.

Q01

BOOL

Output bit 01 (least significant bit).

Q02

BOOL

Output bit 02.

Q03

BOOL

Output bit 03.

Qnn

BOOL

Output bit nn.

Q16

BOOL

Output bit 16 (most significant bit).

Description
The UNPACK16 function block unpacks the low-order 16 bits of INPUT, a 32-bit word, into 16 separate
Boolean outputs (Q01 through Q16). Q01 is the least significant bit and Q16 is the most significant.
The INPUT data type is DWORD. Output NZ is true if any bits are true, and false if all 16 bits are false.
The UNPACK16 function block is useful for unpacking 16 bits that have been transmitted using a
Modbus alias.

Example
VAR MY_UNPACK16 : UNPACK16 ; END_VAR
MY_UNPACK16( CI:=TRUE, INPUT:=16#0000001F ) ;
(*
* Result on Q outputs of MY_UNPACK16:
* Q16
Q01
* 0000000000011111
*)

Runtime Errors
None.

TriStation 1131 Libraries Reference

448

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

UNPACK32

449

UNPACK32
Unpacks a DWORD into 32 separate Boolean outputs.

Syntax
MY_UNPACK32( CI:=b1, INPUT:=w1 ) ;

Table 480

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables UNPACK32.

INPUT

DWORD

The input value.

Table 481

Output Parameters

Name

Data Type

Description

CO

BOOL

True if UNPACK32 executes successfully.

NZ

BOOL

Not zero.

Q01

BOOL

Output bit 01 (least significant bit).

Q02

BOOL

Output bit 02.

Q03

BOOL

Output bit 03.

Qnn

BOOL

Output bit nn.

Q32

BOOL

Output bit 32 (most significant bit).

Description
The UNPACK32 function block unpacks the 32 bits of INPUT, a 32-bit word, into 32 separate Boolean
outputs (Q01 through Q32). Q01 is the least significant bit and Q32 is the most significant.
The INPUT data type is DWORD. Output NZ is true if any of the bits are true, and false if all 32 bits are
false. The UNPACK32 function is useful for unpacking 32 bits that have been transmitted using
peer-to-peer communications.

Example
VAR MY_UNPACK32 : UNPACK32 ; END_VAR
MY_UNPACK32( CI:=TRUE, INPUT:=16#0000001F ) ;
(*
* Result on Q outputs of MY_UNPACK32:
* Q32
Q01
* 00000000000000000000000000011111
*)

Runtime Errors
None.

TriStation 1131 Libraries Reference

450

Chapter 2

Functions and Data Types

Application Notes

Can be used in Safety or Control applications.

Space Saver: a single instance can be executed more than once per scan to reduce memory usage
and increase performance. For directions, see Using a Space Saver Function Block on page 6.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

X_OF_N

451

X_OF_N
Determines whether at least X of the last N measurements exceeds a specified limit.

Syntax
MY_X_OF_N( CI:=b1, RESET:=b2, VALUE:=x1, LMT:=x2, X:=n1, N:=n2 ) ;

Table 482

Input Parameters

Name

Data Type

Description

CI

BOOL

Enables X of N.

RESET

BOOL

Restarts with 0 measurements.

VALUE

REAL

The latest measurement.

LMT

REAL

The limit against which the value is tested.

DINT

The minimum number of N measurements that must exceed the limit to turn output Q
on, where X is less than N.

DINT

The number of measurements entailed, where N is less than or equal to 32.

Table 483

Output Parameters

Name

Data Type

Description

CO

BOOL

True if X of N executes successfully.

BOOL

X of N values exceeding the limit.

Description
The X_OF_N function block determines whether at least X of the last N measurements exceeds a specified
limit. The result is output Q. RESET clears the internal state to start without measurements. RESET clears
the state even if CI is false. If CI and RESET are both false, no operation occurs.

Example
VAR X3oo4 : X_OF_N ; END_VAR
X3oo4( CI:=FALSE, RESET:=TRUE, LMT:=0.5, X:=3, N:=4 ) ;
X3oo4( VALUE:=0.7, CI:=TRUE, RESET:=FALSE ) ;
X3oo4( VALUE:=0.8 ) ;
X3oo4( VALUE:=0.4 ) ;
X3oo4( VALUE:=0.9 ) ;
(*
* result : X3oo4.Q is true because 3 out of 4 values
* are greater than or equal to 0.5.
*)

Runtime Errors
Conditions

Return Values

Error Flags

If N is less than or equal to 0.

CO=false, Q=false

BADPARAM, ERROR

TriStation 1131 Libraries Reference

452

Chapter 2

Functions and Data Types

Conditions

Return Values

Error Flags

If N is greater than 32.

CO=false, Q=false

BADPARAM, ERROR

If X is less than or equal to 0.

CO=false, Q=false

BADPARAM, ERROR

If X is greater than or equal to N.

CO=false, Q=false

BADPARAM, ERROR

Upon detection of a runtime error condition, the function block returns the indicated values and sets the
error flags to true. For more information about error flags and runtime errors, see the CHK_ERR function
block.

Application Notes

Can be used in Safety or Control applications.

Internal State: a single instance can be executed more than once per scan. However, you should
be aware of the internal states that are used from one scan to the next.

Library
Triconex (TCXLIB)

TriStation 1131 Libraries Reference

XOR

453

XOR
Performs a logical exclusive OR of two or more Boolean operands or a bitwise exclusive OR of two or
more bit-strings.

Syntax
b := b1 XOR b2 XOR ... XOR bn ;

Table 484

Input Parameters

Name

Data Type

Description

b1..bn

ANY_BIT

Operands

Table 485

Output Parameters

Data Type

Description

ANY_BIT

b1 XOR b2 XOR ... XOR bn

Description
In graphical languages, the XOR function returns the logical XOR of Boolean operands or the bitwise XOR
of bit-strings. In Structured Text, the XOR operator is used instead of the XOR function.
The maximum number of function inputs is 50.
All operands must be the same type as the return value either all BOOL or all DWORD.
If the operand type is BOOL, then the result is true if the number of true operands is odd. The result is
false if the number of true operands is even.

Table 486

Logical XOR

b1

b2

b1 XOR b2

FALSE

FALSE

FALSE

FALSE

TRUE

TRUE

TRUE

FALSE

TRUE

TRUE

TRUE

FALSE

If the operand type is DWORD, then the result is the bitwise exclusive OR of all the operands. In other
words, the value in each bit position of the result is the exclusive OR of all the values in the same bit
position.

Table 487

Bitwise XOR

w1

w2

w1 XOR w2

2#0011

2#0101

2#0110

TriStation 1131 Libraries Reference

454

Chapter 2

Functions and Data Types

Example
Using Boolean Operands
VAR b, b1:=TRUE, b2:=TRUE, b3:=TRUE : BOOL; END_VAR
b := b1 XOR b2 XOR b3;
(* result is TRUE *)
b := b1 XOR b2;
(* result is FALSE *)

Using Bit-String Operands


VAR w, w1, w2, w3 : DWORD; END_VAR
w1 :=
2#00000000000000000000000000000001
w2 :=
2#00000000000000000000000000000011
w3 :=
2#00000000000000000000000000000111
w := w1 XOR w2 XOR w3; (* 2#00000000000000000000000000000101
w := w1 XOR w2;
(* 2#00000000000000000000000000000010

;
;
;
*)
*)

Note that on the Controller Panel, you will see the example values in hex. The hex values of the operands
are w1=16#00000001, w2=16#00000003, w3=16#00000007, and the hex values of the results are
16#00000005 and 16#00000002.

Runtime Errors
None.

Application Notes

Can be used in Safety or Control applications.

Can be used in CEM Cause cells.

Library
Standard (STDLIB)

TriStation 1131 Libraries Reference

A
Modbus Protocol

Overview 456
Message Response Time 457
Modbus Messages 459
Modbus Functions 465
Transmission Errors and Exception Conditions 476

TriStation 1131 Libraries Reference

456

Appendix A

Modbus Protocol

Overview
This sppendix provides detailed information about Modbus protocol, which is a communication protocol
used with serial ports to transmit data between a Modbus master and slave. Modbus protocol includes
functions which define the message format for the query and response.

Query-Response Sessions
Modbus communication is a query-response session, in which the Modbus master initiates a query and
a Modbus slave responds. In Modbus communication, a serial link transmits data in both directions, but
in only one direction at a time.
A query-response session consists of these actions:

The master sends a query to a slave.

The master starts a fail-safe timer while it waits for the slave response. Typical slave response
time is in hundreds of milliseconds.

The slave returns a response to the master.

The master waits until it has received the response from the slave before sending another query.

If there is a slave response timeout, the master will retry the query. The number of retries and
the timeout interval is configured by the MBCTRL function block (see page 178).

For information on configuring Modbus communication, see the Communication Guide for your controller.

TriStation 1131 Libraries Reference

Message Response Time

457

Message Response Time


This section explains how to estimate the message response time, which is the total time for preparing,
transmitting, receiving, and processing a Modbus query. Function blocks that are the least and most
affected by scan time increases are also identified in this section.
Topics include:

Determining Message Response Time on page 457

Modbus Functions and Scan Time on page 458

Determining Message Response Time


This table explains how to estimate the number of milliseconds required for the message response time
on a Triconex controller acting as a Modbus slave.
Modbus Operation

Equation or Constraints

Prepare Query (master)

Varies depending on the specific Modbus function (message) and any other
program processing

Transmit Query (master)

(1000 Baud Rate) x Bits per Characters x Number of Characters

Receive and Process Query

Tricon EICM slave:


Writes: 3 x Scan Time
Reads: 10 milliseconds
Trident or Tri-GP MP slave:
Writes: 3 x Scan Time
Reads: 2 x Scan Time
Trident or Tri-GP CM slave:
Writes: 3 x Scan Time
Reads: 10 milliseconds

Transmit Response (slave)


(in milliseconds)

(1000 Baud Rate) x Bits per Characters x Number of Characters

Process Response (master)


(in milliseconds)

Depends on customer-provided equipment performance.

Time-Out and Retry Values

Varies depending on settings for the MBCTRL function block, which determines
the time-out and retry values which can increase the message time (see MBCTRL
on page 178).
Message Response Time = the sum of all the results

TriStation 1131 Libraries Reference

458

Appendix A

Modbus Protocol

Modbus Functions and Scan Time


Modbus performance degrades slightly as the scan time of the controller increases.
When the controller acts as a slave, the functions most affected by scan time increases are:

Force Single Coil (Function Code 05) on page 470

Preset Single Register (Function Code 06) on page 471

Force Multiple Coils (Function Code 15) on page 474

Preset Multiple Registers (Function Code 16) on page 475

The functions least affected by scan time increases are:

Read Coil Status Function (Function Code 01) on page 466

Read Input Status (Function Code 02) on page 467

Read Holding Registers (Function Code 03) on page 468

Read Input Registers (Function Code 04) on page 469

TriStation 1131 Libraries Reference

Modbus Messages

459

Modbus Messages
This section describes the Modbus messages (query and response functions) supported by Triconex
communication modules. The serial ports on Triconex communication modules support several Modbus
message formats and functions (queries and responses).
Topics include:

Communication Modes on page 459

Function Names and Aliases on page 460

Modbus Message Formats on page 461

Sample Query and Response Messages on page 463

Modbus Message Lengths on page 464

Communication Modes
A Modbus serial link must use either the Remote Terminal Unit (RTU) or ASCII mode of communication.
If both modes are available, you should choose RTU because it is more efficient and robust than ASCII.
Each serial port can use a different communication mode, assuming that each port is connected to a
separate Modbus master or slave device. If you configure a port for combination Modbus master and
slave operation, you must use RTU mode.

RTU Mode
In RTU mode, data is sent in 8-bit binary characters. Gaps between characters cannot exceed three
character times (the time it takes to send a character). RTU mode uses a 16-bit cyclic redundancy check
(CRC) to detect transmission errors.

ASCII Mode
In ASCII mode, data is transmitted in pairs of ASCII characters. The first character is the ASCII
representation of the most significant 4 bits of the corresponding RTU character. The second character is
the ASCII representation of the least significant 4 bits of the corresponding RTU character. For example,
the RTU character 010011112 (4F16) is sent as the two ASCII characters 4 and F (3416 and 4616). Each ASCII
message has a colon at the beginning and a carriage return and line feed at the end. Gaps between
characters in an ASCII message are not significant.

TriStation 1131 Libraries Reference

460

Appendix A

Modbus Protocol

Function Names and Aliases


The starting address field of a Modbus message ranges from 0 to one less than the number of coils or
registers available.
A Trident or Tri-GP CM or MP serial port maps the Modbus starting address field to an alias by adding
a constant determined by the function code, as shown in this table.
Function Name

Code

Coil or Register

Constant

Read Coil Status

01

Coil

Read Input Status

02

Coil

10001

Read Holding Registers

03

Register

40001

Read Input Registers

04

Register

30001

Force Single Coil

05

Coil

Preset Single Register

06

Register

40001

Read Exception Status

07

Coil

n/a

Loop Back Diagnostic Test

08

Register

n/a

Force Multiple Coils

15

Coil

Preset Multiple Registers

16

Register

40001

TriStation 1131 Libraries Reference

Modbus Messages

461

Modbus Message Formats


For each Modbus function, the message formats for RTU and ASCII modes are depicted as shown in the
following figures.

Message Header Field (ASCII Only)


The Message Header in ASCII mode is a colon (:) and is required. There is no message header in RTU
mode.

Station Address Field


The Station Address field identifies the station to which a query is directed or the station that is sending
a response. In RTU mode, the station address has one character (8 bits). In ASCII mode, the station
address has two characters.
The range for station addresses is 1 through 247. Each station connected to a Modbus serial link must have
a unique address. Station address 0 (zero) is the broadcast address and addresses all slaves. When a slave
receives a query with the broadcast address, the slave processes the query but does not send a response.

Function Code Field


The Function Code field identifies the operation to be performed (the query), or the operation that was
performed (the response). If the most significant bit of the function code in a response is 1, the response
is an exception response.

Data Fields
The Data fields contain information that is specific to the query or response. The length of the data varies,
depending on the function code.

Checksum Field (CRC or LRC)


The Checksum field is a 16-bit word which is a CRC in RTU mode or an LRC in ASCII mode. The error
check is performed by both the transmitting and the receiving units to detect transmission errors. These
sections describe the error check calculations that are performed for CRC and LRC.

CRC Error Check RTU Mode


During a CRC error check, the CRC-16 polynomial is used to compute a checksum for the entire message.
The CRC-16 polynomial is:
x16 + x15 +x2 + 1

TriStation 1131 Libraries Reference

462

Appendix A

Modbus Protocol

The CRC is computed across the station address, the function code, and the data and appended to the end
of the message.

LRC Error Check ASCII Mode


The LRC checksum is an 8-bit binary number represented and transmitted as two ASCII hexadecimal
characters. To calculate the LRC:

Add the hex characters for the message content. (In the example, this includes the address,
function code, starting address, and number of points fields.) The colon, carriage return, and
line feed are ignored.

Take the twos complement.

This table shows how to calculate the LRC for a sample message.

Table 488

LRC Checksum Sample Calculation

Message Field

Message Content

Address

0x30
0x32

Function Code

0x30
0x31

Starting Address (high order)

0x30
0x30

Starting Address (low order)

0x31
0x33

Number of Points (high order)

0x30
0x30

Number of Points (low order)

0x32
0x35

Sum of message content.

0x4E

Take the twos complement.

0xB2

The resulting Error Check (LRC)

0x42 (B)
0x32 (2)

CR Field and LF Field (ASCII Only)


The CR field contains an ASCII carriage return and the LF field contains an ASCII line feed.

TriStation 1131 Libraries Reference

Modbus Messages

463

Sample Query and Response Messages


This table shows the content of a sample query and response in RTU and ASCII modes. The query is a
Read Input Status (Function 02) requesting 37 (2516) points starting at point 20 (1316 + 1). The response
packs the 37 points into five 8-bit bytes, and clears the three high-order bits of the last byte.
Query Message

RTU

ASCII

Header

None

Station Address

0000 0010

02

Function Code

0000 0001

01

Starting Address (High Order)

0000 0000

00

Starting Address (Low Order)

0001 0011

13

Number of Points (High Order)

0000 0000

00

Number of Points (Low Order)

0010 0101

25

Error Check

0000 1100

C5

0010 0111
Trailer

None

CR LF

Response Message

RTU

ASCII

Header

None

Station Address

0000 0010

02

Function Code

0000 0001

01

Byte Count

0000 0101

05

Data Byte 1

1100a 1101b

CD

Data Byte 2

0110 1011

6B

Data Byte 3

1011 0010

B2

Data Byte 4

0000 1110

0E

Data Byte 5

0001 1011

1B

Error Check

0000 0100

E5

1111 1111
Trailer

None

CR LF

a. The underscored digit indicates that Coil #27 is in the On state.


b. The underscored digit indicates that Coil #20 is in the On state.

TriStation 1131 Libraries Reference

464

Appendix A

Modbus Protocol

Modbus Message Lengths


The length of a Modbus message depends on the function being used and whether the message is a query
or a response.
Function
Code

Query

Number of RTU
Characters

Number of ASCII
Characters

01

Read Coil Status

17

02

Read Input Status

17

03

Read Holding Registers

17

04

Read Input Registers

17

05

Force Single Coil

17

06

Preset Single Register

17

15

Force Multiple Coils

9 + (1 per 8 coils)

19 + (2 per 8 coils)

16

Preset Multiple Registers

9 + (2 per register)

19 + (4 per register)

Response

Number of RTU
Characters

Number of ASCII
Characters

01

Read Coil Status

5 + (1 per 8 coils)

11 + (2 per 8 coils)

02

Read Input Status

5 + (1 per 8 coils)

11 + (2 per 8 coils)

03

Read Holding Registers

5 + (2 per register)

11 + (4 per register)

04

Read Input Register

5 + (2 per register)

11 + (4 per register)

05

Force Single Coil

17

06

Preset Single Register

17

15

Force Multiple Coils

17

16

Preset Multiple Registers

17

Function
Code

TriStation 1131 Libraries Reference

Modbus Functions

465

Modbus Functions
This section includes details on Modbus functions.
Functions include:

Read Coil Status Function (Function Code 01) on page 466

Read Input Status (Function Code 02) on page 467

Read Holding Registers (Function Code 03) on page 468

Read Input Registers (Function Code 04) on page 469

Force Single Coil (Function Code 05) on page 470

Preset Single Register (Function Code 06) on page 471

Read Exception Status (Function Code 07) on page 472

Loop-Back Diagnostic Test (Function Code 08) on page 473

Force Multiple Coils (Function Code 15) on page 474

Preset Multiple Registers (Function Code 16) on page 475

TriStation 1131 Libraries Reference

466

Appendix A

Modbus Protocol

Read Coil Status Function (Function Code 01)


The Read Coil Status function requests the On/Off status of a group of logic coils from a station. You can
request the status for as many as 2,000 coils with each query, but some Modbus devices have lower limits.
The coils are numbered beginning at 0. For example, coil 0 is alias 1, coil 1 is alias 2, and so forth.
The Read Coil Status query is also known as the Read Output Status query.

Query Format

Response Format
The Read Coil Status response data is packed with one bit for each coil, where 1=On, and 0=Off. The loworder bit of the first RTU character contains the status of the first coil. For coil quantities that are not even
multiples of eight, the last RTU character is zero-filled at the high-order end.

TriStation 1131 Libraries Reference

Modbus Functions

467

Read Input Status (Function Code 02)


The Read Input Status function operates in the same manner as Read Coil Status (Function Code 01),
except that the status of digital inputs is obtained. Inputs are also numbered beginning at 0. For example,
input status 0 is alias 10001, input status 1 is alias 10002, and so forth. You can request the status of as
many as 2,000 coils with each query, but some Modbus devices have lower limits.

Query Format

Response Format

TriStation 1131 Libraries Reference

468

Appendix A

Modbus Protocol

Read Holding Registers (Function Code 03)


The Read Holding Registers function requests the binary content of holding registers from a station. You
can request the status of as many as 125 registers with each query, but some Modbus devices have lower
limits. The registers are numbered beginning at 0. For example, register 0 is alias 40001, register 1 is alias
40002, and so forth.
The Read Holding Registers query is also known as the Read Output Registers query.

Query Format

Response Format
The Read Holding Registers response data consists of two bytes for each register queried, with the binary
content right-justified. The leftmost character includes the high-order bits, and the rightmost character
includes the low-order bits.

TriStation 1131 Libraries Reference

Modbus Functions

469

Read Input Registers (Function Code 04)


The Read Input Registers function operates in the same manner as the Read Holding Registers query
(Function Code 03), except that it obtains the status of input registers. You can request the status of as
many as 125 registers with each query, but some Modbus devices have lower limits. The registers are
numbered beginning at 0. For example, register 0 is alias 30001, register 1 is alias 30002, and so forth.

Query Format

Response Format

TriStation 1131 Libraries Reference

470

Appendix A

Modbus Protocol

Force Single Coil (Function Code 05)


The Force Single Coil function turns a single coil On or Off, depending on its current state. Because the
slave is actively scanning, it can also alter the state of the coil (unless the coil is disabled). Coils are
numbered beginning at 0. For example, coil 0 is alias 1, coil 1 is alias 2, and so forth.
A coil value of 65,280 (FF0016) turns the coil On, and a coil value of zero (000016) turns the coil Off. All
other values are illegal and do not affect the coil. If the query contains legal values, the slave responds
after the coil state has been altered.

Query Format

Response Format

TriStation 1131 Libraries Reference

Modbus Functions

471

Preset Single Register (Function Code 06)


The Preset Single Register function modifies the content of one holding register. Because the slave is
actively scanning, it can also alter the content of the register. Register values are 16 bits. Holding registers
are numbered beginning at 0. For example, register 0 is alias 40001, register 1 is alias 40002.

Query Format

Response Format

TriStation 1131 Libraries Reference

472

Appendix A

Modbus Protocol

Read Exception Status (Function Code 07)


The Read Exception Status function returns the status of eight coils from the slave application running in
the controller. Which coils and what they represent depends on the slave.
When a serial port, configured as a slave, responds to this query, it sends the status of the first eight coils
(aliases 00001 through 00008) defined in the application. Coils are numbered beginning at 0. For example,
coil 0 is alias 1, coil 1 is alias 2, and so forth.
The status of each coil is packed in the data field, one bit for each coil (1=On, 0=Off). You can program
these coils to hold any type of information; for example, machine on or off, heads retracted, safeties
satisfied, and receipt-in-process error conditions.

Note

A serial port configured as a Modbus master cannot use the Read Exception Status function.

Query Format

Response Format

TriStation 1131 Libraries Reference

Modbus Functions

473

Loop-Back Diagnostic Test (Function Code 08)


The Loop-Back Diagnostic Test function tests the communications link between the Modbus master and
slave. This query does not affect point values in the slave. When the serial port acting as a slave receives
this query, it re-transmits the query as the response.

Note

A serial port configured as a Modbus Master cannot use the Loop-Back Diagnostic Test function.

Query Format

Response Format

TriStation 1131 Libraries Reference

474

Appendix A

Modbus Protocol

Force Multiple Coils (Function Code 15)


The Force Multiple Coils function sets each coil in a consecutive block of coils to the specified state (On
or Off) regardless of whether the coils are enabled or disabled. Because the slave is actively scanning, it
can also alter the state of a coil (unless it is disabled). Coils are numbered beginning at 0. For example, coil
0 is alias 1, coil 1 is alias 2, and so forth. The status of each coil is packed in the data field, one bit for each
coil (1=On, 0=Off).
A single Force Multiple Coils query can set a maximum of 128 coils. The query-response time required
by some Modbus masters might require a much smaller quantity.

Query Format

Response Format

TriStation 1131 Libraries Reference

Modbus Functions

475

Preset Multiple Registers (Function Code 16)


The Preset Multiple Registers function can change the contents of a maximum of 60 consecutive holding
registers, however, some Modbus devices have lower limits. Because the slave is actively scanning, it can
also alter the state of the registers (unless they are disabled). The values are provided in binary code up
to the maximum valid register value of the controller (16-bit for Trident or Tri-GP controllers). Unused
high-order bits must be set to 0. The registers are numbered beginning at 0. For example, register 0 is alias
40001, register 1 is alias 40002, and so forth.

Query Format

Response Format

TriStation 1131 Libraries Reference

476

Appendix A

Modbus Protocol

Transmission Errors and Exception Conditions


During Modbus communication, transmission errors and exception conditions can occur. Transmission
errors do not cause exception conditions and are not acknowledged by Modbus slaves. Programming and
operation errors do cause exception conditions which elicit exception responses from slaves.
Topics include:

Transmission Errors on page 476

Exception Conditions on page 477

Exception Responses on page 478

Exception Response Codes on page 479

Transmission Errors
The most frequent cause of transmission errors is noise. Noise sources include improperly installed or
broken connectors, damaged cables, electrical equipment such as generators and elevators, and lightning.
Transmission errors can be detected through the use of character framing, parity checking, and
redundancy checking.
When a slave detects a transmission error, it does not act on or respond to the message. The master
assumes a communication error has occurred if there is no response within a specified time, usually 3
seconds.
Parity checking helps detect single-bit transmission errors. However, if there are two errors within a
single character, parity checking cannot detect a change. For example, if 1100 0100 is distorted to 1111
0100, the number of 1 bits in the data is still odd.
Modbus protocol provides several levels of error checking to ensure the accuracy of data transmission.
To detect multiple bit errors, the system uses cyclic redundancy check (CRC) for RTU mode, or
longitudinal redundancy check (LRC) for ASCII mode.

TriStation 1131 Libraries Reference

Transmission Errors and Exception Conditions

477

Exception Conditions
If a master detects an exception in a response to a query or does not receive a response, it takes
appropriate actions which usually include re-transmitting the query. This table lists exception conditions
that are returned by the slave if a programming or operation error causes a master to send an incorrect
query.
Exception Condition

Description

Query Message CRC or LRC


Error

The slave does not respond, because the error could be in the station address.
The master uses its response fail-safe timer to recover.

Query Function Code Error

The slave sends an Illegal Function (01) response code when it detects an error
in the function code field.

Query Address Error

The slave sends an Illegal Data Address (02) response code when it detects an
error in the starting address field.

Query Data Error

The slave sends an Illegal Data Value (03) response code when it detects an
error in the data field.

Main Processors Not


Communicating

This exception applies only to serial ports which are configured as slaves.

Remote Write Disabled

The slave port sends a Busy, Reject Message (06) response code if a master
sends one of these queries and the slave port is not enabled for remote
(external) writes:

If the slave port receives a query requiring a data exchange and it cannot
communicate with the Main Processors, it sends a Busy, Reject Message (06)
response code and turns off the Active indicator on the communication
module.

Force Single Coil (Function Code 05)


Preset Single Register (Function Code 06)
Force Multiple Coils (Function Code 15)
Preset Multiple Registers (Function Code 16)

TriStation 1131 Libraries Reference

478

Appendix A

Modbus Protocol

Exception Responses
When a slave detects an exception condition, it sends a response message to the master consisting of the
slaves station address, function code, error code, and error-check fields. To indicate that the message is
an exception response, the slave sets the high-order bit of the function code to 1. This example shows an
exception response to a Preset Multiple Registers (Function Code 16) query.

Sample Query

Sample Exception Response

TriStation 1131 Libraries Reference

Transmission Errors and Exception Conditions

479

Exception Response Codes


This table lists exception response codes which are sent by the slave after an invalid query.
Code

Name

Description

01

Illegal Function

The requested function is not in the slaves repertoire.

02

Illegal Data Address

The alias in the query does not exist in the slave.

03

Illegal Data Value

The value is not in the range allowed for the alias.

04

Failure in Associated
Device

The slave failed to respond to a message or an error that occurred in


the controller. When a master receives this response code, it must issue
a supervisory alert.

05

Acknowledge

A slave port does not send this exception response code.

06

Busy, Rejected Message

The query was received without error, but the slave cannot comply.

07

Negative Acknowledge

A slave port does not send this exception response code.

08

Memory Parity Error

A slave port does not send this exception response code.

TriStation 1131 Libraries Reference

480

Appendix A

Modbus Protocol

TriStation 1131 Libraries Reference

B
Peer-to-Peer Parameters

Overview 482
Parameters of Send Function Blocks 483
Parameters of Receive Function Blocks 486
Peer-to-Peer Runtime Errors 488

TriStation 1131 Libraries Reference

482

Appendix B

Peer-to-Peer Parameters

Overview
This appendix describes the input and output parameters for Peer-to-Peer function blocks, and runtime
errors.
Topics include:

Parameters of Send Function Blocks on page 483

Parameters of Receive Function Blocks on page 486

Peer-to-Peer Runtime Errors on page 488

TriStation 1131 Libraries Reference

Parameters of Send Function Blocks

483

Parameters of Send Function Blocks


This section describes the operation of each parameter in a Send function block and provides details about
the error values returned by the STATUS parameter.

SENDFLG
The SENDFLG input parameter specifies whether a send is initiated. If the value is true, a send is initiated.
If the value is false, a send is not initiated even if the Send function block is executed. In other words, no
data transfer takes place unless the SENDFLG parameter is set to true.
When a Send function block is executed by the TriStation 1131 application for the first time with
SENDFLG set to false, the sending controller attempts to establish communication with the receiving
controller and sets the STATUS parameter to 100.
The sending controller sets the STATUS parameter of the Send function block to 0 if:

Communication is established with the receiving controller

A receiving controller has a matching Send function block with a matching Receive identifier,
Send node number, and Send identifier

If the STATUS parameter of a Send function block (with SENDFLG set to 0) is greater than or equal to 100,
there is a problem in the network. The STATUS parameter indicates the type of problem and the action
you should to take to resolve it. For more information on codes, see STATUS on page 486.
A TriStation 1131 application must execute a Send function block unconditionally, exactly once per scan.
The SENDFLG parameter should be zero for the first scan. If the value of SENDFLG is zero, no send
operation takes place even though the function block is executed. When another application has new data
to send, it should first check the result of the Send function block execution (in other words, the STATUS
output). If the STATUS is zero, then set SENDFLG to true to initiate the send operation so that data can
be transferred.

SENDID
The SENDID input parameter specifies a unique identifier for a Send function block. The legal range for
identifiers is from 1 to the value specified for Maximum Number of Peer-to-Peer Send.
Each Send function block in a TriStation 1131 application must have a unique SENDID. If more than one
Send function block has the same SENDID, the first Send function block in the application will work
properly. Other Send function blocks with the same SENDID will generate an error status of 105.

RECVNODE
The RECVNODE input parameter specifies which controller will receive data from this Send function
block. It should be set to the node number of the receiving Triconex controller. The range is 1 to 63. (Note:
Nodes 32 to 63 are valid for Trident or Tri-GP controllers only.) If RECVNODE is out of range, calls to the
function block set the STATUS output to 102.

RECVID
The RECVID input parameter specifies the unique Receive function block that receives data from this
Send function block. A receive call with a matching RECVID must be defined in the receiving controller.
The legal range for RECVID identifiers is from 1 to the value specified for Maximum Number of Peer-toPeer Receive. If RECVID is out of range, calls to the function block set the STATUS output to 102.

TriStation 1131 Libraries Reference

484

Appendix B

Peer-to-Peer Parameters

N
The N input parameter specifies the number of data values to send (1 to 20 for TR_USEND function
blocks and 1 to 32 for TR_USEND_32 function blocks). The receiving function block must specify the
same value for the N output parameter.

SD_01...SD_nn
The SD_ input parameters send data values to the receiving controller. A TR_USEND function block can
send up to 20 values and a TR_USEND_32 function block can send up to 32 values. These values can be
BOOL, DINT, or REAL data types. There must be matching RD_ parameters in the Receive function block
of the receiving controller.

SENT
The SENT output parameter of type BOOL indicates that a send was initiated and the STATUS parameter
is set to 1 or 4. Instead of testing the STATUS output, you can use the SENT output to change the send
data if you want to send it again, or reset the SENDFLG if you do not want to send the data again.

ACK
The ACK output parameter indicates that the receiving controller has acknowledged the send. In other
words, the last send operation was completed successfully and the STATUS parameter is equal to 3 or 4.

ERROR
The ERROR output parameter indicates that an error has occurred and the STATUS parameter is greater
than or equal to 100.

STATUS
The STATUS output parameter indicates the current state of communication with the receiving
controller. The STATUS values described in the following table allow the TriStation 1131 application to
perform an appropriate action when a problem occurs.

Table 489

Send Function Block STATUS Output Parameter Values

Status

Meaning and Action

Communication is established with the receive node. When you execute a Send function block with
SENDFLG = false, you should receive STATUS = 0 to indicate that communication is established
with the receiving controller and that the receiving TriStation 1131 application has an exactly
matching Receive function block. You can initiate a send operation by setting SENDFLG to true.

A send was initiated by a Send function block call with SENDFLG set to true. Set SENDFLG to false
to coordinate the acknowledgment from the receiving node of the last send. If you do not set
SENDFLG to false, the controller will initiate another send as soon as it completes the current send
(in other words, as soon as it receives an acknowledgment from the receiving controller).

The Send identifier is currently busy sending data to the receiving controller. STATUS is set to 2 on
the scan that immediately follows a scan during which a send was initiated. STATUS remains 2 until
an acknowledgment is received from the receiving controller or a 5-second time-out expires. If an
acknowledgment is received, STATUS changes to 3 and then to 0 (if SENDFLG = false) or 4 (if
SENDFLG = true). If the 5-second time-out expires, STATUS changes to 100 (described below).

TriStation 1131 Libraries Reference

Parameters of Send Function Blocks

Table 489

485

Send Function Block STATUS Output Parameter Values (continued)

Status

Meaning and Action

The last send operation was completed successfully and the receiving controller sent an
acknowledgment. STATUS = 3 only if SENDFLG was set to false after STATUS was equal to 1.
The sending controller gets an acknowledgment from the receiving controller for each successfully
completed send (STATUS = 3). As soon as the acknowledgment is received, the sending controller
initiates another send because SENDFLG is set to true. If SENDFLG is set to true all the time, the
STATUS value oscillates between 2 and 4 unless a communication problem causes another type of
error.

The last send was completed successfully and a new send was initiated. The receiving controller
acknowledged that its TriStation 1131 application received the data.
STATUS = 3 only if SENDFLG was set to false after STATUS was equal to 1.
The sending controller gets an acknowledgment from the receiving node for each successfully
completed send (STATUS = 3). However, as soon as the acknowledgment is received, the sending
controller initiates another send because SENDFLG is set to true. If SENDFLG is set to true all the
time, the STATUS value oscillates between 2 and 4 unless a communication problem causes another
type of error.

100

The controller is trying to recover or establish communication with the receiving controller. This can
happen if there is no receiving controller connected to the network, or if there is no matching
Receive function block in the TriStation 1131 application of the receiving controller. The sending
controller will retry every 2 seconds to establish communication.
Make sure that the receiving controller is connected to the network. If the receiving controller is
connected and running, verify that the TriStation 1131 application includes a Receive function block
with parameters that exactly match those of the Send function block. If STATUS = 100, the
application should inform the operator of communication loss with the receiving controller.

101

The last send operation that was initiated has failed. There is a communication problem or other
problem in the receiving controller. The sending controller will retry every 2 seconds to establish
communication with the receiving controller. If the retry fails, STATUS is set to 100, and the
TriStation 1131 application should inform the operator of communication loss with the receiving
controller.

102

Bad identifier. SENDID, RECVNODE, or RECVID is out of range, or the SENDID is greater than the
Maximum Number of Peer-to-Peer Sends specified in the configuration.

103

The types or number of variables in the Send and Receive function block pair are mismatched. In
other words, the parameters defined for the Send and Receive function block pair do not match
exactly. This is a programming errorin one or both of the TriStation 1131 applicationsthat must
be corrected.

104

Number of values (N parameter) is out of range. The allowable range is 1 to 20 for TR_USEND
function blocks and 1 to 32 for TR_USEND_32 function blocks.

105

More than one Send function block has the same SENDID, or the same Send function block has been
called twice. This is a programming error. Each Send function block in the TriStation 1131
application must have a unique SENDID. If there is more than one Send function block with the
same SENDID, the first Send function block in the application will work properly. Other Send
function blocks with the same SENDID will result in error status 105.
Send function blocks must be evaluated exactly once per scan. Error status 105 results if the
application executes the same Send function block twice per scan. If the application does not execute
the Send function block during every scan, results are unpredictable.

TriStation 1131 Libraries Reference

486

Appendix B

Peer-to-Peer Parameters

Parameters of Receive Function Blocks


This section describes the operation of each parameter in a Receive function block and provides details
about the error values returned by the Status parameter.

RECVID
The RECVID input parameter specifies the identifier for this Receive function block. The legal range is
from 1 to the value specified for the Maximum Number of Receive. There must be a Send function block
in the sending controller with the same RECVID.
Each Receive function block in the application must have a unique RECVID. If there is more than one
Receive function block with the same RECVID, then the first Receive function block in the application will
work properly. Other function blocks with the same RECVID will result in an error status of 105.

SENDNODE
The SENDNODE input parameter specifies which controller will send data to this Receive function block.
The Receive function block will accept data only from the specified SENDNODE. It should be set to the
node number of the sending Triconex controller. The range is 1 to 63. (Note: Nodes 32 to 63 are valid for
Trident or Tri-GP controllers only.) If SENDNODE is out of range, calling the function block sets the
STATUS output to 102.

SENDID
The SENDID input parameter specifies which Send function block in the sending controller will send data
to this Receive block. There must be a Send function block call in the sending controller with the same
SENDID. The legal range is from 1 the value specified for the Maximum Number of Send. If SENDID is
out of range, calling the function block sets the STATUS output to 102.

N
The N input parameter specifies the number of values to be received (1 to 20 for TR_URCV function
blocks and 1 to 32 for TR_URCV_32 function blocks). The sending function block must specify the same
value for its N input parameter.

NDR
The NDR (New Data Received) output parameter indicates that new data has been received and is
available in the RD_01...RD_nn output parameters until new data is received again. NDR is true when the
STATUS parameter has a value of 1.

ERROR
The ERROR output parameter indicates that an error has occurred. ERROR is true when the STATUS
parameter is greater than or equal to 100.

STATUS
The STATUS output parameter allows the application to determine the status of communication with the
sending controller. This table describes the STATUS values.

TriStation 1131 Libraries Reference

Parameters of Receive Function Blocks

Table 490

487

Receive Function Block STATUS Ouput Parameter Values

Status

Meaning and Action

The Receive function block is ready to receive data.

New data has been received from the sending controller and is available in outputs RD_01...RD_nn
until new data is received again.

100

Reserved for future use.

101

Reserved for future use.

102

Bad identifier. RECVID, SENDNODE, or SENDID is out of range, or the RECVID is greater than the
value specified for Maximum Number of Receive.

103

Data was received from the sending controller but the number or type of variables received did not
exactly match the number or type of variables defined for the Receive function block. Data outputs
RD_01...RD_nn do not change. In other words, the parameters defined for the Send and Receive
function blocks do not match. This is a programming error in one or both applications, which should
ask the operator to make a correction.

104

Reserved for future use.

105

The program called the same Receive function block twice, or there is more than one Receive function
block with the same RECVID. This is a programming error. Each Receive function block in the
application must have a unique RECVID. If there is more than one Receive function block with the
same RECVID, then the first Receive function block in the application will work properly, but other
function blocks with the same RECVID will result in error status 105.

RD_01...RD_nn
The RD_ input parameters receive data values from the sending controller. A TR_URCV function block
can receive up to 20 values and a TR_URCV_32 function block can receive up to 32 values. These
parameters must match the number and type of the parameters specified in the corresponding Send
function block.

TriStation 1131 Libraries Reference

488

Appendix B

Peer-to-Peer Parameters

Peer-to-Peer Runtime Errors


The section explains runtime errors associated with these Peer-to-Peer function blocks:

TR_PEER_STATUS

All Send function blocks

All Receive function blocks

It takes 2 to 30 seconds to detect and report time-out and communication errors. A TriStation 1131
application that receives and acts on safety-critical data must verify that new data is received within the
specified process tolerance time. If the data is not received in time, the application must take appropriate
actions.

Table 491

Peer-to-Peer Runtime Error Descriptions

Error

Description

Detection

Suggested Action

COMM_OK is false on
TR_PEER_STATUS
function block

No communication path
between the sending and
receiving controllers.

Diagnostics on the CM
send a message to each
node. If no response is
received within 1 second,
the CM sets the output
false.

After initial start-up, the


TriStation 1131
application can use this
output to set an alarm.

One of the controllers is


disconnected from the
network, the CM has
failed, or the Ethernet
cable or field termination
is bad.
COMM_REDUNDANT is
false on
TR_PEER_STATUS
function block

STATUS is 100 on a Send


function block

No redundant
communication path
between the sending and
receiving controllers.

The MPs set the output


based on the status
received from each of
two CMs.

One of the controllers has


only one CM or has a
failed CM, or the
Ethernet cable or field
termination is bad.

The CMs report their


status to the MPs every
30 seconds.

There is no receiving
controller on the
network.
There is no matching
Receive function
block in the
receiving controller.
The receiving
controller is trying
to recover from a
communication
error.

STATUS is greater than or


equal to 102 on a Send
function block

TriStation 1131 Libraries Reference

The CM reports the


status to the MPs every
30 seconds.

There is a programming
error in the sending or
receiving controller.

This might or might not


be an error, depending
on system configuration.
If redundancy is used,
after initial start-up the
TriStation 1131
application can use the
STATUS output to set an
alarm.

The STATUS output is


updated whenever the
Send function block is
executed. If the
acknowledgment for the
last Send is not received
in 1 second, the sending
controller tries to send
the message again. If the
retry fails, then a
STATUS of 100 is
returned.

After initial start-up, the


TriStation 1131
application can use the
STATUS output to set an
alarm.

The MPs detect


programming errors.

After initial start-up,


programming errors
should not occur. If they
do, then the TriStation
1131 application should
use the STATUS output
to set an alarm.

Peer-to-Peer Runtime Errors

Table 491

489

Peer-to-Peer Runtime Error Descriptions (continued)

Error

Description

Detection

Suggested Action

STATUS is 100 on a
Receive function block

The receiving controller


is trying to establish
communication with the
sending controller.

The STATUS output is


updated whenever the
Receive function block is
executed.

After initial start-up, the


TriStation 1131
application can use the
STATUS output to set an
alarm.

STATUS is greater than or


equal to 101 on a Receive
function block

There is a programming
error in the sending or
receiving controller.

The MPs detect


programming errors.

After initial start-up,


programming errors
should not occur. If they
do, then the TriStation
1131 application should
use the STATUS output
to set an alarm.

TriStation 1131 Libraries Reference

490

Appendix B

Peer-to-Peer Parameters

TriStation 1131 Libraries Reference

Index

Symbols

arc cosine 11

* operator 209

arc sine 59

** operator 115

arc tangent 60

/ operator 101

array 53, 55, 57

+ operator 12

ARRAY32_BOOL function block 53

= operator 109

ARRAY32_DINT function block 55

> operator 136

ARRAY32_REAL function block 57

>= operator 126

ARRAYERR error flag 76

Numerics

ASCII mode
characters in station address 461
defined 459

-1.#INF 205, 206

A
ABS function 10
absolute value 10
ACK output parameter 484
ACOS function 11
ADD function 12
AIN function 14
AIN_BP function 15
AIN_BP12 function 17
AIN_HR function 19
alarm functions
BYPASS_BOOL 69
BYPASS_DINT 71
BYPASS_REAL 73
DEVIATION_ALARM_DINT 21
DEVIATION_ALARM_REAL 25
LEVEL_ALARM_DINT 29
LEVEL_ALARM_REAL 33
ROC_ALARM_DINT 37
ROC_ALARM_REAL 41
TRIP_ALARM 45
analog input 14, 15, 17, 19

ASIN function 59
ATAN function 60

B
BADCONV error flag 76
BADPARAM error flag 76
BADPARAM status flag 261
base ten logarithm 163
bistable 264, 281
bitwise AND 48
bitwise complement 217
bitwise NOT 217
bitwise OR 221
bitwise XOR 453
BLINK function block 61
BLINK_I function block 63
BLINK_R function block 65
BOOL data type 67
BOOL_TO_DWORD function 68
BYPASS_BOOL function 69
BYPASS_DINT function 71

analog output 50, 51

BYPASS_REAL function 73

AND function 48

AND operator 48
AOUT function 50
AOUT_BP12 function 51

calendar clock
adjusting 361
setting 363

492

Index

CEIL function 75

DINT_TO_REAL function 100

ceiling 75

DIV function 101

checksum field, in Modbus message format 461

DIVBYZERO error flag 76

CHK_ERR function block 76

down counter 89

CLR_ERR function block 80

DT data type 103

CONCAT_DT function 82

DT_TO_DATE function 104

concatenate 82

DT_TO_TOD function 105

COS function 83

DWORD data type 106

cosine 83

DWORD_TO_BOOL function 107

count down 89

DWORD_TO_DINT function 108

count up 91
count up-down 93

counting bits 219, 220

edge detector 117


rising 252

CR field 462
CRC error check 461
CSCHED function block 84
CSCHED_I function block 86
CSCHED_R function block 88
CTD function block 89
CTU function block 91

EQ function 109
error flags 76
ERROR output parameter 484, 486
errors 76
errors, Modbus data transmission 476
event collection 272, 274, 276, 278

CTUD function block 93

exception conditions, Modbus 477

exclusive OR 453

data types
BOOL 67
DATE 95
DINT 96
DT 103
DWORD 106
INT 140
LREAL 166
REAL 254
STRING 283
TIME 358
TOD 371

exception responses, Modbus 478, 479


execution scheduling 84, 86, 88, 441, 443, 445
EXP function 111
EXPFLTR function block 113
exponential 111
exponential filter 113
exponentiation 115
EXPT function 115

F
F_TRIG function block 117

date and time 104, 105


data type 103

falling edge 117

DATE data type 95

flags 76

deviation 229

flipflop 264, 281

DEVIATION_ALARM_DINT function 21

floating-point underflow
for LREAL data types 166
for REAL data types 254

DEVIATION_ALARM_REAL function 25
differential bipolar analog input 15, 17
DINT data type 96
DINT_TO_DWORD function 97
DINT_TO_INT function 98
DINT_TO_LREAL function 99

TriStation 1131 Libraries Reference

faults, clear faults function 391

FLOOR function 119


Force Multiple Coils function 474
Force Single Coil function 470

Index

LE function 152

gas detector 120

lead-lag compensation 154, 156

GASDETR function block 120

LEADLAG function block 154

GATDIS function block 123

LEADLAG_R function block 156

gate disable 123

less than or equal to operator 152, 174

gate enable 124

LEVEL_ALARM_DINT function 29

GATENB function block 124

LEVEL_ALARM_REAL function 33

GE function 126

LF field 462

GetDelta_DINT function 128

LIMIT function 158

GetDelta_REAL function 130

line monitor 160

GetDeltaT function 132

LINEMNTR function block 160

GetTimer function 134

LN function 162

gradual underflow
effect on absolute and relative error 167, 255
for LREAL data types 166
for REAL data types 254

LOG function 163

GT function 136

logical AND 48

H
high-resolution analog input 19

I
i.LREAL numbers, precision when approaching
zero 167
I/O modules, status 392
IEC-559 Standard Floating-Point format 254
inclusive OR 221
-INF 205, 206
INFINITY_LREAL function 138
INFINITY_REAL function 139
INT data type 140
INT_TO_DINT function 141
INT_TO_LREAL function 142
INT_TO_REAL function 143
integration 144, 146
INTERNALERR error flag 76
INTGTOR function block 144
INTGTOR_R function block 146
IsFinite_LREAL function 148
IsFinite_REAL function 149
IsNan_LREAL function 150
IsNan_REAL function 151

L
latch 264, 281

493

logarithm
base ten 163
natural 162
logical NOT 217
logical OR 221
logical XOR 453
long reals, precision when approaching zero 167
longitudinal redundancy check. See LRC checksum.
loop detector 164
Loop-Back Diagnostic Test function 473
LOOPDETR function block 164
LRC checksum, calculation 462
LREAL data type 166
LREAL_TO_DINT function 168
LREAL_TO_INT function 170
LREAL_TO_REAL function 172
LT function 174

M
MAX function 176
MBCTRL function block 178
MBREAD_BOOL function block 180
MBREAD_DINT function block 182
MBREAD_REAL function block 184
MBREAD_REAL_TRD function block 188
MBWRITE_BOOL function block 191
MBWRITE_DINT function block 193
MBWRITE_REAL function block 195
MBWRITE_REAL_TRD function block 198
median 201

TriStation 1131 Libraries Reference

494

Index

MEDSEL function 201

NUMBITS function 219

message response time 457

NUMBITS_DWORD function 220

MIN function 203


MINUS_INFINITY_LREAL function 205

MINUS_INFINITY_REAL function 206

OR function 221

MOD function 207

OR operator 221

Modbus, alias mapping 184, 195

OTHER error flag 76

Modbus communication, noise sources 476

output voter diagnostics 223, 224

Modbus devices, RTU and ASCII modes 459

OVDDISABLE function block 223

Modbus functions
list of names and codes 459
supported by serial ports 459

OVDENABLE function block 224

Modbus master
reading values from a slave 180, 182, 184, 188
setting timeout and retry values 178
writing values to a slave 191, 193, 195, 198

Modbus protocol
checksum field 461
exception conditions 477
exception responses 478, 479
function code field, described 461
message format 461
message header 461
message lengths 464
overview 456
performance considerations 458
query and response 463
station address field 461
modulo 207
monitoring analog current loops 160
MOVE function 208
MUL function 209
MUX function 211

N
N input parameter 484, 486
NAN 150, 151, 213, 214
NAN_LREAL function 213
NAN_REAL function 214
natural exponential 111
natural logarithm 162
NDR output parameter 486
NE function 215
noise sources, Modbus communication 476
not a number (NAN) 150, 151, 213, 214
NOT function 217
NOT operator 217

TriStation 1131 Libraries Reference

OVERFLOW error flag 76

PACK16 function 225


PACK32 function 226
packing bits 225, 226, 447, 449
PAGE_EJECT function block 227
parity checking, Modbus transmission errors 476
Peer-to-Peer
receive 411, 413, 415, 417, 419
runtime errors 488
send 421, 423, 425, 427, 429
percent deviation 229
PERDEV function 229
performance, Modbus functions 458
PID function block 230
PID_R function block 232
Poly4 function 234
POLY5 function 235
polynomial 234, 235
power 115
Preset Multiple Registers function 475
Preset Single Register function 471
PRINT_BOOL function block 236
PRINT_CDT function block 238
PRINT_CRLF function block 240
PRINT_CTOD function block 242
PRINT_DINT function block 244
PRINT_REAL function block 246
PRINT_STRING function block 248
PRNTR_FLUSH function block 250
proportional integral derivative (PID) 230, 232

R
R_TRIG function block 252

Index

495

RANGE error flag 76

set reset 281

RD_nn 487

shift left 269

Read Coil Status function 466

shift right 270

Read Exception Status function 472

SHL function 269

Read Holding Registers function 468

SHR function 270

Read Input Registers function 469

shutdown 298, 309, 340, 345, 392, 407, 431

Read Input Status function 467

SIN function 271

REAL data type 254

sine 271

real number, precision when approaching zero 255

SOECLR function block 272

real time clock 266

SOESTAT function block 274

REAL_TO_DINT function 256

SOESTOP function block 276

REAL_TO_INT function 258

SOESTRT function block 278

REAL_TO_LREAL function 260

special numbers 138, 139, 148, 149, 150, 151

RECVID input parameter 483, 486

SQRT function 280

RECVNODE input parameter 483

square root 280

remainder 207

SR function block 281

remote access 124

station address field, Modbus message 461

remote write access 123

status
critical I/O modules 392
safety-critical I/O modules 298
Tricon 64 point 385
Tricon chassis 389
Tricon main processor 395
Tricon Peer-to-Peer 397
Tricon points 399
Tricon port 401
Tricon program 403
Tricon scan 405
Tricon slot 409
Trident analog input module 287
Trident analog output module 289
Trident combo AI/DI input module 300
Trident communication module 295
Trident discrete input module 302
Trident discrete output module 304
Trident high resolution discrete input module 306
Trident I/O module 309
Trident I/O processor 311
Trident main processor 314, 319
Trident pulse input module 324
Trident relay output module 327
Trident supervised discrete output module 329
Trident system 342
Tri-GP analog input module 287
Tri-GP analog output module 289
Tri-GP combo AI/DI input module 300
Tri-GP communication module 295
Tri-GP discrete input module 302
Tri-GP discrete output module 304
Tri-GP high resolution discrete input module 306

ReportBadParam function 261


reset set 264
rising edge detector 252
rising edge trigger 252
ROC_ALARM_DINT function 37
ROC_ALARM_REAL function 41
ROL function 262
ROR function 263
RS function block 264
RTC function block 266
RTU mode 459
runtime error flags 76
runtime errors, Peer-to-Peer 488

S
SCALE function 267
scan time, effect on Modbus performance 458
scheduling execution 84, 86, 88, 441, 443, 445
SD_nn input parameters 484
SEL function 268
select 268
SENDFLG input parameter 483
SENDID input parameter 483, 486
SENDNODE input parameter 486
SENT output parameter 484
sequence of events 272, 274, 276, 278

TriStation 1131 Libraries Reference

496

Index

status (continued)
Tri-GP I/O module 309
Tri-GP I/O processor 311
Tri-GP main processor 314, 319
Tri-GP pulse input module 324
Tri-GP relay output module 327
Tri-GP supervised discrete output module 329
Tri-GP system 342
status flags 76
STATUS output parameter 484
STATUS output values 486
STRING data type 283
STRLEN error flag 76
SUB function 284
subtraction operator 284
SYS_AI32_STATUS function block 287
SYS_AO04_STATUS function block 289
SYS_APP_HALT function 291
SYS_CLEAR_FLTS function 293
SYS_CM_STATUS function block 295
SYS_CRITICAL_IO function block 298
SYS_DI16_AI16_STATUS function block 300
SYS_DI32_STATUS function block 302
SYS_DO16_STATUS function block 304
SYS_HRDI32_STATUS function block 306
SYS_IO_STATUS function block 309
SYS_IOP_STATUS function block 311
SYS_MP_EXT_STATUS function block 314
SYS_MP_RESET_PORTS function 317
SYS_MP_STATUS function block 319
SYS_OVD_INHIBIT function 322
SYS_PI06_STATUS function block 324
SYS_RO32_STATUS function block 327
SYS_SDO16_STATUS function block 329
SYS_SERIAL_PORT function block 332
SYS_SET_APP_LOCK function 334
SYS_SET_PROG_ALARM function 336
SYS_SET_REMOTE_WRT_ENBL function 338
SYS_SHUTDOWN function block 340
SYS_SYSTEM_STATUS function block 342
SYS_VOTE_MODE function block 345

T
TAN function 347
tangent 347

TriStation 1131 Libraries Reference

TCJ_CONV function 348


TCK_CONV function 350
TDD_I function block 352
TDD_R function block 353
TDE_I function block 355
TDE_R function block 356
TGL coil 375
thermocouple 348, 350
TIME data type 358
time of day 105
TIME_TO_SECS function 359, 360
TIMEADJ function block 361
TIMESET function block 363
TMR function block 365
TMR_I function block 367
TMR_R function block 369
TOD data type 371
TOF function block 372
TOGGLE function block 375
TON function block 377
TP function block 379
TP_I function block 381
TP_R function block 383
TR_64_POINT_STATUS function block 385
TR_CALENDAR function block 387
TR_CHASSIS_STATUS function block 389
TR_CLEAR_FLTS 391
TR_CRITICAL_IO function block 392
TR_MP_STATUS function block 395
TR_PEER_STATUS function block 397
TR_POINT_STATUS function block 399
TR_PORT_STATUS function block 401
TR_PROGRAM_STATUS function block 403
TR_SCAN_STATUS function block 405
TR_SHUTDOWN function block 407
TR_SLOT_STATUS function block 409
TR_URCV_BOOL function block 411
TR_URCV_DINT function block 413
TR_URCV_DINT_32 function block 415
TR_URCV_REAL function block 417
TR_URCV_REAL_32 function block 419
TR_USEND_BOOL function block 421
TR_USEND_DINT function block 423
TR_USEND_DINT_32 function block 425

Index

497

TR_USEND_REAL function block 427


TR_USEND_REAL_32 function block 429
TR_VOTE_MODE function block 431
training x
transmission errors, Modbus 476
Triconex contact information x
trigger 117
rising edge 252
TRIP_ALARM function 45
TRUNC_LREAL_TO_DINT function 433
TRUNC_LREAL_TO_INT function 435
TRUNC_REAL_TO_DINT function 437
TRUNC_REAL_TO_INT function 439
TSCHED function block 441
TSCHED_I function block 443
TSCHED_R function block 445
Type J thermocouple 348
Type K thermocouple 350

U
underflow
gradual for LREAL data types 166
gradual for REAL data types 254
UNDERFLOW error flag 76
UNPACK16 function block 447
UNPACK32 function block 449
up counter 91
up-down counter 93

W
write access 123

X
X_OF_N function block 451
XOR function 453
XOR operator 453

TriStation 1131 Libraries Reference

498

Index

TriStation 1131 Libraries Reference

Invensys Operations Management


5601 Granite Parkway Suite 1000
Plano, TX 75024
United States of America
http://iom.invensys.com

Global Customer Support


Inside U.S.: 1-866-746-6477
Outside U.S.: 1-508-549-2424 or contact your
local Invensys representative.
Email: iom.support@invensys.com
Website: http://support.ips.invensys.com