Writing a Script

Z-Tool

Writing a Script

Writing a script to run on Z-Tool Script Engine is simple.  All you need are some JScript and Object Oriented backgrounds.  Make sure that you have read Script Engine topic to have an idea of the functions available in the Script Engine.  Look up ZPI.chm help file for formats of all messages.  Follow these steps to start writing a script:

  1. Ensure devices are referred to by their correct Alias Names.  See Settings page for information on how to set Device Alias Names.

  2. Import required namespaces

    • import System;

    • import System.Text;

    • import TI.ZPI1;  // use OLD Serial Interface format.  Replace with 'TI.ZPI2' to use the NEW one

  3. Declare main class.

    • class ZScriptSampleClass

    • {

    •     // insert the following code here

    • }

    • Create a Start function

      • function Start()

      • {

      •     // insert code here

      • }

    • Create a message handler function

      • function MessageHandler(zportName:String, id:MESSAGE_ID, msg:Object)

      • {

      •     // insert code here

      • }

    • Subscribe to message event

      •  // subscribe to message handler.  Put inside Start function.

      • ZEngine.add_OnMessageZPI1(this.MessageHandler);

    • End script using Complete function

      •  // quit script to Passed status.  Put inside MessageHandler function.

      • ZEngine.Complete(true);

  4. Initialize main class and call start function

    • var zTestScript:ZScriptSampleClass = new ZScriptSampleClass();  // create class object

    • zTestScript.Start();  // run start function

 

See Script Example for sample script which send and receive messages from two devices.