/// <summary> /// /// </summary> /// <param name="mmoni"></param> /// <param name="option"></param> static private void Write(MainMonitor mmoni, int option) { edata.Add(0xf9); int szid = edata.Count(); edata.Add(0x00); edata.Add(0x00); foreach (MonitorVariableTable mvtable in mmoni.tables) { Write(mvtable.TableName); edata.Add(Int32_Low(mvtable.Elements.Count())); foreach (ElementModel emodel in mvtable.Elements) { string vname = emodel.ShowName; if (regids.ContainsKey(vname)) { int id = regids[vname]; edata.Add(Int32_Low(id)); edata.Add(Int32_High(id)); } else { edata.Add(0x00); edata.Add(0x00); } } } int sz = edata.Count() - szid - 2; edata[szid] = Int32_Low(sz); edata[szid + 1] = Int32_High(sz); }
static private void Read(MainMonitor mmoni) { int sz = ReadE16(); sz += eid; while (eid < sz) { string name = ReadTextE8(); MonitorVariableTable mvtable = new MonitorVariableTable(name, mmoni); int count = (int)edata[eid++]; while (count-- > 0) { int regid = ReadE16(); IValueModel ivmodel = regs[regid]; ElementModel emodel = new ElementModel(); emodel.IsIntrasegment = ivmodel.IsVariable; if (ivmodel is BitValue) { emodel.ShowType = "BOOL"; } if (ivmodel is WordValue) { emodel.ShowType = "WORD"; } if (ivmodel is DoubleWordValue) { emodel.ShowType = "DWORD"; } if (ivmodel is FloatValue) { emodel.ShowType = "FLOAT"; } emodel.ShowName = ivmodel.ValueString; mvtable.AddElement(emodel); } } }
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) { } }