Function Blocks ¶ TCP TCP_Client (FunctionBlock) TCP_Connection (FunctionBlock) IPAddress (Property) TCP_Read (FunctionBlock) TCP_ReadBuffer (FunctionBlock) TCP_Server (FunctionBlock) TCP_Write (FunctionBlock) TCP_WriteBuffer (FunctionBlock) UDP UDP_Peer (FunctionBlock) UDP_Receive (FunctionBlock) UDP_ReceiveBuffer (FunctionBlock) UDP_Send (FunctionBlock) UDP_SendBuffer (FunctionBlock)
TCP ¶ TCP_Client (FunctionBlock) TCP_Connection (FunctionBlock) IPAddress (Property) TCP_Read (FunctionBlock) TCP_ReadBuffer (FunctionBlock) TCP_Server (FunctionBlock) TCP_Write (FunctionBlock) TCP_WriteBuffer (FunctionBlock)
TCP_Client (FB) ¶ FUNCTION_BLOCK TCP_Client EXTENDS CBM.LTrig Implements a TCP Client. To connect to a TCP Server at the endpoint defined with ipAddr and uiPort the input xEnable should set to TRUE . While setup the connection xBusy is TRUE but xActive is FALSE . After the connection is established xActive and xBusy is TRUE and the hConnection output is valid. After closing the connection from the server side xActive becomes FALSE hConnection become CAA.gc_hINVALID and xDone becomes TRUE . InOut: Scope Name Type Initial 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 udiTimeOut UDINT 0 Defines the time (µs) after which the connection setup aborts with an error message. ipAddr IP_ADDR IP-Address of server to connect to uiPort UINT Port number of TCP socket to open Output eError ERROR xActive BOOL TRUE if a Connection is established hConnection CAA.HANDLE Valid, if xActive = TRUE
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