DataHub is a solution in Software Toolbox’s portfolio of software that integrates various IT and OT data sources, and is particularly strong in working with a wide range of OPC standards, secure multi-layer data tunneling, databases, historians and more. If you've ever worked with DataHub, you've probably seen the "Scripting" tab shown in the image below with some sample scripts. Perhaps you've wondered what this scripting can do or were curious about the language that DataHub scripts use. With that in mind, in this week’s blog we will cover the "what" and "why" of scripting in DataHub, and point you to "where" you can find more resources of "how" to take advantage of the DataHub scripting engine, included free with all DataHub licenses.
DataHub Scripting provides a means to extend the functionality of the product, but more often, it is used to provide that little bit of touch that is truly custom to your needs and requirements that product development may never have anticipated as a need to build into the configurable UI of the product. By leveraging scripting, your business ends up with an off-the-shelf, supportable software solution where that last little bit can be easily maintained and supported when compared to writing a 100% custom application. The DataHub built-in scripting environment shown below provides a means to view, edit, and activate scripts as well as create new ones.
What is it?
DataHub uses a powerful, built-in scripting language known as Gamma, which was created for use specifically within DataHub. Gamma has a C/C++ like syntax, meaning that it is typically easy for people who have written similar code before to pick up on it.
This language allows you to interact with DataHub in various ways to create solutions that are truly unique to your requirements. The DataHub scripting engine starts as soon as a DataHub instance starts and runs continuously until the DataHub instance shuts down. Scripts written in Gamma can be started manually from the Scripting tab, or automatically upon startup. The Gamma engine allows you to access all live data in the DataHub instance from within your scripts.
These scripts can be event-driven, meaning they will sit on standby, waiting until an event that the script has been programmed to respond to occurs, like a data change event or a timer.
Any syntactical or scripting errors that occur will appear in the DataHub Script Log, displayed alongside the relevant line numbers. You can also enter Gamma expressions directly into the script log and they will be evaluated immediately, which provides a means of interactive debugging or testing of a specific command.
In addition, expressions, lines, and blocks of code can be evaluated independently by highlighting the portion of the code text and selecting Evaluate Selection from the Script menu.
Why use it?
For most DataHub users, the “why” of DataHub scripting comes down to two things: Scalability of implementation and the ability to make dynamic decisions at runtime, such as choosing what data points to perform an action on. What’s even better is that scripting is also a core feature of DataHub, meaning that it’s included for free with any DataHub license!
Together, these features of DataHub’s scripting allow users to solve integration challenges the way that they want to - without needing to write a custom application or being limited by fill-in-the-blank configuration settings.
For a real-world example, one DataHub user came to us with 20 different sites, each with a DataHub instance. Each site needed to log data from 1,000 tags to a database. The challenge? Each site had a different tag list.
Instead of using the Data Logging UI within DataHub to manually add each of those 1,000 tag sets for each site, a script was used that imported in the tag names and logged the tags from the CSV file.
Thanks to DataHub’s scripting capabilities, all the user had to do was modify that CSV tag list, then click run on the script for each site. This allowed for the creation of a template-based approach to logging data and quickly scale out logging to all 20 sites. We have many sample scripts you can download and use to get started. We’ll provide links for those and other resources at the end of the article.
What can I do with it?
The primary purpose of the DataHub scripting is to allow users to interact with the live data represented by DataHub points and to directly interact with the DataHub configuration during runtime. Because of this, some of the most common uses we see are listed below with links to the product documentation:
- Performing a one-shot read on a specific tag
- Reading data on a timer or a data change
- Computing averages
- Creating new DataHub points
- Writing a new value to an existing DataHub point
- Breaking an array into individual points
However, there are many more advanced uses for DataHub scripting, some of which include:
- Creating windows
- Turning features such as bridging, OPC server/client connections, and tunnelling on and off
- Troubleshooting by printing errors and showing debug messages
Where do I find information on how to use it?
You can find some scripting examples in our Knowledgebase. The DataHub User Manual also has sections on Scripting and Gamma which include examples, helpful tips, and lists of all of the methods that can be used.
We hope this blog post has helped you better understand DataHub Scripting and the powerful functions that can be accomplished with it. If you have any questions, please do not hesitate to reach out to our support team. To learn more about DataHub’s powerful feature set, including interfaces to various OPC standards, secure multi-layer data tunneling, interfaces to popular process historians including AVEVA Historian, PI Historian and InfluxDB, visit the DataHub website.
Remember to subscribe to our blog to be notified of future posts about DataHub, as well as our other products!
Want to try scripting with DataHub for yourself? Download the free trial.
Want to learn more about how others use DataHub? View our DataHub case studies list.