예제 #1
0
        /// <summary>
        /// 配置CPU模块
        /// </summary>
        public void ConfigCPUUnits(YZXCPUProject Project)
        {
            int statusL = YZXUDT.GetUDTLength(YZXUDTTypes.UnitStatus);

            UnitStatus = new YZXCPUMemory("UnitStatus", Project.Units.Count * statusL);
            Mermories["UnitStatus"] = UnitStatus;

            Units = new Dictionary <string, YZXUnit>();

            for (int i = 0; i < Project.Units.Count; i++)
            {
                System.Tuple <YZXUnitTypes, YZXUnit> tu = Project.Units[i];

                YZXUnit unit = tu.Item2;
                if (tu.Item1 == YZXUnitTypes.Snap7ClientDB)
                {
                    Snap7ClientDBUnit u = unit as Snap7ClientDBUnit;
                    u.Client.con();
                }
                unit.Init();

                YZXUnitStatus status = (YZXUnitStatus)
                                       UnitStatus.InitUDT(YZXUDTTypes.UnitStatus, this, (i * statusL).ToString());

                status.Unit = unit;

                unit.Status = status;

                Units[unit.Name] = unit;
            }
        }
예제 #2
0
 public void ConfigIronPythonTask(IronPythonTask ipytask)
 {
     foreach (KeyValuePair <string, YZXCPUMemory> m in Mermories)
     {
         string       name   = m.Key;
         YZXCPUMemory memory = m.Value;
         ipytask.Engine.Runtime.Globals.SetVariable(name, memory);
     }
 }
예제 #3
0
 public void ConfigUnitMemoryMaps(YZXCPUProject Project)
 {
     foreach (YZXUnitMemoryMap map in Project.Maps)
     {
         YZXUnit      unit   = Units[map.Unit];
         YZXCPUMemory memory = Mermories[map.Memory];
         ushort       begin  = map.Begin;
         ushort       length = map.Length;
         MapUnit(unit, memory, begin, length);
     }
 }
예제 #4
0
        public void Init()
        {
            InitPY();
            Mermories = new Dictionary <string, YZXCPUMemory>();

            UnitStatus = new YZXCPUMemory();

            Tasks  = new Dictionary <string, YZXTask>();
            Timers = new Dictionary <string, Timer>();

            //HMIs = new Dictionary<string, YZXHMIClient>();
        }
예제 #5
0
        /// <summary>
        /// 配置CPU内存区域
        /// </summary>
        public void ConfigCPUMermories(YZXCPUProject Project)
        {
            foreach (KeyValuePair <string, int> item in Project.Mermories)
            {
                Mermories[item.Key] = new YZXCPUMemory(item.Key, item.Value);
            }

            int statusL = YZXUDT.GetUDTLength(YZXUDTTypes.CPUStatus);

            CPUStatus = new YZXCPUMemory("CPUStatus", statusL);
            Mermories["CPUStatus"] = CPUStatus;
        }
예제 #6
0
        /// <summary>
        /// 映射模块到内存区域
        /// 同时添加读任务
        /// </summary>
        /// <param name="unit">模块</param>
        /// <param name="mermory">内存区域</param>
        /// <param name="begin">起始位置</param>
        /// <param name="end">结束位置</param>
        public void MapReadUnit(
            YZXUnit unit,
            YZXCPUMemory mermory,
            ushort begin,
            ushort length)
        {
            int end = begin + length - 1;

            mermory.Map(begin, length, unit);

            Action      init = (() => { });
            Func <bool> run  = (() =>
            {
                try
                {
                    //从模块内读取所有数据
                    List <bool> bits = unit.UpdateBits();

                    //将读取到的数据更新到内存区域
                    mermory.UpdateBits(begin, end, bits);

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    return(false);
                }
            });

            Action reset = (() => { });

            CSharpTask task = new CSharpTask(init, run, reset);

            task.Name = string.Format("{0}-[{1},{2}]-{3}",
                                      mermory.Name, begin, end, unit.Name);

            Tasks[task.Name] = task;
        }
예제 #7
0
        /// <summary>
        /// 按内存区域类型
        /// 映射模块到不同内存区域
        /// 同时添加读任务
        /// </summary>
        /// <param name="unit">模块</param>
        /// <param name="mermory">内存区域</param>
        /// <param name="begin">起始位置</param>
        /// <param name="end">结束位置</param>
        public void MapUnit(
            YZXUnit unit,
            YZXCPUMemory mermory,
            ushort begin,
            ushort length)
        {
            switch (mermory.MermoryType)
            {
            case MermoryType.Read:
                MapReadUnit(unit, mermory, begin, length);
                break;

            case MermoryType.Write:
                break;

            case MermoryType.S7VPLCInput:
                break;

            case MermoryType.S7VPLCOutput:
                break;
            }
        }
예제 #8
0
 public YZXByte(YZXCPUMemory m, int byteIndex)
 {
     Mermory   = m;
     ByteIndex = byteIndex;
 }
예제 #9
0
 public YZXUint(YZXCPUMemory m, int uintIndex)
 {
     Mermory   = m;
     UintIndex = uintIndex;
 }
예제 #10
0
 public UshortIndexer(YZXCPUMemory m)
 {
     Mermory = m;
 }
예제 #11
0
 public YZXBit(YZXCPUMemory m, bool bit = false)
 {
     Mermory   = m;
     Value     = bit;
     Writeable = true;//默认可写
 }
예제 #12
0
 public void ConfigS7VPLCOutput()
 {
     S7VPLCOut = new YZXCPUMemory("S7VPLCOut", S7VPLC_PIO_Size);
     Mermories["S7VPLCOut"] = S7VPLCOut;
 }
예제 #13
0
 public void ConfigS7VPLCInput()
 {
     S7VPLCIn = new YZXCPUMemory("S7VPLCIn", S7VPLC_PIO_Size);
     Mermories["S7VPLCIn"] = S7VPLCIn;
 }
예제 #14
0
 public YZXUshort(YZXCPUMemory m, ushort ushortIndex)
 {
     Mermory     = m;
     UshortIndex = ushortIndex;
     Writeable   = true;//默认可写
 }
예제 #15
0
 public UintIndexer(YZXCPUMemory m)
 {
     Mermory = m;
 }
예제 #16
0
 public ByteIndexer(YZXCPUMemory m)
 {
     Mermory = m;
 }