how to read values from the remote OPC Server
Posted
by Shailesh Jaiswal
on Stack Overflow
See other posts from Stack Overflow
or by Shailesh Jaiswal
Published on 2010-06-10T11:41:06Z
Indexed on
2010/06/10
11:42 UTC
Read the original article
Hit count: 375
I have created one asp.net web service. In this web service I am using the web method as follows. The web service is related to the OPC ( OLE for process control)
public string ReadServerItems(string ServerName) { string txt = ""; ArrayList obj = new ArrayList(); XmlServer Srv = new XmlServer("XDAGW.CS.WCF.Eval.1"); RequestOptions opt = new RequestOptions(); ReadRequestItemList iList = new ReadRequestItemList(); iList.Items = new ReadRequestItem[3]; iList.Items[0] = new ReadRequestItem(); iList.Items[0].ItemName = "ServerInfo.ConnectedClients"; iList.Items[1] = new ReadRequestItem(); iList.Items[1].ItemName = "ServerInfo.TotalGroups"; iList.Items[2] = new ReadRequestItem(); iList.Items[2].ItemName = "EventSources.Area1.Tracking"; ReplyItemList rslt; OPCError[] err; ReplyBase reply = Srv.Read(opt, iList, out rslt, out err);
if ((rslt == null))
txt += err[0].Text;
else
{
foreach (xmldanet.xmlda.ItemValue iv in rslt.Items)
{
txt += iv.ItemName;
if (iv.ResultID == null) // success
{
txt += " = " + iv.Value.ToString() + "\r\n";
obj.Add(txt);
}
else
txt += " : Error: " + iv.ResultID.Name + "\r\n";
}
}
return txt;
}
I am using the namespaces as follows
using xmldanet; using xmldanet.xmlda;
I have installed XMLDA.NET client component evaluation. In this there is an in built Test client which successfully reads the values of these data items from the remote OPC server. I also provides the template through which we can build the OPC based applications. In the above code I am trying to read the values of the data items but i am not able to read the values. I have applied the breakpoint. In that I can see that the condition if (iv.ResultID == null) becomes false & also there is null values in the variable rslt. Please tell me where I am doing mistake ? how should I correct my mistake ? can provide me the correct code ?
© Stack Overflow or respective owner