Opc Server Subscription AddItems
Posted: 14 Mar 2014, 10:14
hi,
i tested to connect and read/write variables on beckhoff plc (i works fine in the test-projekt in visual studio). then i wrote an new project with the same code, but it was not possible to add the Opc.Da.Items to the subscription-group.
after group.addItems(opcItems) the item-value is Items = {Opc.Da.Item[0]} but the opcItems-array has 15 entries.
can anyone help me?
thx!
ps: in the new project it is not possible to use the group.Refresh() method -> ResultIDException: E_FAIL, IOPCAsyncIO2.RefreshMaxAge
i tested to connect and read/write variables on beckhoff plc (i works fine in the test-projekt in visual studio). then i wrote an new project with the same code, but it was not possible to add the Opc.Da.Items to the subscription-group.
after group.addItems(opcItems) the item-value is Items = {Opc.Da.Item[0]} but the opcItems-array has 15 entries.
can anyone help me?
thx!
ps: in the new project it is not possible to use the group.Refresh() method -> ResultIDException: E_FAIL, IOPCAsyncIO2.RefreshMaxAge
Code: Select all
...
Opc.Da.Server opcServer = null;
Opc.URL url = new Opc.URL("opcda://IPA-HENB236/BECKHOFF.TwinCATOpcServerDA");
OpcCom.Factory fact = new OpcCom.Factory();
Opc.Da.Subscription group;
Opc.Da.SubscriptionState groupState;
Opc.Da.Item[] opcItems;
opcItems = new Opc.Da.Item[pm.variablesList.Count];
opcServer = new Opc.Da.Server(fact, null);
opcServer.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
groupState = new Opc.Da.SubscriptionState();
groupState.Name = "newGroup";
groupState.Active = true;
int i = 0;
foreach (KeyValuePair<string, Variable> e in pm.variablesList)
{
opcItems[i] = new Opc.Da.Item();
opcItems[i].ItemName = ("PLC1." + e.Value.spsName);
i++;
}
group = (Opc.Da.Subscription)opcServer.CreateSubscription(groupState);
group.AddItems(opcItems);
group.DataChanged += new Opc.Da.DataChangedEventHandler(group_DataChanged);
...