public bool GetDevicesByLoopForControllerType8000(ref Model.LoopModel loop) { List <DeviceInfo8000> lstDeviceInfo8000 = new List <DeviceInfo8000>(); string strDeviceQuerySQL = "select bianhao,leixing,geli,lingmd,shuchu1,shuchu2,shuchu3,yanshi,xianggh,zjczbh,GbZone,didian from "; strDeviceQuerySQL += loop.Code; DataTable dtDevices = _databaseService.GetDataTableBySQL(new StringBuilder(strDeviceQuerySQL)); int dtDevicesRowsCount = dtDevices.Rows.Count; for (int j = 0; j < dtDevicesRowsCount; j++) //器件信息 { DeviceInfo8000 device = new DeviceInfo8000(); device.Code = dtDevices.Rows[j]["bianhao"].ToString(); Int16?intTypeCode = dtDevices.Rows[j]["leixing"].ToString().Substring(0, 3).ToNullable <Int16>(); device.TypeCode = (short)intTypeCode; 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.LinkageGroup3 = dtDevices.Rows[j]["shuchu3"].ToString(); device.DelayValue = dtDevices.Rows[j]["yanshi"].ToString().ToNullable <Int16>(); device.sdpKey = dtDevices.Rows[j]["xianggh"].ToString(); device.ZoneNo = dtDevices.Rows[j]["zjczbh"].ToString().ToNullable <Int16>(); device.BroadcastZone = dtDevices.Rows[j]["GbZone"].ToString(); device.Location = dtDevices.Rows[j]["didian"].ToString(); device.Loop = loop; loop.SetDevice <DeviceInfo8000>(device); lstDeviceInfo8000.Add(device); } return(true); }
public EditableDeviceInfo8000(DeviceInfo8000 deviceInfo8000) { this.Loop = deviceInfo8000.Loop; this.LoopID = deviceInfo8000.LoopID; this.ID = deviceInfo8000.ID; this.Code = deviceInfo8000.Code; this.TypeCode = deviceInfo8000.TypeCode; this.SensitiveLevel = deviceInfo8000.SensitiveLevel; this.Feature = deviceInfo8000.Feature; this.Disable = deviceInfo8000.Disable; this.LinkageGroup1 = deviceInfo8000.LinkageGroup1; this.LinkageGroup2 = deviceInfo8000.LinkageGroup2; this.LinkageGroup3 = deviceInfo8000.LinkageGroup3; this.DelayValue = deviceInfo8000.DelayValue; this.sdpKey = deviceInfo8000.sdpKey; this.ZoneNo = deviceInfo8000.ZoneNo; this.BroadcastZone = deviceInfo8000.BroadcastZone; this.Location = deviceInfo8000.Location; }
public DeviceInfo8000 ToDeviceInfo8000() { DeviceInfo8000 deviceInfo8000 = new DeviceInfo8000(); deviceInfo8000.Loop = this.Loop; deviceInfo8000.LoopID = this.LoopID; deviceInfo8000.ID = this.ID; deviceInfo8000.Code = this.Code; deviceInfo8000.TypeCode = this.TypeCode; deviceInfo8000.SensitiveLevel = this.SensitiveLevel; deviceInfo8000.Feature = this.Feature; deviceInfo8000.Disable = this.Disable; deviceInfo8000.LinkageGroup1 = this.LinkageGroup1; deviceInfo8000.LinkageGroup2 = this.LinkageGroup2; deviceInfo8000.LinkageGroup3 = this.LinkageGroup3; deviceInfo8000.DelayValue = this.DelayValue; deviceInfo8000.sdpKey = this.sdpKey; deviceInfo8000.ZoneNo = this.ZoneNo; deviceInfo8000.BroadcastZone = this.BroadcastZone; deviceInfo8000.Location = this.Location; return(deviceInfo8000); }
public int AddDeviceForControllerType8000(DeviceInfo8000 deviceInfo) { throw new NotImplementedException(); }
/// <summary> /// 解析收到的器件数据包 /// </summary> /// <param name="standardLinkagePackage"></param> /// <returns></returns> private Model.DeviceInfo8000 ParsePackageCC(byte[] devicePackage) { ControllerModel cModel = new ControllerModel(2, "8000", ControllerType.FT8000, 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.DeviceAmount = tempDeviceAmount; DeviceInfo8000 deviceInfo = new DeviceInfo8000(); deviceInfo.Loop = loop; deviceInfo.LoopID = Convert.ToInt16(devicePackage[9]); //器件编码 deviceInfo.Code = Convert.ToInt16(devicePackage[10]).ToString(); //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); //设备类型 short tempType = Convert.ToInt16(devicePackage[12]); //根据设备类型的取值,决定是否需要特性字段信息 if (tempType > 36 && tempType < 66) { int tempSubType = Convert.ToInt16((devicePackage[11]) / 8); switch (tempSubType) { case 23: deviceInfo.Feature = 1; break; case 31: deviceInfo.Feature = 2; break; case 30: deviceInfo.Feature = 3; break; default: deviceInfo.Feature = 0; break; } } deviceInfo.TypeCode = tempType; //.ToString().PadLeft(3,'0'); int tempValue; //临时变量 //int tempValue2; //临时变量 tempValue = devicePackage[13] * 256 + devicePackage[14]; //tempValue2 = devicePackage[14];// *256 + devicePackage[14]; //联动组1 // deviceInfo.LinkageGroup1 = (tempValue1*256 +tempValue2).ToString().PadLeft(4, '0'); deviceInfo.LinkageGroup1 = tempValue == 0 ? "" : tempValue.ToString().PadLeft(4, '0'); tempValue = devicePackage[15] * 256 + devicePackage[16]; // tempValue2 = devicePackage[16]; //联动组2 deviceInfo.LinkageGroup2 = tempValue == 0 ? "" : tempValue.ToString().PadLeft(4, '0'); tempValue = devicePackage[17] * 256 + devicePackage[18]; //tempValue = devicePackage[17] * 256 + devicePackage[18]; //联动组3 deviceInfo.LinkageGroup3 = tempValue == 0 ? "" : tempValue.ToString().PadLeft(4, '0'); //延时 //yanshis = Format(m_arrInputData(nStartPos + 8), "00#") tempValue = devicePackage[19]; if (tempValue == 0) { deviceInfo.DelayValue = null; } else { deviceInfo.DelayValue = Convert.ToInt16(tempValue);//== 0 ? "" : tempValue.ToString().PadLeft(2, '0'); } //手操号 tempValue = devicePackage[20] * 256 + devicePackage[21]; deviceInfo.sdpKey = tempValue == 0 ? "" : tempValue.ToString().PadLeft(3, '0'); //区号 //.Fields("xianggh") = Format(nShouCao, "000#")-->此字段考虑字符型 tempValue = devicePackage[22] * 256 + devicePackage[23]; if (tempValue == 0) { deviceInfo.ZoneNo = null; } else { deviceInfo.ZoneNo = Convert.ToInt16(tempValue); } //广播分区 tempValue = devicePackage[24]; deviceInfo.BroadcastZone = tempValue.ToString() == "0" ? "" : tempValue.ToString().PadLeft(3, '0'); byte[] bLocation = new byte[18]; for (int i = 25; i < 43; i++) { bLocation[i - 25] = devicePackage[i]; } deviceInfo.Location = ascii.GetString(bLocation).Trim('\0'); return(deviceInfo); }
protected override List <LoopModel> ConvertToLoopModelFromDataTable(System.Data.DataTable dt, ControllerModel controller, out string loopDetailErrorInfo) { loopDetailErrorInfo = "";//Initialize //取得当前控制器最大器件ID int maxDeviceID = this.GetMaxDeviceID(); ControllerConfig8000 config = new ControllerConfig8000(); //暂停对具体信息进行验证 //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++; } DeviceInfo8000 device = new DeviceInfo8000(); 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(); device.LinkageGroup3 = dt.Rows[i]["输出组3"].ToString(); if (dt.Rows[i]["延时"].ToString() == "") { device.DelayValue = null; } else { device.DelayValue = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["延时"].ToString())); } device.sdpKey = dt.Rows[i]["手操号"].ToString(); if (dt.Rows[i]["区号"].ToString() == "") { device.ZoneNo = null; } else { device.ZoneNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["区号"].ToString())); } device.BroadcastZone = dt.Rows[i]["广播分区"].ToString(); device.Location = dt.Rows[i]["安装地点"].ToString(); if (loop != null) { device.Loop = loop; loop.SetDevice <DeviceInfo8000>(device); loop.DeviceAmount++; } } //更新最大器件ID ProjectManager.GetInstance.MaxDeviceIDInController8001 = maxDeviceID; return(lstLoops); }
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); }