예제 #1
0
        private static string GenGroupDeclareString(DeclareData item)
        {
            const string tabChar   = "\t";
            const string varGlobal = "VAR_GLOBAL";

            var result = string.Empty;

            if (IsWorks3)
            {
                result =
                    item.Prefix +
                    item.Group +
                    item.Postfix +
                    tabChar +
                    GenRealDataType(item.Type) +
                    tabChar +
                    varGlobal;
            }
            else
            {
                result =
                    varGlobal +
                    tabChar +
                    item.Prefix +
                    item.Group +
                    item.Postfix +
                    tabChar +
                    GenRealDataType(item.Type);
            }

            return(result);
        }
예제 #2
0
        private void Button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count < 1)
            {
                return;
            }

            var declareList = new List <DeclareData>();

            for (var i = 0; i < dataGridView1.Rows.Count; i++)
            {
                var item = new DeclareData
                {
                    Name = (string)(dataGridView1.Rows[i].Cells[0].Value)
                };

                if (string.IsNullOrEmpty(item.Name))
                {
                    continue;
                }

                item.Type  = (PlcVarType)Enum.Parse(typeof(PlcVarType), (string)(dataGridView1.Rows[i].Cells[1].Value));
                item.Group = (string)(dataGridView1.Rows[i].Cells[2].Value);

                declareList.Add(item);
            }

            _srcList = declareList;

            txtDeclare.Text = StGenerator.BuildDeclares(declareList).ToString();
            txtProg.Text    = StGenerator.BuildProgs(declareList).ToString();
        }
예제 #3
0
        private static DeclareData GenCyDeclare(DeclareData data)
        {
            var tmp = new DeclareData {
                Prefix = "cy", Type = data.Type
            };

            tmp.Name  = data.Name;
            tmp.Group = data.Group;
            return(tmp);
        }
예제 #4
0
        private static DeclareData GenControlDeclare(DeclareData data)
        {
            var tmp = new DeclareData {
                Prefix = "g", Type = PlcVarType.Bit
            };

            tmp.Name  = data.Name;
            tmp.Group = data.Group;
            return(tmp);
        }
예제 #5
0
        private static DeclareData GenOnDeclare(DeclareData data)
        {
            var tmp = new DeclareData
            {
                Prefix  = "w",
                Type    = PlcVarType.Word,
                Name    = data.Name,
                Group   = data.Group,
                Postfix = "OnT"
            };

            return(tmp);
        }
예제 #6
0
        private static DeclareData GenXActDeclare(DeclareData data)
        {
            var tmp = new DeclareData
            {
                Prefix  = "x",
                Type    = PlcVarType.Bit,
                Name    = data.Name,
                Group   = data.Group,
                Postfix = "Act"
            };

            return(tmp);
        }
예제 #7
0
        public static StringBuilder BuildGroupDeclares(List <string> datas)
        {
            _sb.Clear();

            DeclareData tmp = null;

            if (StructureFirst == false)
            {
                // uiSt1Cycle
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "ui", Postfix = "Cycle"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // St1Cycle
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Postfix = "Cycle"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // autoSt1Cycle
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "auto", Postfix = "Cycle"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // wSt1Index
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "w", Postfix = "Index", Type = PlcVarType.Word
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // wSt1LastIndex
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "w", Postfix = "LastIndex", Type = PlcVarType.Word
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // uiSt1Reset
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "ui", Postfix = "Reset"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // St1InOrg
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Postfix = "InOrg"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // St1CanGoNext
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Postfix = "CanGoNext"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // St1GoNext
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Postfix = "GoNext"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // St1GoNg
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Postfix = "GoNg"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }
            }
            else
            {
                // uiSt1Cycle
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "ui", Postfix = "Cycle"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // autoSt1Cycle
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "auto", Postfix = "Cycle"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // uiSt1Reset
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "ui", Postfix = "Reset"
                    };
                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }

                // dsStation
                foreach (var item in datas)
                {
                    tmp = new DeclareData {
                        Group = item, Prefix = "g", Postfix = ""
                    };
                    tmp.Type = PlcVarType.dsStation;

                    _sb.AppendLine(GenGroupDeclareString(tmp));
                }
            }
            return(_sb);
        }