예제 #1
0
        public Model.LoopModel GetDevicesByLoop(Model.LoopModel loop)
        {
            StringBuilder sbQuerySQL = new StringBuilder("select ID,Code,Disable,Feature,DelayValue,SensitiveLevel,LinkageGroup1,LinkageGroup2,LinkageGroup3,sdpKey,BroadcastZone,ZoneNo,Location,LoopID,TypeCode from DeviceInfo8003 where LoopID=" + loop.ID);

            System.Data.DataTable dt = _databaseService.GetDataTableBySQL(sbQuerySQL);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Model.DeviceInfo8003 model = new Model.DeviceInfo8003();
                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.LinkageGroup1  = dt.Rows[i]["LinkageGroup1"].ToString();
                model.LinkageGroup2  = dt.Rows[i]["LinkageGroup2"].ToString();
                model.LinkageGroup3  = dt.Rows[i]["LinkageGroup3"].ToString();
                model.sdpKey         = Convert.ToInt32(dt.Rows[i]["sdpKey"]);
                model.BroadcastZone  = dt.Rows[i]["BroadcastZone"].ToString();
                model.ZoneNo         = new Nullable <short>(Convert.ToInt16(dt.Rows[i]["ZoneNo"]));
                model.Location       = dt.Rows[i]["Location"].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 <DeviceInfo8003>(model);
            }
            return(loop);
        }
예제 #2
0
        public override void ReceiveDeviceInfo()
        {
            byte[] receivedData = CurrentPackage;
            IEqualityComparer <Model.DeviceInfo8003> c = new DeviceCompare();

            Model.DeviceInfo8003 deviceInfo = ParsePackageCC(receivedData);
            if (!DeviceInfoList.Contains(deviceInfo, c))
            {
                DeviceInfoList.Add(deviceInfo);
                //更新已上传的器件数量
                base.UploadedDeviceInfoAccumulatedAmountInCurrentLoop++;
                base.UpdateProcessBarStatusForUploadedDevice();
            }
        }
예제 #3
0
        /// <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.DeviceInfo8003 deviceInfo)//各控制器不同
        {
            //List<byte[]> lstSendData = new List<byte[]>();
            //foreach (Model.DeviceInfo8036 singleDevInfo in deviceInfo)
            //{
            Model.DeviceInfo8003 singleDevInfo = deviceInfo;
            byte[] sendData = new byte[35];
            sendData[0] = 0xAA;
            sendData[1] = 0x55;
            sendData[2] = 0xDA;
            sendData[3] = 0x00;       //异或值校验
            sendData[4] = 0x00;       //累加和校验
            //??
            sendData[5] = 0x1D;       //数据长度 ?? 暂定为1D
                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);                       //回路号

            //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 == 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);
            }
            //   dsent(13) = shuchu1 Mod 256
            //dsent(14) = shuchu2 Mod 256
            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
            sendData[17] = 0x00;                                                     //固定值00
            sendData[18] = Convert.ToByte(singleDevInfo.ZoneNo);
            //17~33为安装地点
            //将地点信息逐字符取出,将每个字符转换为ANSI代码后,存入sendData数据中;
            int startIndex = 19;

            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;
            }
            byte[] checkValue = base.m_ProtocolDriver.CheckValue(sendData, 6, 34);
            sendData[3] = checkValue[0];
            sendData[4] = checkValue[1];
            return(sendData);
        }