Skip to main content

REST API

 This library provides function blocks for communication between the PLC and a REST-capable web server.

TB_ArrayToJson

TB_ArrayToJson

The function block converts two arrays (key and value array; data type: STRING_128_ARRAY) into a JSON string. This is placed in a byte array (BYTE_4096_BMARRAY) by the function block. Each byte is a character/letter in the JSON string.

Empfohlene Task: Cyclic, Default

Verwendete Bibliotheken: BM_TYPES_40bd04 or higherTECH_TYPES_40bd15 or higher

Eingänge

Marking:Data type:Description:
x_ExecuteBOOLExecute the function block
a_KeysSTRING_128_ARRAYArray of keys; in JSON format, keys are the variable names
a_ValuesSTRING_128_ARRAYArray of the values associated with the keys

Ausgänge

Marking:Data type:Description:
x_BusyBOOLFunction is working
x_DoneBOOLFunction is done and ready for a new measurement
a_JsonDataBYTE_4096_BMARRAYConverted keys and values into a JSON string in a byte array

Ein-/Ausgänge

none
Representation in FBD

TB_ArrayToJson

TB_ArrayToJson

The function block converts two arrays (key and value array; data type: STRING_128_ARRAY) into a JSON string. This is placed in a byte array (BYTE_4096_BMARRAY) by the function block. Each byte is a character/letter in the JSON string.

Empfohlene Task: Cyclic, Default

Verwendete Bibliotheken: BM_TYPES_40bd04 or higherTECH_TYPES_40bd15 or higher

Eingänge

Marking:Data type:Description:
x_ExecuteBOOLExecute the function block
a_KeysSTRING_128_ARRAYArray of keys; in JSON format, keys are the variable names
a_ValuesSTRING_128_ARRAYArray of the values associated with the keys

Ausgänge

Marking:Data type:Description:
x_BusyBOOLFunction is working
x_DoneBOOLFunction is done and ready for a new measurement
a_JsonDataBYTE_4096_BMARRAYConverted keys and values into a JSON string in a byte array

Ein-/Ausgänge

none
Representation in FBD

TB_JsonToArray

TB_JsonToArray

The function block converts a JSON string, which is available in a BYTE_4096_BMARRAY, into two individual arrays (key and value array, STRING_128_ARRAY). This allows This allows, for example, the JSON data received after a request to be converted into a usable format in the PLC.

Empfohlene Task: Cyclic, Default

Verwendete Bibliotheken: BM_TYPES_40bd04 or higherTECH_TYPES_40bd15 or higher

Eingänge

Marking:Data type:Description:
x_ExecuteBOOLExecute the function block
a_JsonDataBYTE_4096_BMARRAYConverted keys and values into a JSON string in a byte array

Ausgänge

Marking:Data type:Description:
x_BusyBOOLFunction is working
x_DoneBOOLFunction is done and ready for a new measurement
x_ErrorBOOLFunction shows an error
s_ErrorInfoSTRINGGives information about the occured error
a_KeysSTRING_128_ARRAYArray of keys; in JSON format, keys are the variable names
a_ValuesSTRING_128_ARRAYArray of the values associated with the keys

Ein-/Ausgänge

none
Representation in FBD

TB_JsonToArray

TB_JsonToArray

The function block converts a JSON string, which is available in a BYTE_4096_BMARRAY, into two individual arrays (key and value array, STRING_128_ARRAY). This allows This allows, for example, the JSON data received after a request to be converted into a usable format in the PLC.

Empfohlene Task: Cyclic, Default

Verwendete Bibliotheken: BM_TYPES_40bd04 or higherTECH_TYPES_40bd15 or higher

Eingänge

Marking:Data type:Description:
x_ExecuteBOOLExecute the function block
a_JsonDataBYTE_4096_BMARRAYConverted keys and values into a JSON string in a byte array

Ausgänge

Marking:Data type:Description:
x_BusyBOOLFunction is working
x_DoneBOOLFunction is done and ready for a new measurement
x_ErrorBOOLFunction shows an error
s_ErrorInfoSTRINGGives information about the occured error
a_KeysSTRING_128_ARRAYArray of keys; in JSON format, keys are the variable names
a_ValuesSTRING_128_ARRAYArray of the values associated with the keys

Ein-/Ausgänge

none
Representation in FBD

TB_RestRequester

TB_RestRequester

This function block makes requests to a web server via a REST API. The module can perform the request types GET, PUT and POST. These will be discussed in more detail later. The function block is based on the TCP blocks of the "SYSTEM2_PCC03_40bd03" library. The IP address and the port of the web server to be requested must be specified. In addition, a string is used to specify the type of request to be used. It is also important to specify the path to be requested on the server. The content type can be specified; if nothing is specified, "application/json" is entered as the default. In the case of a PUT or POST request, its body must be in a be specified in a BYTE_4096_BMARRAY in JSON format. The "TB_ArrayToJson" block can be used for this. After specifying all these input parameters, the request can be executed via an Execute. The received data is also written to a BYTE_4096_BMARRAY. If this comes from a server in JSON format, you can use the "TB_JsonToArray" block to convert it into a readable format.

Empfohlene Task: Cyclic, Default

Verwendete Bibliotheken: SYSTEM2_PCC03_40bd03BM_TYPES_40bd04 or higherTECH_TYPES_40bd15 or higher

Eingänge

Marking:Data type:Description:
x_ExecuteBOOLExecute the function block
s_RequestMethodSTRINGDefining the request method (GET, PUT, POST)
s_IPSTRINGIP address of the device on which the web server to be connected to is running
ui_PortUINTPort on which the web server is running
s_PathSTRINGPath of the server to which the request is made (e.g.: /data)
s_ContentTypeSTRINGType of data sent / received (default: application/json)
a_BodyBYTE_4096_BMARRAYByte array containing the data to be sent (JSON form converted to bytes)

Ausgänge

Marking:Data type:Description:
x_BusyBOOLFunction is working
x_DoneBOOLFunction is done and ready for a new measurement
x_ErrorBOOLTRUE: Error
s_ErrorInfoSTRINGgives Information about the occured error
w_ErrorIDWORDError ID according to Motion Control Error List
s_StatusReceivedSTRINGStatus of the request made (e.g.: 200 OK)
a_DataOutputBYTE_4096_BMARRAYReceived data in a BYTE_4096_BMARRAY in JSON form

Ein-/Ausgänge

none
Representation in FBD

TB_RestRequester

TB_RestRequester

This function block makes requests to a web server via a REST API. The module can perform the request types GET, PUT and POST. These will be discussed in more detail later. The function block is based on the TCP blocks of the "SYSTEM2_PCC03_40bd03" library. The IP address and the port of the web server to be requested must be specified. In addition, a string is used to specify the type of request to be used. It is also important to specify the path to be requested on the server. The content type can be specified; if nothing is specified, "application/json" is entered as the default. In the case of a PUT or POST request, its body must be in a be specified in a BYTE_4096_BMARRAY in JSON format. The "TB_ArrayToJson" block can be used for this. After specifying all these input parameters, the request can be executed via an Execute. The received data is also written to a BYTE_4096_BMARRAY. If this comes from a server in JSON format, you can use the "TB_JsonToArray" block to convert it into a readable format.

Empfohlene Task: Cyclic, Default

Verwendete Bibliotheken: SYSTEM2_PCC03_40bd03BM_TYPES_40bd04 or higherTECH_TYPES_40bd15 or higher

Eingänge

Marking:Data type:Description:
x_ExecuteBOOLExecute the function block
s_RequestMethodSTRINGDefining the request method (GET, PUT, POST)
s_IPSTRINGIP address of the device on which the web server to be connected to is running
ui_PortUINTPort on which the web server is running
s_PathSTRINGPath of the server to which the request is made (e.g.: /data)
s_ContentTypeSTRINGType of data sent / received (default: application/json)
a_BodyBYTE_4096_BMARRAYByte array containing the data to be sent (JSON form converted to bytes)

Ausgänge

Marking:Data type:Description:
x_BusyBOOLFunction is working
x_DoneBOOLFunction is done and ready for a new measurement
x_ErrorBOOLTRUE: Error
s_ErrorInfoSTRINGgives Information about the occured error
w_ErrorIDWORDError ID according to Motion Control Error List
s_StatusReceivedSTRINGStatus of the request made (e.g.: 200 OK)
a_DataOutputBYTE_4096_BMARRAYReceived data in a BYTE_4096_BMARRAY in JSON form

Ein-/Ausgänge

none
Representation in FBD