public void AddList()
        {
            List <TECIO> io = new List <TECIO>
            {
                new TECIO(IOType.AI),
                new TECIO(IOType.AO),
                new TECIO(IOType.DI),
                new TECIO(IOType.DO)
            };
            IOCollection firstColletion   = new IOCollection(io);
            IOCollection secondCollection = new IOCollection(io);

            IOCollection resultCollection = new IOCollection();

            resultCollection.Add(firstColletion.ToList());
            resultCollection.Add(secondCollection.ToList());

            Assert.IsTrue(resultCollection.Contains(IOType.AI));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.AI));

            Assert.IsTrue(resultCollection.Contains(IOType.AO));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.AO));

            Assert.IsTrue(resultCollection.Contains(IOType.DI));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.DI));

            Assert.IsTrue(resultCollection.Contains(IOType.DO));
            Assert.AreEqual(2, resultCollection.IONumber(IOType.DO));
        }
        public void AddIO()
        {
            TECIO ai = new TECIO(IOType.AI);

            ai.Quantity = 5;
            TECIO ao = new TECIO(IOType.AO);

            ao.Quantity = 5;
            TECIO di = new TECIO(IOType.DI);

            di.Quantity = 5;
            TECIO ioDO = new TECIO(IOType.DO);

            ioDO.Quantity = 5;
            List <TECIO> io = new List <TECIO>
            {
                ai,
                ao,
                di,
                ioDO
            };
            IOCollection collection = new IOCollection(io);

            TECIO toAdd = new TECIO(IOType.AI);

            toAdd.Quantity = 2;

            collection.Add(toAdd);

            Assert.AreEqual(7, collection.IONumber(IOType.AI));
        }
        internal static bool addRequiredIOModules(TECProvidedController controller)
        {
            //The IO needed by the points connected to the controller
            IOCollection necessaryIO = new IOCollection();
            bool         needsSave   = false;

            foreach (TECHardwiredConnection ssConnect in
                     controller.ChildrenConnections.Where(con => con is TECHardwiredConnection))
            {
                foreach (TECIO io in ssConnect.Child.HardwiredIO.ToList())
                {
                    for (int i = 0; i < io.Quantity; i++)
                    {
                        //The point IO that exists on our controller at the moment.
                        IOCollection totalPointIO = getPointIO(controller);
                        necessaryIO.Add(io.Type);
                        //Check if our io that exists satisfies the IO that we need.
                        if (!totalPointIO.Contains(necessaryIO))
                        {
                            needsSave = true;
                            bool moduleFound = false;
                            //If it doesn't, we need to add an IO module that will satisfy it.
                            foreach (TECIOModule module in controller.Type.IOModules)
                            {
                                //We only need to check for the type of the last IO that we added.
                                if (module.IOCollection.Contains(io.Type) && controller.CanAddModule(module))
                                {
                                    controller.AddModule(module);
                                    moduleFound = true;
                                    break;
                                }
                            }
                            if (!moduleFound)
                            {
                                controller.DisconnectAll();
                                MessageBox.Show(string.Format("The controller type of the controller '{0}' is incompatible with the connected points. Please review the controller's connections.",
                                                              controller.Name));

                                return(true);
                            }
                        }
                    }
                }
            }
            return(needsSave);

            IOCollection getPointIO(TECController con)
            {
                IOCollection pointIOCollection = new IOCollection();

                foreach (TECIO pointIO in controller.IO.ToList().Where(io => (TECIO.PointIO.Contains(io.Type) || TECIO.UniversalIO.Contains(io.Type))))
                {
                    pointIOCollection.Add(pointIO);
                }
                return(pointIOCollection);
            }
        }
Exemple #4
0
        /// <summary>
        /// Returns the io which make up existing network connections on a controller
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public static IOCollection ExistingNetworkIO(TECController controller)
        {
            IOCollection existingNetwork = new IOCollection();

            foreach (TECNetworkConnection connection in controller.ChildrenConnections.Where(x => x is TECNetworkConnection))
            {
                existingNetwork.Add(connection.NetworkProtocol);
            }
            return(existingNetwork);
        }