/* 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 ExportOPCItems Application { //The name of the file to write filename = "C:\\OPC_Items_Export\\OPCTagList.csv"; //the data domain you are exporting from domainName = "topserver"; //this is not needed unless you are also using the AddOPCItemsCSV.g script for importing connName = "OPCConnectionName"; //this tag is our File Pointer once the file is opened fp; } /* Use methods to create functions outside the 'main line'. */ method ExportOPCItems.writeToFile () { if ((.fp = open(.filename, "w", nil)) != nil); { local tags = datahub_points(.domainName); //this is the first line in the CSV File used for importing. //We must have something because the first line is ignored when importing. //the line variable will hold the line we write out to the file each time. local line = "OPC Connection Name in the DataHub,OPC Server Item ID,Point Name in DataHub (can be the same as ItemID), Seperator\n"; //the line we write to the file writec(.fp, line); with tag in tags do { if(tag.flags != 307) { local temp = datahub_command(format("(OPCQueryPoint %s \"%s\")", .connName, tag.name), 1); local splitArray = list_to_array(string_split(temp, "\"", 0)); local serverItemId = splitArray[5]; princ(format(" Item is named - %a - %a \n", (serverItemId), (tag.name))); line = format("%a,%a,%a,%a\n", .connName, serverItemId, tag.name, ","); writec(.fp, line); } } princ("\n"); } close(.fp); } /* Write the 'main line' of the program here. */ method ExportOPCItems.constructor () { .writeToFile(); } /* Any code to be run when the program gets shut down. */ method ExportOPCItems.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 (ExportOPCItems);