public LoopModel GetDevicesByLoop(LoopModel loop) { StringBuilder sbQuerySQL = new StringBuilder("select ID,Code,Disable,Feature,DelayValue,SensitiveLevel,BroadcastZone,LinkageGroup1,LinkageGroup2,LinkageGroup3,ZoneNo,Location,SDPKey,LoopID,TypeCode from DeviceInfo8000 where LoopID=" + loop.ID); System.Data.DataTable dt = _databaseService.GetDataTableBySQL(sbQuerySQL); for (int i = 0; i < dt.Rows.Count; i++) { Model.DeviceInfo8000 model = new Model.DeviceInfo8000(); model.ID = Convert.ToInt32(dt.Rows[i]["id"]); model.Code = dt.Rows[i]["Code"].ToString(); model.Disable = (bool?)dt.Rows[i]["Disable"]; model.Feature = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["Feature"])); model.DelayValue = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["DelayValue"])); model.SensitiveLevel = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["SensitiveLevel"])); model.BroadcastZone = dt.Rows[i]["SensitiveLevel"].ToString(); model.LinkageGroup1 = dt.Rows[i]["LinkageGroup1"].ToString(); model.LinkageGroup2 = dt.Rows[i]["LinkageGroup2"].ToString(); model.LinkageGroup3 = dt.Rows[i]["LinkageGroup3"].ToString(); model.ZoneNo = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["ZoneNo"])); model.Location = dt.Rows[i]["Location"].ToString(); model.sdpKey = dt.Rows[i]["sdpKey"].ToString(); model.LoopID = Convert.ToInt32(dt.Rows[i]["LoopID"]); model.TypeCode = Convert.ToInt16(dt.Rows[i]["TypeCode"]); model.Loop = loop; model.LoopID = loop.ID; loop.SetDevice <DeviceInfo8000>(model); } return(loop); }
public override void ReceiveDeviceInfo() { byte[] receivedData = CurrentPackage; IEqualityComparer <Model.DeviceInfo8000> c = new DeviceCompare(); Model.DeviceInfo8000 deviceInfo = ParsePackageCC(receivedData); if (!DeviceInfoList.Contains(deviceInfo, c)) { DeviceInfoList.Add(deviceInfo); } }
/// <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.DeviceInfo8000 deviceInfo)//各控制器不同 { //List<byte[]> lstSendData = new List<byte[]>(); //foreach (Model.DeviceInfo8036 singleDevInfo in deviceInfo) //{ Model.DeviceInfo8000 singleDevInfo = deviceInfo; byte[] sendData = new byte[42]; sendData[0] = 0xAA; sendData[1] = 0x55; sendData[2] = 0xDA; sendData[3] = 0x00; //异或值校验 sendData[4] = 0x00; //累加和校验 //?? sendData[5] = 0x24; //数据长度 ?? 固定24? sendData[6] = 0xBB; //发送器件命令 //sendData[7] = Convert.ToByte(deviceInfo.Count); //器件总数 //sendData[7] = Convert.ToByte(0x2E); //器件总数 sendData[7] = Convert.ToByte(base.DownloadedDeviceInfoTotalAmountInCurrentLoop); //器件总数 sendData[8] = Convert.ToByte(singleDevInfo.Loop.Controller.MachineNumber); //控制器号 sendData[9] = Convert.ToByte(singleDevInfo.Loop.SimpleCode); //回路号 //回路的Code已经包含了机器号 2017-04-05 sendData[10] = Convert.ToByte(singleDevInfo.Code.Substring(singleDevInfo.Loop.Code.Length, 3)); //地编号 sendData[11] = Convert.ToByte(GetDevType(singleDevInfo.TypeCode, singleDevInfo.Feature) * 8 + (singleDevInfo.Disable == true?1:0) * 4 + (singleDevInfo.SensitiveLevel - 1)); //器件状态(灵敏度、屏蔽);NT8001还有特性;根据这些值转换为“器件内部编码” sendData[12] = Convert.ToByte(singleDevInfo.TypeCode); //设备类型 if (sendData[12] > 100) { sendData[12] = Convert.ToByte(Convert.ToInt16(sendData[12]) - 64); } sendData[13] = Convert.ToByte((Convert.ToInt16(singleDevInfo.LinkageGroup1.NullToZero()) / 256)); //输出组1高位 sendData[14] = Convert.ToByte((Convert.ToInt16(singleDevInfo.LinkageGroup1.NullToZero()) % 256)); //输出组1低位 sendData[15] = Convert.ToByte((Convert.ToInt16(singleDevInfo.LinkageGroup2.NullToZero()) / 256)); //输出组2 高位 sendData[16] = Convert.ToByte((Convert.ToInt16(singleDevInfo.LinkageGroup2.NullToZero()) % 256)); //输出组2 低位 sendData[17] = Convert.ToByte((Convert.ToInt16(singleDevInfo.LinkageGroup3.NullToZero()) / 256)); //输出组3 高位 sendData[18] = Convert.ToByte((Convert.ToInt16(singleDevInfo.LinkageGroup3.NullToZero()) % 256)); //输出组3 低位 sendData[19] = Convert.ToByte(singleDevInfo.DelayValue); //延时 //手操号 sendData[20] = Convert.ToByte((Convert.ToInt16(singleDevInfo.sdpKey.NullToZero()) / 256)); // 高位 sendData[21] = Convert.ToByte((Convert.ToInt16(singleDevInfo.sdpKey.NullToZero()) % 256)); // 低位 //分区 sendData[22] = Convert.ToByte(singleDevInfo.ZoneNo / 256); // 高位 sendData[23] = Convert.ToByte(singleDevInfo.ZoneNo % 256); // 低位 //广播分区 sendData[24] = Convert.ToByte(singleDevInfo.BroadcastZone.NullToZero()); //17~33为安装地点 //将地点信息逐字符取出,将每个字符转换为ANSI代码后,存入sendData数据中; int startIndex = 25; char[] charArrayLocation = singleDevInfo.Location.ToArray(); //采用Base64编码传递数据 System.Text.Encoding ascii = System.Text.Encoding.GetEncoding(54936); for (int j = 0; j < charArrayLocation.Length; j++) { 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 <= 41; j++) { sendData[j] = 0x00; } byte[] checkValue = base.m_ProtocolDriver.CheckValue(sendData, 6, 42); sendData[3] = checkValue[0]; sendData[4] = checkValue[1]; return(sendData); }