Create the VTScada Module

To fully understand the following block of code requires some knowledge of VTScada's programming language. However, the important points are easily described:

GetTagValue is the name of the subroutine which will do exactly that function: get the requested tag's value.

The ServiceActive line includes a call to the function SetWSDL. This function requires four parameters:

  • The location of the WSDL file,
  • The name of the realm,
  • The scope of the call (in this case, 'self' - the current module),
  • The name of the service - which was pointed out in the preceding section on the WSDL file

The 5th parameter is ErrMsg: a pointer to an error message to return should SetWSDL fail. While optional, this parameter is strongly recommended as it can be invaluable when debugging.

The MAIN section of the code is somewhat cryptic, but what it does is rather simple: It takes any given tag name and attempts to find the current value associated with that tag. If found, the value will be returned along with a "0" to indicate success. Otherwise, a value of "-1" is returned to indicate failure.

Text lines between braces {...} are comments.

{=========================== TagQueryServices =========================}
{ This module contains the code that implements the services provided.       }
{======================================================================}
[
  ServiceActive               { Return value from SetWSDL                    };
  GetTagValue    Module;
  ErrMsg;       { Error message from SetWSDL. Invalid if none. }
]
Init [
  If Watch(1);
  [
    ServiceActive = System.WebService\SetWSDL(
                     "file://C:/vts/Station1/TagQueryServices.wsdl",
                     "QueryServicesRealm",
                     Self,"TagQueryServices",
                     &ErrMsg);
  ]
]
<
{============================= GetTagValue ==========================}
{ Subroutine called through SOAP to request the value of a tag.              }
{====================================================================}
GetTagValue
(
  request;
  response;
)
[
  TagName;
  TagObj;
]
Main [
  If 1;
  [
    TagName = (*request)\TagName;
    TagObj = Scope(\Code, TagName);
    IfElse(Valid(TagObj), Execute(
      (*response)\TagValue = TagObj\Value; { get the tag's value }
      (*response)\ReturnCode = 0;     { success }
    );
    {Else}
      (*response)\ReturnCode = -1;    { error - tag doesn't exist }
    );
    Return (0);
  ]
]
>