1

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

如何读取标签名称缓存?

4

1 回答 1

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

于 2013-08-26T01:28:50.820 回答