This time I would like to explain how to “Group” and “Ungroup” the Byte,Word and DWord variables to Bool Array ,Struct or User data type.Sure that you can use Variable.%X0 to finish your task, but that is not bad to learn a new things, Right?:)
While we open the Online help in the TIA,
The “Parse the bit sequence into individual bits” instruction parses a tag of the BYTE, WORD, DWORD or LWORD data type into individual bits and saves them in an ARRAY of BOOL, an anonymous STRUCT or a PLC data type exclusively with Boolean elements.
It means that you can parse the Byte ,word DWord, LWord Variables to Bool Array, Structure, PLC Data type.
SCATTER(IN := #SourceWord,
OUT => #DestinationArray);
|IN||Byte,Word,DWord||Byte,Word,DWord,LWord||Source data that you want to parse|
|OUT||Array[*] of Bool,|
PLC data type,The length of * should be 8,16,32 or 64.
|Array[*] of Bool,|
PLC data type, The length of * should be 8,16,32 or 64.
|Variables that you would like to parse to|
Example1-Word to Bool Array
Example2-DWord to Bool Array
Example3-Byte to Bool Array
Example4-Word to Structure
Example5-PLC data type to structure
Firstly, we define a PLC data type that is named udt1.
the variables , there are 16 bool.
And here is the Program.
Please download the source code in here: