|
Please use our Code Center to obtain source-code and example projects/solutions:
http://codecenter.softwaretoolbox.com
|
|
|

|
|
|
|
|

|
|
Web Service Consumption
The following example shows you how to write to tags in C# by consuming the OPC Web Client Web Service.
Writing to a Single Tag:
string strPCName = ""; string strOPCServer = "OPCLabs.KitServer.2"; string strTag = "Simulation.Register_I4"; int iValue = 10;
try { //'create the opc web client object OPCLabs.EasyOPCDANet.EasyDAWS objOWC = new OPCLabs.EasyOPCDANet.EasyDAWS();
//make the call to write the value
objOWC.WriteItemValue ( strPCName, strOPCServer, strTag, iValue,
null, null, null ); //display a message MessageBox.Show("Wrote value!");
//clean up objOWC = null; } catch(System.Web.Services.Protocols.SoapException webex) {
MessageBox.Show("Error: " + webex.Message.ToString()); } 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.EasyDAWS o = new OPCLabs.EasyOPCDANet.EasyDAWS(); //make the call to read multiple tags object values = (object)o.WriteMultipleItemValues(
oPC, oOPC, oTags, new object[]{10, 20}, null, null, 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()); }
|
|

|
|
|
|

|
|
|