Siemens Tutorial
Tutorial to transform Siemens UDT to JSON
This tutorial has been tested against the Siemens Simatic 1507 PLC version 2.7.0, being programmed and controlled with TIA Portal version 16.
Ensure the FairCom server is installed and running.
Confirm server access by running the FairCom API Explorer (see API Explorer to learn about the user interface).
Siemens UDT to JSON transform tutorials
Export the schema that pertains to the user-defined data type that will be serialized and sent to FairCom Edge using your Siemens development environment TIA Portal.
Navigate to PLC data types.
Right-click the desired data type.
Select Generate source from blocks/including all dependent blocks to save the
.UDT
file to disk.Copy the
.UDT
file to the machine that you are performing your FairCom development on.Observe the
.UDT
file contents.Example 1..UDT
file contentsTYPE "Machine_Status"
TITLE = Realtime status of stamper 1
VERSION : 0.1
STRUCT
XPos : Real;
YPos : Real;
StatusCode : Int;
Info : String[54];
CycleID : Array[1.."Cycle_ID_Array_Length"] of Char;
END_STRUCT;
END_TYPE
Make a note of the root
TYPE
name — for example,"Machine_Status"
in Example 1, “.UDT
file contents”, you will need this rootTYPE
name to Create the Siemens UDT-to-JSON transform.Note
If your UDT has multiple nested data structures, use the root TYPE name of the parent structure that nests all other structures. Often it is the last structure listed in the
.UDT
file.Prepare the UDT for insertion into JSON, using the following conversions so that the
.UDT
file can be passed to FairCom Edge inside a JSON document.Replace any array-length variables with their actual integer values.
Example 2. Replace array-length variables with actual integer valuesCycleID : Array[1.."Cycle_ID_Array_Length"] of Char;
to
CycleID : Array[1..30] of Char;
Replace double-quotes/quotation marks with single quotes/apostrophes.
Replace End-Of-Line control chars (
\r\n
in Windows) with the following 2-character string:\n
Example 3. ConversionThe listed conversions in Step 3 convert the
.UDT
file contents in Example 1, “.UDT
file contents” to:TYPE 'Machine_Status'\nTITLE = Realtime status of stamper 1\nVERSION : 0.1\nSTRUCT\n XPos : Real;\n YPos : Real;\n StatusCode : Int;\n Info : String[54];\n CycleID : Array[1..30] of Char;\nEND_STRUCT;\nEND_TYPE\n
The project running in your PLC must be configured to connect to the FairCom Edge MQTT broker and publish MQTT messages to that broker which contains a serialized version of your UDT data. How that is done depends on the PLC model and the development language and environment used to program it.
Navigate to and open the FairCom Edge
services.json
file in the<faircom>\config
folder.Locate the
"listeners"
array in theservices.json
file and determine which one of the following objects matches how your PLC connects to the MQTT broker."serviceName": "mqtt1883"
"serviceName": "mqtts8883"
"serviceName": "mqttws9001"
"serviceName": "mqttwss9002"
Ensure that the
"enabled"
property is set totrue
for the relevant block.Observe the MQTT topic that the messages are being published to and how often they are being published.
Open
services.json
from the<faircom>\config
folder in a text editor.Locate the
"transformServices"
object and ensure the"enabled"
property is set totrue
."transformServices": [ { "serviceName": "siemensUDT2JSON", "serviceLibrary": "siemensudtservice.dll", "enabled": true } ]
Note
The
"serviceLibrary"
property value will differ depending on your operating system.Save any changes.
Restart the server for the changes to take effect.
Ensure changes made to the PLC project are uploaded to the PLC.
Set the PLC to RUN mode.
Validate that the PLC is connected and publishing messages to the FairCom EdgeMQTT broker:
Open the FairCom MQ Explorer (https://localhost:8443//MQExplorer/index.html).
Select MQTT Management from the button ().
Click Manage Subscriptions window.
() to open theSelect the MQTT topic that the PLC is publishing to from the Topic dropdown menu.
Click
().Close the Manage Subscriptions window.
Observe your messages, displayed under Incoming Messages each time the PLC publishes a message to that topic.
Note
The format of the messages is binary.
If the topic is not visible or the messages are not arriving in the topic:
Check for error messages in the
CTSTATUS.FCS
file in the FairCom Edgedata
folder.Perform any necessary debugging on the PLC side.
Open the FairCom MQ Explorer (https://localhost:8443//MQExplorer/index.html).
Select API Explorer from the Control menu ().
Replace the JSON in the API Request editor with the following JSON:
Update the
"schema"
property value with the converted UDT schema noted in Conversion.Update the
"rootTypeName"
property value with the root type name noted from the.UDT
file contents.
{ "authToken": "ReplaceWithValidToken", "api": "hub", "apiVersion": "1.0", "action": "createTransform", "params": { "transformName": "PLCData_transform", "transformActions": [ { "transformService": "siemensUDT2JSON", "transformActionName": "siemensUdtPayloadToJSON", "inputFields": [ "source_payload" ], "outputFields": [ "aValidFieldName" ], "transformParams": { "schema": "ReplaceWithConvertedUDTSchema", "rootTypeName": "ReplaceWithRootName", "udtDebugTracing": true } } ] } }
Click Apply defaults to JSON request () to replace the
"authToken"
value with the valid one from your session.Click Send request () to issue the JSON-based request.
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Select MQ API from the Select API dropdown menu.
Select
"configureTopic"
from the JSON Actions dropdown menu.Replace the JSON in the API Request editor with the following JSON:
{ "authToken": "ReplaceWithValidToken", "api": "mq", "apiVersion": "1.0", "action": "configureTopic", "params": { "topic": "ReplaceWithTopicName", "transformName": "PLCData_transform", "outputPayloadField": "aValidFieldName" } }
Update the
"topic"
property value with the name of the MQTT topic that the PLC is publishing to.Click Apply defaults to JSON request () to replace the
"authToken"
value with the valid one from your session.Click Send request () to issue the JSON-based request.
Observe the response and ensure the action completed successfully.
Note
"errorCode"
with a value of0
indicates success."errorCode"
with a non-zero value indicates a failure. See Errors and contact FairCom for more information about an error.
Complete the tutorial requirements before this procedure.
Open the FairCom MQ Explorer (https://localhost:8443//MQExplorer/index.html).
Select MQ Explorer from the button ().
Observe your messages, displayed under Incoming Messages each time the PLC publishes a message to that topic.