Write Single Tag
Home Product
Details Free 
Demo Pricing &
Ordering Related
Products Support About Us

Please use our Code Center to obtain source-code and example projects/solutions:

http://codecenter.softwaretoolbox.com

 

Web Based Applications using the OPC Web Client Web Servicev

Quick Links within this page

Objective

    To display the value of a Tag wihin the Browser. This value will be read from the OPC Server by means of the OPC Web Client Web Service, which utilizes the power of XML.

Writing to a single Tag

    JAVASCRIPT

<html>
<head>
<title>OPC Web Client running in IE, using OPC Web Client WEB SERVICE</title>
<SCRIPT LANGUAGE="JScript" src="ArgumentFormat.js"></SCRIPT>
<script language="javascript">

function fnInit()
{
  provider.init();
}

function fnWriteResult()
{
  if(event.error)
  {
   alert('error' + event.errorMessage);
  }
  else
  {
   alert('Write success!');
  }
}

function btnWrite_click()
{
  provider.write({ServerClass: "OPCLabs.KitServer.2", ItemID: "Simulation.Register_I4", Value: document.all.tagvalue.value});
}

</script>
</head>

<body onload="fnInit();">
<DIV id="service" style="behavior:url(webservice.htc)"></DIV>
<DIV id="provider" style="behavior:url(eagateway.htc)" webService="service" onWriteResult="fnWriteResult()"></DIV>
<p>OPC Server: OPCLabs.Kitserver.2<br>
<b>Tag Value:</b>
<input type="text" name="tagvalue" value="" size="10">
<input type="button" name="b1" value="write" onClick="btnWrite_click();">
</p>
</body>


</html>

Writing to Multiple Tags within a single transaction:

    VBScript

    Due to the limitations of VBScript and an easy way to pass-in complex arrays, the ability to read multiple tags in a single transaction is not currently available, but will be in the near future.

    JavaScript

    <html>
    <head>
    <title>OPC Web Client running in IE, using OPC Web Client WEB SERVICE</title>
    <SCRIPT LANGUAGE="JScript" src="ArgumentFormat.js"></SCRIPT>
    <script language="javascript">

    function fnInit()
    {
      provider.init();
    }

    function fnWriteResult()
    {
      if(event.error)
      {
       alert('error' + event.errorMessage);
      }
      else
      {
       alert('Write success!');
      }
    }

    function btnWriteMultiple_click()
    {
      provider.writeMultiple(
       new Array(
         {ServerClass: "OPCLabs.Kitserver.2", ItemID: "Simulation.Register_I4", Value: document.all.tag1value.value},
         {ServerClass: "OPCLabs.Kitserver.2", ItemID: "Simulation.Register_R8", Value: document.all.tag2value.value},
         {ServerClass: "OPCLabs.Kitserver.2", ItemID: "Simulation.Register_BSTR", Value: document.all.tag3value.value}
       ),
       new Array(
         "tag1",
         "tag2",
         "tag3"
       )
      );
    }

    </script>
    </head>

    <body onload="fnInit();">
    <DIV id="service" style="behavior:url(webservice.htc)"></DIV>
    <DIV id="provider" style="behavior:url(eagateway.htc)" webService="service" onWriteResult="fnWriteResult()"></DIV>
    <p>OPC Server: OPCLabs.Kitserver.2<br>
    <b>Tag Values:</b>
    <br>Simlator.Register_I4: <input type="text" name="tag1value" value="" size="10">
    <br>Simlator.Register_R8: <input type="text" name="tag2value" value="" size="10">
    <br>Simlator.Register_BSTR: <input type="text" name="tag3value" value="" size="10">
    <input type="button" name="b1" value="write" onClick="btnWriteMultiple_click();">
    </p>
    </body>

    </html>

Copyright Software Toolbox, Inc., 1996-2004, All Rights Reserved Worldwide.
148A East Charles Street, Matthews, North Carolina, USA 28105
Phone: 704-849-2773 or 1-888-665-3678 (US), Fax: 704-849-6388
sales@softwaretoolbox.com | support@softwaretoolbox.com