XMLWrite (FB) ¶ FUNCTION_BLOCK XMLWrite Writes a xml file. Use the function block XMLWriteAsync for large XML files to write the values asynchronously. To write to file set sFileName to file path and paDataArray = 0. To write to data array set sFileName = ‘’ and paDataArray to data pointer. InOut: Scope Name Type Initial Comment Input sFileName STRING(255) Path to a file paElements POINTER TO XMLElement Pointer to the result set udiCountElements UDINT Number elements in paElements eEncoding Encoding File encoding paDataArray POINTER TO BYTE 0 Pointer to XML data array, if 0 write to file (sFileName) udiDataArraySize UDINT 0 Size of paDataArray xAddDeclaration BOOL TRUE Adds XML declaration with encoding info like ‘<?xml version=”1.0” encoding=..’, default: TRUE Output eError ERROR Error
XMLWriteAsync (FB) ¶ FUNCTION_BLOCK XMLWriteAsync EXTENDS CBM.ETrig Writes a xml file asynchronously, i.e. distributed on several cycles. This function block should be used to write large xml files. To write to file set sFileName to file path and paDataArray = 0. To write to data array set sFileName = ‘’ and paDataArray to data pointer. InOut: Scope Name Type Initial Comment Inherited from Input xExecute BOOL Rising edge: Action starts Falling edge: Resets outputs If a falling edge occurs before the function block has completed its action, the outputs operate in the usual manner and are only reset if either the action is completed or in the event of an error. In this case, the corresponding output values ( xDone , xError ) are present at the outputs for exactly one cycle. ETrig Output xDone BOOL TRUE : Action successfully completed ETrig xBusy BOOL TRUE : Function block active ETrig xError BOOL TRUE : Error occurred, function block aborts action FALSE : No error ETrig Input sFileName STRING(255) Path to a file paElements POINTER TO XMLElement Pointer to the result set udiCountElements UDINT Number elements in paElements eEncoding Encoding File encoding paDataArray POINTER TO BYTE 0 Pointer to XML data array, if 0 write to file (sFileName) udiDataArraySize UDINT 0 Size of paDataArray xAddDeclaration BOOL TRUE Adds XML declaration with encoding info like ‘<?xml version=”1.0” encoding=..’, default: TRUE Output eError ERROR Error code if xError is true eLastError ERROR The last error
Parameter ¶ Param (ParamList)
Function Blocks ¶ WebSocketClient (FunctionBlock) Read (Method) SetInitialValue (Method) Write (Method) WebSocketRead (FunctionBlock) WebSocketWrite (FunctionBlock)
WebSocketClient (FB) ¶ FUNCTION_BLOCK WebSocketClient EXTENDS CBML.LCon IMPLEMENTS IWebSocketClient Function block to establish a connetion to a WebSocket server. InOut: Scope Name Type Initial Comment Inherited from Input xEnable BOOL TRUE : Activates the defined operation FALSE : Aborts/resets the defined operation LCon Output xDone BOOL TRUE : Ready condition reached LCon xBusy BOOL TRUE : Operation is running LCon xError BOOL TRUE : Error condition reached LCon Inout sUri STRING(1024) The uri of the server. e.g ‘ws://localhost:8080’ ws-URI = “ws:” “//” host [ “:” port ] path [ “?” query ] wss-URI = “wss:” “//” host [ “:” port ] path [ “?” query ] Input itfTLSContext NBS.ITLSContext 0 User defined TLS context for encrypted TCP connections (only for wss-URIs). If the TLS context is 0 then a default TLS context will be created for wss-URIs. Usage: Static initialization, as shown in the following code snippet. VAR commonName : STRING := 'MyRrasPi' ; ciCertInfo : NBS.CERT_INFO := ( psInfo := ADR ( commonName ), udiSize := LEN ( commonName )); myTLSContext : NBS.TLSContext := ( ePurpose := NBS.PURPOSE.CLIENT_SIDE , sUseCaseName := 'NBSTest' , sTLSVersion := '1.3' , ciCertInfo := ciCertInfo , udiVerificationMode := 2 ); END_VAR itfAsyncProperty NBS.IAsyncProperty 0 Runs the connect process in a own background task. Use this property if the connection setup takes longer than one task cycle (e.g. TLS connections) udiTimeOut UDINT 0 Defines the time (µs) after which the connection setup aborts with xError. sProtocol STRING ‘chat’ Sec-WebSocket-Protocol The underlaying subprotocols like ‘mqtt’. Default: ‘chat’ sExtensions STRING ‘’ Sec-WebSocket-Extensions Note: The extension data must be added manually to the payload data. Default: ‘’, no extension sAdditionalHttpHeader STRING ‘’ Additional http header data Additional http headers must be delimited and closed with $R$N Default: ‘’ tPingInterval TIME TIME#0ms Ping interval, T#0s: no ping httpProxySettings HttpProxySettings STRUCT(sProxyUser := ‘’, sProxyPassword := ‘’, sProxyServer := ‘’, uiProxyPort := 8080) Optional http proxy settings Input Const udiBufferSize UDINT 2024 The maximum size of the send and receive buffer. Changes during an online change have no effect on the buffer size. Output xActive BOOL TRUE if a connection is established eError ERROR Error state sSupportedProtocols STRING Supported protocols (server side) sSupportedExtensions STRING Supported extensions (server side) Methods: Read SetInitialValue Write Structure: Read (Method) SetInitialValue (Method) Write (Method)
WebSocketClient.Read (METH) ¶ METHOD Read : NBS.ERROR Read incoming messages. If a message was received, then the message is copied to pData and xReceived is set to TRUE . udiCount corresponds to the size of the received data. Note This method MUST be called in each cycle because the method also handles other requests in background (ping, pong etc.). The method can be called directly OR via the function block WebSocketRead . InOut: Scope Name Type Comment Return Read NBS.ERROR Input pData __XWORD Pointer to the payload data udiSize UDINT Maximum size of the payload Output udiCount UDINT Size of the received data xReceived BOOL TRUE if data received eFrameType FRAME_TYPE Type of the payload xIsFinalFragment BOOL FALSE if the payload is incomplete and is sent via multiple packets. TRUE, if the payload is complete or if the payload was incomplete and this packet is the last packet of a message.
WebSocketClient.SetInitialValue (METH) ¶ METHOD SetInitialValue : NBS.ERROR This method is used for setting the tls context to tcp client as an initial value. Note If the itfContext is zero this method uses default settings for tls. InOut: Scope Name Type Initial Return SetInitialValue NBS.ERROR Input itfContext NBS.ITLSContext itfAsyncProperty NBS.IAsyncProperty 0 itfTSNContext NBS.ITSNContext 0
WebSocketClient.Write (METH) ¶ METHOD Write : NBS.ERROR Sends messages to a WebSocket server. This method sends the payload pData with the size udiSize to the server. InOut: Scope Name Type Initial Comment Return Write NBS.ERROR Input pData __XWORD Pointer to the payload data udiSize UDINT Size of the payload eFrameType FRAME_TYPE FRAME_TYPE.BINARY Type of the payload data Output udiCount UDINT Number of sent bytes. Note It can take more than one cycles to send a message if the payload is greater than the maximum buffer size.
WebSocketRead (FB) ¶ FUNCTION_BLOCK PUBLIC FINAL WebSocketRead EXTENDS CBML.LConC Function block to read incoming messages using the Common Behavior Model (e.g. for CFC applications). Note This function block OR the Write method of the WebSocketClient MUST be called in each cycle because the method also handles other requests in background (ping, pong etc.). Set xEnable to TRUE if xActive of the WebSocketClient is TRUE . InOut: Scope Name Type Comment Inherited from Input xEnable BOOL TRUE : Activates the defined operation FALSE : Aborts/resets the defined operation LConC Output xBusy BOOL TRUE : Operation is running LConC xError BOOL TRUE : Error condition reached LConC Input itfWebSocketClient IWebSocketClient Reference to the WebSocketClient pData __XWORD Pointer to the payload data udiSize UDINT Maximum size of the payload Output xReady BOOL TRUE if data received udiCount UDINT Size of the received data eFrameType FRAME_TYPE Type of the payload xIsFinalFragment BOOL FALSE if the payload is incomplete and is sent via multiple packets. TRUE, if the payload is complete or if the payload was incomplete and this packet is the last packet of a message.
WebSocketWrite (FB) ¶ FUNCTION_BLOCK PUBLIC FINAL WebSocketWrite EXTENDS CBML.ETrigTo Function block to send messages to WebSocket server using the Common Behavior Model (e.g. for CFC applications). InOut: Scope Name Type Initial Comment Inherited from Input xExecute BOOL Rising edge: Starts defined operation FALSE : Resets the defined operation after ready condition was reached ETrigTo udiTimeOut UDINT Max. operating time for executing [µs], 0: No operating time limit ETrigTo Output xDone BOOL Ready condition reached ETrigTo xBusy BOOL Operation is running ETrigTo xError BOOL Error condition reached ETrigTo Input itfWebSocketClient IWebSocketClient Reference to the WebSocketClient pData __XWORD Pointer to the payload data udiSize UDINT Size of the payload eFrameType FRAME_TYPE FRAME_TYPE.BINARY Type of the payload data Output udiCount UDINT Number of sent bytes. Note It can take more than one cycles to send a message if the payload is greater than the maximum buffer size.