【问题标题】:Retrieve Proficy Historian tag names via IHUAPI通过 IHUAPI 检索 Proficy Historian 标记名称
【发布时间】:2012-12-07 22:23:43
【问题描述】:

使用 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)
{//...}

如何读取标签名缓存?

【问题讨论】:

    标签: c# historian proficy


    【解决方案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 导入定义,因此我的代码可能看起来略有不同,但差异应该是微不足道的。 p>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-17
      相关资源
      最近更新 更多