[英]Retrieve Proficy Historian tag names via IHUAPI
Using the c# User API wrapper for Proficy Historian, how can I retrieve all (or a filtered list of) tag names? 使用Proficy Historian的c#用户API包装器,如何检索所有(或过滤的列表)标记名?
I have located the method ihuFetchTagCache, which populates a cache returns a count of tags, but I cannot find a way to access this cache. 我已经找到了ihuFetchTagCache方法,该方法填充了一个缓存并返回了标签数量,但是我找不到访问该缓存的方法。
My code so far: 到目前为止,我的代码:
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)
{//...}
How do I read the tag name cache? 如何读取标签名称缓存?
It is actually better to use the new tag cache methods provided in 4.5 and above. 实际上,最好使用4.5及更高版本中提供的新标签缓存方法。 Here are the DLL import definitions I use.
这是我使用的DLL导入定义。 1
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);
Then you can use the following code. 然后,您可以使用以下代码。
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 Note that I do not use the provided DLL import definitions provided by GE so my code may look slightly different, but the differences should be mostly trivial. 1 请注意,我没有使用GE提供的提供的DLL导入定义,因此我的代码看起来可能略有不同,但是这些差异应该很小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.