通过IHUAPI检索Proficy Historian标记名称

时间:2012-12-07 22:23:44

标签: c# historian proficy

使用Proficy Historian的c#User API包装器,如何检索标签名称的所有(或过滤后的列表)?

我找到了方法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 个答案:

答案 0 :(得分:1)

使用4.5及更高版本中提供的新标记缓存方法实际上更好。以下是我使用的DLL导入定义。 1

[DllImport("ihuapi.dll", EntryPoint = "ihuCreateTagCacheContext@0")]
public static extern IntPtr CreateTagCacheContext();

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

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

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

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

[DllImport("ihuapi.dll", EntryPoint = "ihuGetStringTagPropertyByIndexEx2@20")]
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);
    }
}

1 请注意,我不使用GE提供的DLL导入定义,因此我的代码可能看起来略有不同,但差异应该是微不足道的。