private TDConfiguration CreateTestConfiguration() { TDConfiguration configuration = new TDConfiguration(); OPCServer opcServer = new OPCServer(); opcServer.HostName = "localhost"; opcServer.ServerName = "Advosol.SimDAServer.1"; OPCGroup opcGroup = new OPCGroup(); opcGroup.OwnerServer = opcServer; opcGroup.GroupName = "SimulatedData"; opcServer.Groups.Add(opcGroup); OPCItem opcItem = new OPCItem(); opcItem.FullName = "SimulatedData.Random"; opcItem.ItemName = "SimulatedData.Random"; opcItem.ValueUpdatedEvent += new EventHandler<PollItem.PollItemValueUpdatedEventArgs>(opcItem_ValueUpdatedEvent); opcGroup.Items.Add(opcItem); TDOpcDataSource opcDataSource = new TDOpcV2DataSource(); opcDataSource.OpcServer = opcServer; opcDataSource.PollDelay = 1000; configuration.GetDataSources.AddDataSource(opcDataSource); return configuration; }
private static TDConfiguration CreateTestConfiguration() { TDConfiguration configuration = new TDConfiguration(); OPCServer opcServer = new OPCServer(); opcServer.HostName = "localhost"; opcServer.ServerName = "Advosol.SimDAServer.1"; OPCGroup opcGroup = new OPCGroup(); opcGroup.OwnerServer = opcServer; opcGroup.GroupName = "SimulatedData"; opcServer.Groups.Add(opcGroup); OPCItem opcItem = new OPCItem(); opcItem.FullName = "SimulatedData.Random"; opcItem.ItemName = "SimulatedData.Random"; opcGroup.Items.Add(opcItem); _monitorPollItems.Add(opcItem); TDOpcDataSource opcDataSource = new TDOpcV2DataSource(); opcDataSource.OpcServer = opcServer; configuration.GetDataSources.AddDataSource(opcDataSource); return configuration; }
/// <summary> /// .ctor /// </summary> /// <param name="opcServer">OPC server instance (intrenal)</param> /// <param name="currentDataManager">Cerrent data manager</param> /// <param name="pollDelay">Poll delay in milliseconds (500 ms by default)</param> protected TDOpcPollProcess(OPCServer opcServer, TDDataManager currentDataManager, int pollDelay) : base(currentDataManager, pollDelay, opcServer.FullNetworkName) { _isServerConnected = ConnectToServer(opcServer.HostName, opcServer.ServerName); _opcItemNames = GetOpcItemNames(opcServer); IList<CommonDataContract.PollItem> pollItems = GetPollItems(opcServer); currentDataManager.RegisterPollItems(pollItems); }
private List<CommonDataContract.PollItem> GetPollItems(OPCServer opcServer) { List<CommonDataContract.PollItem> result = new List<CommonDataContract.PollItem>(); foreach (var currentGroup in opcServer.Groups) { foreach (var currentItem in currentGroup.Items) { result.Add(currentItem); } } return result; }
private string[] GetOpcItemNames(OPCServer opcServer) { List<string> result = new List<string>(); foreach (var currentGroup in opcServer.Groups) { foreach (var currentItem in currentGroup.Items) { result.Add(currentItem.ItemName); } } return result.ToArray(); }
private static TDDataSource CreateOPCDataSourceByXml(System.Xml.XmlNode dataSourceNode) { TDOpcDataSource opcDataSource; string dataSourceType = dataSourceNode.Attributes["type"].Value.ToString(); if (dataSourceType.ToLower() == "opc_v3") { opcDataSource = new TDOpcV3DataSource(); } // OPC_V2 is created by default else { opcDataSource = new TDOpcV2DataSource(); } OPCServer opcServer = new OPCServer(); opcServer.HostName = dataSourceNode.Attributes["hostname"].Value.ToString(); opcServer.ServerName = dataSourceNode.Attributes["name"].Value.ToString(); opcDataSource.PollDelay = Convert.ToInt16(dataSourceNode.Attributes["poll-delay"].Value); opcDataSource.OpcServer = opcServer; OPCGroup opcGroup; OPCItem opcItem; foreach (System.Xml.XmlNode groupNode in dataSourceNode) { if (groupNode.Name == "group") { opcGroup = new OPCGroup(); opcServer.Groups.Add(opcGroup); opcGroup.GroupName = groupNode.Attributes["name"].Value.ToString(); foreach (System.Xml.XmlNode itemNode in groupNode.ChildNodes) { if (itemNode.Name == "item") { opcItem = new OPCItem(); opcGroup.Items.Add(opcItem); opcItem.FullName = itemNode.Attributes["name"].Value.ToString(); bool isPack = Convert.ToBoolean(itemNode.Attributes["is-pack"].Value); if (isPack) { opcItem.IsPackage = true; opcItem.PackLength = Convert.ToInt16(itemNode.Attributes["pack-length"].Value); CreateSubItems(opcItem, itemNode); } //opcItem.ValueUpdatedEvent += new EventHandler<PollItem.PollItemValueUpdatedEventArgs>(opcItem_ValueUpdatedEvent); } } } } return opcDataSource; }
/// <summary> /// .ctor /// </summary> /// <param name="opcServer">OPC server instance (intrenal)</param> /// <param name="currentDataManager">Cerrent data manager</param> /// <param name="pollDelay">Poll delay in milliseconds (500 ms by default)</param> internal TDOpcV2PollProcess(OPCServer opcServer, TDDataManager currentDataManager, int pollDelay) : base(opcServer, currentDataManager, pollDelay) { }