コード例 #1
0
        private void AddValveIslandCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // TODO: This dialog can only add one valve island to a station. A second will overwrite the first.
            // TODO: I/O addresses are not set by this method.
            AddValveIslandDlg dlg = new AddValveIslandDlg
            {
                Owner = this,
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                Tag = "Valve Isalnd"
            };

            dlg.ShowDialog();
            if (dlg.DialogResult == true)
            {
                if (SelectedItem.GetType().ToString() == "PLCcodeGen.Station")
                {
                    // Create a new valve island with basic configuration.
                    string      location    = ((App)Application.Current).MyProjects[0].PlcName + ((Station)SelectedItem).Name.Substring(1);
                    ValveIsland valveIsland = new ValveIsland(location, dlg.vIslandName.Text);

                    // Add all valves in station
                    // TODO: Need to be modified to handle more than one valve island in a station.
                    int modNum = 1; // Start on first input module.
                    int ioNum  = 2; // Start with third input. (First input occupied by pilot air valve sensor.)
                    foreach (Item item in ((Station)SelectedItem).Items)
                    {
                        if (item.ItemType == TypeOfItem.valve)
                        {
                            Valve v = (Valve)item;
                            foreach (PneuCyl cyl in v.PneuCyls)
                            {
                                if (ioNum > valveIsland.Modules[modNum].Size)
                                {
                                    modNum = valveIsland.InsertModule(v.Name + "." + modNum.ToString(), 8, IOtype.inp, "bool");
                                    ioNum  = 0;
                                }
                                valveIsland.Modules[modNum].Ios[ioNum++].Name = cyl.SensBxF;
                                if (ioNum > valveIsland.Modules[modNum].Size)
                                {
                                    modNum = valveIsland.InsertModule(v.Name + "." + modNum.ToString(), 8, IOtype.inp, "bool");
                                    ioNum  = 0;
                                }
                                valveIsland.Modules[modNum].Ios[ioNum++].Name = cyl.SensBxR;
                            }
                            // TODO: Add outputs for valves.
                            valveIsland.Valves.Add(v);
                        }
                    }
                    ((Station)SelectedItem).Items.Add(valveIsland);
                }
                else
                {
                    MessageBox.Show("You can only add Valve Islands to a Station.", "Input Error",
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
コード例 #2
0
ファイル: ItemLib.cs プロジェクト: LarsGIF/PLCcodeGen
        void CreateLib()
        {
            LibItem curLI = root;
            LibItem newLI = new LibItem("ValveIslands", null, root);

            curLI.Children.Add(newLI);
            curLI = newLI;
            ValveIsland island = new ValveIsland("", "CPX");

            island.Components.Add(new Component());
            island.Components.Add(new Component());
            island.Components.Add(new Component());
            island.Components.Add(new Component());
            island.Components.Add(new Component());
            island.Components.Add(new Component());
            island.Components.Add(new Component());
            island.Components.Add(new Component());
            newLI = new LibItem("Festo CPX", island, curLI);
            curLI.Children.Add(newLI);
            this.root
        }