public bool AddDeviceForControllerType8007(LoopModel loop) { List <DeviceInfo8007> lstDeviceInfo8007 = new List <DeviceInfo8007>(); string strDeviceQuerySQL = "select bianhao,leixing,texing,geli,lingmd,shuchu1,shuchu2,louhao,quhao,cenghao,fangjianhao,didian from "; strDeviceQuerySQL += loop.Code; DataTable dtDevices = _databaseService.GetDataTableBySQL(new StringBuilder(strDeviceQuerySQL)); int dtDevicesRowsCount = dtDevices.Rows.Count; for (int j = 0; j < dtDevicesRowsCount; j++) //器件信息 { DeviceInfo8007 device = new DeviceInfo8007(); device.Code = dtDevices.Rows[j]["bianhao"].ToString(); Int16?intTypeCode = dtDevices.Rows[j]["leixing"].ToString().Substring(0, 3).ToNullable <Int16>(); device.TypeCode = (short)intTypeCode; //device.Feature = dtDevices.Rows[j]["texing"].ToString(); device.Disable = dtDevices.Rows[j]["geli"].ToString().ToNullable <bool>(); device.SensitiveLevel = dtDevices.Rows[j]["lingmd"].ToString().ToNullable <Int16>(); device.LinkageGroup1 = dtDevices.Rows[j]["shuchu1"].ToString(); device.LinkageGroup2 = dtDevices.Rows[j]["shuchu2"].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.Location = dtDevices.Rows[j]["didian"].ToString(); device.Loop = loop; loop.SetDevice <DeviceInfo8007>(device); lstDeviceInfo8007.Add(device); } return(true); }
public EditableDeviceInfo8007(DeviceInfo8007 deviceInfo8007) { this.Loop = deviceInfo8007.Loop; this.LoopID = deviceInfo8007.LoopID; this.ID = deviceInfo8007.ID; this.Code = deviceInfo8007.Code; this.TypeCode = deviceInfo8007.TypeCode; this.SensitiveLevel = deviceInfo8007.SensitiveLevel; this.Feature = deviceInfo8007.Feature; this.Disable = deviceInfo8007.Disable; this.LinkageGroup1 = deviceInfo8007.LinkageGroup1; this.LinkageGroup2 = deviceInfo8007.LinkageGroup2; this.BuildingNo = deviceInfo8007.BuildingNo; this.ZoneNo = deviceInfo8007.ZoneNo; this.FloorNo = deviceInfo8007.FloorNo; this.RoomNo = deviceInfo8007.RoomNo; this.Location = deviceInfo8007.Location; }
public DeviceInfo8007 ToDeviceInfo8007() { DeviceInfo8007 deviceInfo8007 = new DeviceInfo8007(); deviceInfo8007.Loop = this.Loop; deviceInfo8007.LoopID = this.LoopID; deviceInfo8007.ID = this.ID; deviceInfo8007.Code = this.Code; deviceInfo8007.TypeCode = this.TypeCode; deviceInfo8007.Disable = this.Disable; deviceInfo8007.LinkageGroup1 = this.LinkageGroup1; deviceInfo8007.LinkageGroup2 = this.LinkageGroup2; deviceInfo8007.Feature = this.Feature; deviceInfo8007.SensitiveLevel = this.SensitiveLevel; deviceInfo8007.BuildingNo = this.BuildingNo; deviceInfo8007.ZoneNo = this.ZoneNo; deviceInfo8007.FloorNo = this.FloorNo; deviceInfo8007.RoomNo = this.RoomNo; deviceInfo8007.Location = this.Location; return(deviceInfo8007); }
public int AddDeviceForControllerType8007(DeviceInfo8007 deviceInfo) { throw new NotImplementedException(); }
protected override List <LoopModel> ConvertToLoopModelFromDataTable(System.Data.DataTable dt, ControllerModel controller, out string loopDetailErrorInfo) { loopDetailErrorInfo = "";//Initialize //取得当前控制器最大器件ID int maxDeviceID = this.GetMaxDeviceID(); ControllerConfig8007 config = new ControllerConfig8007(); //暂停对具体信息进行验证 //Dictionary<string, RuleAndErrorMessage> dictDeviceDataRule = config.GetDeviceInfoRegularExpression(controller.DeviceAddressLength); List <LoopModel> lstLoops = new List <LoopModel>(); string loopCode = ""; LoopModel loop = null; int[] loopIndexRange = base.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++; } DeviceInfo8007 device = new DeviceInfo8007(); maxDeviceID++; device.ID = maxDeviceID; device.Code = dt.Rows[i]["编码"].ToString(); device.TypeCode = config.GetDeviceCodeViaDeviceTypeName(dt.Rows[i]["器件类型"].ToString()); if (dt.Rows[i]["特性"].ToString() == "") { device.Feature = null; } else { device.Feature = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["特性"].ToString())); } device.Disable = new Nullable <bool>(Convert.ToBoolean(dt.Rows[i]["屏蔽"].ToString() == "0" ? false : true)); if (dt.Rows[i]["灵敏度"].ToString() == "") { device.SensitiveLevel = null; } else { device.SensitiveLevel = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["灵敏度"].ToString())); } device.LinkageGroup1 = dt.Rows[i]["输出组1"].ToString(); device.LinkageGroup2 = dt.Rows[i]["输出组2"].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 <DeviceInfo8007>(device); loop.DeviceAmount++; } } //更新最大器件ID ProjectManager.GetInstance.MaxDeviceIDInController8007 = maxDeviceID; return(lstLoops); }
/// <summary> /// 解析收到的器件数据包 /// </summary> /// <param name="standardLinkagePackage"></param> /// <returns></returns> private Model.DeviceInfo8007 ParsePackageCC(byte[] devicePackage) { ControllerModel cModel = new ControllerModel(2, "8007", ControllerType.NT8007, 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(); loop.Code = Convert.ToInt16(devicePackage[9]).ToString().PadLeft(2, '0'); loop.DeviceAmount = tempDeviceAmount; loop.Controller = cModel; //** 设置回路中器件总数,用于更新进度状态 2017-04-28 base.UploadedDeviceInfoTotalAmountInCurrentLoop = tempDeviceAmount; DeviceInfo8007 deviceInfo = new DeviceInfo8007(); deviceInfo.Loop = loop; //deviceInfo.LoopID = Convert.ToInt16(devicePackage[9]); deviceInfo.Code = tempMachineNo + loop.Code + Convert.ToInt16(devicePackage[10]).ToString().PadLeft(3, '0'); //器件编码 //deviceInfo.Code = Convert.ToInt16(devicePackage[10]).ToString(); //屏蔽 deviceInfo.Disable = ((devicePackage[11] % 8) / 4) == 1?true:false; //灵敏度 deviceInfo.SensitiveLevel = Convert.ToInt16((devicePackage[11] % 4) + 1); //设备类型 short tempType = Convert.ToInt16(devicePackage[12]); deviceInfo.TypeCode = tempType; int tempValue;//临时变量 tempValue = devicePackage[13]; //联动组1 deviceInfo.LinkageGroup1 = tempValue == 0 ? "" : tempValue.ToString().PadLeft(3, '0'); tempValue = devicePackage[14]; //* 256 + devicePackage[16]; //联动组2 deviceInfo.LinkageGroup2 = tempValue == 0 ? "" : tempValue.ToString().PadLeft(3, '0'); //tempValue = devicePackage[17] * 256 + devicePackage[18]; ////联动组3 //deviceInfo.LinkageGroup3 = tempValue == 0 ? "" : tempValue.ToString().PadLeft(4, '0'); //第15及16字节为空 tempValue = devicePackage[15]; // deviceInfo.DelayValue = Convert.ToInt16(tempValue);//== 0 ? "" : tempValue.ToString().PadLeft(2, '0'); //好像是16个字节,需确认字符长度是否正确 byte[] bLocation = new byte[17]; for (int i = 17; i < 34; i++) { bLocation[i - 17] = devicePackage[i]; } deviceInfo.Location = ascii.GetString(bLocation).Trim('\0'); //deviceInfo.BuildingNo = devicePackage[35]; //deviceInfo.ZoneNo = devicePackage[36]; //deviceInfo.FloorNo = devicePackage[37]; //deviceInfo.RoomNo = devicePackage[38]; if (devicePackage[35] == 0) { deviceInfo.BuildingNo = null; } else { deviceInfo.BuildingNo = devicePackage[35]; } if (devicePackage[36] == 0) { deviceInfo.ZoneNo = null; } else { deviceInfo.ZoneNo = devicePackage[36]; } if (devicePackage[37] == 0) { deviceInfo.FloorNo = null; } else { deviceInfo.FloorNo = devicePackage[37]; } if (devicePackage[38] == 0) { deviceInfo.RoomNo = null; } else { deviceInfo.RoomNo = devicePackage[38]; } return(deviceInfo); }