Time management instructions: Dates, Times, Duration. Schneider Electric PL7 Micro/Junior/Pro - Detailed
Advertisement
Advertisement
2.8
Advanced instructions
Time management instructions: Dates, Times,
Duration
Introduction
Aim of this subsection
What's in this
Section?
This sub-section describes the time management instructions: Dates, Times,
Duration, of PL7 language
This Section contains the following Maps:
Topic
Format of parameters in the time management instructions
Using system bits and words
Real time clock function
Reading system date
Updating the system date
Reading stop date and code
Reading day of the week
Addition / Subtraction of a duration from a date
Addition / Subtraction of a duration from a time of day
Interval between two dates (without time)
Interval between two dates (with time)
Interval between two times
Conversion of a date into a string of characters
Conversion of a complete date into a string of characters
Conversion of a duration into a string of characters
Conversion of a time of day to a character string
Conversion of a duration into HHHH:MM:SS
Page
TLX DR PL7 xxE
199
Advanced instructions
Format of parameters in the time management instructions
General The Date, Time, Duration parameters used by these instructions correspond to the typical formats defined by the standard IEC1131-3.
Duration Format
(TIME Type)
This format is used to encode durations periods expressed in tenths of a second and corresponds to the TIME format in the standard.
Such values are displayed in the form: sssssssss.d
This gives for example: 3674.3 , for 1 hour, 1 minute, 14 seconds et 3 tenths
The value is coded in 32 bits (a double word) with the range fixed at [0, 4294967295] tenths of a second, which represents approximately 13 years and 7 months.
Note: Only values within the interval [00:00:00, 23:59:59] are allowed.
Date Format
(DATE Type)
This format is used to code the year, the month and the day. It corresponds to the
DATE format in the standard.
The value is displayed in the form: yyyy-mm-dd
This gives for example: 1984-06-25
The value is coded in BCD in 32 bits (a double word) with 3 fields:
31
Year
16 8
Month Day
0
Year: 4 digits
Month: 2 digits
Day: 2 digits
Example, expressed in hexadecimals:
19H 84H 06H 25H = 1984-06-25
Note: Only values within the interval [1990-01-01, 2099-12-31] are allowed.
200
TLX DR PL7 xxE
Time of day
Format (TOD
Type)
Advanced instructions
This format is used to code the hour, the minutes and the seconds. It corresponds to the TIME_OF_DAY format in the standard.
The value is displayed in the form: hh:mm:ss
This gives for example: 23:12:34
The value is coded in BCD in 32 bits (a double word) with 3 fields:
31 24 16 8 0
Hour Mins.
Sec.
Hours: 2 digits (most significant words)
Minutes: 2 digits (most significant words)
Seconds: 2 digits (least significant words)
Example, expressed in hexadecimals:
23H 12H 34H = 23:12:34
Note: Only values within the interval [00:00:00, 23:59:59] are allowed.
Date and time
Format (DT Type)
This format is used to code the year, the month, the day, the hour, the minutes and the seconds. It corresponds to the DATE_AND_TIME format in the standard.
The value is displayed in the form: yyyy-mm-dd-hh:mm:ss
This gives for example: 1984-06-25-23:12:34
The value is coded in BCD in 64 bits (a table of words of length 4):
64
Year
48 40
Month Day
32
Hour
24
Mins.
16
Sec.
8 0
Example, expressed in hexadecimals:
1984H 06H 25H 23H 12H 34H
Note: Only values within the interval [1990-01-01-00:00:00, 2099-12-31-23:59:59] are allowed.
TLX DR PL7 xxE
201
Advanced instructions
Hour, Minute,
Second Format
(HMS Type)
This format used exclusively by the TRANS_TIME function is used to code the hours, the minutes and the seconds.
The value is displayed in the form: hh:mm:ss
This gives for example: 23:12:34
The value is coded in BCD in 32 bits (a double word) with 3 fields:
31 16 8 0
Hour Mins.
Sec.
Hours: 4 digits (most significant words)
Minutes: 2 digits (least significant words)
Seconds: 2 digits (least significant
Example, expressed in hexadecimals:
23H 12H 34H = 23:12:34
202
TLX DR PL7 xxE
Advanced instructions
Using system bits and words
System bit %S17 The system bit %S17 is set in the following cases: l l
Result of an operation outside the range of permitted values
An input parameter cannot be interpreted and is not coherent with the desired format (DATE, DT or TOD) l l
Operation on a Time of Day (TOD) format involving a change of day
Real time clock access conflict
System bit %S15 The system bit %S15 is set to 1 when a string is being written in a table, when this string is longer than the size of the table.
System words System words: l %SD18 : absolute time counter is also used to calculate durations (incremented l every 1/10 of a second by the system)
%SW49 à %SW53 (See
Description of system words %SW48 to %SW59, p. 302)
can also be used to display dates
TLX DR PL7 xxE
203
Advanced instructions
Real time clock function
General
Syntax
This function is used to send commands at predefined or calculated times and dates.
It sets the output parameter OUT to 1 providing the date provided by the PLC clock at the moment of the function call falls within the period programmed in the input parameters.
Real time clock function operator
SCHEDULE (DBEG, DEND, WEEK, HBEG, HEND, OUT)
Characteristics of parameters:
Output OUT
Start date
End date
Day of the week
DBEG
DEND
WEEK
Start time
End time
HBEG
HEND
Bit containing the result of the comparisons made by the real time clock function: at 1 during the periods defined by the parameters.
Word encoding the start date of the period (monthdate) in BCD (thresholds: 01-01 to 12-31)
Word encoding the end date of the period (monthdate) in BCD (thresholds: 01-01 to 12-31)
Word encoding the day or days of the week which are included in the period defined by the parameters
DBEG and DEND.
The 7 least significant bits represent the 7 days of the week: bit 6 = Monday, bit 5 = Tuesday,…, bit 0 =
Sunday.
Double word encoding the start time of the period in the day (hours-minutes-seconds) in Time of Day
BCD format (type: TOD). Thresholds: 00:00:00,
23:59:59
Double word encoding the end time of the period in the day (hours-minutes-seconds) in Time of Day
BCD format (type: TOD). Thresholds: 00:00:00,
23:59:59
204
TLX DR PL7 xxE
Structure
Advanced instructions
Ladder language
OPERATE
SCHEDULE(%KW0,%KW1,%KW2,%KD3,%KD5,%M0)
Examples
Instruction list language
LD TRUE
[SCHEDULE(%KW0,%KW1,%KW2,%KD3,%KD5,%M0)]
Structured text language
SCHEDULE(%KW0,%KW1,%KW2,%KD3,%KD5,%M0) ;
Example: Programming 2 non-continuous time ranges
SCHEDULE (16#0501,
16#1031,
2#0000000001111100,
16"08300000,
16#12000000,
%M0
);
SCHEDULE (16#0501,
16#1031,
2#0000000001111100,
16"14000000,
16#18000000,
%M1
);
%Q0.0:=%M0 OR %M1;
(*start date: 1st May*)
(*end date: 31st October*)
(*Monday to Friday*)
(*start time: 8.30a.m.*)
(*end time: 6p.m.*)
(*result in %M0*)
(*start date: 1st May*)
(*end date: 31st October*)
(*Monday to Friday*)
(*start time: 2p.m.*)
(*end time: 6p.m.*)
(*result in %M1*)
TLX DR PL7 xxE
205
Advanced instructions
Operands Real time clock function operands
Type
Indexable words
Non-indexable words
Indexable double words
Non-indexable double words
Bits
DBEG,DEND,WEEK HBEG,HEND
%MW,%KW,%Xi.T
-
%IW,%QW,%SW,%N
W,Imm.val.,Num.expr.
%MD,%KD
-
-
%ID,%QD,Imm.val.,
Num.expr.
-
OUT
-
-
-
-
%I,%Q,%M,%S,
%BLK,%*:Xk,%X
Note: l The 2 parameters DBEG and DEND define a range of days in the year; this range can overlap 2 civil years. Example: from 10th October to 7th April. The l
29th February can be included in this period; it will ignored in non-leap years.
The 2 parameters HBEG and HEND define a range of time in the day; this range can overlap 2 civil days. Example: from 10p.m. to 6:10:20a.m.
l If one of the DBEG and DEND dates or one of the HBEG and HEND times is invalid, i.e. it does not correspond to a real date or time, the OUT output will be at 0 and the %S17 bit will be set to 1.
l l
If the target PLC does not have an internal clock (as in TSX37-10), the output will be at 0 and the system bit %S17 will be set to 1.
It is possible to lighten the load on a PLC processor where precision is not important by cadencing the call to the SCHEDULE function using the system bit
%S6 or %S7.
206
TLX DR PL7 xxE
Advanced instructions
Reading system date
General
Structure
Reading the system date (Real Time Clock) and transferring into the object set in the parameters in Date and Time format (DT).
Ladder language
%M6
OPERATE
RRTC(%MW2:4)
Examples
Syntax
Instruction list language
LD %M6
[RRTC(%MW2:4)]
Structured text language
IF %M6 THEN
RRTC(%MW2:4) ;
END_IF;
Example: RRTC(%MW2:4)
The result is transferred to the table of internal words of length 4: %MW2 to %MW5.
System date read operator
Syntax
RRTC (date)
System date read operands
Type
Table of 4 Words in Date and
Time format
Date
%MW:4
TLX DR PL7 xxE
207
Advanced instructions
Updating the system date
General
Structure
Updating the system date (Real Time Clock) and transferring into the object given in parameter in Date and Time format (DT).
Language data
%M7
OPERATE
%MW2:=16#4300
OPERATE
%MW3:=16#1732
OPERATE
%MW4:=16#1124
OPERATE
%MW5:=16#1995
OPERATE
WRTC(%MW2:4)
Instruction list language
LD %M7
[%MW2:=16#4300]
[%MW3:=16#1732]
[%MW4:=16#1124]
[%MW5:=16#1995]
[WRTC(%MW2:4)]
Structured text language
IF %M7 THEN
%MW2:=16#4300 ;
%MW3:=16#1732 ;
%MW4:=16#1124 ;
%MW5:=16#1995 ;
WRTC(%MW2:4) ;
END_IF;
208
TLX DR PL7 xxE
Examples
Syntax
Advanced instructions
Example: The new date is loaded into an internal word table with a length of 4
%MW2:4, then sent to the system by the WRTC functions
System date updating operator
Syntax
WRTC (date)
System date updating operands
Type
4 Word Table
Date
%MW:4,%KW:4 in date and time format
TLX DR PL7 xxE
209
Advanced instructions
Reading stop date and code
General
Structure
Reading of the date of the last PLC stop and of the code specifying the cause of this stop (in the 5th word, equivalent to %SW58 (See Description of system words
Ladder language
%M7
OPERATE
PTC(%MW4:5)
Examples
Syntax
Instruction list language
LD %M7
[PTC(%MW4:5)]
Structured text language
IF %M7 THEN
PTC(%MW4:5) ;
END_IF;
Example: PTC(%MW4:5)
The result is transferred to the table of internal words of length 5: %MW4 to %MW8
Read stop date and code operator
Syntax
PTC (date)
Read stop date and code operands
Type
5 Word table in Date and Time format
Date
%MW:5
210
TLX DR PL7 xxE
Advanced instructions
Reading day of the week
General
Structure
This result of this function is to supply current day of the week information in the form of a digit between 1 and 7 transferred in a word (1 = Monday, 2 = Tuesday, 3 =
Wednesday, 4 = Thursday. 5 = Friday, 6 = Saturday, 7 = Sunday).
Ladder language
%M7
OPERATE
%MW5:=DAY_OF_WEEK()
Examples
Syntax
Instruction list language
LD %M7
[%MW5:=DAY_OF_WEEK()]
Structured text language
IF %M7 THEN
%MW5:=DAY_OF_WEEK() ;
END_IF;
Example: %MW5:=DAY_OF_WEEK()
%MW5:=4 corresponds to Thursday
Read day of the week operator
Syntax
Result:= DAY_OF_WEEK()
Read day of the week operands
Type
Indexable words
Result (res)
%MW
Non-indexable words %QW,%SW,%NW
Note: If the function has not been able to update the result following a real-time clock access error, the result returned is 0 and the system bit %S17 is set at 1.
TLX DR PL7 xxE
211
Advanced instructions
Addition / Subtraction of a duration from a date
General
Structure
Addition or subtraction of a duration (in tenths of a second) (In2) from a source date
(In1). The result is a new date transferred in a 4 word table.
ADD_DT () = Addition of a duration
SUB_DT () = Subtraction of a duration
Ladder language
%M7 OPERATE
RRTC(%MW2:4)
OPERATE
%MD8:=906
OPERATE
%MW2:4:=ADD_DT(%MW2:4,%MD8)
OPERATE
WRTC(%MW2:4)
Instruction list language
LD %M7
[RRTC(%MW2:4)]
[%MD8:=906]
[%MW2:4:=ADD_DT(%MW2:4,%MD8)]
[WRTC(%MW2:4)]
Structured text language
IF %M7 THEN
RRTC(%MW2:4);
%MD8:=906;
%MW2:4:=ADD_DT(%MW2:4,%MD8) ;
WRTC(%MW2:4);
END_IF;
212
TLX DR PL7 xxE
Examples
Syntax
Advanced instructions
Example: %MW2:4:=ADD_DT(%MW2:4,%MD8)
%MW2:4:= Source date
%MD8:=906 (906 tenths of a second rounded off to 1 min. 31s)
%MW2:4:= New date
Operators for addition/subtraction of a time duration from a date
Syntax
Result:= ADD_DT (In1, In2)
Result:= SUB_DT (In1, In2)
Operands for addition/subtraction of a time duration from a date
Type Result (res)
Tables of 4 Words in
Date and Time format
%MW4
Indexable double words
Non-indexable double words
-
In1 (source date) In2 (duration)
%MW4:4,%KW:4 -
-
-
%MD,%KD
%ID,%QD,Imm.val.,
Num.expr.
l l
Note: l The rounding off principle will be applied to the ‘duration’ parameter (expressed in tenths of a second) to enable the addition or subtraction from the date (precise to the second).
l sssssssss.0 à sssssssss.4 rounded off to sssssssss.0
l sssssssss.5 à sssssssss.9 rounded off to sssssssss.0 +1.0
The application is to provide for the management of leap years.
If the result of the operation is outside the interval for permitted values, the system bit %S17 is set at 1 and the result value is equal to the minimum limit l
(for SUB_DT) or remains blocked at the maximum (for ADD_DT).
If the input parameter ‘source date’ cannot be interpreted and is not coherent in
DT format (DATE_AND_TIME), the system bit %S17 is set at 1 and the result value is equal to 0001-01-01-00:00:00.
TLX DR PL7 xxE
213
Advanced instructions
Addition / Subtraction of a duration from a time of day
General
Structure
Addition or subtraction of a duration to a time of day. The result is a new time of day transferred in a double word.
ADD_TOD () = Addition of a duration
SUB_TOD () = Subtraction of a duration
Ladder language
%M7
OPERATE
%MD8:=906
OPERATE
%MD2:=ADD_TOD(%MD2,%MD8)
Examples
Instruction list language
LD %M7
[%MD8:=906]
[%MD2:=ADD_TOD(%MD2,%MD8)]
Structured text language
IF %M7 THEN
%MD8:=906;
%MD2:=ADD_TOD(%MD2,%MD8) ;
END_IF;
Example: %MD2:=ADD_TOD(%MD2,%MD8)
%MD2:= Source time (e.g.: 12:30:00)
%MD8:= 906 (906 tenths of a second rounded off to 1 min. 31s)
%MD2:= New time (e.g.: 13:31:31)
214
TLX DR PL7 xxE
Syntax
Advanced instructions
Operators for addition/subtraction of a time duration from a time of day
Syntax
Result:= ADD_TOD (In1, In2)
Result:= SUB_TOD (In1, In2)
Operands for addition/subtraction of a time duration from a time of day
Type
Indexable double words
Non-indexable double words
Result (res)
%MD
%QD
In1 (source time) and In2 (duration)
%MD,%KD
%ID,%QD,Imm.val.,Num.expr.
result and In1 are in TOD format, In2 is in duration format.
Note: l The rounding off principle will be applied to the ‘duration’ parameter (expressed in tenths of a second) to enable the addition or subtraction from the date (precise l to the second).
l sssssssss.0 à sssssssss.4 rounded off to sssssssss.0
l sssssssss.5 à sssssssss.9 rounded off to sssssssss.0 +1.0
The day is changed if the result of the operation is outside the interval for l permitted values. In this case, the system bit %S17 is set at 1 and the value of the result can be interpreted with a 24:00:00 rollover.
If the input parameter ‘time of day’ cannot be interpreted in TOD format, the system bit %S17 is set at 1 and the result value is equal to 00:00:00.
TLX DR PL7 xxE
215
Advanced instructions
Interval between two dates (without time)
General
Structure
Calculates the time interval between two dates. The result, given as an absolute value, is transferred in a double word.
Ladder language
%M7
OPERATE
%MD10:=DELTA_D(%MD2,%MD4)
Examples
Syntax
216
Instruction list language
LD %M7
[%MD10:=DELTA_D(%MD2,%MD4)]
Structured text language
IF %M7 THEN
%MD10:=DELTA_D(%MD2,%MD4) ;
END_IF;
%MD10:=DELTA_D(%MD2,%MD4)
%MD2:= Date number1 (e.g.: 1994-05-01)
%MD4:= Date number2 (e.g.: 1994-04-05)
==> %MD10:= 22464000 (==> interval = 26 days)
Operator for an interval between two dates (without time)
Syntax
Result:= DELTA_D (Date1, Date2)
Operands for an interval between two dates (without time)
Type
Indexable double words
Non-indexable double words
Result (res)
%MD
%QD
Date 1 and 2
%MD,%KD
%ID,%QD,Imm.val.,Num.expr.
result is in TIME format, Date 1 and 2 are in DATE format.
TLX DR PL7 xxE
Advanced instructions
The TIME format is defined with precision to a tenth of a second. The DATE format is defined with precision to a day. The calculated time interval will be a multiple of
864000 (= 1day = 24 h x 60 mn x 60 s x 10 tenths).
Note: l There is overflow if the result exceeds the maximum value permitted for a duration (TIME). In this case, the result is equal to 0 and the system bit %S18 is set at 1.
l If one of the input parameters cannot be interpreted and is not coherent in DATE format, the system bit %S17 is set at 1 and the result is equal to 0.
TLX DR PL7 xxE
217
Advanced instructions
Interval between two dates (with time)
General
Structure
Calculates the time interval between two dates. The result, given as an absolute value, is transferred in a double word.
Ladder language
OPERATE
%MD10:=DELTA_DT(%MW2:4,%MW6:4)
Examples
Instruction list language
LD TRUE
[%MD10:=DELTA_DT(%MW2:4,%MW6:4)]
Structured text language
%MD10:=DELTA_DT(%MW2:4,%MW6:4) ;
%MD10:=DELTA_DT(%MW2:4,%MW6:4)
%MW2:4:= Date number1 (e.g.: 1994-05-01-12:00:00)
%MW6:4:= Date number2 (e.g.: 1994-05-01-12-01-30)
==> %MD10:= 900 (==> interval = 1 minute and 30 seconds)
218
TLX DR PL7 xxE
Syntax
Advanced instructions
Operator for an interval between two dates (with time)
Syntax
Result:= DELTA_DT (Date1, Date2)
Operands for an interval between two dates (with time)
Type
Indexable double words
Non-indexable double words
4 word table in DT format
Result (res)
%MD
%QD
-
Date 1 and 2
-
-
%MW:4,%KW:4 result is in TIME format, Date 1 and 2 are in DT format.
The TIME format is defined with precision to a tenth of a second. The DT format is defined with precision to a second. The calculated time interval is a multiple of 10.
Note: l There is overflow if the result exceeds the maximum value permitted for a duration (TIME). In this case, the result is equal to 0 and the system bit %S18 is set at 1.
l If one of the input parameters cannot be interpreted and is not coherent in DT format, the system bit %S17 is set at 1 and the result is equal to 0.
TLX DR PL7 xxE
219
Advanced instructions
Interval between two times
General
Structure
Calculates the time interval between two times of day. The result is transferred in a double word as an absolute value giving a duration.
Ladder language
OPERATE
%MD10:=DELTA_TOD(%MD2,%MD4)
Examples
Syntax
220
Instruction list language
LD TRUE
[%MD10:=DELTA_TOD(%MD2,%MD4)]
Structured text language
%MD10:=DELTA_TOD(%MD2,%MD4) ;
%MD10:=DELTA_TOD(%MD2,%MD4)
%MD2:= Time1 (e.g.: 02:30:00)
%MD4:= Time2 (e.g.: 02 41 00)
==> %MD10:= 6600 (==> interval = 11 minutes)
Operator for an interval between two times
Syntax
Result:= DELTA_TOD (Date1, Date2)
Operands for an interval between two times
Type
Indexable double words
Non-indexable double words
Result (res)
%MD
%QD
Time 1 and 2
%MD,%KD
%ID,%QD, Immediate value, Numeric expr.
result is in TIME format, Time 1 and 2 are in TOD format.
The TIME format is defined with precision to a tenth of a second. The TOD format is defined with precision to a second. The calculated time interval is a multiple of 10.
TLX DR PL7 xxE
Advanced instructions
Note: If one of the input parameters cannot be interpreted and is not coherent in
TOD format, the system bit %S17 is set at 1 and the result is equal to 0.
TLX DR PL7 xxE
221
Advanced instructions
Conversion of a date into a string of characters
General
Structure
This instruction converts a date into a string of characters (without time) in the following format: YYYY-MM-DD (10 characters). This string ends with an end character Ø. Each character Y,M,D symbolizes a digit.
Ladder language
OPERATE
%MB2:11=DATE_TO_STRING(%MD40)
Examples
Instruction list language
LD TRUE
[%MB2:11=DATE_TO_STRING(%MD40)]
Structured text language
%MB2:11=DATE_TO_STRING(%MD40) ;
%MB2:11=DATE_TO_STRING(%MD40)
%MD40:= Date (e.g.: 1998-12-27)
%MB 2 3 4 5 6 7 8 9 10 11 12
‘1’ ‘9’ ‘9’ ‘8’ ‘-’ ‘1’ ‘2’ ‘-’ ‘2’ ‘7’ Ø
222
TLX DR PL7 xxE
Syntax
Advanced instructions
Date to string conversion operator
Syntax
Result:= DATE_TO_STRING (Date)
Date to string conversion operands
Type
Tables of 11 bytes
Indexable double words
Non-indexable double words
Result (res)
%MB:11
-
-
Date
-
%MD,%KD
%ID,%QD, Immediate value, Numeric expr.
Note: l If the input (date) parameter cannot be interpreted and is not coherent in DATE format, the system bit %S17 is set at 1 and the function returns the string **** l
- ** - ** .
If the output string is too short, it is truncated and the system bit %S15 is set to 1.
%MB2:8 := DATE_TO_STRING(%MD40)
==> %MB 2 3 4 5 6 7 8 9
‘1’ ‘9’ ‘9’ ‘8’ ‘-’ ‘1’ ‘2’ ‘-’
==> %S15 = 1 l If the output string is too long, it is completed with end characters Ø.
%MB2:12 := DATE_TO_STRING(%MD40)
==> %MB 2 3 4 5 6 7 8 9 10 11 12 13
‘1’ ‘9’ ‘9’ ‘8’ ‘-’ ‘1’ ‘2’ ‘-’ ‘2’ ‘7’ Ø Ø
TLX DR PL7 xxE
223
Advanced instructions
Conversion of a complete date into a string of characters
General
Structure
This instruction converts a complete date (with time) into a string of characters in the following format: YYYY-MM-DD-HH:MM:SS (19 characters). This string ends with an end character Ø. Each character Y,M,D,H,M,S symbolizes a digit.
Ladder language
OPERATE
%MB2:20=DT_TO_STRING(%MW50:4)
Examples
Instruction list language
LD TRUE
[%MB2:20=DT_TO_STRING(%MW50:4)]
Structured text language
%MB2:20=DT_TO_STRING(%MW50:4) ;
%MB2:20=DT_TO_STRING(%MW50:4)
%M50:4:= Date and time (type DT) (e.g.: 1998-12-27-23:14:37)
==>
%MB 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
‘1’ ‘9’ ‘9’ ‘8’ ‘-’ ‘1’ ‘2’ ‘-’ ‘2’ ‘7’ ‘-’ ‘2’ ‘3’ ‘:’ ‘1’ ‘4’ ‘:’ ‘3’ ‘7’ Ø Ø
224
TLX DR PL7 xxE
Syntax
Advanced instructions
Complete date to string conversion operator
Syntax
Result:=DT_TO_STRING(Date)
Complete date to string conversion operands
Type
Tables of 20 bytes
4 word table in DT format
Result (res)
%MB:20
-
Date
-
%MW:4,%KW:4
Note: l If the (date) input parameter cannot be interpreted and is not coherent in
DT (DATE_AND_TIME) format, the system bit %S17 is set at 1 and the function l returns the string ****-**-**-**:**:** .
If the output string is too short, it is truncated and the system bit %S15 is set to 1.
%MB2:8:=DT_TO_STRING(%MW50:4)
==> %MB 2 3 4 5 6 7 8 9
‘1’ ‘9’ ‘9’ ‘8’ ‘-’ ‘1’ ‘2’ ‘-’
==> %S15 = 1 l If the output string is too long, it is completed with end characters Ø.
%MB2:21:=DT_TO_STRING(%MD50:4)
==>
%MB 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
‘1’ ‘9’ ‘9’ ‘8’ ‘-’ ‘1’ ‘2’ ‘-’ ‘2’ ‘7’ ‘-’ ‘2’ ‘3’ ‘:’ ‘1’ ‘4’ ‘:’ ‘3’ ‘7’ Ø Ø
TLX DR PL7 xxE
225
Advanced instructions
Conversion of a duration into a string of characters
General
Structure
This instruction converts a duration (in TIME format) into a string of characters. The format of the result is in hours, minutes, seconds and tenths of a second expressed in 15 characters: HHHHHH:MM:SS.D. This string ends with the end character Ø.
Each character H,M,S,D symbolizes a digit.
The maximum duration corresponds to 119304 hours, 38 minutes, 49 seconds and
5 tenths.
Ladder language
OPERATE
%MB2:15=TIME_TO_STRING(%MD40)
Examples
Instruction list language
LD TRUE
[%MB2:15=TIME_TO_STRING(%MD40)]
Structured text language
%MB2:15=TIME_TO_STRING(%MD40) ;
%MB2:15=TIME_TO_STRING(%MD40)
%MD40:= 27556330.3 (TIME format)
%MB 2 3 4 5 6 7 8 9 10 11 12 13
‘0’ ‘0’ ‘7’ ‘6’ ‘5’ ‘4’ ‘:’ ‘3’ ‘2’ ‘:’ ‘1’ ‘0’
14 15 16
‘.’ ‘3’ Ø
226
TLX DR PL7 xxE
Syntax
Advanced instructions
Duration to string conversion operator
Syntax
Result:= TIME_TO_STRING (Duration)
Duration to string conversion operands
Type
Tables of 15 bytes
Indexable double words
Non-indexable double words
Result (res)
%MB:15
-
-
Duration
-
%MD,%KD
%ID,%QD, Immediate value, Numeric expr.
Duration is in TIME format
Note: l If the output string is too short, it is truncated and the system bit %S15 is set to 1.
%MB2:8:=TIME_TO_STRING(%MD40)
==> %MB 2 3 4 5 6 7 8
‘0’ ‘0’ ‘7’ ‘6’ ‘5’ ‘4’ ‘:’
9
‘3’
==> %S15 = 1 l If the output string is too long, it is completed with end characters Ø.
%MB2:16:=TIME_TO_STRING(%MD40)
==>
%MB 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
‘0’ ‘0’ ‘7’ ‘6’ ‘5’ ‘4’ ‘:’ ‘3’ ‘2’ ‘:’ ‘1’ ‘0’ ‘.’ ‘3’ Ø Ø
TLX DR PL7 xxE
227
Advanced instructions
Conversion of a time of day to a character string
General
Structure
This instruction converts a time of day (in TOD – TIME_OF_DAY format) into a character string with 8 characters in HH:MM:SS format plus an end character Ø.
Each chracter H,M,S symbolizes a digit.
Ladder language
OPERATE
%MB2:9=TOD_TO_STRING(%MD40)
Examples
Instruction list language
LD TRUE
[%MB2:9=TOD_TO_STRING(%MD40)]
Structured text language
%MB2:9=TOD_TO_STRING(%MD40);
%MB2:9=TOD_TO_STRING(%MD40)
%MD40:= 23:12:27 (TOD format)
%MB 2 3 4 5 6 7 8 9 10
‘2’ ‘3’ ‘:’ ‘1’ ‘2’ ‘:’ ‘2’ ‘7’ Ø
228
TLX DR PL7 xxE
Syntax
Advanced instructions
Time of day to string conversion operator
Syntax
Result:=TOD_TO_STRING(Duration)
Time of day to string conversion operands
Type
9 byte tables
Indexable double words
Non-indexable double words
Result (res)
%MB:9
-
-
Time
-
%MD,%KD
%ID,%QD, Immediate value, Numeric expr.
Time is in TOD format
Note: l If the output string is too short, it is truncated and the system bit %S15 is set to 1.
%MB2:8 := TOD_TO_STRING (%MD40) (where %MD40 := 23:12:27)
==> %MB 2 3 4 5 6 7 8 9
‘2’ ‘3’ ‘:’ ‘1’ ‘2’ ‘:’ ‘2’ ‘7’
==> %S15 = 1 l If the output string is too long, it is completed with end characters Ø.
%MB2:10 := TOD_TO_STRING (%MD40) (where %MD40 := 23:12:27)
==>
%MB 2 3 4 5 6 7 8 9 10 11
‘2’ ‘3’ ‘:’ ‘1’ ‘2’ ‘:’ ‘2’ ‘7’ Ø Ø
TLX DR PL7 xxE
229
Advanced instructions
Conversion of a duration into HHHH:MM:SS
General
Structure
This instruction converts a duration (in TIME format) into hours-minutes-seconds:
HHHH:MM:SS. Threshold [0000:00:00 , 9999:59:59].
Ladder language
OPERATE
%MD100=TRANS_TIME(%MD2)
Examples
Instruction list language
LD TRUE
[%MD100=TRANS_TIME(%MD2)]
Structured text language
%MD100=TRANS_TIME(%MD2) ;
%MD100=TRANS_TIME(%MD2) where %MD2:= 36324873 tenths of a second
==> %MD2
31 16
2 3 9 7 values are expressed in hexadecimal
5 4
8
4 7
0
230
TLX DR PL7 xxE
Syntax
Advanced instructions
Duration to HHHH:MM:SS conversion operator
Syntax
Result:= TRANS_TIME (Duration)
Duration to HHHH:MM:SS conversion operator
Type
Indexable double words
Non-indexable double words
Result (res)
%MD
%QD
Duration
%MD,%KD
%ID,%QD, Immediate value, Numeric expr.
Result is in HMS format
Duration is in TIME format
Note: l The rounding off principle will be applied to the "duration" parameter (expressed in tenths of a second) to enable conversion (precise to the second).
l l sssssssss.0 à sssssssss.4 rounded off to sssssssss.0
l sssssssss.5 à sssssssss.9 rounded off to sssssssss.0 +1.0
The maximum converted duration may be up to 10000 hours. This means that if the duration value (TIME) in the parameter is equal or greater than
360000000, it cannot be converted. %S15 system bit is set to 1 and the result is equal to 0000:00:00.
TLX DR PL7 xxE
231
Download
Advertisement