我們的品牌

Impact-Company-Logo-English Black-01-177x54

歡迎造訪施耐德電機全球網站

歡迎訪問我們的網站
		
我们今天能为您提供什么帮助?
Structured Text user function block to return the Day of the Week

DISCLAIMER

The example below is intended to demonstrate one or more features or methods and is presented as a configuration example only. Schneider Electric assumes no liability for the use or application of this example or any portion thereof.



ClearSCADA allows the user to create its own Structured Text library, where several user function blocks can be stored.
A function that is periodically requested by users is one that returns the day of the week from a DATE_AND_TIME input variable. The code below returns the day of the week as a number (0 = Sunday to 6 = Saturday):

FUNCTION_BLOCK DayOfTheWeek

VAR_INPUT
InDate : DATE_AND_TIME;
END_VAR

VAR_OUTPUT
DayOfWeek : INT;
END_VAR

VAR
Year : INT;
cYear : INT;
Month : INT;
Day : INT;

CP : INT;
YP : INT;
MP : INT;

LeapYear : BOOL := FALSE;
Valid :BOOL;
END_VAR

Year := EXTRACT_DT_YEAR(InDate);
cYear := STRING_TO_INT(RIGHT(INT_TO_STRING(Year),2));
Month := EXTRACT_DT_MONTH(InDate);
Day := EXTRACT_DT_DAY(InDate);

Valid := TRUE;
CASE Year OF
1752..1799 : CP := 4;
1800..1899 : CP := 2;
1900..1999 : CP := 0;
2000..2099 : CP := 6;
ELSE  Valid := FALSE;
END_CASE;

YP := cYear / 4;

IF (MOD(cYear,400) = 0) THEN
LeapYear := TRUE;
ELSIF (MOD(cYear,100) = 0) THEN
LeapYear := FALSE;
ELSIF (MOD(cYear,4) = 0) THEN
LeapYear := TRUE;
ELSE
LeapYear := FALSE;
END_IF;

CASE Month OF
1 :
IF LeapYear THEN
MP := 6;
ELSE
MP := 0;
END_IF;
2 :
IF LeapYear THEN
MP := 2;
ELSE
MP := 3;
END_IF;
3 : MP := 3;
4 : MP := 6;
5 : MP := 1;
6 : MP := 4;
7 : MP := 6;
8 : MP := 2;
9 : MP := 5;
10 : MP := 0;
11 : MP := 3;
12 : MP := 5;
END_CASE;

IF Valid THEN
DayOfWeek := MOD(CP + cYear + YP + MP + Day, 7 );
ELSE
DayOfWeek := -1;
END_IF;

END_FUNCTION_BLOCK


Once added to a library, this function can be called from both ST or FBD logic program.
Below a picture of the function being called from an FBD program:
FBD

Below a picture of the function being called from an ST program:
Structured Text

Note: Don't forget to add the library that contains the function block you are going to use to your logic program before calling the function. For more information on how to do that, please search the manual for "ST and Function Block Libraries".

施耐德電機Taiwan

探索更多
產品:
探索更多
產品:
  • 產品文檔
  • 軟體下載
  • 產品選型工具
  • 產品替代和替換
  • 幫助和聯絡中心
  • 尋找我們的辦公室
  • 取得報價
  • 施耐德電機社群
  • 人才招募
  • 公司簡介
  • 舉報不當行為
  • 無障礙
  • 新聞中心
  • 投資者
  • 專業洞察
  • 台灣施耐德電機學院
  • 綠色影響力落差調查
  • Schneider Go Green 2025
  • 隱私政策
  • Cookie通告
  • 使用條款
  • Change your cookie settings