Exemple #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;
            }
        }
Exemple #2
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);
     }
 }
        /// <summary>
        /// 映射模块到内存区域的某一个部分
        /// 信息记录在每个YZXBit上
        /// </summary>
        /// <param name="begin">起始</param>
        /// <param name="length">长度</param>
        /// <param name="unit">模块</param>
        public void Map(ushort begin, ushort length, YZXUnit unit)
        {
            for (ushort i = 0; i < length; i++)
            {
                YZXUshort us = this[begin + i];
                us.Unit = unit;
                us.UShortIndexInUnit = i;

                for (int j = 0; j < 16; j++)
                {
                    YZXBit b = us[j];
                    b.Unit = unit;
                    b.UShortIndexInUnit = i;
                    b.BitIndexInUnit    = j;
                }
            }
        }
Exemple #4
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;
        }
Exemple #5
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;
            }
        }