GEN (FB) ¶ FUNCTION_BLOCK GEN Generates periodic functions of different, given types The generation may be done relative to a specific time base or a given call-count base ( BASE ). An example set of available types of periodic functions are shown in the following image. InOut: Scope Name Type Initial Comment Input MODE GEN_MODE Types available: TRIANGLE : Triangular from - AMPLITUDE to + AMPLITUDE TRIANGLE_POS : Triangular from 0 to + AMPLITUDE SAWTOOTH_RISE : Sawtooth increasing from - AMPLITUDE to + AMPLITUDE SAWTOOTH_FALL : Sawtooth decreasing from + AMPLITUDE to - AMPLITUDE RECTANGLE : Rectangular switching from - AMPLITUDE to + AMPLITUDE SINE : Sine COSINE : Cosine BASE BOOL FALSE : Period referring to call ( CYCLES ) TRUE : Period referring to time ( PERIOD ) PERIOD TIME TIME#1s0ms Period time, only relevant if BASE = TRUE CYCLES INT 1000 Number of calls per period, only relevant if BASE = FALSE AMPLITUDE INT Amplitud of the function to be generated RESET BOOL TRUE : Sets OUT to zero Output OUT INT Generated function value
TimerSwitch ¶ A timer switch is a clock that switches a number of outputs on or off at set times. The switching times are individually configurable. The following snippet exposes the definition of a specific TimeZone . Example The main islands of New Zealand use New Zealand Standard Time (NZST), 12 hours in advance of UTC. During summer months — from the last Sunday in September until the first Sunday in April — daylight saving time (NZDT) is observed and clocks are advanced one hour. See: https://en.wikipedia.org/wiki/Time_in_New_Zealand tzTimeZoneNZST : TimeZone := ( iBias := 12 * 60 (* T#1M *) , asgPeriod := [ ( (* (NZDT -> NZST) - First Sunday in April at 03:00:00.000 (NZDT) *) sName:='NZST', dtDate := (uiMonth := 4, eWeekday := WEEKDAY.SUNDAY, uiDay := 1, uiHour := 3) ),( (* (NZST -> NZDT) - Last Sunday in September at 02:00:00.000 (NZST) *) sName := 'NZDT', dtDate := (uiMonth := 9, eWeekday := WEEKDAY.SUNDAY, uiDay := 5, uiHour := 2), iBias := 60 (* T#1M *) )] ); Note Due to current deficiencies in the compiler, no constants can be used for the tzTimeZone input of the TimerSwitch block. It is therefore necessary to declare a variable of type TimeZone and then assign the values of the predefined constants (e.g. TSW.gc_tzTimeZoneCET or TSW.gc_tzTimeZoneUTC ) to this variable. tzTimeZoneUTC : TimeZone := TSW.gc_tzTimeZoneUTC ; myTimerSwitch : TimerSwitch := ( tzTimeZone := tzTimeZoneUTC ); Due to another deficiencies in the compiler, the data type of the input aslSchedule of the TimerSwitch block is displayed wrongly. The following would be correct: FUNCTION_BLOCK PUBLIC FINAL TimerSwitch EXTENDS CBML.LConC IMPLEMENTS ITimeSwitch , IDateTimeProvider VAR_INPUT CONSTANT /// Source for the current date and time information in milliseconds since 1.1.1970 00:00:00.000 itfDateTimeProvider : IDateTimeProvider := Globals.g_dtpDateTimeProvider ; /// Compensation speed [ms/h] for the transition from one time zone period to another. tCompensationSpeed : TIME ; END_VAR VAR_IN_OUT (* CONSTANT *) /// Switching Schedule aslSchedule : ARRAY [*] OF Schedule ; END_VAR [...] Enums ERROR (Enum) PERIOD (Enum) WEEKDAY (Enum) FunctionBlocks DateTimeProvider (FunctionBlock) GetDateTime (Method) TimerSwitch (FunctionBlock) IDateTimeProvider GetDateTime (Method) Functions CombineDateTime (Function) DateTimeFromWeek (Function) DayOfWeek (Function) GetDateTime (Function) GetLocalDateTime (Function) GetTimeStampsDifference (Function) IsLeapYear (Function) JoinDateTime (Function) LocalDateTime (Function) SeparateDateTime (Function) SplitDateTime (Function) WeekOfYear (Function) GlobalConstants DAY_FLAGS (GVL) TSW (GVL) Interfaces IDateTimeProvider (Interface) GetDateTime (Method) Structs DateTime (Struct) Schedule (Struct) Segment (Struct) TimeZone (Struct) Types DAY (Alias) DAYS (Alias) HOUR (Alias) MILLISECOND (Alias) MINUTE (Alias) MONTH (Alias) SECOND (Alias) TZ_NAME (Alias) WEEK (Alias) YEAR (Alias)
Enums ¶ ERROR (Enum) PERIOD (Enum) WEEKDAY (Enum)
ERROR (ENUM) ¶ TYPE ERROR : Attributes: qualified_only InOut: Name Initial NO_ERROR WRONG_CONFIGURATION 2 RTC_HIGHRES_NOT_SUPPORTED SYS_TIMEZONE_NOT_SUPPORTED
PERIOD (ENUM) ¶ TYPE PERIOD : Attributes: qualified_only InOut: Name Initial UNKNOWN 0 STANDARD 1 DAYLIGHT 2
POINT (STRUCT) ¶ TYPE POINT : STRUCT InOut: Name Type X DINT Y DINT
PT_SIZE (STRUCT) ¶ TYPE PT_SIZE : STRUCT InOut: Name Type Comment pString POINTER TO BYTE Pointer to the text uiSize UINT Size of the text
Encoding ¶ BASE64 (Function)
BASE64 (FUN) ¶ FUNCTION BASE64 : PT_SIZE encodes 8 bit binary data into ASCII data A text block (string, binary, array of bytes) will be base64 encoded. The maximum of the block is set in the TextBlockSize parameter. This size can be changed but must be divisible by 3. If the text block is only a part of a text and followed by more text, the size must be TextBlockSize.iBlockSize and the isLastBlock variable must be set to FALSE . If a text is not followed by another block, the specific length of it must be used and isLastBlock has to be set to TRUE , as shown in the following example. The reason is three 8-bit letters will become four 6-bit letters. If only two 8-Bit letters are remaining at the end, the encoded text is filled with “=”. This must only be at the end of a text. Example: StringToConvert : PT_SIZE ; EncodedString : PT_SIZE ; byError : BYTE ; sText : STRING := 'This is a test string.' ; StringToConvert.uiSize := LEN ( sText ); (* When another block follows, use the size TextBlockSize.iBlockSize and set isLastBlock to FALSE. *) StringToConvert.pString := ADR ( sText ); EncodedString := Base64 ( TextToEncode := StringToConvert , isLastBlock := TRUE , pbyError := ADR ( byError )); InOut: Scope Name Type Comment Return BASE64 PT_SIZE A structure with a pointer to the text and its size (comprising the terminating character) Input TextToEncode PT_SIZE The text block which should be encoded isLastBlock BOOL TRUE : The current text block is the end of a text FALSE : The current text block is just a small text pbyError POINTER TO BYTE 0: No error 1: Text block is too long 2: Not divisible through 3 4: Empty string
Function Manipulators ¶ CHARCURVE (FunctionBlock) RAMP_INT (FunctionBlock) RAMP_REAL (FunctionBlock)