Blog

Dynamically Specifying the Folder for Importing & Exporting Siemens HMI Recipes

Dynamically Specifying the Folder for Importing & Exporting Siemens HMI Recipes

One way to implement tasks when using Siemens products is to utilize the built-in recipe functionality. For applications in which the same PLC/HMI code is used across multiple standalone projects, it can be useful to configure a recipe on one PLC and then transfer it to other devices. To effectively transfer recipes between the PLC and HMI, please refer to this blog instead. This blog will cover dynamically setting the location of import files and export folders.

It is important to note that this implementation will not work with basic panels!

Exporting and Importing Files

Siemens HMI’s have built-in functions for importing and exporting files that are relatively easy to implement. Both functions are triggered by events that are named ExportDataRecords and ImportDataRecords, which are built-in Siemens functions. The events can trigger on a large variety of actions, but for this example, I had them trigger on HMI button presses. 

These events can be set by going to a component's properties and clicking on the events tab (shown below). 

recipe components
Component Properties on the HMI interface

Figure 1
Sample Configuration for ExportDataRecords

Figure 2
Sample Configuration for ImportDataRecords

For both importing and exporting data records, the input that specifies the desired pathing is the filename input. This parameter is the system path to the file in the form of a string. The string containing the import variable, and the string containing the export variable can be set using the same built-in HMI event function called OpenFileBrowser. Note that for this implementation, the export path and the import will need to be held in separate variables.

Figure 3
Sample Configuration for OpenFileBrowser

This event lets the user navigate to a desired folder/file and save the computer pathing of that file to the tag passed into the Path input. In this application, a specific file is used for importing recipes, and a folder is specified for exporting recipes. To do this, toggle the file input of the open file browser event.

When this parameter is set to true, the file browser will return a path to a file, when it is false it will return the path to a folder. When this field is set to true, you can also mask the browser to only show specific file extensions such as .csv or .ap by using the mask field. This can be useful for ignoring irrelevant files.

The event that exports recipes needs a file pathing to export, and since our file browsing event is grabbing a folder pathing, some basic scripting is needed to create an export file path we can use. The script below concatenates the folder pathing we got from the file browser with a name tag I created for the current recipe. This script should be triggered on the value change of either the folder path or the recipe name.

Sub ExportPathing()

HmiRuntime.SmartTags("sExportPath") = HmiRuntime.SmartTags("sExportPathFolder")  + HmiRuntime.SmartTags("dbRecipes_udtCurrentRecipe_sRecipeName") + ".csv

End Sub

Once the correct path is specified for importing and exporting, the import and export event are ready to be triggered. By using the tips outlined for importing and exporting recipes, you should be able to specify computer locations for importing and exporting recipes easily. I hope this will help in your future endeavors.

Learn more about DMC's HMI and SCADA Expertise and our partnership with Siemens.

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above: