Packing ¶ PackArrayOfBoolToArrayOfByte (Function) PackBitsToByte (Function) PackBitsToDword (Function) PackBitsToWord (Function) PackBytesToDword (Function) PackBytesToWord (Function) PackWordsToDword (Function) UnpackArrayOfByte (Function) UnpackByte (FunctionBlock) UnpackDWord (FunctionBlock) UnpackWord (FunctionBlock)
PackArrayOfBoolToArrayOfByte (FUN) ¶ FUNCTION PackArrayOfBoolToArrayOfByte : UINT The function packs an “ARRAY OF BOOL” into an “ARRAY OF BYTE”. axSource[0] -> abyDestination[0].0 axSource[1] -> abyDestination[0].1 … axSource[8] -> abyDestination[1].0 … axSource[15] -> abyDestination[1].7 … The function copies “uiNumberOfBits” from “axSource” to “abyDestination”. It will return the necessary number of bytes in “abyDestination”. Only if “paxSource”, “pabyDestination” or “uiNumberOfBits” are set to “0”, the copying will not be carried out and the function will return “0”. Example: axSource : ARRAY [0..9] OF BOOL := FALSE , TRUE , FALSE , FALSE , TRUE , TRUE , FALSE , FALSE , TRUE , FALSE ; abyDestination : ARRAY [0..2] OF BYTE ; uiNumberofBytes := MEM.PackArrayOfBool ( ADR ( abSource ), ADR ( abyDestination ), 10 ) ; -> uiNumberofBytes = 2 abyDestination [0] = 16#32 abyDestination [1] = 16#01 abyDestination [2] = 16#00 Note The size of the ARRAY “abyDestination” has to be adjusted to the amount of bits copied! Source and target may not overlap! InOut: Scope Name Type Comment Return PackArrayOfBoolToArrayOfByte UINT functon returns the necessary number of bytes in “abyDestination” Input paxSource POINTER TO BYTE address of ARRAY OF BOOL pabyDestination POINTER TO BYTE address of ARRAY OF BYTE uiNumberOfBits UINT number of bits to copy from “paxSource” to “pabyDestination”
PackBitsToByte (FUN) ¶ FUNCTION PackBitsToByte : BYTE Function packs 8 Bits “xBit0” .. “xBit7” into a BYTE. Example: PackBitsToByte ( FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE ) = 16#01 InOut: Scope Name Type Comment Return PackBitsToByte BYTE functions returns the BYTE defined by the BOOL inputs Input xBit7 BOOL Bit 7 of the Byte xBit6 BOOL Bit 6 of the Byte xBit5 BOOL Bit 5 of the Byte xBit4 BOOL Bit 4 of the Byte xBit3 BOOL Bit 3 of the Byte xBit2 BOOL Bit 2 of the Byte xBit1 BOOL Bit 1 of the Byte xBit0 BOOL Bit 0 of the Byte
PackBitsToDword (FUN) ¶ FUNCTION PackBitsToDword : DWORD Function packs 32 Bits “xBit0” .. “xBit31” into a DWORD. Example: PackBitsToDword ( FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE , TRUE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE , FALSE , FALSE ) = 16#01020304 InOut: Scope Name Type Comment Return PackBitsToDword DWORD function returns the DWORD defined by the BOOL inputs Input xBit31 BOOL Bit 31 of the Dword xBit30 BOOL Bit 30 of the Dword xBit29 BOOL Bit 29 of the Dword xBit28 BOOL Bit 28 of the Dword xBit27 BOOL Bit 27 of the Dword xBit26 BOOL Bit 26 of the Dword xBit25 BOOL Bit 25 of the Dword xBit24 BOOL Bit 24 of the Dword xBit23 BOOL Bit 23 of the Dword xBit22 BOOL Bit 22 of the Dword xBit21 BOOL Bit 21 of the Dword xBit20 BOOL Bit 20 of the Dword xBit19 BOOL Bit 19 of the Dword xBit18 BOOL Bit 18 of the Dword xBit17 BOOL Bit 17 of the Dword xBit16 BOOL Bit 16 of the Dword xBit15 BOOL Bit 15 of the Dword xBit14 BOOL Bit 14 of the Dword xBit13 BOOL Bit 13 of the Dword xBit12 BOOL Bit 12 of the Dword xBit11 BOOL Bit 11 of the Dword xBit10 BOOL Bit 10 of the Dword xBit9 BOOL Bit 9 of the Dword xBit8 BOOL Bit 8 of the Dword xBit7 BOOL Bit 7 of the Dword xBit6 BOOL Bit 6 of the Dword xBit5 BOOL Bit 5 of the Dword xBit4 BOOL Bit 4 of the Dword xBit3 BOOL Bit 3 of the Dword xBit2 BOOL Bit 2 of the Dword xBit1 BOOL Bit 1 of the Dword xBit0 BOOL Bit 0 of the Dword
PackBitsToWord (FUN) ¶ FUNCTION PackBitsToWord : WORD Function packs 16 Bits “xBit0” .. “xBit15” into a WORD. Example: PackBitsToWord ( FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE , FALSE , FALSE , FALSE , FALSE , FALSE , FALSE , TRUE , FALSE ) = 16#0102 InOut: Scope Name Type Comment Return PackBitsToWord WORD function returns the WORD defined by the BOOL inputs Input xBit15 BOOL Bit 15 of the Word xBit14 BOOL Bit 14 of the Word xBit13 BOOL Bit 13 of the Word xBit12 BOOL Bit 12 of the Word xBit11 BOOL Bit 11 of the Word xBit10 BOOL Bit 10 of the Word xBit9 BOOL Bit 9 of the Word xBit8 BOOL Bit 8 of the Word xBit7 BOOL Bit 7 of the Word xBit6 BOOL Bit 6 of the Word xBit5 BOOL Bit 5 of the Word xBit4 BOOL Bit 4 of the Word xBit3 BOOL Bit 3 of the Word xBit2 BOOL Bit 2 of the Word xBit1 BOOL Bit 1 of the Word xBit0 BOOL Bit 0 of the Word
PackBytesToDword (FUN) ¶ FUNCTION PackBytesToDword : DWORD Function pack four BYTEs into a DWORD. Example: MEM.PackBytesToDword ( 16#01 , 16#02 , 16#03 , 16#04 ) = 16#01020304 InOut: Scope Name Type Comment Return PackBytesToDword DWORD functions returns the DWORD defined by the BYTE inputs Input byHHByte BYTE HH byte of the Word byHLByte BYTE HL byte of the Word byLHByte BYTE LH byte of the Word byLLByte BYTE LL byte of the Word
PackBytesToWord (FUN) ¶ FUNCTION PackBytesToWord : WORD Function packs low and high BYTE into a WORD. Example: MEM.PackBytesToWord ( 16#01 , 16#02 ) = 16#0102 InOut: Scope Name Type Comment Return PackBytesToWord WORD function returns the WORD defined by the BYTE inputs Input byHighByte BYTE high byte of the Word byLowByte BYTE low byte of the Word
PackWordsToDword (FUN) ¶ FUNCTION PackWordsToDword : DWORD Function packs low and high WORD into a DWORD. Example: MEM.PackWordsToDword ( 16#0102 , 16#0304 ) = 16#01020304 InOut: Scope Name Type Comment Return PackWordsToDword DWORD function returns the DWORD defined by the WORD inputs Input wHighWord WORD high word of the Dword wLowWord WORD low word of the Dword
UnpackArrayOfByte (FUN) ¶ FUNCTION UnpackArrayOfByte : UINT The function unpacks an “ARRAY OF BYTE” in an “ARRAY OF BOOL”. abySource[0].0 -> axDestination[0] abySource[0].1 -> axDestination[1] … abySource[1].0 -> axDestination[8] … abySource[1].7 -> axDestination[15] … The function copies the amount of “uiNumberOfBits” from “abySource” to “axDestination”. The function will return the number of bytes considered in “abySource”. If “pabySource”, “paxDestination” or “uiNumberOfBits” are set to “0”, the copying will not be carried out and the function will return “FALSE”. Example: abySource : ARRAY [0..2] OF BYTE := 16#32 , 16#01 , 16#00 ; axDestination : ARRAY [0..9] OF BOOL ; uiNumberofBytes := MEM.UnpackArrayOfByte ( ADR ( abySource ), ADR ( axDestination ), 10 ) ; -> uiNumberofBytes = 2 axDestination [0] = FALSE axDestination [1] = TRUE axDestination [2] = FALSE axDestination [3] = FALSE axDestination [4] = TRUE axDestination [5] = TRUE axDestination [6] = FALSE axDestination [7] = FALSE axDestination [8] = TRUE axDestination [9] = FALSE Note The size of the array “axDestination” has to be adjusted to the number of bits to be copied! Source and target may not overlap! InOut: Scope Name Type Comment Return UnpackArrayOfByte UINT function returns the number of bytes considered in “abySource” Input pabySource POINTER TO BYTE address of BYTE ARRAY paxDestination POINTER TO BYTE address of BOOL ARRAY uiNumberOfBits UINT number of bits to copy from “abySource” to “axDestination”
UnpackByte (FB) ¶ FUNCTION_BLOCK UnpackByte Function block unpacks “byValue” and returns the 8 bits “xBit0” .. “xBit7”. Prefix: “memuby”. Example: byInput = 16#01 = 2#00000001 -> xBit0 = TRUE xBit1..xBit7 = FALSE InOut: Scope Name Type Comment Input byValue BYTE BYTE to analyse Output xBit0 BOOL Bit 0 of byValue xBit1 BOOL Bit 1 of byValue xBit2 BOOL Bit 2 of byValue xBit3 BOOL Bit 3 of byValue xBit4 BOOL Bit 4 of byValue xBit5 BOOL Bit 5 of byValue xBit6 BOOL Bit 6 of byValue xBit7 BOOL Bit 7 of byValue