public void timer1_Tick(object sender, EventArgs e) { if (QueueInstance.Instance.IsMessageShowHasData()) { //增加方法 //_del = new showdelegate(UpdateBox); _del = UpdateBox; // string mmstr = ImsRecvTask.getstring(); string mmstr = QueueInstance.Instance.GetMessageShowList(); //应用 _del(mmstr); } //出队 //对每一个arrive之后的字符串进行处理 for (int i = 0; i < 100; i++) { if (QueueInstance.Instance.IsYourMessageHasData()) { string str = QueueInstance.Instance.GetYourMessageList(); //if (str != null) //{ // // MessageBox.Show(str); //} //将得到的数据转换成json对象 AGV_V1._0.SendData dataObj; dataObj = (AGV_V1._0.SendData)JsonConvert.DeserializeObject(str, typeof(AGV_V1._0.SendData)); if (dataObj.State == Const.State.cannotToDestination) { dataObj.EndLoc = "RestArea"; } else { if (msflag == 0) { //工作 #region dataObj = (AGV_V1._0.SendData)JsonConvert.DeserializeObject(str, typeof(AGV_V1._0.SendData)); if (dataObj.Arrive == true) { if (dataObj.StartLoc == "RestArea") { dataObj.EndLoc = "WaitArea"; } else if (dataObj.StartLoc == "WaitArea") { dataObj.EndLoc = "ScanArea"; dataObj.State = Const.State.free; } else if (dataObj.StartLoc == "ScanArea") { dataObj.EndLoc = "DestArea"; dataObj.State = Const.State.carried; // Thread.Sleep(AGVConstDefine.AfterScanPause_Time); } else if (dataObj.EndLoc == "DestArea" && dataObj.State == Const.State.carried) { dataObj.EndLoc = "DestArea"; dataObj.State = Const.State.carried; } else if (dataObj.EndLoc == "DestArea" && dataObj.State == Const.State.unloading) { dataObj.EndLoc = "DestArea"; dataObj.State = Const.State.unloading; } else if (dataObj.EndLoc == "DestArea" && dataObj.State == Const.State.free) { dataObj.EndLoc = "WaitArea"; dataObj.State = Const.State.free; } } #endregion } else { //休息 dataObj = (AGV_V1._0.SendData)JsonConvert.DeserializeObject(str, typeof(AGV_V1._0.SendData)); if (dataObj.Arrive == true) { if (dataObj.StartLoc == "RestArea") { //dataObj.EndLoc = ""; //break; } else if (dataObj.EndLoc == "DestArea" && dataObj.State == Const.State.carried) { dataObj.EndLoc = "DestArea"; dataObj.State = Const.State.carried; } else if (dataObj.EndLoc == "DestArea" && dataObj.State == Const.State.unloading) { dataObj.EndLoc = "DestArea"; dataObj.State = Const.State.unloading; } else if (dataObj.EndLoc == "DestArea" && dataObj.State == Const.State.free) { dataObj.EndLoc = "RestArea"; dataObj.State = Const.State.free; } } } } if (dataObj.StartLoc == "DestArea" && dataObj.EndLoc == "DestArea") { } else if (dataObj.StartLoc == "RestArea" && msflag == 1) { } else { AGVConstDefine.AGV[dataObj.Num].BeginX = dataObj.BeginX; AGVConstDefine.AGV[dataObj.Num].BeginY = dataObj.BeginY; AGVConstDefine.AGV[dataObj.Num].StartLoc = dataObj.StartLoc; AGVConstDefine.AGV[dataObj.Num].EndLoc = dataObj.EndLoc; AGVConstDefine.AGV[dataObj.Num].State = dataObj.State; AGVDestination.Confirm_EndPoint(AGVConstDefine.AGV[dataObj.Num], AGVConstDefine.AGV[dataObj.Num].StartLoc, AGVConstDefine.AGV[dataObj.Num].BeginX, AGVConstDefine.AGV[dataObj.Num].BeginY, AGVConstDefine.AGV[dataObj.Num].EndLoc); AGV_V1._0.SendData sd = JsonHelper.GetSendObj(AGVConstDefine.AGV[dataObj.Num]); string sendjs = Newtonsoft.Json.JsonConvert.SerializeObject(sd); //出队 if (AGVConstDefine.AGV[i].StartLoc == "ScanArea") { Task.Factory.StartNew(() => { Thread.Sleep(AGVConstDefine.AfterScanPause_Time); }); } ImsResponse pathmessage = new ImsResponse(); pathmessage.obj = "PATH"; pathmessage.data = sendjs; QueueInstance.Instance.AddMyMessageList(pathmessage); } } } }
public SearchData(SendData sendData, bool isReSearch) { this._sendData = sendData; this._isReSearch = isReSearch; }
void HandleData(object sender, MessageEventArgs e) { if (e.Type == MessageType.move) { //工作 msflag = 0; #region string mstr = System.DateTime.Now.ToString() + ":" + "工作"; QueueInstance.Instance.AddMessageShowList(mstr); // #region 与界面建立socket连接,归位,所有小车回到RestArea //工作消息,所有小车去往RestArea,将处理得到的数据放到队列里 for (int i = 0; i < AGVConstDefine.AGV.Count(); i++) { if (AGVConstDefine.AGV[i].State == Const.State.free && AGVConstDefine.AGV[i].StartLoc != "WaitArea") { AGVDestination.Confirm_EndPoint(AGVConstDefine.AGV[i], "", AGVConstDefine.AGV[i].BeginX, AGVConstDefine.AGV[i].BeginY, "WaitArea"); } //else if (AGVConstDefine.AGV[i].StartLoc=="WaitArea") //{ // AGVDestination.Confirm_EndPoint(AGVConstDefine.AGV[i], "WaitArea", AGVConstDefine.AGV[i].BeginX, AGVConstDefine.AGV[i].BeginY, "ScanArea"); //} //else if(AGVConstDefine.AGV[i].State == Const.State.carried) //{ // AGVConstDefine.AGV[i].StartLoc = "ScanArea"; // AGVConstDefine.AGV[i].EndLoc = "DestArea"; //} AGV_V1._0.SendData sd = JsonHelper.GetSendObj(AGVConstDefine.AGV[i]); string sendjs = Newtonsoft.Json.JsonConvert.SerializeObject(sd); //放进队列里 if (sendjs.Trim() != "") { if (AGVConstDefine.AGV[i].StartLoc == "ScanArea") { Task.Factory.StartNew(() => { Thread.Sleep(AGVConstDefine.AfterScanPause_Time); }); } ImsResponse pathmessage = new ImsResponse(); pathmessage.obj = "PATH"; pathmessage.data = sendjs; //一个一个入队 QueueInstance.Instance.AddMyMessageList(pathmessage); } } #endregion } if (e.Type == MessageType.reStart) { //去休息 msflag = 1; #region string mstr = System.DateTime.Now.ToString() + ":" + "休息"; QueueInstance.Instance.AddMessageShowList(mstr); // #region 与界面建立socket连接,归位,所有小车回到RestArea //归位消息,所有小车去往RestArea,将处理得到的数据放到队列里 for (int i = 0; i < AGVConstDefine.AGV.Count(); i++) { if (AGVConstDefine.AGV[i].State == Const.State.free) { AGVDestination.Confirm_EndPoint(AGVConstDefine.AGV[i], "", AGVConstDefine.AGV[i].BeginX, AGVConstDefine.AGV[i].BeginY, "RestArea"); } else if (AGVConstDefine.AGV[i].State == Const.State.carried) { AGVConstDefine.AGV[i].StartLoc = "ScanArea"; AGVConstDefine.AGV[i].EndLoc = "DestArea"; } AGV_V1._0.SendData sd = JsonHelper.GetSendObj(AGVConstDefine.AGV[i]); string sendjs = Newtonsoft.Json.JsonConvert.SerializeObject(sd); //放进队列里 if (sendjs.Trim() != "") { if (AGVConstDefine.AGV[i].StartLoc == "ScanArea") { Task.Factory.StartNew(() => { Thread.Sleep(AGVConstDefine.AfterScanPause_Time); }); } ImsResponse pathmessage = new ImsResponse(); pathmessage.obj = "PATH"; pathmessage.data = sendjs; //一个一个入队 QueueInstance.Instance.AddMyMessageList(pathmessage); } } #endregion } else if (e.Type == MessageType.arrived) { #region string strContent = e.Message;//Encoding.ASCII.GetString(bRecTmp, 1, receiveNumber - 1); string mstr = System.DateTime.Now.ToString() + ":Arrive消息" + strContent + "\n"; QueueInstance.Instance.AddMessageShowList(mstr); List <AGV_V1._0.SendData> jsonObj = new List <AGV_V1._0.SendData>(); //从第0个位置开始查找json数据对象 int start = strContent.IndexOf("{", 0); int endx = strContent.IndexOf("}", 0); while (start >= 0) { string str = strContent.Substring(start, endx - start + 1); //对收到的消息进行处理 QueueInstance.Instance.AddYourMessageList(str); start = strContent.IndexOf("{", endx); endx = strContent.IndexOf("}", endx + 1); } #endregion } else if (e.Type == MessageType.msg) { } else if (e.Type == MessageType.AgvFile) { // Response.Write(e.Message); string agvpath = System.Configuration.ConfigurationManager.AppSettings["AGVPath"].ToString().Trim(); string[] xmlstr = new string[1]; xmlstr[0] = e.Message; //System.IO.File.WriteAllLines(agvpath, xmlstr, Encoding.UTF8); // System.IO.File.WriteAllLines(agvpath, xmlstr); using (FileStream fswrite = new FileStream(agvpath, FileMode.Create, FileAccess.Write)) { StreamWriter sw = new StreamWriter(fswrite); sw.Write(e.Message); sw.Flush(); sw.Close(); } AgvLoad(); } else if (e.Type == MessageType.mapFile) { // Response.Write(e.Message); string mappath = System.Configuration.ConfigurationManager.AppSettings["MAPPath"].ToString().Trim(); string[] xmlstr = new string[1]; xmlstr[0] = e.Message; //System.IO.File.WriteAllLines(agvpath, xmlstr, Encoding.UTF8); System.IO.File.WriteAllLines(mappath, xmlstr); MapLoad(); } }
public static string VehicleToJson(Vehicle v) { SendData obj = GetSendObj(v); return(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); }