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

|
|
|
|
|

|
|
Reading an Array-Tag Example
This example assumes you have the TOPServer installed with the "simdemo.opf" project loaded.
The following example builds upon the Tutorial - Using with C#.
This tutorial uses the modified "Simdemo.opf" project.
Reading an Array-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 = "SWToolbox.TOPServer"; string strTag = "
Channel_1.Device_1.TagArray_1"; string strAccessPath = ""; int iDataType = 0;
try { // //define our OPC Web Client objects EASYOPCDALib.EasyDA objOWC = new EASYOPCDALib.EasyDAClass();
EASYOPCDALib.VTQ objTagVTQ; // //read the tag objTagVTQ = (EASYOPCDALib.VTQ)objOWC.ReadItem(strPCName,
strOPCServer, strTag, strAccessPath, iDataType); // //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(Exception ex) {
MessageBox.Show("Error: " + ex.Message.ToString()); }
|
|

|
|
|
|

|
|
|