TCP_Connection (FB) ¶ FUNCTION_BLOCK TCP_Connection EXTENDS CBM.LTrig The next free connection is determined by handle exchange and set to active. As long as xActive is TRUE the handle of the connection is valid. If xActiveis FALSE the handle of the connection is invalid. hConnection can be used as input hConnection for function blocks TCP_Write , TCP_WriteBuffer , TCP_Read and TCP_ReadBuffer . InOut: Scope Name Type Comment Inherited from Input xEnable BOOL TRUE : Action starts FALSE : Action stops, outputs xDone , xBusy , xError are resetted LTrig Output xDone BOOL TRUE : Action successfully completed LTrig xBusy BOOL TRUE : Function block active LTrig xError BOOL TRUE : Error occurred, function block aborts action FALSE : No error LTrig Input hServer CAA.HANDLE Output eError ERROR xActive BOOL hConnection CAA.HANDLE Properties: IPAddress Structure: IPAddress (Property)
TCP_Read (FB) ¶ FUNCTION_BLOCK TCP_Read EXTENDS CBM.LTrig This function block serves to read data from the previously established connection given in hConnection . As long as xEnable is TRUE the handle of the connection is valid. The pointer pData specifies the memory area to write the read data to. szSize defines the max number of bytes to read. When the data was read successfully, xReady is set to TRUE and szCount indicates the actually read number of bytes. InOut: Scope Name Type Comment Inherited from Input xEnable BOOL TRUE : Action starts FALSE : Action stops, outputs xDone , xBusy , xError are resetted LTrig Output xDone BOOL TRUE : Action successfully completed LTrig xBusy BOOL TRUE : Function block active LTrig xError BOOL TRUE : Error occurred, function block aborts action FALSE : No error LTrig Input hConnection CAA.HANDLE szSize CAA.SIZE pData CAA.PVOID Output eError ERROR xReady BOOL szCount CAA.SIZE
TCP_ReadBuffer (FB) ¶ FUNCTION_BLOCK TCP_ReadBuffer EXTENDS CBM.LTrig Like TCP_Read this function block serves to read data from the previously established connection given in hConnection . As long as xEnable is TRUE the handle of the connection is valid. The function block returns the handle of the buffer containing the data. If xReady is TRUE , data has been read successfully and the handle of the buffer is valid. The buffer is passed on and not copied like at TCP_Read . InOut: Scope Name Type Comment Inherited from Input xEnable BOOL TRUE : Action starts FALSE : Action stops, outputs xDone , xBusy , xError are resetted LTrig Output xDone BOOL TRUE : Action successfully completed LTrig xBusy BOOL TRUE : Function block active LTrig xError BOOL TRUE : Error occurred, function block aborts action FALSE : No error LTrig Input hConnection CAA.HANDLE Output eError ERROR xReady BOOL hBuffer CAA.HANDLE
Decode (FUN) ¶ FUNCTION Decode : BOOL Function decodes “Source” (ARRAY OF BYTE) into “Destination” (ARRAY OF DWORD), meaning 4 BYTEs are decoded into 1 DWORD. Assumes “uiNumberOfBytes” is a multiple of 4, whereas if it is not “FALSE” will be returned. InOut: Scope Name Type Comment Return Decode BOOL function returns “TRUE” if decoding succeded Input pSource POINTER TO ARRAY [0..0] OF BYTE address of source memory pDestination POINTER TO ARRAY [0..0] OF DWORD address of destination memory uiNumberOfBytes UINT number of bytes to decode
Encode (FUN) ¶ FUNCTION Encode : BOOL Function encodes “Source” (ARRAY OF DWORD) into “Destination” (ARRAY OF BYTE), meaning 1 DWORD is split up into 4 BYTEs. Assumes “uiNumberOfBytes” is a multiple of 4, whereas if it is not “FALSE” is returned. InOut: Scope Name Type Comment Return Encode BOOL function returns “TRUE” if encoding succeeded Input pSource POINTER TO ARRAY [0..0] OF DWORD address of source memory pDestination POINTER TO ARRAY [0..0] OF BYTE address of destination memory uiNumberOfBytes UINT number of bytes to encode
MemFill (FUN) ¶ FUNCTION MemFill : BOOL Function fills all bytes of a memory block with the value “byFillValue”. In case of success, the function will return “TRUE”. Only if “MemoryBlock” is set to “0”, the initialization will not be carried out and the function will return “FALSE”. InOut: Scope Name Type Comment Return MemFill BOOL function returns “TRUE” if filling succeeded Input pMemoryBlock POINTER TO BYTE address of memory block uiLength UINT length of memory block in byte byFillValue BYTE Fill value for the memory block
MemMove (FUN) ¶ FUNCTION MemMove : BOOL The function copies the amount of “uiNumberOfBytes” of memory from memory area “Source” to “Destination”, wheras these memory areas are allowed to overlap! In case of success, the function will return “TRUE”. Only if “Source” or “Destination” are set to “0” the copying will not be carried out and the function will return “FALSE”. InOut: Scope Name Type Comment Return MemMove BOOL function return “TRUE” if the moving of bytes succeeded Input pSource POINTER TO BYTE address of source memory pDestination POINTER TO BYTE address of destination memory uiNumberOfBytes UINT number of bytes to move
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