MEMSET block
Short summary
Name |
MEMSET |
→POU type |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard |
Graphical interface |
|
Available since |
|
Functionality
The block initializes bytes of the input value with a specified value.
You enter the input value at input IN and the value for the initialization at input VAL. At input LEN, enter the numer of bytes to be initialized in the input value.
By default, value 0 is specified for the initialization and for the number of bytes.
Special cases:
In case of LEN = 0, the block automatically calculates the number of bytes to initialize in the input value.
If the value for LEN is > than the maximally possible size of the input value IN, the block initializes until the maximally possible size of the input value. In this case, the output ENO is set to value FALSE.
If a STRING element with a length is connected to IN, the length of the STRING buffer is used. The length of the STRING buffer is determined by the declaration.
STRING elements with a length are STRING variables declared by you; see " Declaration of STRING variables (incl. access)".If a STRING element without a length is connected to IN, the length of the STRING buffer is also used. However, the length of the STRING buffer is determined by the resulting value.
STRING elements without a user-defined length are resulting, if you are using STRING functions or →character string literals.
Inputs, outputs
|
Identifier |
Description |
|
In-outs (VAR_IN_OUT): |
IN |
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING, CHAR, DATE_AND_TIME, DATE, TIME_OF_DAY or a →user-defined data type |
input value |
Inputs: |
VAL |
USINT |
value for initialization; default value = 0 |
LEN |
UDINT |
the number of bytes to set to VAL; default value = 0 |
Input EN and output ENO are available when →calling
the block. See "Execution control: EN, ENO" for information on input EN and output ENO.
Internal error diagnostic for block
The block checks the value connected to the inpu
ts
before it is executed.
If the value for
LEN
is > than the maximally possible size of the input value
IN
,
the output ENO of the block is set to value value FALSE (or an equivalent).
Example for usage within ST-editor
PROGRAM Test
VAR
Var1, Var2 : BYTE :=
0
;
Var3, Var4 : DINT :=
0
;
END_VAR
MEMSET(IN := Var1, VAL :=
16
#0A, LEN :=
1
); (* The variable
'Var1'
evaluates to
'10'
. *)
MEMSET(IN := Var2, VAL :=
16
#0C, LEN :=
1
); (* The variable
'Var2'
evaluates to
'12'
. *)
MEMSET(IN := Var3, VAL :=
16
#0C, LEN :=
1
); (* The variable
'Var3'
evaluates to
'12'
. *)
MEMSET(IN := Var4, VAL :=
16
#0A, LEN :=
3
); (* The variable
'Var4'
evaluates to
'657930'
. *)
END_PROGRAM
When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.