private void TimeScan(object parm) { while (true) { try { string zone = parm.ToString(); DataTable dt = crc.GetTask(zone);//获取SC任务 if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { CRNObject co = CRNOBList.Find( delegate(CRNObject info) { return(info.ScNo == "CRN00" + row["num"].ToString().Substring(5, 1) && info.zone == zone); } ); if (co != null) { //((GenSongSRM)co.BllSrm).SendTask(row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), row[5].ToString()); ((GenSongSRM)co.BllSrm).SendTask(row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), row[5].ToString(), row[6].ToString(), row[7].ToString(), row[8].ToString()); } } } Thread.Sleep(1000); } catch { } } }
private void AddSRM(string scno, string ipaddress, int port, int aisle, string equipmentid, string zone) { CRNObject newcrc = new CRNObject(); GenSongSRM srm = new GenSongSRM(scno, ipaddress, port, aisle, zone); newcrc.BllSrm = srm; newcrc.ScNo = scno; newcrc.zone = zone; newcrc.IpAddress = ipaddress; newcrc.Port = port; CRNOBList.Add(newcrc); }
public bool SendTask(string num, string taskno, string fromstation, string tostation, string secfromstation, string sectostation, int type, string zone) { string msg = ""; CRNObject co = CRNOBList.Find( delegate(CRNObject info) { return(info.ScNo == num && info.zone == zone); } ); if (co != null) { if (type != 0) { return(((GenSongSRM)co.BllSrm).SendCommand(num, type, taskno, fromstation, tostation, secfromstation, sectostation)); } else { return(((GenSongSRM)co.BllSrm).SendCode(int.Parse(fromstation), int.Parse(taskno), tostation, ref msg)); } } return(false); }
//CRLConveryControl bll = new CRLConveryControl(); /// <summary> /// 更新堆垛机状态 /// </summary> /// <param name="num">堆垛机编号</param> /// <param name="str">交互信息</param> /// <param name="aisle">巷道</param> public string UpdateSCStatus(string num, string str, string aisle, string zone) { if (str.Length == 43) { num = "CRN00" + (int.Parse(str.Substring(41, 1)) + 2); aisle = str.Substring(41, 1); } if (str.Length == 17) { num = "CRN00" + (int.Parse(str.Substring(15, 1)) + 2); aisle = str.Substring(15, 1); } CRNStatus css = CRNList.Find( delegate(CRNStatus info) { return(info.CRCNum == num && info.Zone == zone); } ); if (css == null) { CRNStatus status = new CRNStatus(); status.CRCNum = num; //status.AisleNumber = aisle; status.Zone = zone; status.CraneMode = "MCT已连接"; status.CrcStatus = "Socket已连接!"; status.Position = "0000"; status.RackSide = "0"; status.RackLevel = "0"; status.FunctionReport = "112"; status.AlarmMessage = "无故障"; CRNList.Add(status); return(""); } string alarmMsg = ""; #region 关闭模式 if (str == "Break") { css.CraneMode = "MCT断开!"; css.CrcStatus = "Socket断开!"; css.Position = "0000"; css.RackSide = "0"; css.RackLevel = "0"; css.FunctionReport = "112"; css.AlarmMessage = "Socket断开!"; alarmMsg = css.AlarmMessage; css.LabelInfo = "任务号:" + css.TaskNo + ".位置:" + css.Position + ".是否在站点位置:否" + ".状态:" + alarmMsg + ".事件类型:无" + ".起止:" + css.Fromstation + "-->" + css.Tostation + ".无故障"; dal.UpdateSCStatus("SC" + (int.Parse(num.Substring(5, 1)) + 2).ToString(), "Equipment_Error"); } #endregion #region 连接 if (str == "Connect") { css.CraneMode = "MCT已连接"; css.CrcStatus = "Socket已连接!"; css.Position = "0000"; css.RackSide = "0"; css.RackLevel = "0"; css.FunctionReport = "112"; css.AlarmMessage = "无故障"; css.LabelInfo = "任务号:" + css.TaskNo + ".位置:" + css.Position + ".是否在站点位置:否" + ".MCT模式:" + css.CraneMode + ".状态:" + css.CrcStatus + ".事件类型:无" + ".货叉1起止:" + css.Fromstation + "-->" + css.Tostation + ".货叉2起止:" + css.SecFromstation + "-->" + css.SecTostation + ".无故障"; if (css.CrcStatus == "Equipment_OK") { dal.UpdateSCStatus(num, "Equipment_OK"); } } #endregion #region 返回堆垛机状态信息 else if (str.Substring(1, 2) == "LA") { //css.CraneMode = GetGenSongMode(str.Substring(3, 2)); css.CrcStatus = GetGenSongStatus(str.Substring(3, 2)); if (str.Substring(3, 2) == "02") { css.CraneMode = "可调度"; } else { css.CraneMode = "不可调度"; } css.Position = GetGenSongPosition(str.Substring(5, 6)).Replace("?", "0"); css.RackPosition = str.Substring(5, 3).Replace("?", "0"); css.RackLevel = str.Substring(8, 3).Replace("?", "0"); string stationPosistion = str.Substring(12, 1); css.AlarmMessage = "无故障"; foreach (DictionaryEntry de in AlarmHash) { if (de.Key.ToString() == str.Substring(13, 4)) { css.AlarmMessage = de.Value.ToString(); } } string eventType = GetEventType(str.Substring(17, 1)); int etype = int.Parse(str.Substring(17, 1)); css.TaskNo = str.Substring(30, 10).Replace("GOT", "000"); css.RackSide = str.Substring(26, 1); css.RackStatus = str.Substring(28, 1); //货叉1状态 1无货,2有货,3故障 css.SecRackStatus = str.Substring(29, 1); //货叉2状态 1无货,2有货,3故障 int number = int.Parse(str.Substring(40, 2)); if (etype < 2) { css.FunctionReport = CR_GETC_WAIT_H; } else if (etype == 3) { css.FunctionReport = CR_GETC_EXECUTED; } else if (etype == 4) { css.FunctionReport = CR_PUTC_PUT_RUNNING; } else if (etype == 5) { css.FunctionReport = CR_PUTC_EXECUTED; } else { css.FunctionReport = CR_GETC_WAIT_H; } css.LabelInfo = "任务号:" + css.TaskNo + ".位置:" + css.Position + ".是否在站点位置:" + (stationPosistion == "1" ? "是" : "否") + ".MCT模式:" + css.CraneMode + ".状态:" + css.CrcStatus + ".事件类型:" + eventType + ".货叉1起止:" + css.Fromstation + "-->" + css.Tostation + ".货叉2起止:" + css.SecFromstation + "-->" + css.SecTostation + "." + css.AlarmMessage; } #endregion #region 返回堆垛机动作信息 else if (str.Substring(1, 2) == "LD") { string scno = str.Substring(14, 2); string taskStatus = str.Substring(3, 1); string taskno1 = str.Substring(4, 5); string taskno2 = str.Substring(9, 5);//.TrimStart('0'); string[] taskinfo = dal.GetTostation(taskno1); string[] sectaskinfo = dal.GetTostation(taskno2); string[] stainfo = null; string[] secstainfo = null; if (taskStatus == "1")//取货完成 { if (taskinfo != null && taskinfo[0] != null && taskinfo[0].Length == 4) { dal.UpdateMiniGetState(taskno1); stainfo = new string[11];// ConveryClass.ReadStationInfo(int.Parse(taskinfo[0])); stainfo[0] = taskinfo[0]; for (int i = 1; i < 11; i++) { stainfo[i] = "0"; } ConveryClass.WriteStationInfo(stainfo); } if (sectaskinfo != null && sectaskinfo[0] != null && sectaskinfo[0].Length == 4) { dal.UpdateMiniGetState(taskno2); secstainfo = new string[11];// ConveryClass.ReadStationInfo(int.Parse(taskinfo[0])); secstainfo[0] = sectaskinfo[0]; for (int i = 1; i < 11; i++) { secstainfo[i] = "0"; } if (secstainfo[0] == "5211") { secstainfo[0] = "5011"; } if (secstainfo[0] == "5212") { secstainfo[0] = "5012"; } if (secstainfo[0] == "5215") { secstainfo[0] = "5015"; } ConveryClass.WriteStationInfo(secstainfo); } alarmMsg += num + "堆垛机取货完成:" + css.TaskNo; } else if (taskStatus == "2" || taskStatus == "4")//堆垛机放货完成 { #region 堆垛机放货完成 if (taskinfo != null && taskinfo[0] != null) { if (taskinfo[1].Length == 4)//放货到输送机 { stainfo = ConveryClass.ReadStationInfo(int.Parse(taskinfo[1])); if (int.Parse(stainfo[1]) > 0) { alarmMsg += taskinfo[1] + "站台有货物!"; } else { stainfo[1] = taskno1; stainfo[2] = "0"; stainfo[3] = "0"; stainfo[4] = "3"; //类型 件烟 stainfo[5] = taskinfo[1]; // "0"; //起始站台 taskinfo[1];// stainfo[6] = "5156"; //5156或0 stainfo[7] = "0"; stainfo[8] = "0"; stainfo[9] = "0"; stainfo[10] = "0"; if (scno == "01") { stainfo[6] = "5353"; } else if (scno == "02") { stainfo[6] = "5343"; } else if (scno == "03") { stainfo[6] = "5342"; } ConveryClass.WriteStationInfo(stainfo); if (dal.UpdateTaskStatus(taskno1, "SC", "1", "1") != "0")//堆垛机完成任务 { dal.UpdateTaskStatus(taskno1, "STA", "2", "1"); } } } else { dal.UpdateTaskStatus(taskno1, "SC", "1", "1");//堆垛机完成任务 } } if (sectaskinfo != null && sectaskinfo[0] != null) { if (sectaskinfo[1].Length == 4)//放货到输送机 { secstainfo = ConveryClass.ReadStationInfo(int.Parse(sectaskinfo[1]) + 200); if (int.Parse(secstainfo[1]) > 0) { alarmMsg += sectaskinfo[1] + "站台有货物!"; } else { secstainfo[1] = taskno2; secstainfo[2] = "0"; secstainfo[3] = "0"; secstainfo[4] = "3"; //类型 件烟 secstainfo[5] = (int.Parse(sectaskinfo[1]) + 200).ToString(); // "0"; 起始站台 secstainfo[6] = "5156"; //5156或0 secstainfo[7] = "0"; secstainfo[8] = "0"; secstainfo[9] = "0"; secstainfo[10] = "0"; if (scno == "01") { secstainfo[6] = "5353"; } else if (scno == "02") { secstainfo[6] = "5343"; } else if (scno == "03") { secstainfo[6] = "5342"; } ConveryClass.WriteStationInfo(secstainfo); if (dal.UpdateTaskStatus(taskno2, "SC", "1", "1") != "0")//堆垛机完成任务 { dal.UpdateTaskStatus(taskno2, "STA", "2", "1"); } } } else { dal.UpdateTaskStatus(taskno2, "SC", "1", "1");//堆垛机完成任务 } } #endregion if (taskinfo[1].Length == 4 && (css.CrcStatus == "无货待命" || css.CrcStatus == "无货运行" || css.CrcStatus == "有货运行" || css.CrcStatus == "有货待命")) { DataSet ds = dal.GetGSInTask(scno); if (ds != null && ds.Tables[0].Rows.Count > 0) { foreach (DataRow row in ds.Tables[0].Rows) { CRNObject co = CRNOBList.Find( delegate(CRNObject info) { return(info.ScNo == "CRN00" + row["equipmentnumber"].ToString().Substring(5, 1) && info.zone == zone); } ); if (co != null) { //((GenSongSRM)co.BllSrm).SendTask(row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), row[5].ToString()); ((GenSongSRM)co.BllSrm).SendTask(row["taskno"].ToString(), row["fromstation"].ToString(), row["tostation"].ToString(), row["sectaskno"].ToString(), row["secfromstation"].ToString(), row["sectostation"].ToString(), row["currentstation"].ToString(), row["field2"].ToString()); } } } } } else if (taskStatus == "3") { alarmMsg += "任务被取消,任务号:" + taskno1 + taskno2; } } #endregion //if (css.LabelInfo == css.OldLabelInfo) // css.Change = false; //else //{ if (str.Substring(1, 2) == "LA") { //if (str.Substring(15, 4) != "0000") string test = str.Substring(13, 4); if (str.Substring(13, 4) != "0000") { //dal.UpdateSCStatus(num, "Equipment_Error");//"SC" + int.Parse(num.Substring(5, 3)).ToString() dal.UpdateSCStatus("SC" + int.Parse(num.Substring(5, 1)).ToString(), "Equipment_Error"); alarmMsg = css.AlarmMessage; } //else //{ // dal.UpdateSCStatus("SC" + int.Parse(num.Substring(5, 1)).ToString(), "Equipment_OK"); //} //dal.UpdateSCStatus(num, "Equipment_OK"); if (str.Substring(3, 2) == "11" || str.Substring(3, 2) == "12") { dal.UpdateSCStatus("SC" + int.Parse(num.Substring(5, 1)).ToString(), "Equipment_Error"); alarmMsg = "未连接或手动状态"; } } css.OldLabelInfo = css.LabelInfo; css.Change = true; //} return(alarmMsg); }
private void OSRM_AnalyseMessageEvent(NotifyCommand command, string msg) { CRNObject findcob = CRNOBList.Find( delegate(CRNObject info) { //return (info.ScNo == m_strSRMNo && info.Port == int.Parse(m_strport) && info.zone == m_zone); return(info.ScNo == m_strSRMNo && info.Port == int.Parse(m_strport) && info.zone == m_zone); //"CRN00" + msg.Substring(41, 1) } ); try { string alarmMsg = ""; if (command == NotifyCommand.Connect) { CheckConnectTimer.Stop(); findcob.connectstatus = 1; alarmMsg = crc.UpdateSCStatus(m_strSRMNo, "Connect", m_strSRMNo.Substring(5, 1), m_zone); ShowText("C", msg); } else if (command == NotifyCommand.RecvData) { string mesgs = msg; //if (mesgs.Substring(1, 2) == "LA") //{ // //GetSCStatusTimer.Start();//建立连接结束,开始心跳检测 // mesgs.Substring(0, mesgs.Length); //} //string num = "CRN00" + (int.Parse(msg.Substring(41, 1))+2);//m_strSRMNo; string num = m_strSRMNo; if (mesgs.Substring(1, 2) == "LD") { OSRM.ReturnLDMsg(mesgs.Substring(3, 13)); } if (m_strSRMNo == "CRN006") { num = "CRN00" + mesgs.Substring(mesgs.Length - 2, 1); } alarmMsg = crc.UpdateSCStatus(num, mesgs, m_strSRMNo.Substring(5, 1), m_zone); if (!string.IsNullOrEmpty(alarmMsg)) { ShowText("", alarmMsg); if (mesgs.Substring(1, 2) != "LA") { log.WriteLog(alarmMsg); } } } else if (command == NotifyCommand.SendData) { //ShowText("", msg); } else if (command == NotifyCommand.Break) { CheckConnectTimer.Start(); alarmMsg = crc.UpdateSCStatus(m_strSRMNo, "Break", m_strSRMNo.Substring(5, 1), m_zone); findcob.connectstatus = 0; if (!string.IsNullOrEmpty(alarmMsg)) { ShowText("", alarmMsg); } } if (ENotifyTypeEventHandler != null) { ENotifyTypeEventHandler(m_strSRMNo, m_strport, "", msg); } } catch (Exception ex) { //log.WriteLog("********************************************"); //log.WriteLog("错误信息:" + ex.Message); //log.WriteLog("********************************************"); } }