2016-03-11 98 views
0

我在寫一個代碼,它從OPC服務器讀取數據。OPC服務器添加項錯誤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; 

它會得到OPCItems上的ServerHandle,但不會在特定的項目上。但是你應該得到一個特定項目的ServerHandle,但不是整個項目。

嘗試

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