コード例 #1
0
        public bool GetDevicesByLoopForControllerType8021(ref LoopModel loop)
        {
            List <DeviceInfo8021> lstDeviceInfo8021 = new List <DeviceInfo8021>();
            string strDeviceQuerySQL = "select bianhao,leixing,geli,didian,louhao,quhao,cenghao,fangjianhao,dlbaojing,wdbaojing from ";

            strDeviceQuerySQL += loop.Code;
            DataTable dtDevices          = _databaseService.GetDataTableBySQL(new StringBuilder(strDeviceQuerySQL));
            int       dtDevicesRowsCount = dtDevices.Rows.Count;

            for (int j = 0; j < dtDevicesRowsCount; j++) //器件信息
            {
                DeviceInfo8021 device = new DeviceInfo8021();
                device.Code    = dtDevices.Rows[j]["bianhao"].ToString();
                device.Disable = dtDevices.Rows[j]["geli"].ToString().ToNullable <bool>();
                Int16?intTypeCode = dtDevices.Rows[j]["leixing"].ToString().Substring(0, 3).ToNullable <Int16>();
                device.TypeCode             = (short)intTypeCode;
                device.Location             = dtDevices.Rows[j]["didian"].ToString();
                device.BuildingNo           = dtDevices.Rows[j]["louhao"].ToString().ToNullable <Int16>();
                device.ZoneNo               = dtDevices.Rows[j]["quhao"].ToString().ToNullable <Int16>();
                device.FloorNo              = dtDevices.Rows[j]["cenghao"].ToString().ToNullable <Int16>();
                device.RoomNo               = dtDevices.Rows[j]["fangjianhao"].ToString().ToNullable <Int16>();
                device.CurrentThreshold     = dtDevices.Rows[j]["dlbaojing"].ToString().ToNullable <float>();
                device.TemperatureThreshold = dtDevices.Rows[j]["wdbaojing"].ToString().ToNullable <float>();
                device.Loop = loop;
                loop.SetDevice <DeviceInfo8021>(device);
                lstDeviceInfo8021.Add(device);
            }
            return(true);
        }
コード例 #2
0
 public EditableDeviceInfo8021(DeviceInfo8021 deviceInfo8021)
 {
     this.Loop   = deviceInfo8021.Loop;
     this.LoopID = deviceInfo8021.LoopID;
     this.ID     = deviceInfo8021.ID;
     this.Code   = deviceInfo8021.Code;
     //     this.SimpleCode = deviceInfo8021.SimpleCode;
     this.TypeCode             = deviceInfo8021.TypeCode;
     this.Disable              = deviceInfo8021.Disable;
     this.CurrentThreshold     = deviceInfo8021.CurrentThreshold;
     this.TemperatureThreshold = deviceInfo8021.TemperatureThreshold;
     this.BuildingNo           = deviceInfo8021.BuildingNo;
     this.ZoneNo   = deviceInfo8021.ZoneNo;
     this.FloorNo  = deviceInfo8021.FloorNo;
     this.RoomNo   = deviceInfo8021.RoomNo;
     this.Location = deviceInfo8021.Location;
 }
コード例 #3
0
        public DeviceInfo8021 ToDeviceInfo8021()
        {
            DeviceInfo8021 deviceInfo8021 = new DeviceInfo8021();

            deviceInfo8021.Loop   = this.Loop;
            deviceInfo8021.LoopID = this.LoopID;
            deviceInfo8021.ID     = this.ID;
            deviceInfo8021.Code   = this.Code;
            //  deviceInfo8021.SimpleCode = this.SimpleCode;
            deviceInfo8021.TypeCode             = this.TypeCode;
            deviceInfo8021.Disable              = this.Disable;
            deviceInfo8021.CurrentThreshold     = this.CurrentThreshold;
            deviceInfo8021.TemperatureThreshold = this.TemperatureThreshold;
            deviceInfo8021.BuildingNo           = this.BuildingNo;
            deviceInfo8021.ZoneNo   = this.ZoneNo;
            deviceInfo8021.FloorNo  = this.FloorNo;
            deviceInfo8021.RoomNo   = this.RoomNo;
            deviceInfo8021.Location = this.Location;
            return(deviceInfo8021);
        }
コード例 #4
0
        /// <summary>
        /// 解析收到的器件数据包
        /// </summary>
        /// <param name="standardLinkagePackage"></param>
        /// <returns></returns>
        private Model.DeviceInfo8021 ParsePackageCC(byte[] devicePackage)
        {
            ControllerModel cModel = new ControllerModel(2, "8021", ControllerType.NT8021, 3);

            cModel.MachineNumber = "00";
            //第7字节作为基址
            //采用GB18030编码
            System.Text.Encoding ascii = System.Text.Encoding.GetEncoding(54936);
            //器件总数
            int tempDeviceAmount = Convert.ToInt16(devicePackage[7]);

            //机号
            string tempMachineNo = Convert.ToInt16(devicePackage[8]).ToString();

            switch (base.ControllerModel.DeviceAddressLength)
            {
            case 7:
                tempMachineNo = tempMachineNo.PadLeft(2, '0');
                break;

            case 8:
                tempMachineNo = tempMachineNo.PadLeft(3, '0');
                break;

            default:    //默认7位,但此分支不应该走,此时应该知道编码位数
                tempMachineNo = tempMachineNo.PadLeft(2, '0');
                break;
            }
            cModel.MachineNumber = tempMachineNo;
            //#---------start
            //将“器件总数”及"回路号"存入系统设置表中-->机号+路号作为回路号
            //回路号作为"存储器件的表名": 表名的规则为“路号+编号"
            //
            //#----------end


            //回路信息
            Model.LoopModel loop = new LoopModel();
            loop.Code         = Convert.ToInt16(devicePackage[9]).ToString().PadLeft(2, '0');
            loop.DeviceAmount = tempDeviceAmount;
            loop.Controller   = cModel;
            DeviceInfo8021 deviceInfo = new DeviceInfo8021();

            deviceInfo.Loop = loop;
            //deviceInfo.Loop.Code =devicePackage[9].ToString();
            //器件编码
            deviceInfo.Code = tempMachineNo + loop.Code + Convert.ToInt16(devicePackage[10]).ToString().PadLeft(3, '0');

            //deviceInfo.MachineNo = tempMachineNo;
            //.Fields("geli") = CStr((m_arrInputData(nStartPos + 4) Mod 8) \ 4)

            //.Fields("lingmd") = CStr(m_arrInputData(nStartPos + 4) Mod 4 + 1)
            //屏蔽
            deviceInfo.Disable = Convert.ToInt16((devicePackage[11] % 8) / 4) == 1?true:false;
            //灵敏度
            //deviceInfo.SensitiveLevel = Convert.ToInt16((devicePackage[11] % 4) + 1);

            //第12位无用???

            //设备类型
            short tempType = Convert.ToInt16(devicePackage[13]);

            deviceInfo.TypeCode = tempType;//.ToString().PadLeft(3,'0');

            //电流预警值 .Fields("DLbaojing") = Format(DLbj, "000#")
            float?tempValue; //临时变量

            tempValue = devicePackage[14] * 256 + devicePackage[15];
            deviceInfo.CurrentThreshold = tempValue == 0?null:tempValue;

            //温度预警值
            tempValue = devicePackage[16];
            deviceInfo.TemperatureThreshold = tempValue == 0 ? null : tempValue;


            byte[] bLocation = new byte[25];

            for (int i = 17; i < 42; i++)
            {
                bLocation[i - 17] = devicePackage[i];
            }

            deviceInfo.Location = ascii.GetString(bLocation).Trim('\0');

            if (devicePackage[43] == 0)
            {
                deviceInfo.BuildingNo = null;
            }
            else
            {
                deviceInfo.BuildingNo = devicePackage[43];
            }
            if (devicePackage[44] == 0)
            {
                deviceInfo.ZoneNo = null;
            }
            else
            {
                deviceInfo.ZoneNo = devicePackage[44];
            }
            if (devicePackage[45] == 0)
            {
                deviceInfo.FloorNo = null;
            }
            else
            {
                deviceInfo.FloorNo = devicePackage[45];
            }
            if (devicePackage[46] == 0)
            {
                deviceInfo.RoomNo = null;
            }
            else
            {
                deviceInfo.RoomNo = devicePackage[46];
            }



            return(deviceInfo);
        }
コード例 #5
0
 public int AddDeviceForControllerType8021(DeviceInfo8021 deviceInfo)
 {
     throw new NotImplementedException();
 }
コード例 #6
0
        private bool GenerateDeviceID(ControllerType controllerType, ref LoopModel loop)
        {
            bool resultFlag = false;

            try
            {
                switch (controllerType)
                {
                case ControllerType.NT8001:
                {
                    int maxDeviceID = ProjectManager.GetInstance.MaxDeviceIDInController8001;
                    List <DeviceInfo8001> lstDeviceInfo = loop.GetDevices <DeviceInfo8001>();
                    for (int i = 0; i < lstDeviceInfo.Count; i++)
                    {
                        maxDeviceID++;
                        DeviceInfo8001 deviceInfo = lstDeviceInfo[i];
                        deviceInfo.ID    = maxDeviceID;
                        lstDeviceInfo[i] = deviceInfo;
                    }
                    ProjectManager.GetInstance.MaxDeviceIDInController8001 = maxDeviceID;
                }
                break;

                case ControllerType.NT8007:
                {
                    int maxDeviceID = ProjectManager.GetInstance.MaxDeviceIDInController8007;
                    List <DeviceInfo8007> lstDeviceInfo = loop.GetDevices <DeviceInfo8007>();
                    foreach (var device in lstDeviceInfo)
                    {
                        maxDeviceID++;
                        device.ID = maxDeviceID;
                    }
                    ProjectManager.GetInstance.MaxDeviceIDInController8007 = maxDeviceID;
                }
                break;

                case ControllerType.NT8021:
                {
                    int maxDeviceID = ProjectManager.GetInstance.MaxDeviceIDInController8021;
                    List <DeviceInfo8021> lstDeviceInfo = loop.GetDevices <DeviceInfo8021>();
                    for (int i = 0; i < lstDeviceInfo.Count; i++)
                    {
                        maxDeviceID++;
                        DeviceInfo8021 deviceInfo = lstDeviceInfo[i];
                        deviceInfo.ID    = maxDeviceID;
                        lstDeviceInfo[i] = deviceInfo;
                    }
                    ProjectManager.GetInstance.MaxDeviceIDInController8021 = maxDeviceID;
                }
                break;

                case ControllerType.NT8036:
                {
                    int maxDeviceID = ProjectManager.GetInstance.MaxDeviceIDInController8036;
                    List <DeviceInfo8036> lstDeviceInfo = loop.GetDevices <DeviceInfo8036>();
                    for (int i = 0; i < lstDeviceInfo.Count; i++)
                    {
                        maxDeviceID++;
                        DeviceInfo8036 deviceInfo = lstDeviceInfo[i];
                        deviceInfo.ID    = maxDeviceID;
                        lstDeviceInfo[i] = deviceInfo;
                    }
                    ProjectManager.GetInstance.MaxDeviceIDInController8036 = maxDeviceID;
                }
                break;

                case ControllerType.FT8000:
                {
                    int maxDeviceID = ProjectManager.GetInstance.MaxDeviceIDInController8000;
                    List <DeviceInfo8000> lstDeviceInfo = loop.GetDevices <DeviceInfo8000>();
                    for (int i = 0; i < lstDeviceInfo.Count; i++)
                    {
                        maxDeviceID++;
                        DeviceInfo8000 deviceInfo = lstDeviceInfo[i];
                        deviceInfo.ID    = maxDeviceID;
                        lstDeviceInfo[i] = deviceInfo;
                    }
                    ProjectManager.GetInstance.MaxDeviceIDInController8000 = maxDeviceID;
                }
                break;

                case ControllerType.FT8003:
                {
                    int maxDeviceID = ProjectManager.GetInstance.MaxDeviceIDInController8003;
                    List <DeviceInfo8003> lstDeviceInfo = loop.GetDevices <DeviceInfo8003>();
                    for (int i = 0; i < lstDeviceInfo.Count; i++)
                    {
                        maxDeviceID++;
                        DeviceInfo8003 deviceInfo = lstDeviceInfo[i];
                        deviceInfo.ID    = maxDeviceID;
                        lstDeviceInfo[i] = deviceInfo;
                    }
                    ProjectManager.GetInstance.MaxDeviceIDInController8003 = maxDeviceID;
                }
                break;
                }
                resultFlag = true;
            }
            catch
            {
            }
            return(resultFlag);
        }
コード例 #7
0
        protected override List <LoopModel> ConvertToLoopModelFromDataTable(System.Data.DataTable dt, ControllerModel controller, out string loopDetailErrorInfo)
        {
            loopDetailErrorInfo = "";//Initialize
            //取得当前控制器最大器件ID
            int maxDeviceID             = this.GetMaxDeviceID();
            ControllerConfig8021 config = new ControllerConfig8021();
            //暂停对具体信息进行验证
            //Dictionary<string, RuleAndErrorMessage> dictDeviceDataRule = config.GetDeviceInfoRegularExpression(controller.DeviceAddressLength);
            List <LoopModel> lstLoops = new List <LoopModel>();


            string    loopCode = "";
            LoopModel loop     = null;

            int[] loopIndexRange = ParseLoopSheetName(dt.TableName);//取得工作表内回路的起始编号
            int   loopsAmount    = loopIndexRange[1] - loopIndexRange[0] + 1;

            int[] loopIndex = new int[loopsAmount];
            for (int i = 0; i < loopsAmount; i++)
            {
                loopIndex[i] = loopIndexRange[0] + i;
            }
            int loopCount = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (loopCode != dt.Rows[i]["编码"].ToString().Substring(0, controller.DeviceAddressLength - 3))//器件编码为3位
                {
                    //新建回路
                    loopCode  = dt.Rows[i]["编码"].ToString().Substring(0, controller.DeviceAddressLength - 3);
                    loop      = new LoopModel();
                    loop.Code = loopCode;
                    loop.Name = loopCode;
                    lstLoops.Add(loop);
                    string machineNumberOfDevice = loop.Code.Substring(0, controller.DeviceAddressLength - 5);
                    bool   blnErrorFlag          = false;
                    if (controller.MachineNumber != machineNumberOfDevice)  //控制器机号验证
                    {
                        loopDetailErrorInfo += ";" + dt.TableName + "-器件(" + dt.Rows[i]["编码"].ToString() + ")机号(" + machineNumberOfDevice + ")与模板机号(" + controller.MachineNumber + ")不符";
                        blnErrorFlag         = true;
                    }
                    if (!blnErrorFlag)
                    {
                        if (loopIndex[loopCount].ToString().PadLeft(controller.LoopAddressLength, '0') != loop.Code.Substring(machineNumberOfDevice.Length)) //回路号验证
                        {
                            loopDetailErrorInfo += ";器件(" + dt.Rows[i]["编码"].ToString() + ")回路号(" + loop.Code.Substring(machineNumberOfDevice.Length) + ")与模板回路号(" + loopIndex[loopCount].ToString().PadLeft(controller.LoopAddressLength, '0') + ")不符";
                            blnErrorFlag         = true;
                        }
                    }
                    if (blnErrorFlag)  //机号或回路号不正确,停止处理,返回调用
                    {
                        return(null);
                    }
                    loopCount++;
                }
                DeviceInfo8021 device = new DeviceInfo8021();
                maxDeviceID++;
                device.ID       = maxDeviceID;
                device.Code     = dt.Rows[i]["编码"].ToString();
                device.TypeCode = config.GetDeviceCodeViaDeviceTypeName(dt.Rows[i]["器件类型"].ToString());
                device.Disable  = new Nullable <bool>(Convert.ToBoolean(dt.Rows[i]["屏蔽"].ToString() == "0" ? false : true));
                if (dt.Rows[i]["电流报警值"].ToString() == "")
                {
                    device.CurrentThreshold = null;
                }
                else
                {
                    device.CurrentThreshold = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["电流报警值"].ToString()));
                }
                if (dt.Rows[i]["温度报警值"].ToString() == "")
                {
                    device.TemperatureThreshold = null;
                }
                else
                {
                    device.TemperatureThreshold = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["温度报警值"].ToString()));
                }


                if (dt.Rows[i]["楼号"].ToString() == "")
                {
                    device.BuildingNo = null;
                }
                else
                {
                    device.BuildingNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["楼号"].ToString()));
                }
                if (dt.Rows[i]["区号"].ToString() == "")
                {
                    device.ZoneNo = null;
                }
                else
                {
                    device.ZoneNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["区号"].ToString()));
                }
                if (dt.Rows[i]["层号"].ToString() == "")
                {
                    device.FloorNo = null;
                }
                else
                {
                    device.FloorNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["层号"].ToString()));
                }
                if (dt.Rows[i]["房间号"].ToString() == "")
                {
                    device.RoomNo = null;
                }
                else
                {
                    device.RoomNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["房间号"].ToString()));
                }
                device.Location = dt.Rows[i]["安装地点"].ToString();
                if (loop != null)
                {
                    device.Loop = loop;
                    //在合适位置设置
                    //device.LoopID
                    loop.SetDevice <DeviceInfo8021>(device);
                    loop.DeviceAmount++;
                }
            }
            //更新最大器件ID
            ProjectManager.GetInstance.MaxDeviceIDInController8021 = maxDeviceID;
            return(lstLoops);
        }