2016-03-11 1 views
0

Я пишу код, который считывает данные с сервера OPC.OPC Server add items error HResult

public void setOPC() 
{ 
      int count = 1; 

      try 
      { 
       opcServer = new OPCServer(); 
       opcServer.Connect("OPCTechs.SiemensNet30DA", ""); 
       opcServer.OPCGroups.DefaultGroupIsActive = true; 
       opcServer.OPCGroups.DefaultGroupDeadband = 0f; 
       opcServer.OPCGroups.DefaultGroupUpdateRate = 10; 

       opcGroup = opcServer.OPCGroups.Add("MP"); 
       opcGroup.IsSubscribed = false; 
       opcGroup.OPCItems.DefaultIsActive = false; 

       int[] h = new int[844]; 

       for (int i = 69; i >= 60; i--, count++) 
       { 
        h[count] = opcGroup.OPCItems.AddItem("HH1001.B" + i, count).ServerHandle; 
       } 

       for (int i = 69; i >= 60; i--, count++) 
       { 
        h[count] = opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle; 
       } 
} 

В приведенной выше коде, так как он выполняет второй цикл & достигает линию

h[count] = opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle; 

это дает ошибке

Exception from HRESULT: 0x0040007 

Если он выполняет первую петлю AddItem успешно, почему это проблема со вторым?

ответ

1
opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle; 

Он будет получать ServerHandle на OPCItems, но не на определенный элемент. Но вы должны получить ServerHandle для определенного элемента, но не для всех элементов.

Попробуйте

opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count); 
h[count] = opcGroup.OPCItems[count].ServerHandle; 
Смежные вопросы