Ejemplo n.º 1
0
 public static PointMeDataList GetInstance()
 {
     if (Instance == null)
     {
         lock (locker)
         {
             if (Instance == null)
             {
                 Instance = new PointMeDataList();
             }
         }
     }
     return(Instance);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据XML配置文件创建Modbus点表
        /// 并将点表绑定到通用点表(PointMapping)
        /// </summary>
        /// <param name="workBook"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public static PointVirtualCollcet CreateMoudbus(XMLWorkbook workBook, ILog log)
        {
            PointMeDataList mappingIdexList = PointMeDataList.GetInstance();
            var             result          = new PointVirtualCollcet();
            List <string>   colums          = workBook.llStrings[0];//第一行列表为索引列数据;

            workBook.llStrings.RemoveAt(0);
            foreach (var ls in workBook.llStrings)
            {
                string     addressName = "";
                int        address;
                string     pointName    = "";
                int        bindingIndex = 0;
                BindingWay bindingWay   = BindingWay.OneWay;

                ByteOrder byteOrder = ByteOrder.None;
                if (ls.Count < colums.Count)
                {
                    continue;
                }
                for (int i = 0; i < colums.Count; i++)
                {
                    switch (colums[i].ToLower())
                    {
                    case "addressname":
                        addressName = ls[i];
                        break;

                    case "pointname":
                        var pointGroup = ls[i].Split(new char[] { '[' });

                        if (pointGroup != null && pointGroup.Length >= 2)
                        {
                            pointName     = pointGroup[0];
                            pointGroup[1] = pointGroup[1].Replace("]", "");    //string类型处理,去掉‘]’
                            int.TryParse(pointGroup[1], out bindingIndex);
                        }
                        break;

                    case "bindingway":
                        int temp;
                        if (int.TryParse(ls[i], out temp))
                        {
                            bindingWay = (BindingWay)temp;
                        }
                        break;

                    case "byteorder":
                        int temp1;
                        if (int.TryParse(ls[i], out temp1))
                        {
                            byteOrder = (ByteOrder)temp1;
                        }
                        break;
                    }
                }
                string type;

                /*
                 * ===============================
                 * 1.根据地址名生成相应的Modbus点
                 * 2.根据配置表绑定到对应的主地址表
                 * 3.如果绑定成功则添加到list中
                 * 4。根据不同的绑定类型分为:只读,只写,可读可写
                 * ===============================
                 */

                if (addressName != "" && int.TryParse(addressName, out address) && pointName != "")
                {
                    if (addressName.Substring(0, 1) == "0" || addressName.Substring(0, 1) == "1")
                    {
                        if (mappingIdexList.Find(pointName, out type) && type == ds.ValueType.Bool)
                        {
                            VirtulPoint <bool> boolPoint = new VirtulPoint <bool>(addressName, type)
                            {
                            };
                            var sourcePoint = PointMapping <bool> .GetInstance(log).GetPoint(pointName);

                            if (PointsBinding.BoolBinding(sourcePoint, bindingIndex, boolPoint, bindingWay))
                            {
                                result.BoolPoints.Add(boolPoint);
                            }
                        }
                    }
                    if (addressName.Substring(0, 1) == "3" || addressName.Substring(0, 1) == "4")
                    {
                        if (mappingIdexList.Find(pointName, out type))
                        {
                            VirtulPoint <ushort> ushortPoint1 = new VirtulPoint <ushort>(addressName, ds.ValueType.UInt16);
                            VirtulPoint <ushort> ushortPoint2 = new VirtulPoint <ushort>((address + 1).ToString(), ds.ValueType.UInt16);

                            if (type == ds.ValueType.Byte)
                            {
                                var sourcePoint = PointMapping <byte> .GetInstance(log).GetPoint(pointName);

                                if (PointsBinding.UshortBinding(sourcePoint, bindingIndex, ushortPoint1, bindingWay))
                                {
                                    result.UshortPoints.Add(ushortPoint1);
                                }
                            }
                            if (type == ds.ValueType.Int16)
                            {
                                var sourcePoint = PointMapping <short> .GetInstance(log).GetPoint(pointName);

                                if (PointsBinding.UshortBinding(sourcePoint, bindingIndex, ushortPoint1, bindingWay))
                                {
                                    result.UshortPoints.Add(ushortPoint1);
                                }
                            }
                            if (type == ds.ValueType.UInt16)
                            {
                                var sourcePoint = PointMapping <ushort> .GetInstance(log).GetPoint(pointName);

                                if (PointsBinding.UshortBinding(sourcePoint, bindingIndex, ushortPoint1, bindingWay))
                                {
                                    result.UshortPoints.Add(ushortPoint1);
                                }
                            }
                            if (type == ds.ValueType.Int32)
                            {
                                var sourcePoint = PointMapping <int> .GetInstance(log).GetPoint(pointName);

                                if (PointsBinding.UshortBinding(sourcePoint, bindingIndex, new VirtulPoint <ushort>[] { ushortPoint1, ushortPoint2 }, byteOrder, bindingWay))
                                {
                                    result.UshortPoints.Add(ushortPoint1);
                                    result.UshortPoints.Add(ushortPoint2);
                                }
                            }
                            if (type == ds.ValueType.UInt32)
                            {
                                var sourcePoint = PointMapping <uint> .GetInstance(log).GetPoint(pointName);

                                if (PointsBinding.UshortBinding(sourcePoint, bindingIndex, new VirtulPoint <ushort>[] { ushortPoint1, ushortPoint2 }, byteOrder, bindingWay))
                                {
                                    result.UshortPoints.Add(ushortPoint1);
                                    result.UshortPoints.Add(ushortPoint2);
                                }
                            }
                            if (type == ds.ValueType.Float)
                            {
                                var sourcePoint = PointMapping <float> .GetInstance(log).GetPoint(pointName);

                                if (PointsBinding.UshortBinding(sourcePoint, bindingIndex, new VirtulPoint <ushort>[] { ushortPoint1, ushortPoint2 }, byteOrder, bindingWay))
                                {
                                    result.UshortPoints.Add(ushortPoint1);
                                    result.UshortPoints.Add(ushortPoint2);
                                }
                            }
                        }
                    }
                }
                else
                {
                    log.ErrorLog(string.Format("adderss error or binding point is null!"));
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
 private PointMapping(ILog log)
 {
     this._log  = log;
     _indexList = PointMeDataList.GetInstance();
 }