static public void ListHDAServers(String node) { IDiscovery discovery = new OpcCom.ServerEnumerator(); Opc.Server[] servers; try { if (string.IsNullOrEmpty(node)) { servers = discovery.GetAvailableServers(Specification.COM_HDA_10); } else { servers = discovery.GetAvailableServers(Specification.COM_HDA_10, node, null); } Console.WriteLine("Available servers are:"); foreach (Opc.Server s in servers) { Console.WriteLine(s.Name); } } catch (System.Runtime.InteropServices.ExternalException e) { Console.WriteLine("Error getting available servers: {0}", e.Message); } }
private void OpcOptionsEditor_Loaded(object sender, RoutedEventArgs e) { var dispatcher = Dispatcher; var action = new Action(() => { try { IDiscovery discovery = new OpcCom.ServerEnumerator(); var localservers = discovery.GetAvailableServers(Specification.COM_DA_20) .Select(s => s.Url) .ToArray(); dispatcher.Invoke(new Action(() => { ItemsSource = localservers; })); } catch (Exception exception) { MessageBox.Show(exception.Message); } }); action.BeginInvoke(action.EndInvoke, null); }
//protected override IEnumerable<IOpcNode> CreateNodes(OpcNodeReferenceCollection references) //{ // OpcFolderNode machineOne = new OpcFolderNode(new OpcName("Machine_1")); // //references.Add(machineOne, OpcObjectTypes.ObjectsFolder); // return new IOpcNode[] { machineOne }; //} private void Brown_OPC_Server_Click(object sender, EventArgs e) { try { listBox1.Items.Clear(); //OpcFolderNode machineOne = new OpcFolderNode("localhost"); //String ss = machineOne.Parent.ToString(); //Console.WriteLine(ss); System.Net.NetworkCredential mCredentials = new System.Net.NetworkCredential(); Opc.ConnectData mConnectData = new Opc.ConnectData(mCredentials); OpcCom.ServerEnumerator se = new OpcCom.ServerEnumerator(); Opc.Server[] servers = se.GetAvailableServers(Opc.Specification.COM_DA_20, Node.Text.ToString(), mConnectData); for (int i = 0; i < servers.Length; i++) { //Console.WriteLine("Server {0}: >{1}<", i, servers[i].Name); listBox1.Items.Add(servers[i].Name); } } catch (Exception ex) { MessageBox.Show("Error \n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static IList <HdaServer> GetAvailableServers(string host) { var opcServers = new OpcCom.ServerEnumerator().GetAvailableServers(Specification.COM_HDA_10, String.IsNullOrWhiteSpace(host) ? "localhost" : host, null); var servers = new List <HdaServer>(); foreach (var opcServer in opcServers) { servers.Add(new HdaServer(host, opcServer.Name)); } return(servers); }
/// <summary> /// 取得可用的Opc服务器 /// </summary> /// <param name="host">Opc服务器主机名称或者IP,默认值为本机</param> /// <returns>可用的服务器</returns> private static Opc.Server[] getOpcServers(string host = "127.0.0.1") { try { Opc.IDiscovery opcdiscovery = new OpcCom.ServerEnumerator(); Opc.Server[] servers = opcdiscovery.GetAvailableServers(Specification.COM_DA_20, host, null); return(servers); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); return(null); } }
//public bool IsConnectedToOPCDAServer { get { if (oPCDAServer == null) return false; else return oPCDAServer.IsConnected; } } #endregion public OPCClassicBrowserEngine() { this.OPCGroupSizeLimit = OPCBackEnd.Config.OPCClassic_SubscriptionGroupSizeLimit.ToInt(40); _OPCWrapper = new OpcCom.ServerEnumerator(); _BrowseFilters = new Opc.Da.BrowseFilters() { ReturnAllProperties = true, ReturnPropertyValues = true, BrowseFilter = Opc.Da.browseFilter.all, MaxElementsReturned = 0 }; //Check for Tag Inactivity every 5s. Every call by client will update it's activity. //If tag has been inactive for more than 3x it's update interval, remove the tag from subscription (5s min inactivity time) OPTimer CheckInactivityTimer = new OPTimer("OPC Classic Browser Engine Check Inactivity Timer", 5000); CheckInactivityTimer.Elapsed += (s) => { List <RegisteredTag> InactiveTags = this.RegisteredTags.Values.Where(RT => { if (RT.UpdateIntervalInMS <= 5000) { return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 5000); } else { return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 3 * RT.UpdateIntervalInMS); } }).ToList(); foreach (RegisteredTag InactiveTag in InactiveTags) { foreach (Opc.Da.Server OPCServer in _OPCDAServers) { if (!OPCServer.IsConnected) { continue; } Subscription SubscriptionWhereInactiveTagIs = OPCServer.Subscriptions.FindSubcriptionThatHasItem(InactiveTag.Id, out Item InactiveItem); if (SubscriptionWhereInactiveTagIs != null) { SubscriptionWhereInactiveTagIs.RemoveItems(new ItemIdentifier[] { InactiveItem }); } } this.RegisteredTags.Remove(InactiveTag.Id); } return(Task.CompletedTask); }; CheckInactivityTimer.Start(); }
private void uiRefresh_Click(object sender, EventArgs e) { if (uiHostName.Text == string.Empty) { return; } IDiscovery discovery = new OpcCom.ServerEnumerator(); try { uiServerBindingSource.DataSource = discovery.GetAvailableServers(Specification.COM_DA_20, uiHostName.Text, null); CheckValidity(null, null); } catch { MessageBox.Show("OPC сервера не найдены", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public ObservableCollection <mServerItem> GetServers(string hostname) { try { OpcCom.ServerEnumerator discovery = new OpcCom.ServerEnumerator(); if (hostname == "") { hostname = "localhost"; } selectedServer.Host = hostname; //Get all local OPC DA servers of version 3.0 Opc.Server[] localservers = discovery.GetAvailableServers(Opc.Specification.COM_DA_20, hostname, null); listServers.Clear(); foreach (Opc.Server srv in localservers) { mServerItem si = new mServerItem(true); si.Name = srv.Name; si.Description = srv.Locale; si.UrlString = srv.Url.ToString(); listServers.Add(si); } } catch (Exception ex) { OnReportMessage("Opc server enumerator failed"); OnReportMessage(ex.Message); } //Get all OPC DA servers of version 2.0 of machine "MyMachine" //Opc.Server[] hostservers = discovery.GetAvailableServers(Opc.Specification.COM_DA_20, "MNS1-179N", null); return(listServers); }
private static Opc.Server[] enumServers(string addr) { using (var gen = new OpcCom.ServerEnumerator()) { return(gen.GetAvailableServers(Opc.Specification.COM_DA_20, addr, null)); } }
public OPCUABrowserEngine(string SSLCertificateDirectory = null) { this.OPCGroupSizeLimit = OPCBackEnd.Config.OPCCUA_SubscriptionGroupSizeLimit.ToInt(40); #region GENERATE APPLICATION CONFIGURATION _OPCWrapper = new OpcCom.ServerEnumerator(); if (SSLCertificateDirectory == null) { _SSLCertificateDirectory = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Vlix\\VlixOPC\\Certs"; } else { _SSLCertificateDirectory = SSLCertificateDirectory; } _Config = new ApplicationConfiguration() { ApplicationName = "VlixOPCUABrowser", ApplicationType = ApplicationType.Client, SecurityConfiguration = new SecurityConfiguration { //This is the App's certificate that should exist it the 'Own' directory ApplicationCertificate = new CertificateIdentifier { StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Own", SubjectName = Utils.Format(@"CN={0}, DC={1}", "VlixOPCUABrowser", System.Net.Dns.GetHostName()) }, TrustedPeerCertificates = new CertificateTrustList { StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Trusted", }, TrustedIssuerCertificates = new CertificateTrustList { StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Issuers", }, RejectedCertificateStore = new CertificateTrustList { StoreType = @"Directory", StorePath = _SSLCertificateDirectory + "\\Rejected", }, NonceLength = 32, AutoAcceptUntrustedCertificates = true }, TransportConfigurations = new TransportConfigurationCollection(), TransportQuotas = new TransportQuotas { OperationTimeout = 15000 }, ClientConfiguration = new ClientConfiguration { DefaultSessionTimeout = 60000 }, DisableHiResClock = true }; _Config.Validate(ApplicationType.Client); //This only checks if any certificates exists (in the predefined area). If no certificates exist, nothing will happen. #endregion OPTimer CheckInactivityTimer = new OPTimer("OPCUABrowserEngine Check Inactivity Timer", 5000); CheckInactivityTimer.Elapsed += (s) => { List <RegisteredTag> InactiveTags = this.RegisteredTags.Values.Where(RT => { if (RT.UpdateIntervalInMS <= 5000) { return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 5000); } else { return((DateTime.Now - RT.LastCalled).TotalMilliseconds > 3 * RT.UpdateIntervalInMS); } }).ToList(); foreach (RegisteredTag InactiveTag in InactiveTags) { foreach (OPCUAServer OPCServer in _OPCUAServers) { if (OPCServer.Session == null || !OPCServer.Session.Connected) { continue; } //ILocalNode NodeIdObject = OPCServer.Session.NodeCache.Find(new NodeId(InactiveTag.Id)) as ILocalNode; Subscription SubscriptionWhereInactiveTagIs = OPCServer.Session.Subscriptions.FindSubcriptionThatHasItem(InactiveTag.Id, out MonitoredItem InactiveItem); if (SubscriptionWhereInactiveTagIs != null) { SubscriptionWhereInactiveTagIs.RemoveItem(InactiveItem); } } this.RegisteredTags.Remove(InactiveTag.Id); } }; CheckInactivityTimer.Start(); }