public LoopModel GetDevicesByLoop(LoopModel loop) { StringBuilder sbQuerySQL = new StringBuilder("select ID,Code ,Disable,LinkageGroup1,LinkageGroup2,AlertValue ,ForcastValue ,DelayValue ,BuildingNo ,ZoneNo ,FloorNo ,RoomNo ,Location ,LoopID,TypeCode from DeviceInfo8036 where LoopID=" + loop.ID); System.Data.DataTable dt = _databaseService.GetDataTableBySQL(sbQuerySQL); for (int i = 0; i < dt.Rows.Count; i++) { Model.DeviceInfo8036 model = new Model.DeviceInfo8036(); model.ID = Convert.ToInt16(dt.Rows[i]["id"]); model.Code = dt.Rows[i]["Code"].ToString(); model.Disable = Convert.ToInt16(dt.Rows[i]["Disable"]); model.LinkageGroup1 = dt.Rows[i]["LinkageGroup1"].ToString(); model.LinkageGroup2 = dt.Rows[i]["LinkageGroup2"].ToString(); model.AlertValue = Convert.ToSingle(dt.Rows[i]["AlertValue"]); model.ForcastValue = Convert.ToSingle(dt.Rows[i]["ForcastValue"]); model.DelayValue = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["DelayValue"])); model.BuildingNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["BuildingNo"])); model.ZoneNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["ZoneNo"])); model.FloorNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["FloorNo"])); model.RoomNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["RoomNo"])); model.Location = dt.Rows[i]["Location"].ToString(); model.LoopID = new Nullable <int>(Convert.ToInt32(dt.Rows[i]["LoopID"])); model.TypeCode = Convert.ToInt16(dt.Rows[i]["TypeCode"]); model.Loop = loop; model.LoopID = loop.ID; loop.SetDevice <DeviceInfo8036>(model); } return(loop); }
public override void ReceiveDeviceInfo() { byte[] receivedData = CurrentPackage; IEqualityComparer <Model.DeviceInfo8036> c = new DeviceCompare(); Model.DeviceInfo8036 deviceInfo = ParsePackageCC(receivedData); if (!DeviceInfoList.Contains(deviceInfo, c)) { DeviceInfoList.Add(deviceInfo); } }
//public byte[] AssemblePackage66() //{ // return base.AssemblePackage66(); //} //public byte[] AssemblePackageB9() //{ // return base.AssemblePackageB9(); //} /// <summary> /// /// </summary> /// <param name="deviceInfo"></param> /// <returns></returns> //public List<byte[]> AssemblePackageBB(List<Model.DeviceInfo8036 > deviceInfo)//各控制器不同 commented at 2017-04-05 public byte[] AssemblePackageBB(Model.DeviceInfo8036 deviceInfo) //各控制器不同 { //List<byte[]> lstSendData = new List<byte[]>(); //foreach (Model.DeviceInfo8036 singleDevInfo in deviceInfo) //{ Model.DeviceInfo8036 singleDevInfo = deviceInfo; byte[] sendData = new byte[43]; sendData[0] = 0xAA; sendData[1] = 0x55; sendData[2] = 0xDA; sendData[3] = 0x00; //异或值校验 sendData[4] = 0x00; //累加和校验 //?? sendData[5] = 0x25; //数据长度 ?? 暂定为01 ?? sendData[6] = 0xBB; //发送器件命令 //sendData[7] = Convert.ToByte(deviceInfo.Count); //器件总数 sendData[7] = Convert.ToByte(0x2E); //器件总数 sendData[8] = Convert.ToByte(singleDevInfo.Loop.Controller.MachineNumber); //控制器号 sendData[9] = Convert.ToByte(singleDevInfo.Loop.SimpleCode); //回路号 //sendData[10] = Convert.ToByte(singleDevInfo.Code.Substring(singleDevInfo.Loop.Controller.MachineNumber.Length + singleDevInfo.Loop.Code.Length, 3)); //地编号 //回路的Code已经包含了机器号 2017-04-05 sendData[10] = Convert.ToByte(singleDevInfo.Code.Substring(singleDevInfo.Loop.Code.Length, 3)); //地编号 sendData[11] = Convert.ToByte(GetDevType(singleDevInfo.TypeCode) * 8 + singleDevInfo.Disable * 4); //器件状态(灵敏度、屏蔽);NT8001还有特性;根据这些值转换为“器件内部编码” //GetDevType(CInt(leixing)) * 8 + geli * 4 sendData[12] = Convert.ToByte(singleDevInfo.TypeCode); //设备类型 // dsent(12) = Left(Trim(.Text), 3) ' 设备类型 if (sendData[12] > 100) { sendData[12] = Convert.ToByte(Convert.ToInt16(sendData[12]) - 64); } sendData[13] = Convert.ToByte(singleDevInfo.LinkageGroup1.NullToZero()); //输出组1 sendData[14] = Convert.ToByte(singleDevInfo.LinkageGroup2.NullToZero()); //输出组2 sendData[15] = Convert.ToByte(singleDevInfo.DelayValue); //延时 sendData[16] = 0x00; //防火分区,固定值00 //17~33为安装地点 //将地点信息逐字符取出,将每个字符转换为ANSI代码后,存入sendData数据中; //Convert.ToBase64String(); int startIndex = 17; char[] charArrayLocation = singleDevInfo.Location.ToArray(); //采用Base64编码传递数据 System.Text.Encoding ascii = System.Text.Encoding.GetEncoding(54936); for (int j = 0; j < charArrayLocation.Length; j++) { //sendData[startIndex]=Convert.ToByte(Convert.ToBase64String(System.Text.Encoding.GetEncoding(54936).GetBytes(charArrayLocation[j].ToString()))); Byte[] encodedBytes = ascii.GetBytes(charArrayLocation[j].ToString()); if (encodedBytes.Length == 1) { sendData[startIndex] = encodedBytes[0]; startIndex++; } else { sendData[startIndex] = encodedBytes[0]; startIndex++; sendData[startIndex] = encodedBytes[1]; startIndex++; } } //补足位数 for (int j = startIndex; j < 34; j++) { sendData[j] = 0x00; } #region 地址转换参考代码 // sendData[17]=0x; // n = 17 //For j = 1 To lenc // ascchina = Asc(Mid(sstrchina, j, 1)) // If ascchina >= 0 And ascchina < 128 Then // dsent(n) = ascchina // Else // getasc (Mid(sstrchina, j, 1)) // dsent(n) = m4 // n = n + 1 // dsent(n) = m1 // End If // n = n + 1 //Next j //For nn = n To 33 // dsent(nn) = 0 //Next nn #endregion sendData[34] = 0x00; //固定值00 //楼号 if (singleDevInfo.BuildingNo == null) { sendData[35] = 0x00; } else { sendData[35] = Convert.ToByte(singleDevInfo.BuildingNo); } //区号 if (singleDevInfo.ZoneNo == null) { sendData[36] = 0x00; } else { sendData[36] = Convert.ToByte(singleDevInfo.ZoneNo); } //层号 if (singleDevInfo.FloorNo == null) { sendData[37] = 0x00; } else { sendData[37] = Convert.ToByte(singleDevInfo.FloorNo); } //房间号 if (singleDevInfo.RoomNo == null) { sendData[38] = 0x00; } else { sendData[38] = Convert.ToByte(singleDevInfo.RoomNo); } float?alartValue = singleDevInfo.AlertValue; float?forcastValue = singleDevInfo.ForcastValue; if (alartValue == null) { alartValue = 0; } if (forcastValue == null) { forcastValue = 0; } int sendData39 = (int)(alartValue / 256); int sendData40 = (int)(alartValue % 256); int sendData41 = (int)(forcastValue / 256); int sendData42 = (int)(forcastValue % 256); sendData[39] = Convert.ToByte(sendData39); sendData[40] = Convert.ToByte(sendData40); sendData[41] = Convert.ToByte(sendData41); sendData[42] = Convert.ToByte(sendData42); //int intSumCheck=0; //for (int j = 6; j < 43; j++) //{ // sendData[3] = Convert.ToByte(sendData[3] ^ sendData[j]); // intSumCheck = intSumCheck + sendData[j]; //} //sendData[4] = Convert.ToByte(intSumCheck % 256); byte[] checkValue = base.m_ProtocolDriver.CheckValue(sendData, 6, 43); sendData[3] = checkValue[0]; sendData[4] = checkValue[1]; // lstSendData.Add(sendData); //} //return lstSendData; return(sendData); }