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;
        }
示例#2
0
        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;
        }
        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;
        }