public static List <Tuple <string, Guid> > GetOPCServiceList(string opcSerHostIp) { try { Host host = new Host(opcSerHostIp); OpcServerBrowser opcServerBrowser = new OpcServerBrowser(host); string[] servers; Guid[] serverGuids; opcServerBrowser.GetServerList(out servers, out serverGuids); if (null != servers) { List <Tuple <string, Guid> > serverList = new List <Tuple <string, Guid> >(); for (int i = 0; i < servers.Length; i++) { serverList.Add(new Tuple <string, Guid>(servers[i], serverGuids[i])); } return(serverList); } } catch (Exception ex) { NLogHelper.ExceptionInfo(ex, "GetOPCServiceList error :{0}", ex.Message); } return(null); }
public string[] DisplayLocalOpcV2V3Servers() { string[] Servers; OpcServerBrowser srvBrowse = new OpcServerBrowser(); // local server srvBrowse.GetServerList(out Servers); return(Servers); }
public DCO(string pamater) { this.ItemPoints = new List <IDataPoint>(); thread = new System.Threading.Thread(new System.Threading.ThreadStart(Monitor)); ILE.LEResult res = new LEResult(); //用这个数据点的配置,启动OPC连接,正因如此,此处注意,无法支持一台设备存在两个OPC_server地址 string[] pmts = pamater.Split(','); strMachine = pmts[0]; //服务PC的IP地址 string strServerName = pmts[1]; //服务名 string strPointName = pmts[2]; //数据点地址名 OpcServerBrowser myBrowser = new OpcServerBrowser(strMachine); try { myBrowser.CLSIDFromProgID(strServerName, out SrvGuid); //获取OPC服务组件的注册ID,获取不到会直接报错 } catch { res.ExtMessage = "服务不存在或无法访问!"; res.Result = false; //return res; throw new Exception("服务不存在或无法访问"); } Host host = new Host(strMachine); server = new OpcServer(); host.Domain = strMachine.ToUpper(); host.HostName = strMachine; host.UserName = ""; host.Password = ""; int rtc = server.Connect(strMachine, SrvGuid); try { HRESULTS.Succeeded(rtc); //this.label1.Text = "连接成功!"; //守护线程 } catch (Exception exc) { res.Result = false; res.ExtMessage = exc.Message; this.server.Disconnect(); this.server = null; throw new Exception("服务连接失败"); } }
public static Dictionary <string, Guid> GetServersNameAndGuid(string hostNameOrAddress) { string[] servers = null; Guid[] guids = null; Dictionary <string, Guid> serverAndGuidDic = new Dictionary <string, Guid>(); try { IPHostEntry ip_host = Dns.GetHostEntry(hostNameOrAddress); Host host = new Host(ip_host.HostName); OpcServerBrowser browser = new OpcServerBrowser(host); browser.GetServerList(out servers, out guids); for (int i = 0; i < servers.Length; i++) { serverAndGuidDic[servers[i]] = guids[i]; } } catch (Exception err) { NLogHelper.ExceptionInfo(err, "GetServersNameAndGuid error :{0}", err.Message); } return(serverAndGuidDic); }