DataHub Scripting

Version 6.4

December 01, 2010

A user's guide to scripting in the DataHub.

Copyright, trademark, and software license information.

Table of Contents


1. Introduction

2. What's Different About DataHub Scripting?
2.1. Scripts and their Environment
2.1.1. Dynamic Environment
2.1.2. Event Driven
2.1.3. Object Oriented
2.2. Symbols, Variables, and Evaluation
2.2.1. Symbols and Variables
2.2.2. The Read/Evaluate Cycle
2.3. Access to DataHub Points
2.3.1. Point Names
2.3.2. Point Values
2.3.3. Point Timestamps and Qualities
2.4. ODBC and Windows Scripting
2.4.1. DataHub ODBC (Open Database Connectivity) Scripting
2.4.2. DataHub Windows Scripting

3. Getting Started
3.1. How to Run a Script
3.2. The Script Editor
3.3. The Script Log
3.4. The Script Application Manager

4. Writing Scripts
4.1. Creating a Script
4.2. Hello World
4.3. Accessing Data
4.4. Modifying Data
4.5. Two-Way Data Manipulation
4.5.1. Adapt it for your needs
4.6. Making a Window
4.7. Encrypting a Script
4.8. Scripting Tips
4.8.1. Copying a complete tutorial
4.8.2. Setting up a scripting environment

5. The Application class
5.1. Class Definition
5.2. Construction and Destruction
5.3. Handling Events
5.4. Timers
5.5. Menus

A. Basic Troubleshooting
B. License Copyright Information

I. Example Scripts
LogFile.g - logs data to a text file when a point changes value.
ReadCSV.g - reads a CSV file and writes the points and values to the DataHub.
WriteCSV.g - writes data to CSV files.
ParseExcel.g - parses data from an Excel spreadsheet.
LinearXform.g - performs linear transformation functions on points.
MakeArray.g - creates an array point from individual points.
IntToBit.g - converts an integer data point into a set of single-bit points.
ConnectionTrack.g - changes a point when a connection is made or broken.
QualityTrack.g - writes the quality of a point as the value of another point.
TagMonitor.g - monitors DataHub points for changes in quality or failure to change value.
FixQuality.g - changes point quality for OPC clients that treat bad quality as a disconnection.
OPCItemLoader.g - reads a list of OPC tags from a CSV file and configures DataHub points for them.
OPCReconnect.g - disconnects and reconnects an OPC server.
OPCReload.g - requests a reload of OPC server data with no disconnect.
AutoCalculation.g - automatically calculates formulas based on data points.
matlabtest.g - test a connection to Matlab.

II. Built-in Classes
DH_Domain - the structure of a DataHub domain.
DH_Item - the structure of a DataHub point.

III. Special Gamma Functions for DataHub Scripting
_ - looks up a translation text.
add_menu_action - adds a menu action.
allow_self_reference - permits changes to be written back to the point of origin.
datahub_command - sends commands to the DataHub.
datahub_domaininfo - gives information about data domains.
datahub_domains - creates a list of all domains.
datahub_points - shows the points in a data domain.
datahub_read - creates a list of all points for a domain.
datahub_write - assigns a value to a DataHub point.
edit_file - opens a file in the Script Editor.
get_point_queue_count - counts the number of DataHub points queued for Gamma.
get_point_queue_depth - gets the depth of the DataHub's per-point queue for Gamma.
get_tray_menu - returns a pointer to the tray menu.
on_change - evaluates an expression when a variable changes value.
remove_change - removes an on_change function.
remove_menu_action - removes a menu action.
set_point_flush_flags - determines which data types are not buffered.
set_point_queue_depth - sets the depth of the DataHub's per-point queue for Gamma.
show_log - displays the Script Log.
symcmp - compares symbols to see if they are equal.

IV. Methods and Functions from Application.g
AddCustomMenuItem - a convenience method for creating a menu item.
AddCustomSubMenu - a convenience method for adding a menu.
AddMenuItem - adds a menu item and attaches code to it.
AddPermanentMenuItem - should not be used.
AddStartMenuItem - should not be used.
AddStopMenuItem - creates a menu item that destroys the running application.
AddSubMenu - creates a submenu on a parent menu.
ApplicationMultiple - allows creation of multiple instances of the class.
ApplicationSingleton - allows creation of only one instance of the class.
CreateSystemMenu - adds a submenu to the system tray menu.
droptimer - for internal use only.
OnChange - attaches an event handler to a point change event.
RemoveAllChanges - removes event handlers from all point change events.
RemoveAllEventHandlers - removes all point change events and all timers.
RemoveAllMenus - removes all script menus, submenus, and menu actions.
RemoveAllTimers - cancels all timers.
RemoveChange - removes an event handler from a point change event.
RemoveSystemMenu - for internal use only.
RemoveTimer - cancels a timer.
TimerAfter - attaches an event handler to an "after" timer.
TimerAt - attaches an event handler to an "at" timer.
TimerEvery - attaches an event handler to an "every" timer.

V. Time Conversion Functions from Time.g
GetCurrentWindowsTime - returns the current clock time in Windows time format.
PointGetUnixTime - gets the Unix time stamp from a point.
PointGetWindowsTime - gets the Windows time stamp from a point.
PointMetadata - queries a point for its metadata structure.
UnixLocalToUTC - converts a local Unix time into UTC.
UnixTimeToWindowsTime - converts from Unix time to Windows time.
UnixUTCToLocal - converts a UTC Unix time into local time.
WindowsLocalToUTC - converts a local Windows time into UTC.
WindowsTimeToUnixTime - converts from Windows time to Unix time.
WindowsUTCToLocal - converts a UTC Windows time into local time.

VI. Quality Name Function from Quality.g
GetQualityName - converts the quality value of a point to a text string.
Index