/// <summary> /// 总状态为成功的表 /// </summary> /// <param name="tempmeter"></param> /// <param name="session"></param> private void Xiugaisuc(MeterInfo tempmeter, MySession session, MyRequestInfo info) { try { //修改总结果为成功 tempmeter.MeterState = "成功"; //下发8f,8E, 改变测试状态为准备,正准备修改到正式服务器 string send8F = DownCommond.GenerateSendFrame(DownCommond.GenerateCore8F(tempmeter.MeterRand_num), info, true, false); string send8E = DownCommond.GenerateSendFrame(DownCommond.GenerateCore8E(tempmeter.MeterRand_num), info, false, false); ArraySegment <byte> f = new ArraySegment <byte>(DataHelper.Str2Byte(send8F)); ArraySegment <byte> f2 = new ArraySegment <byte>(DataHelper.Str2Byte(send8E)); session.Send(f); Thread.Sleep(1000); session.Send(f2); LogHelper.Info("发送命令" + send8F); LogHelper.Info("发送命令" + send8E); //修改测试状态为准备 +++++++++++++++++++++++++++++++ tempmeter.MeterTest = "准备"; //Myadapter.UpdateMeterState(tempmeter.MeterRand_num, tempmeter.MeterTime, tempmeter.MeterState, tempmeter.MeterTest, tempmeter.MeterId); 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.ChangeSuc(); } catch (Exception e) { LogHelper.Info(tempmeter.MeterId + e); } }
private bool Up_Dj(MeterInfo tempmeter, bool is_complete, string type) { try { if (is_complete) { tempmeter.MeterState = tempmeter.MeterChuState.Equals("不合格") || tempmeter.MeterIcState.Equals("不合格") || tempmeter.MeterComState.Equals("不合格") || tempmeter.MeterZhongState.Equals("不合格") ? "不合格" : "完成"; 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); } else { Up_test(tempmeter, type); } return(true); } catch (Exception) { LogHelper.Info("单机测试结果更新失败:" + tempmeter.MeterId); return(false); } }
private void button1_Click(object sender, EventArgs e) { try { foreach (string key in CommonFunction.dic_cancel.Keys) { MeterInfo tempmeter = new MeterInfo(); tempmeter = DataHelper.Dt2Ob(Myadapter.GetDataBy1(key)); if (tempmeter != null) { Myadapter_r.InsertMeter(tempmeter.MeterId, tempmeter.MeterType, tempmeter.MeterComState, tempmeter.MeterIcState, tempmeter.MeterChuState, tempmeter.MeterZhongState, CommonFunction.dic_cancel[key], tempmeter.MeterTest, tempmeter.MeterRand_num, tempmeter.Meteriport, tempmeter.MeterTime, CommonFunction.dic_cancel[key], tempmeter.MeterEvery, tempmeter.MeterPrivilege, tempmeter.CheckTime, tempmeter.ManufactureName_id, tempmeter.Subtime); Myadapter.DeleteMeter(key); } } } catch (Exception) { LogHelper.Error("取消测试失败"); MessageBox.Show("取消测试失败"); } CommonFunction.platm.ChangeMeter(); CommonFunction.platm.ChangeHG(); CommonFunction.platm.ChangeBHG(); CommonFunction.platm.ChangeSB(); CommonFunction.dic_cancel.Clear(); this.Close(); }
/// <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); }
/// <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("表不再检测列表中"); } } }