FUNCTION_BLOCK FB10
VAR_TEMP
// Temporary Variables
iTemp:INT;
ThetimeBCD:DATE_AND_TIME;
Thetime AT ThetimeBCD:STRUCT
Year:BYTE;
Month:BYTE;
Day:BYTE;
Hour:BYTE;
Minute:BYTE;
Second:BYTE;
MillisecondA:BYTE;
MsBandWeekDay:BYTE;
END_STRUCT;
sfc1Return:INT;
END_VAR
sfc1Return:=sfc1(CDT:=TheTimeBCD);
iTemp:=WORD_TO_INT(BYTE_TO_WORD(TheTime.Year));
END_FUNCTION_BLOCK
andr said:i did it like that :
using SFC1 - READ_CLK(...)
in fact, i saw something in help's examples
//=================================
FUNCTION SetSummerTime: BOOL //FC510 // function for correcting summer /winter time
// Andr. !!! will work until 2089 year. Of course, plc will die before
AUTHOR: ANDR
VAR_TEMP
SummerNow : BOOL; // Признак времени зима-лето в момент вызова функции: летнее время (=TRUE), зимнее (=FALSE)
Err_ReadDate : INT; // error code return
zdn : INT; // help variable
year : INT; // year, format: ХХ (19XX - 20XX)
num_of_month : INT; // number of month, jan -1, feb -2,...
day_of_month : INT; // no comments
day_of_week : INT; // !!! sun -1, mon -2, tus -3,..., .
tmpDATE : DT; // time structure
current_DT AT tmpDATE: ARRAY[1..8] OF BYTE; // array for access to time structures
END_VAR
Err_ReadDate := READ_CLK( CDT := tmpDATE); // Getting of current date
year := WORD_TO_INT(SHR(IN:=current_DT[1],N:=4))*10 + WORD_TO_INT(current_DT[1] AND 16#0F); // calculation of year
num_of_month := WORD_TO_INT(SHR(IN:=current_DT[2],N:=4))*10 + WORD_TO_INT(current_DT[2] AND 16#0F); // calculation numb of month
day_of_month := WORD_TO_INT(SHR(IN:=current_DT[3],N:=4))*10 + WORD_TO_INT(current_DT[3] AND 16#0F); // calculation of day
day_of_week := WORD_TO_INT(current_DT[8] AND 16#0F); // calculation day of week
.
.
.
Because the OP wanted an SCL solution not STLI am not sure why answers to simple questions have to be so complicated... Usually simple-ist is best-ist
Here is my code. This takes the current date and tme and puts it into individual integers. You can create a FC with this (hence the # before the variable) or just make it a rung in your program.
Here's the basis for the SCL implementation. As there are no BCD to integer conversions available in SCL, you will need to provide a conversion function yourself. I've shown an example assignment to make iTemp equal to the current year in BCD. Unless this is a programming exercise using SCL, I'd stick with krk's FC.
FUNCTION DT_TO_INT : VOID
VAR_INPUT
IN_TIME : DATE_AND_TIME;
TidIn AT IN_TIME : ARRAY[0..7] OF BYTE;
//Byte 0 Year:BYTE;
//Byte 1 Month:BYTE;
//Byte 2 Day:BYTE;
//Byte 3 Hour:BYTE;
//Byte 4 Minute:BYTE;
//Byte 5 Second:BYTE;
//Byte 6 mS:BYTE;
//Byte 7 WeekDay:BYTE;
END_VAR
VAR_OUTPUT
Artal:INT;
Manad:INT;
Dag:INT;
Veckodag:INT;
Timme:INT;
Minut:INT;
Sekund:INT;
milliSekund:INT;
END_VAR
BEGIN
Artal:=BCD_TO_INT(TidIn[0]);
Manad:=BCD_TO_INT(TidIn[1]);
Dag:=BCD_TO_INT(TidIn[2]);
Veckodag:=BCD_TO_INT(TidIn[7] AND 2#00001111);
Timme:=BCD_TO_INT(TidIn[3]);
Minut:=BCD_TO_INT(TidIn[4]);
Sekund:=BCD_TO_INT(TidIn[5]);
milliSekund:=BCD_TO_INT(TidIn[6])*10 + (BCD_TO_INT(TidIn[7] AND 2#11110000) / 10);
END_FUNCTION
Thanks for the reply. Next try replying to the poster with the problem and try to help them out.