|
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 read/write to tags of type Array in C# by consuming the OPC Web Client Web Service.
Reading an Array Tag:
string strPCName = ""; string strOPCServer = "SWToolbox.TOPServer"; string strTag = "Channel_1.Device_1.TagArray_1";
try {
//define our OPC Web Client objects OPCLabs.EasyOPCDANet.EasyDAWS objOWC = new OPCLabs.EasyOPCDANet.EasyDAWS();
OPCLabs.EasyOPCDANet.IVTQNet objTagVTQ; //read the tag objTagVTQ = objOWC.ReadItem
( strPCName, strOPCServer, strTag, null, null, null); //get the type of the tag value - this should indicate
//if it is an array or not Type ty = objTagVTQ.Value.GetType(); //now check if it is an array if (ty.IsArray)
{ //get the tag value into an array System.Array ar;
ar = (System.Array)objTagVTQ.Value; //use a stringbuilder to build our string of values so that
//we can display them on-screen easily System.Text.StringBuilder sb = new System.Text.StringBuilder();
//iterate thru all objects within array foreach(Object o in ar)
{ sb.Append(o.ToString() + " "); }
//display the finished result to screen MessageBox.Show(sb.ToString());
//clean-up sb = null;
ar = null; } else { MessageBox.Show("Not an array!");
} //clean-up objTagVTQ = null; 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 an Array Tag:
string strPCName = ""; string strOPCServer = "SWToolbox.TOPServer"; string strTag = "Channel_1.Device_1.TagArray_1";
try
{ // //create our array of values we want to write to the tag int[] values = new int[]{0, 1, 2, 4, 5, 6, 7, 8, 9, 10};
// //define our OPC Web Client objects OPCLabs.EasyOPCDANet.EasyDAWS objOWC = new OPCLabs.EasyOPCDANet.EasyDAWS();
// //now to do the write objOWC.WriteItemValue ( strPCName, strOPCServer, strTag,
values, null, null,
null ); // //display a message MessageBox.Show("Tag write a success!"); //
//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()); }
|
|

|
|
|
|

|
|
|