Beispiel #1
0
        public int CheckCircuit(TextBox report)
        {
            int ret = 0;

            _lgraph = _lchart.Generate();
            if (_lgraph.checkOpenCircuit())
            {
                report.Dispatcher.Invoke(new Execute(() => { report.Text += String.Format("{0:s} 的 {1:s} 出现断路错误!", _parent.Name, Name); }));
                ret += 1;
            }
            if (_lgraph.checkShortCircuit())
            {
                report.Dispatcher.Invoke(new Execute(() => { report.Text += String.Format("{0:s} 的 {1:s} 出现短路错误!", _parent.Name, Name); }));
                ret += 1;
            }
            if (ret > 0)
            {
                return(ret);
            }
            if (_lgraph.CheckFusionCircuit())
            {
                report.Dispatcher.Invoke(new Execute(() => { report.Text += String.Format("{0:s} 的 {1:s} 出现混联错误!", _parent.Name, Name); }));
                ret += 1;
            }
            return(ret);
        }
        public void Update()
        {
            int           rowid = 0;
            RowDefinition rdef;

            NetworkHeader.Text = String.Format("Network {0:d}", lnvmodel?.NetworkNumber);
            insts = new List <PLCOriginInst>();
            G_Inst.RowDefinitions.Clear();
            G_Inst.Children.Clear();
            rdef        = new RowDefinition();
            rdef.Height = new GridLength(20);
            TextBlock tberr = new TextBlock();

            tberr.Background = Brushes.Red;
            Grid.SetRow(tberr, 0);
            Grid.SetColumn(tberr, 0);
            Grid.SetColumnSpan(tberr, 6);
            G_Inst.RowDefinitions.Add(rdef);
            G_Inst.Children.Add(tberr);
            if (lnvmodel == null)
            {
                Status     = STATUS_ERROR;
                tberr.Text = App.CultureIsZH_CN()
                    ? "找不到 Network。"
                    : "Cannot found network.";
                return;
            }
            if (IsMasked)
            {
                tberr.Background = Brushes.Gray;
                tberr.Text       = String.Format(
                    App.CultureIsZH_CN() ? "Network {0:d} 已被屏蔽!" : "Network {0:d} has been masked!",
                    lnvmodel.NetworkNumber);
                return;
            }
            ismodified  = false;
            this.lchart = GenerateHelper.CreateLadderChart(lnvmodel.GetElements().Union(lnvmodel.GetVerticalLines()));
            if (lchart.checkOpenCircuit())
            {
                Status     = STATUS_OPEN;
                tberr.Text = String.Format(
                    App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在断路错误!" : "There have broken circuit in ladder of Network {0:d}.",
                    lnvmodel.NetworkNumber);
                return;
            }
            this.lgraph = lchart.Generate();
            if (lgraph.checkShortCircuit())
            {
                Status     = STATUS_SHORT;
                tberr.Text = String.Format(
                    App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在短路错误!" : "There have short circuit in ladder of Network {0:d}.",
                    lnvmodel.NetworkNumber);
                return;
            }
            if (lgraph.CheckFusionCircuit())
            {
                Status     = STATUS_FUSION;
                tberr.Text = String.Format(
                    App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在混连错误!" : "There have fusion circuit in ladder of Network {0:d}.",
                    lnvmodel.NetworkNumber);
                return;
            }
            Status = STATUS_ACCEPT;
            List <PLCInstruction> _insts       = lgraph.GenInst();
            SortedSet <int>       prototypeids = new SortedSet <int>();

            foreach (PLCInstruction inst in _insts)
            {
                insts.Add(inst.ToOrigin());
                if (inst.PrototypeID != -1)
                {
                    if (prototypeids.Contains(inst.PrototypeID))
                    {
                        Status     = STATUS_FUSION;
                        tberr.Text = String.Format(
                            App.CultureIsZH_CN() ? "Network {0:d} 的梯形图存在混连错误!" : "There have fusion circuit in ladder of Network {0:d}.",
                            lnvmodel.NetworkNumber);
                        return;
                    }
                    prototypeids.Add(inst.PrototypeID);
                }
            }
            G_Inst.RowDefinitions.Clear();
            G_Inst.Children.Clear();
            foreach (PLCOriginInst inst in insts)
            {
                rdef        = new RowDefinition();
                rdef.Height = new GridLength(20);
                G_Inst.RowDefinitions.Add(rdef);
                TextBlock tb = new TextBlock();
                tb.Text       = rowid.ToString();
                tb.Foreground = inst.ProtoType != null ? Brushes.Black : Brushes.Gray;
                tb.Background = (rowid & 1) == 0 ? Brushes.AliceBlue : Brushes.LightCyan;
                Grid.SetRow(tb, rowid);
                Grid.SetColumn(tb, 0);
                G_Inst.Children.Add(tb);
                for (int colid = 1; colid <= 6; colid++)
                {
                    tb            = new TextBlock();
                    tb.Text       = inst[colid - 1];
                    tb.Foreground = inst.ProtoType != null ? Brushes.Black : Brushes.Gray;
                    tb.Background = (rowid & 1) == 0 ? Brushes.AliceBlue : Brushes.LightCyan;
                    Grid.SetRow(tb, rowid);
                    Grid.SetColumn(tb, colid);
                    G_Inst.Children.Add(tb);
                }
                rowid++;
            }
            rdef        = new RowDefinition();
            rdef.Height = new GridLength(1, GridUnitType.Star);
            G_Inst.RowDefinitions.Add(rdef);
            G_Inst.Children.Add(Cursor);
            UpdateComment();
        }