Ejemplo n.º 1
0
        static private void Read(ModbusTableViewModel mtvmodel)
        {
            int sz = ReadE16();

            sz += eid;
            while (eid < sz)
            {
                int mid = (int)edata[eid++];
                ModbusTableModel mtmodel = new ModbusTableModel();
                mtmodel.Name = ReadTextE8();
                if ((option & OPTION_COMMENT) != 0)
                {
                    mtmodel.Comment = ReadTextE8();
                }
            }
        }
Ejemplo n.º 2
0
        public bool Open(XElement rootNode)
        {
            ProjectName = rootNode.Attribute("Name").Value;
            PLCDeviceManager.GetPLCDeviceManager().SetSelectDeviceType((PLCDeviceType)Enum.Parse(typeof(PLCDeviceType), rootNode.Attribute("DeviceType").Value));
            SubRoutines.Clear();
            FuncBlocks.Clear();
            ValueAliasManager.Clear();
            ValueCommentManager.Clear();
            InstructionCommentManager.Clear();
            ProjectHelper.LoadValueCommentsByXElement(rootNode.Element("ValueComments"));
            ProjectHelper.LoadValueAliasByXElement(rootNode.Element("ValueAlias"));
            ProjectPropertyManager.LoadProjectPropertyByXElement(rootNode.Element("ProjectPropertyParams"));
            MMonitorManager.MMWindow.LoadTablesByXElement(rootNode.Element("Tables"));
            EleInitializeData = rootNode.Element("EleInitialize");
            var ldnodes = rootNode.Elements("Ladder");

            foreach (XElement ldnode in ldnodes)
            {
                var ldmodel = ProjectHelper.CreateLadderDiagramByXElement(ldnode, this);
                if (ldmodel.IsMainLadder)
                {
                    MainRoutine = ldmodel;
                }
                else
                {
                    SubRoutines.Add(ldmodel);
                    TreeViewItem item = new TreeViewItem();
                    item.Header = ldmodel;
                }
            }
            // Open FunctionBlock
            var fbnodes = rootNode.Elements("FuncBlock");

            foreach (XElement fbnode in fbnodes)
            {
                var fbmodel = ProjectHelper.CreateFuncBlockByXElement(fbnode, this);
                FuncBlocks.Add(fbmodel);
            }
            var mtnodes = rootNode.Element("Modbus");
            var mtmodel = new ModbusTableViewModel(this);

            mtmodel.Load(mtnodes);
            MTVModel = mtmodel;
            return(true);
        }
Ejemplo n.º 3
0
        public ProjectModel(string projectname)
        {
            ProjectName = projectname;
            MainRoutine = new LadderDiagramViewModel("Main", this);
            MainRoutine.IsMainLadder = true;
            MMonitorManager          = new MonitorManager(this);
            MTVModel = new ModbusTableViewModel(this);
            MMonitorManager.MMWindow.Manager = MMonitorManager;
            PManager = new SerialPortManager();
            UManager = new USBManager();
            StreamReader sr = new StreamReader(
                String.Format(@"{0:s}\simug\simuflib.c", FileHelper.AppRootPath));
            FuncBlockViewModel libfuncblock = new FuncBlockViewModel(Properties.Resources.Library_Function, this);

            libfuncblock.Code       = sr.ReadToEnd();
            libfuncblock.IsReadOnly = true;
            LibFuncBlock            = libfuncblock;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 写入Modbus表格
        /// </summary>
        /// <param name="mtvmodel">Modbus表格</param>
        /// <param name="option">选项</param>
        static private void Write(ModbusTableViewModel mtvmodel, int option)
        {
            // 名称和注释信息写入压缩数据
            edata.Add(0xfb);
            int szid = edata.Count();

            edata.Add(0x00);
            edata.Add(0x00);
            byte mtid = 0;

            foreach (ModbusTableModel mtmodel in mtvmodel.Models)
            {
                edata.Add(mtid++);
                Write(mtmodel.Name);
                if ((option & OPTION_COMMENT) != 0)
                {
                    Write(mtmodel.Comment);
                }
            }
            int sz = edata.Count() - szid - 2;

            edata[szid] = Int32_Low(sz);
            edata[szid] = Int32_High(sz);
        }
Ejemplo n.º 5
0
        static private void Read(ProjectModel pmodel, IList <byte> _odata, IList <byte> _edata)
        {
            odata = _odata;
            oid   = 0;
            edata = _edata;
            eid   = 0;
            regs.Clear();
            try
            {
                option = edata[eid++];
                while (eid < edata.Count)
                {
                    int head = edata[eid++];
                    switch (head)
                    {
                    case 0xff:
                        LadderDiagramViewModel ldvmodel = new LadderDiagramViewModel(String.Empty, pmodel);
                        Read(ldvmodel);
                        if (ldvmodel.ProgramName.Equals("main"))
                        {
                            pmodel.MainRoutine = ldvmodel;
                        }
                        else
                        {
                            pmodel.Add(ldvmodel);
                        }
                        break;

                    case 0xfd:
                        FuncBlockViewModel fbvmodel = new FuncBlockViewModel(String.Empty, pmodel);
                        Read(fbvmodel);
                        pmodel.Add(fbvmodel);
                        break;

                    case 0xfc:
                        ReadRegisters();
                        break;

                    case 0xfb:
                        ModbusTableViewModel mtvmodel = new ModbusTableViewModel(pmodel);
                        Read(mtvmodel);
                        pmodel.MTVModel = mtvmodel;
                        break;

                    case 0xf9:
                        MainMonitor mmoni = new MainMonitor(pmodel);
                        Read(mmoni);
                        pmodel.MMonitorManager.MMWindow = mmoni;
                        break;

                    default:
                        throw new FormatException(
                                  String.Format("非法头标志符0x{0x2X}", head));
                    }
                }
                pmodel.MainRoutine = new LadderDiagramViewModel("main", pmodel);
            }
            catch (OutOfMemoryException)
            {
            }
            catch (FormatException)
            {
            }
        }