2012-12-07 58 views
1

使用Proficy Historian的c#User API封裝器,我如何檢索所有(或過濾的)標籤名稱列表?通過IHUAPI檢索Proficy Historian標籤名稱

我找到了方法ihuFetchTagCache,它填充緩存返回一個標籤的計數,但我找不到一種方法來訪問此緩存。

我迄今爲止代碼:

string servername = "testServer"; 
int handle; 
ihuErrorCode result; 
result = IHUAPI.ihuConnect(servername, "", "", out handle); 
if (result != ihuErrorCode.OK) 
{//...} 

int count; 
result = IHUAPI.ihuFetchTagCache(handle, txtFilter.Text, out count); 
if (result != ihuErrorCode.OK) 
{//...} 

如何讀取標籤名稱緩存?

回答

1

實際上使用4.5和更高版本中提供的新標籤緩存方法會更好。這裏是我使用的DLL導入定義。

[DllImport("ihuapi.dll", EntryPoint = "[email protected]")] 
public static extern IntPtr CreateTagCacheContext(); 

[DllImport("ihuapi.dll", EntryPoint = "[email protected]")] 
public static extern ErrorCode CloseTagCacheEx2(IntPtr TagCacheContext); 

[DllImport("ihuapi.dll", EntryPoint = "[email protected]")] 
public static extern ErrorCode FetchTagCacheEx2(IntPtr TagCacheContext, int ServerHandle, string TagMask, ref int NumTagsFound); 

[DllImport("ihuapi.dll", EntryPoint = "[email protected]")] 
public static extern ErrorCode GetTagnameCacheIndexEx2(IntPtr TagCacheContext, string Tagname, ref int CacheIndex); 

[DllImport("ihuapi.dll", EntryPoint = "[email protected]")] 
public static extern ErrorCode GetNumericTagPropertyByIndexEx2(IntPtr TagCacheContext, int Index, TagProperty TagProperty, ref double Value); 

[DllImport("ihuapi.dll", EntryPoint = "[email protected]")] 
public static extern ErrorCode GetStringTagPropertyByIndexEx2(IntPtr TagCacheContext, int Index, TagProperty TagProperty, StringBuilder Value, int ValueLength); 

然後你可以用下面的代碼。

IntPtr context = IntPtr.Zero; 
try 
{ 
    context = IHUAPI.CreateTagCacheContext(); 
    if (context != IntPtr.Zero) 
    { 
     int number = 0; 
     ihuErrorCode result = IHUAPI.FetchTagCacheEx2(context, Connection.Handle, mask, ref number); 
     if (result == ihuErrorCode.OK) 
     { 
      for (int i = 0; i < number; i++) 
      { 
       StringBuilder text = new StringBuilder(); 
       IHUAPI.GetStringTagPropertyByIndexEx2(context, i, ihuTagProperties.Tagname, text, 128); 
       Console.WriteLine("Tagname=" + text.ToString()); 
      } 
     } 
    } 
} 
finally 
{ 
    if (context != IntPtr.Zero) 
    { 
     IHUAPI.CloseTagCacheEx2(context); 
    } 
} 

請注意,我不使用由GE提供的提供DLL導入的定義,所以我的代碼可能會略有不同,但差異應主要微不足道。

相關問題