Configuring the Examples
This section of the document describes the Lua scripting capabilities using some simple examples. Each example has a different focus and can be configured independently from the others unless indicated. In this chapter we firstly configure the three examples (DemoData, Lua HTTP Access and Lua ODBC Access) from a variety of data sources. By using the Mass Config display in DataStudio we can configure multiple items simultaneously, including the embedding of Lua scripts and libraries. In the next chapter we will work with these examples and highlight the role of the Lua scripting.
|Before the example configuration is started, make sure the Mass Config Reference delimiter is set to pipe '|'. This is done by opening the General Settings dialogue (or F10), selecting the MassConfig page and changing the default configuration, reference delimiter to '|'.|
This example configures a set of demo objects that generate simulated process data and (by default) a year of history. The demo is mainly intended to enable you to start working with DataStudio’s display types, but it also contains some basic calculations that are explained in the next chapter.
To configure the demo data, first download the
Examples_DemoData.xlsx Mass Config file that matches your system:inmation
version from the resources page and then follow these steps:
Start DataStudio and login with administrative rights
Open a new Mass Config display (Ctrl+M shortcut). Click the Import Display Content icon in the menu bar., or use theFigure 1. Icon Menu Import
Select the downloaded
Examples_DemoData.xlsxfile from the Open File dialog and click Ok to load it into the display.Figure 2. Mass Config of DemoData
The provided configuration uses
Coreas name of the Core. This may be different in your environment (default object name of the Core is the name of the machine hosting it), and should be changed to match your system.
To do this , use the shortcut
Ctrl+Hto open the
Replacedialogue, and replace
MasterCorewith the object name of your Core.Figure 3. Replace Dialogue
Click Replace All; you should see 27 replacements.Figure 4. Replacement Message
In the Mass Config display click ''Simulate'' to test if the content can be applied to your system now.Figure 5. Simulate Changes
You should see 24 successes (this could be less if you already created some of the folders in a previous example).Figure 6. Simulate Result
Click ''Apply'' to accept the changes. The demo data objects should exist now in the I/O model tree.Figure 7. DemoData Objects
This example configures a set of demo objects that will illustrate how to access a http server outside of the system to retrieve data (here freely available information about US airports). This example also shows how Lua scripts can dynamically create objects in the tree hierarchy in addition to dealing with their values.
|In order to be able to retrieve the http server data, the machine hosting the Core needs to have access to the internet!|
To configure this example, download the Examples_LUA.xlsx file from the resources page and open it in the Mass Config display. After the import and the first run of the DataProcessing scripts included in the import, the I/O model tree should look like this:
This example configures a set of demo objects that illustrate how to access an ODBC data source.
|The provided sample scripts work with a very simplistic SQL demo database, and requires a System DSN configured to access this database on the Core host. Also it requires the DemoData Example to be already configured!|
To configure this example first create the SQL environment following these steps:
Make sure you have first configured the DemoData example shown above.
Create the sample sql database by either restoring the DemoData.bak or running the DemoData.sql provided with this document at a SQL Server instance of your choice (see note below for details of setting up an example SQL server).
Create a System DSN called 'DemoData' pointing to the DemoData SQL database (can be found in Administrative tools in the control panel). Double click on ODBC Data Source Administrator (32/64bit, depending on your environment), select the System DSN tab and click Add. Choose an appropriate driver (depending on the SQL Server you are using - ODBC Driver 11 for SQL Server works for MS SQL Express)
Give the System DSN a name in the dialog and connect it to the SQL Server you are using (it may not appear automatically in the drop-down menu). If using MS SQL Express this will be <hostname>\SQLEXPRESS.
Set up the SQL server authentication using same authentication details as during the SQL server set up (see note below for details of setting up an example SQL server) and click Next.
Change the default database to DemoData, click Next and then Finish. Test Data source and then click OK until all dialog windows are closed.
|If you do not have a SQL server available, you can download the 2014 Express version here. Be sure to download the Express with Tools download package as this contains the SQL Server Management Studio. During setup, enable the mixed mode authentication and enter DemoData!1 as the password for the system administrator (sa) account. This is important for this example as the embedded Lua script uses this authentication to access the ODBC database. To restore the DemoData.bak database, open the management studio and right-click on Databases in the left hand panel and select Restore Database. Select Source → Device → "…" and click Add to browse to the .bak file.|
The objects needed for the Lua ODBC example are included as part of the Examples_LUA.xlsx Mass Config file used to configure the Lua HTTP Access example. Download the Examples_Lua.xlsx file from the resources page if you haven’t already, and open it in the Mass Config display. After the import and the first run of the DataProcessing scripts included in the import, the I/O model tree should look like this: