/// <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(); } }
/// <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("表不再检测列表中"); } } }