Hello,
I need convert "TOD" or "DATE_AND_TIME" format in DINT seconds value;
I am lokking for zip file at this link:
http://support.automation.siemens.com/W ... aller=view
Thank's
[Request] Step 7 V5.X: TIME_to_DINT.zip
-
- Posts: 17
- Joined: Wed Feb 28, 2007 11:57 am
- Location: France
-
- Posts: 87
- Joined: Wed May 19, 2010 2:22 pm
- Location: Bulgaria
Re: [Request] Step 7 V5.X: TIME_to_DINT.zip
here is the simple source code to split DATE_AND_TIME to Year,Month,Day,Hour,Minute,Second.
Sorry, but I can't find how to attach source file . That is why I paste it.
You can easy convert to DINT seconds value by multiply Hour by 3600, Minute by 60 ... and finaly sum it.
I am not sure what exactly you want to do, but this example is a good start.
Hope you can understand the following
source code:
Sorry, but I can't find how to attach source file . That is why I paste it.
You can easy convert to DINT seconds value by multiply Hour by 3600, Minute by 60 ... and finaly sum it.
I am not sure what exactly you want to do, but this example is a good start.
Hope you can understand the following
source code:
Code: Select all
FUNCTION_BLOCK FB 1
TITLE =
VERSION : 0.1
VAR_INPUT
i_DT : DATE_AND_TIME ;
END_VAR
VAR_OUTPUT
o_Year : BYTE ; //output YEAR
o_Month : BYTE ; //output MONTH
o_Day : BYTE ; //output DAY
o_Hour : BYTE ; //output HOUR
o_Min : BYTE ; //output MINUTE
o_Sec : BYTE ; //output SECOND
END_VAR
BEGIN
NETWORK
TITLE =
L P##i_DT;
LAR1 ;
L B [AR1,P#0.0];
T #o_Year;
L B [AR1,P#1.0];
T #o_Month;
L B [AR1,P#2.0];
T #o_Day;
L B [AR1,P#3.0];
T #o_Hour;
L B [AR1,P#4.0];
T #o_Min;
L B [AR1,P#5.0];
T #o_Sec;
NETWORK
TITLE =
NETWORK
TITLE =
BE ;
END_FUNCTION_BLOCK
DATA_BLOCK DB 1
TITLE =
VERSION : 0.0
FB 1
BEGIN
i_DT := DT#90-1-1-0:0:0.000;
o_Year := B#16#0;
o_Month := B#16#0;
o_Day := B#16#0;
o_Hour := B#16#0;
o_Min := B#16#0;
o_Sec := B#16#0;
END_DATA_BLOCK
ORGANIZATION_BLOCK OB 1
TITLE = "Main Program Sweep (Cycle)"
VERSION : 0.1
VAR_TEMP
OB1_EV_CLASS : BYTE ; //Bits 0-3 = 1 (Coming event), Bits 4-7 = 1 (Event class 1)
OB1_SCAN_1 : BYTE ; //1 (Cold restart scan 1 of OB 1), 3 (Scan 2-n of OB 1)
OB1_PRIORITY : BYTE ; //Priority of OB Execution
OB1_OB_NUMBR : BYTE ; //1 (Organization block 1, OB1)
OB1_RESERVED_1 : BYTE ; //Reserved for system
OB1_RESERVED_2 : BYTE ; //Reserved for system
OB1_PREV_CYCLE : INT ; //Cycle time of previous OB1 scan (milliseconds)
OB1_MIN_CYCLE : INT ; //Minimum cycle time of OB1 (milliseconds)
OB1_MAX_CYCLE : INT ; //Maximum cycle time of OB1 (milliseconds)
OB1_DATE_TIME : DATE_AND_TIME ; //Date and time OB1 started
t_Year : BYTE ;
t_Month : BYTE ;
t_Day : BYTE ;
t_Hour : BYTE ;
t_Min : BYTE ;
t_Sec : BYTE ;
END_VAR
BEGIN
NETWORK
TITLE =
CALL FB 1 , DB 1 (
i_DT := #OB1_DATE_TIME);
END_ORGANIZATION_BLOCK
-
- Posts: 9
- Joined: Fri Sep 04, 2009 7:55 am
- Location: Europe
Re: [Request] Step 7 V5.X: TIME_to_DINT.zip
The provided sample is for DATE_AND_TIME datatype, TOD is an IEC datatype which is the elapsed time since 0:00 midnight and is stored in milliseconds.
So just copy the TOD to a DINT variable and you will have the elapsed time in ms.
So just copy the TOD to a DINT variable and you will have the elapsed time in ms.
-
- Site Admin
- Posts: 1122
- Joined: Wed Sep 06, 2006 12:03 pm
- Location: CIS