制作opc服务器,力控服务器怎样做为OPC服务器,供其他OPC客户端程序访问

制作opc服务器,力控服务器怎样做为OPC服务器,供其他OPC客户端程序访问publicvoidListAll(Guidcatid,outOpcServers[]serverslist){serverslist=null;Dispose();Guidguid=newGuid(13486D51-4821-11D2-A494-3CB306C10000);Typetypeoflist=Type.GetTypeFromCLSID(guid);OPCL…

大家好,又见面了,我是你们的朋友全栈君。

public void ListAll(Guid catid, out OpcServers[] serverslist)

{

serverslist = null;

Dispose();

Guid guid = new Guid(13486D51-4821-11D2-A494-3CB306C10000);

Type typeoflist = Type.GetTypeFromCLSID(guid);

OPCListObj = Activator.CreateInstance(typeoflist);

ifList = (IOPCServerList)OPCListObj;

if (ifList == null)

Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

ifList.EnumClassesOfCategories(1, ref catid, 0, ref catid, out EnumObj);

if (EnumObj == null)

Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

ifEnum = (IEnumGUID)EnumObj;

if (ifEnum == null)

Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

int maxcount = 300;

IntPtr ptrGuid = Marshal.AllocCoTaskMem(maxcount * 16);

int count = 0;

ifEnum.Next(maxcount, ptrGuid, out count);

if (count 1)

{ Marshal.FreeCoTaskMem(ptrGuid); return; }

serverslist = new OpcServers[count];

byte[] guidbin = new byte[16];

int runGuid = (int)ptrGuid;

for (int i = 0; i count; i++)

{

serverslist[i] = new OpcServers();

Marshal.Copy((IntPtr)runGuid, guidbin, 0, 16);

serverslist[i].ClsID = new Guid(guidbin);

ifList.GetClassDetails(ref serverslist[i].ClsID,

out serverslist[i].ProgID, out serverslist[i].ServerName);

runGuid += 16;

}

Marshal.FreeCoTaskMem(ptrGuid);

Dispose();

}

取消

评论

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151317.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月20日 下午6:00
下一篇 2022年6月20日 下午6:00


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号