Simple Write
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

 

Simple Write Example

The following example builds upon the Tutorial - Using with C#.

Writing to a Single Tag:

Simply copy & paste the code below into the form constructor:

{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
string strPCName = "";
string strOPCServer = "OPCLabs.KitServer.2";
string strTag = " Simulation.Random";
string strAccessPath = "";
int iValue = 10;

try
{
   EASYOPCDALib.EasyDA objOWC = new EASYOPCDALib.EasyDAClass();

   objOWC.WriteItemValue(strPCName, strOPCServer, strTag, strAccessPath, iValue);
  
   MessageBox.Show("Wrote value!");
  
   objOWC = null;
}
catch(Exception ex)
{
   MessageBox.Show("Error: " + ex.Message.ToString());
}

Writing to Multiple Tags within a single transaction:

    try
    {
    //define our initial variables and set their values
     
    object oPC = "127.0.0.1";
      object oOPC = "OPCLabs.KitServer.2";
      object oTags = new object[]{"Simulation.Register_I4", "Simulation.Register_R4"};
      object oAccess = System.Runtime.InteropServices.VarEnum.VT_ERROR;
      object oDTypes = System.Runtime.InteropServices.VarEnum.VT_ERROR;
      object oModes = System.Runtime.InteropServices.VarEnum.VT_ERROR;
              
    //'create the opc web client object
     
    OPCLabs.EasyOPCDANet.EasyDACOM o = new OPCLabs.EasyOPCDANet.EasyDACOM();
              
    //make the call to read multiple tags
     
    object values = (object)o.WriteMultipleItemValues(
       oPC,
       oOPC,
       oTags,
       new object[]{10, 20},
       System.Reflection.Missing.Value,
       System.Reflection.Missing.Value,
       null);
              
    //string needed to generate output message
     
    System.Text.StringBuilder sb = new System.Text.StringBuilder();

    //create an array so we can iterate thru it
     
    Array ar = (Array)values;

    //iterate thru array
     
    for(int i = 0; i < ar.GetLength(0); i++)
      {
    //build-up our string message
      
    sb.Append(ar.GetValue(i) + "\n");
      }

    //display the message output to screen
     
    MessageBox.Show(sb.ToString());
    }
    catch(Exception ex)
    {
      MessageBox.Show("Err: " + ex.Message.ToString());
    }

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