Пример #1
0
        /// <summary>
        /// 从成功和失败的表中查询表
        /// 判断表的总结果是否为成功,表的测试状态为准备下发81命令
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            lock (obj3)
            {
                Myadapter_r = new DT_ResultTableAdapter();
                DataTable dt        = new DataTable();
                MeterInfo tempmeter = new MeterInfo();
                bool      f         = true;
                Thread.Sleep(1000);
                var info = requestInfo;
                dt = Myadapter_r.GetDataBy_r(info.EquipmentID, "合格", "初始", "失败");
                if (dt != null && dt.Rows.Count > 0)
                {
                    tempmeter = DataHelper.Dt2Ob(dt);
                }
                else
                {
                    f = false;
                }

                if (tempmeter != null && f)
                {
                    DateTime dtime = DateTime.Now;
                    tempmeter.MeterTime = dtime;
                    //成功的下发81修改网络参数,失败的不处理
                    if ((tempmeter.MeterState.Equals("合格") || tempmeter.MeterCancel.Equals("合格")) && tempmeter.MeterTest.Equals("准备"))
                    {
                        string ip              = CommonFunction.dicBooks["strJituanHostIP"];
                        string port            = CommonFunction.dicBooks["strJituanHostPort"];
                        string domain          = CommonFunction.dicBooks["strJituanHostDomain"];
                        string send81          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore81(ip, port, true, domain, tempmeter.MeterRand_num), info, false, true);
                        ArraySegment <byte> f2 = new ArraySegment <byte>(DataHelper.Str2Byte(send81));
                        session.Send(f2);
                        tempmeter.MeterTest = "就绪";
                        //更新测试状态和修改时间
                        Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                    }
                    else
                    {
                        LogHelper.Info("燃气表错误发送恢复出厂设置");
                    }
                }
                else
                {
                    LogHelper.Info("表不在检测列表中");
                }
            }
        }
Пример #2
0
 private void Cancel_Test_Load(object sender, EventArgs e)
 {
     Myadapter   = new Dt_MeterInfoTableAdapter();
     Myadapter_r = new DT_ResultTableAdapter();
     foreach (string key in CommonFunction.dic_cancel.Keys)
     {
         int index = DGV_CANCEL.Rows.Add();
         DGV_CANCEL.Rows[index].Cells[0].Value = key;
         DGV_CANCEL.Rows[index].Cells[1].Value = CommonFunction.dic_cancel[key];
         if (CommonFunction.dic_cancel[key].Equals("合格"))
         {
             DGV_CANCEL.Rows[index].Cells[1].Style.ForeColor = Color.Green;
         }
         else
         {
             DGV_CANCEL.Rows[index].Cells[1].Style.ForeColor = Color.Red;
         }
     }
     DGV_CANCEL.ClearSelection();
 }
Пример #3
0
        /// <summary>
        /// 取消测试的命令(若表没在测试怎么办,在ll哪处理吗)
        /// 将表的cancel字段改为是,将表的总状态改为失败。等到22命令的时候将表以失败移到meter_result中,可以发送8e命令,让其休眠。
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            string send = "00";

            Myadapter   = new Dt_MeterInfoTableAdapter();
            Myadapter_r = new DT_ResultTableAdapter();
            DataTable dt        = null;
            MeterInfo tempmeter = null;
            var       info      = requestInfo;
            int       id        = Convert.ToInt32(info.Data.Substring(2, 2), 16);
            string    ip        = DataHelper.Str2IP(info.Data.Substring(4, 8));
            string    port      = Convert.ToInt32(info.Data.Substring(12, 4), 16).ToString();
            string    type      = info.Data.Substring(16, 2);
            string    meterid   = info.Data.Substring(18, 12);

            try
            {
                dt        = Myadapter.GetDataBy1(meterid);
                tempmeter = DataHelper.Dt2Ob(dt);
            }
            catch (Exception e)
            {
                send = "55";
                LogHelper.Error("77命令:" + e);
            }
            if (tempmeter != null)
            {
                string[] re = tempmeter.Meteriport.Split('@');
                tempmeter.MeterCancel = "是";
                tempmeter.MeterState  = "失败";
                try
                {
                    Myadapter_r.InsertMeter(
                        tempmeter.MeterId,
                        tempmeter.MeterType,
                        tempmeter.MeterComState,
                        tempmeter.MeterIcState,
                        tempmeter.MeterChuState,
                        tempmeter.MeterZhongState,
                        tempmeter.MeterState,
                        tempmeter.MeterTest,
                        tempmeter.MeterRand_num,
                        tempmeter.Meteriport,
                        tempmeter.MeterTime,
                        tempmeter.MeterCancel,
                        tempmeter.MeterEvery,
                        tempmeter.MeterPrivilege,
                        tempmeter.CheckTime,
                        tempmeter.ManufactureName_id,
                        tempmeter.Subtime
                        );
                    Myadapter.DeleteMeter(meterid);
                    send = "AA";
                }
                catch (Exception e)
                {
                    send = "55";
                    LogHelper.Info("取消测试失败:" + meterid);
                }
            }
            else
            {
                LogHelper.Info("检测平台不存在需要取消测试表" + meterid);
                send = send.Equals("55") ? "55" : "BB";
            }
            //回复检测平台,是否取消测试成功
            IPAddress Ip      = IPAddress.Parse(ip);
            int       Port    = Convert.ToInt32(port);
            string    send_77 = DownCommond.GenerateSendFrame("77" + send, info, true, false);
            Socket    socket  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(Ip, Port);
            socket.Send(DataHelper.Str2Byte(send_77));
            socket.Close();
            LogHelper.Info("回复77:" + send_77);
        }
Пример #4
0
        /// <summary>
        /// 收到检测平台的检测结果
        /// ip+port+cmd+num+(id+AA/55+单项+修改网络参数是否成功+是否是单机)*num
        /// 字节4+2+1+2+(6+1+单项)*n
        /// AA通过;55不合格但修改网络参数成功
        /// 修改表测试状态为空闲,表对应的检测项结果,表在meterinfo表中
        /// 修改检测平台为空闲
        ///
        /// 单机操作:1.temper对象,修改对象属性为测试结果 2.判断是否测完 3.未测完,更新meter_test的数据库 4.测完,表移到meter_result中
        /// 1.前提获取测试类型和表类型。
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            lock (obj_22)
            {
                Myadapter   = new Dt_MeterInfoTableAdapter();
                Myadapter_r = new DT_ResultTableAdapter();
                Myadapter_p = new Dt_PlateInfoTableAdapter();
                var           info       = requestInfo;
                string        ip         = DataHelper.Str2IP(info.Data.Substring(2, 8));
                string        port       = Convert.ToInt32(info.Data.Substring(10, 4), 16).ToString();
                string        cmd_isauto = info.Data.Substring(14, 1);
                string        cmd_type   = info.Data.Substring(15, 1);
                int           num        = Convert.ToInt32(info.Data.Substring(16, 4), 16);
                StringBuilder info_sb    = new StringBuilder();
                info_sb.Append("22");
                info_sb.Append(info.Data.Substring(16, 4));
                switch (cmd_type)
                {
                //膜式表
                case "1":
                    len       = 24;
                    len_every = 10;
                    starti    = 0;
                    break;

                //IC
                case "2":
                    len       = 18;
                    len_every = 4;
                    starti    = 10;
                    break;

                //命令
                case "3":
                    len       = 20;
                    len_every = 6;
                    starti    = 14;
                    break;

                //终检
                case "4":
                    len       = 26;
                    len_every = 12;
                    starti    = 20;
                    break;
                }
                for (int i = 0; i < num; i++)
                {
                    string id       = info.Data.Substring(20 + i * len, 12);
                    string result   = info.Data.Substring(32 + i * len, 2);
                    string re_every = info.Data.Substring(34 + i * len, len_every);
                    info_sb.Append(id);
                    bool is_danji = re_every.Substring(len_every - 2, 1).Equals("1") ? true : false;
                    bool isscu    = re_every.Substring(re_every.Length - 1, 1).Equals("A") ? true : false;
                    try
                    {
                        dt        = Myadapter.GetDataBy1(id);
                        tempmeter = DataHelper.Dt2Ob(dt);
                        if (tempmeter == null)
                        {
                            dt        = Myadapter_r.GetDataBy_r(id, "合格", "初始", "失败");
                            tempmeter = DataHelper.Dt2Ob(dt);
                        }
                    }
                    catch (Exception e)
                    {
                        info_sb.Append("55");
                        LogHelper.Error("数据库连接异常" + e);
                    }
                    if (tempmeter != null)
                    {
                        //更新单项测试结果
                        StringBuilder re_ev   = new StringBuilder(tempmeter.MeterEvery);
                        string        oldchar = tempmeter.MeterEvery.Substring(starti, len_every);
                        re_ev.Replace(oldchar, re_every, starti, len_every);
                        tempmeter.MeterEvery = re_ev.ToString();
                        DateTime dtime = DateTime.Now;
                        tempmeter.MeterTime = dtime;
                        if (!is_danji)
                        {
                            string   re  = tempmeter.Meteriport;
                            string[] tip = re.Split('@');
                            tempmeter.MeterTest = "空闲";
                            if (result.Equals("AA"))
                            {
                                string st = "合格";
                                if (Xiugai(tip, st, tempmeter.MeterCancel, true, isscu, is_danji))
                                {
                                    info_sb.Append("AA");
                                }
                                else
                                {
                                    info_sb.Append("55");
                                }
                            }
                            else if (result.Equals("55"))
                            {
                                string st = "不合格";
                                if (Xiugai(tip, st, tempmeter.MeterCancel, false, isscu, is_danji))
                                {
                                    info_sb.Append("AA");
                                }
                                else
                                {
                                    info_sb.Append("55");
                                }
                            }
                            else
                            {
                                LogHelper.Info("错误的22命令");
                            }
                        }
                        else
                        {
                            string type = "";
                            switch (cmd_type)
                            {
                            case "1":
                                tempmeter.MeterChuState = result.Equals("AA") ? "合格" : "不合格";
                                type = "chu";
                                break;

                            case "2":
                                tempmeter.MeterIcState = result.Equals("AA") ? "合格" : "不合格";
                                type = "ic";
                                break;

                            case "3":
                                tempmeter.MeterComState = result.Equals("AA") ? "合格" : "不合格";
                                type = "com";
                                break;

                            case "4":
                                tempmeter.MeterZhongState = result.Equals("AA") ? "合格" : "不合格";
                                type = "zho";
                                break;
                            }
                            bool is_complete = tempmeter.MeterChuState.Equals("待测") || tempmeter.MeterIcState.Equals("待测") || tempmeter.MeterComState.Equals("待测") || tempmeter.MeterZhongState.Equals("待测") ? false : true;
                            if (Up_Dj(tempmeter, is_complete, type))
                            {
                                info_sb.Append("AA");
                            }
                            else
                            {
                                info_sb.Append("55");
                            }
                        }
                    }
                    else
                    {
                        info_sb.Append("55");
                        LogHelper.Info("表具不在检测列表中");
                    }
                    Thread.Sleep(100);
                }
                try
                {
                    IPAddress Ip     = IPAddress.Parse(ip);
                    int       Port   = Convert.ToInt32(port);
                    string    send22 = DownCommond.GenerateSendFrame(info_sb.ToString(), info, false, false);
                    Socket    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    socket.Connect(Ip, Port);
                    socket.Send(DataHelper.Str2Byte(send22));
                    socket.Close();
                    LogHelper.Info("回复22:" + send22);
                }
                catch (Exception e)
                {
                    LogHelper.Error("回复22命令连接检测平台异常" + e);
                    LogHelper.Info("检测平台通信异常");
                }

                //更新界面
                CommonFunction.platm.ChangeMeter();
                CommonFunction.platm.ChangePlat();
                CommonFunction.platm.ChangeBHG();
                Thread.Sleep(500);
            }
        }
Пример #5
0
        /// <summary>
        /// 检测平台连接表后回复命令
        /// (id ,IP,port)+结果(AA/55/66)
        /// 表没有正确修改,检测平台要回复没有修改成功
        /// 修改成功(表在meterinfo中),表test=正测,检测平台 = 正忙
        /// 修改失败(表在meterinfo中(表移入到meterfail中,State=失败),表在meterfail中(不用管))检测平台=空闲
        /// 解析失败(表在meterinfo中,后把表的测试状态改为空闲,延迟15s检测平台的状态改为空闲)
        ///
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            lock (obj_33)
            {
                Myadapter   = new Dt_MeterInfoTableAdapter();
                Myadapter_r = new DT_ResultTableAdapter();
                Myadapter_p = new Dt_PlateInfoTableAdapter();
                var    info   = requestInfo;
                string result = info.Data.Substring(26, 2);
                try
                {
                    dt        = Myadapter.GetDataBy1(info.EquipmentID);
                    tempmeter = DataHelper.Dt2Ob(dt);
                    if (tempmeter == null)
                    {
                        dt        = Myadapter_r.GetDataBy_r(info.EquipmentID, "合格", "初始", "初始");
                        tempmeter = DataHelper.Dt2Ob(dt);
                    }
                }
                catch (Exception)
                {
                    LogHelper.Error("数据库连接异常");
                }
                switch (result)
                {
                case "AA":
                    if (tempmeter != null)
                    {
                        DateTime dtime2 = DateTime.Now;
                        tempmeter.MeterTime = dtime2;
                        tempmeter.MeterTest = "正测";
                        if (tempmeter.MeterCancel.Equals("合格"))
                        {
                            Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                        }
                        else
                        {
                            Myadapter.UpdateMeterTest2(tempmeter.MeterTime, tempmeter.MeterTest, tempmeter.MeterId);
                        }
                        //修改检测平台=正忙
                        Thread.Sleep(100);
                        Xiugai(tempmeter, "正忙");
                    }
                    else
                    {
                        LogHelper.Info("错误的33命令1");
                    }
                    break;

                case "55":
                    if (tempmeter != null)
                    {
                        if (tempmeter.MeterCancel.Equals("否"))
                        {
                            tempmeter.MeterState      = "失败";
                            tempmeter.MeterComState   = tempmeter.MeterComState.Equals("待测") ? "失败" : tempmeter.MeterComState;
                            tempmeter.MeterIcState    = tempmeter.MeterIcState.Equals("待测") ? "失败" : tempmeter.MeterIcState;
                            tempmeter.MeterChuState   = tempmeter.MeterChuState.Equals("待测") ? "失败" : tempmeter.MeterChuState;
                            tempmeter.MeterZhongState = tempmeter.MeterComState.Equals("待测") ? "失败" : tempmeter.MeterZhongState;
                            Myadapter_r.InsertMeter(tempmeter.MeterId,
                                                    tempmeter.MeterType,
                                                    tempmeter.MeterComState,
                                                    tempmeter.MeterIcState,
                                                    tempmeter.MeterChuState,
                                                    tempmeter.MeterZhongState,
                                                    tempmeter.MeterState,
                                                    tempmeter.MeterTest,
                                                    tempmeter.MeterRand_num,
                                                    tempmeter.Meteriport,
                                                    tempmeter.MeterTime,
                                                    tempmeter.MeterCancel,
                                                    tempmeter.MeterEvery,
                                                    tempmeter.MeterPrivilege,
                                                    tempmeter.CheckTime,
                                                    tempmeter.ManufactureName_id,
                                                    tempmeter.Subtime);
                            Myadapter.DeleteMeter(tempmeter.MeterId);
                        }
                        CommonFunction.platm.ChangeBHG();
                        Xiugai(tempmeter, "空闲");
                    }
                    else
                    {
                        dt        = Myadapter_r.GetDataBy_r(info.EquipmentID, "失败", "失败", "失败");
                        tempmeter = DataHelper.Dt2Ob(dt);
                        if (tempmeter != null)
                        {
                            Thread.Sleep(3 * 1000);
                            Xiugai(tempmeter, "空闲");
                        }
                        else
                        {
                            LogHelper.Info("此表具不再任何检测表中");
                        }
                    }
                    break;

                case "66":
                    if (tempmeter.MeterCancel.Equals("否"))
                    {
                        DateTime dtime = DateTime.Now;
                        tempmeter.MeterTime = dtime;
                        tempmeter.MeterTest = "空闲";
                        Myadapter.UpdateMeterTest2(tempmeter.MeterTime, tempmeter.MeterTest, tempmeter.MeterId);
                        Thread.Sleep(15 * 1000);
                        string s = "空闲";
                        Xiugai(tempmeter, s);
                    }
                    break;

                default:
                    LogHelper.Info("错误的33命令");
                    break;
                }
                //更新界面
                CommonFunction.platm.ChangeMeter();
                CommonFunction.platm.ChangePlat();
            }
        }
Пример #6
0
        /// <summary>
        /// tempi为表具在meterinfos的索引号
        /// tempmeter为收到请求的表具
        /// 调用logical中的函数来安排
        /// 将成功或失败的表移到成功和失败的表中,8E的时候从这两个表中查询
        /// 判断表具恢复出厂设置功能是否成功(8E)()
        /// </summary>
        /// <param name="session"></param>
        /// <param name="requestInfo"></param>
        public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
        {
            lock (obj)
            {
                Myadapter_r   = new DT_ResultTableAdapter();
                Myadapter_csb = new Dt_Chu_csbTableAdapter();
                Myadapter_xzy = new Dt_Chu_xzyTableAdapter();
                Myadapter_msb = new Dt_Chu_msbTableAdapter();
                Myadapter_Ic  = new Dt_IcTableAdapter();
                Myadapter_Mp  = new Dt_MPTableAdapter();
                Myadapter_p   = new Dt_PlateInfoTableAdapter();
                Myadapter     = new Dt_MeterInfoTableAdapter();
                bool     ishavepri = false;
                Boolean  flag_sen  = true;
                Boolean  flag_xiu  = true;
                Boolean  flag_xinx = true;
                var      info      = requestInfo;
                DateTime dtime2    = DateTime.Now;
                //LogHelper.Error(dtime2 + "  " + info.EquipmentID + "  " + info.Key + "获取锁");
                try
                {
                    dt = Myadapter.GetDataBy1(info.EquipmentID);
                    if (Myadapter.SQ_Privilege("1") != 0)
                    {
                        ishavepri = true;
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Info("数据库连接异常90" + e);
                }
                tempmeter = DataHelper.Dt2Ob(dt);
                if (tempmeter != null)
                {
                    //随机数与datetime
                    tempmeter.MeterRand_num = info.Data.Substring(52, 8);
                    DateTime dtime = DateTime.Now;
                    tempmeter.MeterTime = dtime;
                    switch (tempmeter.MeterState)
                    {
                    case "完成":
                        //如果表上传,说明恢复出厂设置不成功
                        XiugaiSF(tempmeter, session, info);
                        break;

                    case "失败":
                        //不可能一旦失败表就会移入到meterfail表中
                        break;

                    case "不合格":
                        //不可能一旦失败表就会移入到meterfail表中
                        break;

                    case "合格":
                        //免检产品
                        Xiugaisuc(tempmeter, session, info);
                        break;

                    case "初始":
                        //查询测量标志位
                        if (tempmeter.MeterTest.Equals("正测") || tempmeter.MeterTest.Equals("准备") || tempmeter.MeterTest.Equals("就绪"))
                        {
                            //更新随机数
                            //下发1F
                            string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", 2, 1), info, true, true);
                            ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                            session.Send(f0);
                            LogHelper.Info("发送命令4" + send0F);
                            Myadapter.UpdateRand_num(tempmeter.MeterRand_num, tempmeter.MeterId);
                        }
                        else if (tempmeter.MeterTest.Equals("空闲"))
                        {
                            //安排分
                            string[] re = Logical.Meter_AnPai(tempmeter, ishavepri);
                            //LogHelper.Error(tempmeter.MeterId + re[1]);
                            //返回2222代表此表合格,其需要回复出厂设置并修改到正式服务器
                            if (re[1].Equals("成功"))
                            {
                                Xiugaisuc(tempmeter, session, info);
                            }
                            //返回3333代表此表的所有测试都失败
                            else if (re[1].Equals("失败"))
                            {
                                //Xiugaifai(tempmeter, session, info);
                            }
                            //返回安排的结果
                            else if (!re[1].Equals("空"))
                            {
                                //获取对应的IP与port
                                //下发8f与81命令
                                //并向检测平台下发33命令
                                //修改表的测试状态为准备2
                                //修改检测平台的测试状态为就绪
                                //保存表对应检测平台的IP与port
                                try
                                {
                                    IPAddress ip     = IPAddress.Parse(re[1]);
                                    int       port   = Convert.ToInt32(re[2]);
                                    Socket    socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                    socket.Connect(ip, port);
                                    string send34 = null;
                                    try
                                    {
                                        switch (re[3])
                                        {
                                        case "PlatComs":
                                            string typee = "";
                                            if (tempmeter.MeterType.Equals("膜式表"))
                                            {
                                                dt_temp = Myadapter_msb.GetData(tempmeter.MeterId);
                                                typee   = "msb";
                                            }
                                            else if (tempmeter.MeterType.Equals("修正仪"))
                                            {
                                                dt_temp = Myadapter_xzy.GetData(tempmeter.MeterId);
                                                typee   = "xzy";
                                            }
                                            else if (tempmeter.MeterType.Equals("超声波"))
                                            {
                                                dt_temp = Myadapter_csb.GetData(tempmeter.MeterId);
                                                typee   = "csb";
                                            }
                                            send34 = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Com(dt_temp, typee), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, re[0], "-1", "-1", "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Com(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatCom("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatIcs":
                                            dt_temp = Myadapter_Ic.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Ic(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", re[0], "-1", "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_IC(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatIc("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatChus_msb":
                                            dt_temp = Myadapter_msb.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Chu_msb(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", re[0], "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Chu(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatChu_msb("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatChus_xzy":
                                            dt_temp = Myadapter_xzy.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Chu_xzy(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", re[0], "-1");
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Chu(re[0], tempmeter.MeterId);
                                            }
                                            Myadapter_p.UpdatePlatChu_xzy("就绪", int.Parse(re[0]));
                                            break;

                                        case "PlatChus_csb":
                                            dt_temp = Myadapter_csb.GetData(tempmeter.MeterId);
                                            send34  = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Chu_csb(dt_temp), info, false, false);
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", re[0], "-1");
                                            }
                                            else
                                            {
                                                Myadapter_p.UpdatePlatChu_csb("就绪", int.Parse(re[0]));
                                            }
                                            break;

                                        case "PlatZhos":
                                            //dt_temp =
                                            //send34 = DownCommond.GenerateSendFrame(DownCommond.GenerateCore33(tempmeter.MeterId) + DownCommond.GenerateCore34_Zho(dt_temp), info, false, false);
                                            //socket.Send(DataHelper.Str2Byte(send34));
                                            socket.Close();
                                            Myadapter_p.UpdatePlatZho("就绪", int.Parse(re[0]));
                                            //有问题
                                            if (Convert.ToInt64(Myadapter_Mp.SQ_MP(tempmeter.MeterId)) == 0)
                                            {
                                                Myadapter_Mp.Insert_MP(tempmeter.MeterId, "-1", "-1", "-1", re[0]);
                                            }
                                            else
                                            {
                                                Myadapter_Mp.Update_MP_Zho(re[0], tempmeter.MeterId);
                                            }
                                            break;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        flag_xinx = false;
                                        flag_sen  = false;
                                        flag_xiu  = false;
                                        LogHelper.Error("检测平台修改数据库或读取燃气表测试信息异常" + e);
                                    }
                                    if (flag_xinx)
                                    {
                                        socket.Send(DataHelper.Str2Byte(send34));
                                        socket.Close();
                                        LogHelper.Info("发送命令33" + send34);
                                    }
                                }
                                catch (Exception e)
                                {
                                    flag_sen = false;
                                    flag_xiu = false;
                                    LogHelper.Error("检测平台异常或数据异常" + e);
                                }
                                if (flag_sen)
                                {
                                    try
                                    {
                                        string send8F3          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore8F(tempmeter.MeterRand_num), info, true, false);
                                        string send813          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore81(re[1], re[2], false, "", tempmeter.MeterRand_num), info, false, true);
                                        ArraySegment <byte> f3  = new ArraySegment <byte>(DataHelper.Str2Byte(send8F3));
                                        ArraySegment <byte> f23 = new ArraySegment <byte>(DataHelper.Str2Byte(send813));
                                        session.Send(f3);
                                        Thread.Sleep(1000);
                                        session.Send(f23);
                                        LogHelper.Info("发送命令8F" + send8F3);
                                        LogHelper.Info("发送命令81" + send813);
                                    }
                                    catch (Exception e)
                                    {
                                        flag_xiu = false;
                                        LogHelper.Error("修改网络参数下发失败" + e);
                                    }
                                }
                                else
                                {
                                    //更新随机数
                                    //下发1F
                                    string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", 2, 1), info, true, true);
                                    ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                                    session.Send(f0);
                                    LogHelper.Info("发送命令3" + send0F);
                                    Myadapter.UpdateRand_num(tempmeter.MeterRand_num, tempmeter.MeterId);
                                }
                                if (flag_xiu)
                                {
                                    tempmeter.MeterTest  = "准备";
                                    tempmeter.Meteriport = re[0] + "@" + re[1] + "@" + re[2] + "@" + re[3];
                                    Myadapter.UpdateMeterTest(tempmeter.MeterRand_num, tempmeter.Meteriport, tempmeter.MeterTime, tempmeter.MeterTest, tempmeter.MeterId);
                                }
                            }
                            else if (re[1].Equals("空"))
                            {
                                LogHelper.Info("无空闲检测平台");
                                Random rd              = new Random();
                                int    uplod_time      = rd.Next(10, 20);
                                string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", uplod_time, 5), info, true, true);
                                ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                                session.Send(f0);
                                LogHelper.Info("发送命令2" + send0F);
                                Myadapter.UpdateRand_num(tempmeter.MeterRand_num, tempmeter.MeterId);
                            }
                            else
                            {
                                LogHelper.Info("安排出错,大于检测平台数");
                            }
                        }
                        else
                        {
                            LogHelper.Info("非规定测量标志位");
                        }
                        break;

                    default:
                        LogHelper.Info("未知状态");
                        break;
                    }
                    CommonFunction.platm.ChangeMeter();
                    CommonFunction.platm.ChangePlat();
                }
                else
                {
                    try
                    {
                        dt = Myadapter_r.GetDataBy_r(info.EquipmentID, "合格", "初始", "失败");
                    }
                    catch (Exception e)
                    {
                        LogHelper.Info("数据库连接异常90" + e);
                    }
                    tempmeter = DataHelper.Dt2Ob(dt);
                    if (tempmeter != null)
                    {
                        //随机数与datetime
                        //在11之前修改为合格,表在metersuccess中,metertest=空闲,metercancel=合格
                        //如果测试状态为正测
                        tempmeter.MeterRand_num = info.Data.Substring(52, 8);
                        DateTime dtime = DateTime.Now;
                        tempmeter.MeterTime = dtime;
                        if ((tempmeter.MeterCancel.Equals("合格") && tempmeter.MeterTest.Equals("空闲")) || (tempmeter.MeterCancel.Equals("是") && tempmeter.MeterState.Equals("失败")))
                        {
                            Cancel_meter(tempmeter, session, info);
                        }
                        else if (tempmeter.MeterCancel.Equals("合格") && tempmeter.MeterTest.Equals("正测"))
                        {
                            //更新随机数
                            //下发1F
                            string send0F          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore0F("1F", 2, 1), info, true, true);
                            ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                            session.Send(f0);
                            LogHelper.Info("发送命令1" + send0F);
                            Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                        }
                    }
                }
            }
        }
Пример #7
0
 /// <summary>
 /// 上行81命令
 /// 测试完成,修改正式域名(此时表state为成功,Test为就绪)从metersuccess中查找
 /// 准备去检测平台测试(此时表的state为初始,test状态为准备)从meterinfo中查找
 /// 判断表的修改网络参数是否成功?(这里要考虑数据库更新的IP port是否在+81之前
 /// 不在这里判断修改网络参数若检测平台没有回复,就不能排除是表的问题了)
 /// 让这个线程休眠500ms来等待数据库操作
 /// </summary>
 /// <param name="session"></param>
 /// <param name="requestInfo"></param>
 public override void ExecuteCommand(MySession session, MyRequestInfo requestInfo)
 {
     lock (obj2)
     {
         Myadapter   = new Dt_MeterInfoTableAdapter();
         Myadapter_r = new DT_ResultTableAdapter();
         DataTable dt        = new DataTable();
         MeterInfo tempmeter = new MeterInfo();
         bool      issuccess = false;
         Thread.Sleep(1000);
         var info = requestInfo;
         try
         {
             dt = Myadapter.GetDataBy1(info.EquipmentID);
             if (dt != null && dt.Rows.Count > 0)
             {
                 tempmeter = DataHelper.Dt2Ob(dt);
             }
             else
             {
                 dt        = Myadapter_r.GetDataBy_r(info.EquipmentID, "合格", "初始", "初始");
                 tempmeter = DataHelper.Dt2Ob(dt);
                 issuccess = true;
             }
         }
         catch (Exception e)
         {
             LogHelper.Error("数据库连接异常" + e);
         }
         if (tempmeter != null)
         {
             DateTime dtime = DateTime.Now;
             tempmeter.MeterTime = dtime;
             string IP     = DataHelper.Str2IP(info.Data.Substring(4, 8));
             string port   = Convert.ToInt32(info.Data.Substring(12, 4), 16).ToString();
             string domain = Encoding.ASCII.GetString(DataHelper.SplitArray(DataHelper.Str2Byte(info.Data), 8, 32));
             //修改到正式服务器的表,不需检测网络修改功能
             if (issuccess)
             {
                 if ((tempmeter.MeterState.Equals("合格") || (tempmeter.MeterCancel.Equals("合格") && tempmeter.MeterState.Equals("初始"))) && tempmeter.MeterTest.Equals("就绪"))
                 {
                     string send0F = S0f(info.EquipmentType, info);
                     if (send0F.Equals("0"))
                     {
                         LogHelper.Info("设备类型不是标准值");
                     }
                     else
                     {
                         //of不需要发送
                         ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                         session.Send(f0);
                         LogHelper.Info("发送命令" + send0F);
                         tempmeter.MeterState = "完成";
                         tempmeter.MeterTest  = "空闲";
                         Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                     }
                 }
                 else if (tempmeter.MeterCancel.Equals("合格") && tempmeter.MeterState.Equals("初始") && tempmeter.MeterTest.Equals("准备"))
                 {
                     tempmeter.MeterTest = "特殊";
                     string ip    = CommonFunction.dicBooks["strMainHostIP"];
                     string port2 = CommonFunction.dicBooks["strMainHostPort"];
                     //下发81,修改回来,修改状态为就绪,下次上传81时再修改正式域
                     string send813          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore81(ip, port2, false, "", tempmeter.MeterRand_num), info, false, true);
                     ArraySegment <byte> f23 = new ArraySegment <byte>(DataHelper.Str2Byte(send813));
                     session.Send(f23);
                     LogHelper.Info("发送命令81" + send813);
                     Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                 }
                 else if (tempmeter.MeterState.Equals("初始") && tempmeter.MeterTest.Equals("特殊"))
                 {
                     tempmeter.MeterTest = "准备";
                     string send8E          = DownCommond.GenerateSendFrame(DownCommond.GenerateCore8E(tempmeter.MeterRand_num), info, false, false);
                     ArraySegment <byte> f2 = new ArraySegment <byte>(DataHelper.Str2Byte(send8E));
                     session.Send(f2);
                     LogHelper.Info("发送命令" + send8E);
                     Myadapter_r.Update_wait(tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterId);
                 }
             }
             else if (tempmeter.MeterState.Equals("初始") && tempmeter.MeterTest.Equals("准备") && !issuccess)
             {
                 string   re  = tempmeter.Meteriport;
                 string[] tip = re.Split('@');
                 //修改网络参数成功
                 if (tip[1].Equals(IP) && tip[2].Equals(port))
                 {
                     string send0F = S0f(info.EquipmentType, info);
                     if (send0F.Equals("0"))
                     {
                         LogHelper.Info("设备类型不是标准值");
                     }
                     else
                     {
                         ArraySegment <byte> f0 = new ArraySegment <byte>(DataHelper.Str2Byte(send0F));
                         session.Send(f0);
                         LogHelper.Info("发送命令" + send0F);
                         tempmeter.MeterTest = "就绪";
                         Myadapter.UpdateMeterTest2(tempmeter.MeterTime, tempmeter.MeterTest, tempmeter.MeterId);
                     }
                 }
                 else
                 {
                     //修改网络参数失败
                     //下发8e休眠,并将其移到测试失败的表中
                     //检测平台将收不到表,会回复33没有连上的命令,需要在33哪里修改检测平台的状态为空闲
                     tempmeter.MeterState = "失败";
                     tempmeter.MeterTest  = "空闲";
                     LogHelper.Info("网络参数未正确修改到检测平台");
                     Myadapter_r.InsertMeter(tempmeter.MeterId,
                                             tempmeter.MeterType,
                                             tempmeter.MeterComState,
                                             tempmeter.MeterIcState,
                                             tempmeter.MeterChuState,
                                             tempmeter.MeterZhongState,
                                             tempmeter.MeterState,
                                             tempmeter.MeterTest,
                                             tempmeter.MeterRand_num,
                                             tempmeter.Meteriport,
                                             tempmeter.MeterTime,
                                             tempmeter.MeterCancel,
                                             tempmeter.MeterEvery,
                                             tempmeter.MeterPrivilege,
                                             tempmeter.CheckTime,
                                             tempmeter.ManufactureName_id,
                                             tempmeter.Subtime);
                     Myadapter.DeleteMeter(tempmeter.MeterId);
                     CommonFunction.platm.ChangeSB();
                 }
             }
             else
             {
                 LogHelper.Info("分配逻辑出错");
             }
             //更新界面
             CommonFunction.platm.ChangeMeter();
             CommonFunction.platm.ChangePlat();
             CommonFunction.platm.ChangeHG();
         }
         else
         {
             LogHelper.Info("表不再检测列表中");
         }
     }
 }