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.
| Recommended task: | Cyclic, Default |
| Libraries used: | SYSTEM2_PCC03_40bd03 BM_TYPES_40bd04 or higher TECH_TYPES_40bd15 or higher |
The general description explains the available request types in more detail and provides an integration example.
| none |
| Marking: | Data type: | Description: |
|---|---|---|
| x_Execute | BOOL | Execute the function block |
| s_RequestMethod | STRING | Defining the request method (GET, PUT, POST) |
| s_IP | STRING | IP address of the device on which the web server to be connected to is running |
| ui_Port | UINT | Port on which the web server is running |
| s_Path | STRING | Path of the server to which the request is made (e.g.: /data) |
| s_ContentType | STRING | Type of data sent / received (default: application/json) |
| a_Body | BYTE_4096_BMARRAY | Byte array containing the data to be sent (JSON form converted to bytes) |
| Marking: | Data type: | Description: |
|---|---|---|
| x_Busy | BOOL | Function is working |
| x_Done | BOOL | Function is done and ready for a new measurement |
| x_Error | BOOL | TRUE: Error |
| s_ErrorInfo | STRING | gives Information about the occured error |
| w_ErrorID | WORD | Error ID according to Motion Control Error List |
| s_StatusReceived | STRING | Status of the request made (e.g.: 200 OK) |
| a_DataOutput | BYTE_4096_BMARRAY | Received data in a BYTE_4096_BMARRAY in JSON form |