Executing a Tag Command from Java

Help Contents

Introduction

The following code fragment shows how to execute a tag command from Java:

import com.fernhillsoftware.datagateway.Connection;

public class TestClient {

    public static void main(String[] args) {

        Connection c = new Connection();

        try {

            // Connect to Fernhill SCADA
            // Note: The connection uses guest access unless Connection.logonUser() is called
            c.connect("localhost");

            // The tagCommand() function is used to execute any tag command.  
            // You must pass at least two parameters:
            //  1) The full name of the tag, in this example: TestFolder.DigitalTag
            //  2) The tag command to execute.  In this example: WriteValue
            // The remaining parameters depend on the tag command.  This example uses WriteValue,
            // which requires one extra parameter - the value to write.
            c.tagCommand("TestFolder.DigitalTag", "WriteValue", true);

            // Close the connection
            c.close();

        } catch (Exception e) {

            e.printStackTrace();
        }
    }
}

Further Information

Fernhill SCADA Download

For a download link to the Fernhill SCADA Java API.