/* All user scripts should derive from the base "Application" class */ require ("Application"); /* Get the Gamma library functions and methods for ODBC and/or * Windows programming. Uncomment either or both. */ require ("WindowsSupport"); //require ("ODBCSupport"); /* Applications share the execution thread and the global name * space, so we create a class that contains all of the functions * and variables for the application. This does two things: * 1) creates a private name space for the application, and * 2) allows you to re-load the application to create either * a new unique instance or multiple instances without * damaging an existing running instance. */ class WriteAtTime Application { //The name of the file to read - Change the path and filename as needed filename = "C:\\DataHub\\TestWrite.txt"; //the data domain you are exporting from - Change the domain you are using in DataHub domainName = "default"; //this tag is our File Pointer once the file is opened - No need to change fp; } /* Use methods to create functions outside the 'main line'. * This method writes all tags from the domain named above * with value <> nil * to the file named above */ method WriteAtTime.writeToFile () { if ((.fp = open(.filename, "w", nil)) != nil); //The "w" will overwrite file. Use "a" to append { local tags = datahub_points(.domainName); with tag in tags do { if(tag.value != nil) { line = format("%a,%a\n", tag.name, tag.value); writec(.fp, line); } } } close(.fp); } /* This method calls the WriteToFile on a timed basis. * Change the desired time using format * TimerAt (day, month, year, hour, minute, second, `(@self).writeToFile()) * where "hour" uses a 24-hour clock. * The follwoing triggers the WriteToFile method every evening at 5:45 PM. */ method WriteAtTime.constructor () { .TimerAt(nil,nil,nil,17,45,00, `(@self).writeToFile()); } /* Any code to be run when the program gets shut down. */ method WriteAtTime.destructor () { } /* Start the program by instantiating the class. If your * constructor code does not create a persistent reference to * the instance (self), then it will be destroyed by the * garbage collector soon after creation. If you do not want * this to happen, assign the instance to a global variable, or * create a static data member in your class to which you assign * 'self' during the construction process. ApplicationSingleton() * does this for you automatically. */ ApplicationSingleton (WriteAtTime);