PACK block
Short summary
Name |
PACK |
→POU type |
|
Category |
|
Conform to →IEC-standard |
not defined in IEC-standard |
Graphical interface |
|
Available since |
|
Functionality
The block returns the transferred values of the bytes connected to the inputs IN0 – IN7. In case of target systems saving data in little →endian format, the byte of input IN0 is transferred to the lowest significant byte of the return value, the byte of input IN7 to the highest significant byte of the return value. A reversed behavior is true for target systems saving data in big endian format.
Special cases (see under "Example for usage within ST-editor"):
If the size of the result data type (number of bytes representing the data type) is > than the number of the connected input bytes, the higher significant bytes of the return value remain not-initialized.
In case of BOOL values for the return value, TRUE is returned for each value ≠ 0 at input IN0.If more input bytes are connected than the result data type can hold, only the lower significant input bytes are transferred to the return value. In case of target systems saving data in little endian format, these are the inputs positioned in the upper part of the block.
It is possible that the block does not behave as expected when there is a nested usage together with other blocks. This behavior is caused due to the typing using to the lowest common data type (see under "Typing of expressions" for details).
Inputs, return value
|
Identifier |
Description |
|
Inputs: |
IN0 |
BYTE |
1st value |
IN1 |
BYTE |
2nd value |
|
... (extensible until) |
|||
IN7 |
BYTE |
8th value |
|
Return value: |
– |
REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, DATE_AND_TIME, DATE or TIME_OF_DAY |
|
Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.
Example for usage within ST-editor
The following example is valid for target systems saving data in little endian format . The calculated values are evaluated by using the Assert block .
FUNCTION_BLOCK ExamplePack
VAR
result1, result2 : DWORD;
result2a : WORD;
END_VAR
result1 := PACK(IN0 :=
16
#
01
, IN1 :=
16
#
02
); (* DWORD =
4
bytes *)
result2 := PACK(IN0 :=
16
#
01
, IN1 :=
16
#
02
, IN2 :=
16
#
04
, IN3 :=
16
#
07
);
result2a := PACK(IN0 :=
16
#
01
, IN1 :=
16
#
02
, IN2 :=
16
#
03
, IN3 :=
16
#
04
); (* WORD =
2
bytes *)
Assert(result1 =
16
#
0201
); (*
'16#0201'
equals to
'513'
(decimal). *)
Assert(result2 =
16
#
07040201
); (*
'16#07040201'
equals
'117_703_169'
(decimal). *)
Assert(result2a =
16
#
0201
); (*
'16#0201'
equals
'513'
(decimal). *)
END_FUNCTION_BLOCK
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.