protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { //object obj = ObjectUtil.GetObject(stateItem.State); //if (obj == null) // return; switch (stateItem.ItemName) { case "CraneTaskFinished": object obj = ObjectUtil.GetObject(stateItem.State); if (obj.ToString() == "50") { string TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(stateItem.Name, "CraneTaskNo"))); //存储过程处理 Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo); //更新任务状态 DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) }; bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param); WriteToService(stateItem.Name, "ReplyFinished", 49); } break; case "Run": blRun = (int)stateItem.State == 1; break; default: break; } if (blRun) { tmWorkTimer.Start(); Logger.Info("堆垛机联机"); } else { tmWorkTimer.Stop(); Logger.Info("堆垛机脱机"); } return; }
//反馈给总控WCS设备状态 //string m = "[{\"id\":\"" + id + "\",\"deviceNo\":\"" + deviceNo + "\",\"mode\":\"" + mode + "\",\"status\":\"" + status + "\",\"taskNo\":\"" + taskNo + "\",\"fork\":\"" + fork + "\",\"load\":\"" + load + "\",\"aisleNo\":\"" + aisleNo + "\",\"column\":\"" + column + "\",\"layer\":\"" + layer + "\",\"alarmCode\":\"" + alarmCode + "\",\"sendDate\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\",\"sender\":\"" + sender + "\",\"field1\":\"\",\"field2\":\"\",\"field3\":\"\"" + "}]"; #region 堆垛机监控 void Car_OnDataChanged(object sender, DataChangedEventArgs e) { if (e.State == null) { return; } if (e.ItemName == "abc") { return; } string AisleNo = e.ServerName.Substring(5, 2); string CarNo = ""; if (e.ItemName.IndexOf("CarStatus") >= 0 || e.ItemName.IndexOf("CarAlarm") >= 0 || e.ItemName.IndexOf("CarTask") >= 0) { CarNo = e.ItemName.Substring(e.ItemName.Length - 2, 2); } CarNo = AisleNo + CarNo; GetCar(CarNo); if (e.ItemName.IndexOf("CarStatus") >= 0) { dicCar[CarNo].Mode = int.Parse(e.States[0].ToString()); dicCar[CarNo].Status = int.Parse(e.States[12].ToString()); dicCar[CarNo].Row = int.Parse(e.States[1].ToString()); dicCar[CarNo].Column = int.Parse(e.States[2].ToString()); dicCar[CarNo].Layer = int.Parse(e.States[3].ToString()); dicCar[CarNo].Load = int.Parse(e.States[10].ToString()); dicCar[CarNo].ForkStatus = int.Parse(e.States[11].ToString()); } else if (e.ItemName.IndexOf("CarAlarm") >= 0) { dicCar[CarNo].AlarmCode = int.Parse(e.States[0].ToString()); } else if (e.ItemName.IndexOf("CarTask") >= 0) { dicCar[CarNo].TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(e.States)); } Cars.CarInfo(dicCar[CarNo]); }
private void tmCraneWorker1(object sender, System.Timers.ElapsedEventArgs e) { try { tmCrane1.Stop(); string binary = Convert.ToString(255, 2).PadLeft(8, '0'); string serviceName = "CranePLC1"; string plcTaskNo = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo")).ToString(); if (plcTaskNo == "0") { plcTaskNo = ""; } string craneMode = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneMode")).ToString(); string craneFork = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneFork")).ToString(); object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneAlarmCode")); Crane crane = new Crane(); crane.CraneNo = 1; crane.Row = int.Parse(obj[4].ToString()); crane.Column = int.Parse(obj[2].ToString()); crane.Height = int.Parse(obj[3].ToString()); crane.ForkStatus = int.Parse(craneFork); crane.Action = int.Parse(craneMode); crane.TaskType = int.Parse(obj[1].ToString()); crane.ErrCode = int.Parse(obj[0].ToString()); crane.PalletCode = ""; crane.TaskNo = plcTaskNo; Cranes.CraneInfo(crane); } catch (Exception ex) { Logger.Error(ex.Message); } finally { tmCrane1.Start(); } }
private void InsertCarOrder(DataTable dt, string CarNo, string WriteItem, long CurStation, string ReadItem) { object[] obj1 = ObjectUtil.GetObjects(WriteToService("StockPLC_02", ReadItem + "_1")); //小车任务号, 状态 object[] obj2 = ObjectUtil.GetObjects(WriteToService("StockPLC_02", ReadItem + "_2")); //小车位置,目标地址 //小车位置 long Position = long.Parse(obj2[0].ToString()); int Status = int.Parse(obj1[1].ToString()); //小车目的地址 long DesPosition = long.Parse(obj2[1].ToString()); if (Status != 2)//故障 { DataRow dr = dt.NewRow(); dr["CAR_NO"] = CarNo; dr["State"] = Status; //状态 dr["WriteItem"] = WriteItem; dr["CurStation"] = Position; //当前位置 if (Position <= CurStation) { dr["OrderNo"] = Position + 10000; //小车位置小于当前位置,加上最大码尺地址。 } else { dr["OrderNo"] = Position; } //目的地 dr["ToStation"] = DesPosition; //目的地址排序字段 dr["ToStationOrder"] = DesPosition; if (DesPosition < 5000) { dr["ToStationOrder"] = DesPosition + 10000;//最大码尺地址 } dt.Rows.Add(dr); } }
//任务输送到某一位置后,通知更新状态。【入库口任务到位,密集存储道穿过到位】 public override void Execute() { try { for (int i = 1; i <= count; i++) { string positionName = string.Empty; int taskID = 0; object state = AutomationContext.Read(plcServiceName, I_Task_Arrive_Process_Request + i); object obj = ObjectUtil.GetObjects(state); if (obj is Array) { Array arrayObj = (Array)obj; if (arrayObj.Length == 2) { positionName = arrayObj.GetValue(0).ToString(); taskID = Convert.ToInt32(arrayObj.GetValue(1)); } } if (positionName == string.Empty || positionName == "0" || taskID == 0) { continue; } int[] data = new int[] { Convert.ToInt32(positionName), taskID }; AutomationContext.Write(memoryServiceName, memoryItemName, data); AutomationContext.Write(plcServiceName, O_Task_Arrive_Process_Complete + i, data); Logger.Info(string.Format("TaskArriveRequest : {0}", data.ConvertToString(AutomationContext.Converters))); } } catch (Exception ex) { Logger.Error("TaskArriveRequestProcess 出错,原因:" + ex.Message + "/n" + ex.StackTrace); } }
private void tmCraneWorker2(object sender, System.Timers.ElapsedEventArgs e) { try { tmCrane2.Stop(); string serviceName = "CranePLC2"; string plcTaskNo = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo")).ToString(); string craneMode = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneMode")).ToString(); string craneFork = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneFork")).ToString(); object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneAlarmCode")); Crane crane2 = new Crane(); crane2.CraneNo = 2; crane2.Row = int.Parse(obj[4].ToString()); crane2.Column = int.Parse(obj[2].ToString()); crane2.Height = int.Parse(obj[3].ToString()); crane2.ForkStatus = int.Parse(craneFork); crane2.Action = int.Parse(craneMode); crane2.TaskType = int.Parse(obj[1].ToString()); crane2.ErrCode = int.Parse(obj[0].ToString()); crane2.PalletCode = ""; crane2.TaskNo = plcTaskNo; Cranes.CraneInfo(crane2); } catch (Exception ex) { Logger.Error("2号堆垛机监控故障:" + ex.Message); } finally { tmCrane2.Start(); } }
/// <summary> /// 检查堆垛机入库状态 /// </summary> /// <param name="piCrnNo"></param> /// <returns></returns> private bool Check_Crane_Status_IsOk(int craneNo) { string serviceName = dCrnStatus[craneNo].ServiceName; string plcTaskNo1 = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo1"))); string craneMode = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneMode")).ToString(); string CraneState1 = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneState1")).ToString(); string CraneAlarmCode = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneAlarmCode")).ToString(); string plcTaskNo2 = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo2"))); string craneState2 = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneState2")).ToString(); string CraneLoad1 = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneLoad1")).ToString(); string CraneLoad2 = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService(serviceName, "CraneLoad1")).ToString(); if (plcTaskNo1 == "" && craneMode == "1" && CraneAlarmCode == "0" && CraneState1 == "1" && plcTaskNo2 == "" && craneState2 == "1" && CraneLoad1 == "0" && CraneLoad2 == "0") { return(true); } else { return(false); } }
/// <summary> /// 检查小车入库状态 /// </summary> /// <param name="piCrnNo"></param> /// <returns></returns> private bool Check_Car_Status_IsOk(string carNo, string serviceName) { try { object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CarStatus" + carNo)); int CarMode = int.Parse(obj[0].ToString()); int State = int.Parse(obj[12].ToString()); //int CraneAlarmCode = int.Parse(obj[0].ToString()); if (CarMode == 1 && State == 0) { return(true); } else { return(false); } } catch (Exception ex) { Logger.Error("检查小车" + carNo + "状态时出现错误:" + ex.Message); return(false); } }
/// <summary> /// 小车出库是否准备好 /// </summary> /// <param name="piCrnNo"></param> /// <returns></returns> private bool Check_Car_In_Status_IsOk(string carNo) { try { string itemName = carNo + "_CarInfo"; int[] carInfo = new int[6]; object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", itemName)); for (int j = 0; j < 6; j++) { carInfo[j] = Convert.ToInt16(obj[j]) - 48; } itemName = carNo + "_CarTaskInfo"; obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", itemName)); object[] taskNo = new object[10]; for (int j = 0; j < 10; j++) { taskNo[j] = obj[j]; } if (carInfo[0] == 1 && carInfo[2] == 2 && carInfo[4] == 0) { return(true); } else { return(false); } } catch (Exception ex) { Logger.Error(ex.Message); return(false); } }
/// <summary> /// 判断能否给小车下任务 /// </summary> /// <param name="dt"></param> /// <param name="carNo"></param> /// <param name="carToLayer"></param> /// <returns></returns> private bool CheckOtherCarStatus(DataTable dt, string carNo, int carFromLayer, int carToLayer, int carTaskType, object[] carobj) { int carLayer = int.Parse(carobj[3].ToString()); int carColumn = int.Parse(carobj[2].ToString()); bool carOK = true; for (int i = 0; i < dt.Rows.Count; i++) { string DeviceNo = dt.Rows[i]["DeviceNo"].ToString(); string serviceName = dt.Rows[i]["ServiceName"].ToString(); if (DeviceNo != carNo) { //读取小车状态 object[] obj = ObjectUtil.GetObjects(WriteToService(serviceName, "CarStatus" + carNo)); object[] obj1 = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "WriteFinished")); object[] obj2 = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "TaskAddress")); int TaskFlag = int.Parse(obj1[0].ToString()); int OpMode = int.Parse(obj[0].ToString()); int Column = int.Parse(obj[2].ToString()); int Layer = int.Parse(obj[3].ToString()); int FromColumn = int.Parse(obj[5].ToString()); int FromLayer = int.Parse(obj[6].ToString()); int ToLayer = int.Parse(obj[9].ToString()); int ToColumn = int.Parse(obj[5].ToString()); int TaskType = int.Parse(obj[12].ToString()); //如果出库站台有任务,不下发出库任务 if (TaskType == 11) { //string TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("TranLine", "ConveyorInfo11"))); //if (TaskNo.Length > 0) // return false; } //防止读到PLC目标层不准,读到标识还没移走,那么读上位机下发的目标层 if (TaskFlag == 1) { ToLayer = int.Parse(obj2[8].ToString()); } //Logger.Debug("小车" + dicCars[i].CarNo + "目标层" + ToLayer + "当前层:" + Layer + ",任务类型:" + TaskType); //入库类型 if (carTaskType == 11) { //1入库站台不能有车 if (Layer == 1 && Column == 0) { carOK = false; break; } //2其他车任务起始层也在这层,但车不在这层 if (carFromLayer == FromLayer && Layer > 1 && TaskType > 0) { carOK = false; break; } //3其他车任务目标层在起始层 出库 if (carFromLayer == ToLayer && carColumn > 0 && TaskType == 11) { carOK = false; break; } //4其他车任务目标层在起始层 if (carFromLayer == ToLayer && carColumn > 0 && Layer > 1 && TaskType == 9) { carOK = false; break; } //4目标层有车 if (carToLayer == Layer) { carOK = false; break; } //6目标层有任务起始层 if (carToLayer == FromLayer) { carOK = false; break; } } if (carTaskType == 12) { //1站台不能有车 if (Layer == 1 && Column == 0) { carOK = false; break; } //起始层有车 if (carFromLayer == Layer) { carOK = false; break; } //其他车任务起始层也在这层 if (carFromLayer == FromLayer && carFromLayer != carLayer && TaskType > 0) { carOK = false; break; } //其他车任务目标层在起始层 if (carFromLayer == ToLayer && ToColumn > 0 && TaskType > 0) { carOK = false; break; } //目标层有车 if (carToLayer == Layer && Column == 0) { carOK = false; break; } //目标层有任务起始层 //if (FromLayer == 1 && FromColumn == 0) //{ // carOK = false; // break; //} } if (carTaskType == 13) { //1站台不能有车 if (Layer == 1 && Column == 0) { carOK = false; break; } //起始层有车 if (carFromLayer == Layer) { carOK = false; break; } //其他车任务起始层也在这层 if (carFromLayer == FromLayer && TaskType > 0) { carOK = false; break; } //其他车任务目标层在起始层 if (carFromLayer == ToLayer && TaskType > 0) { carOK = false; break; } //目标层有车 if (carToLayer == Layer) { carOK = false; break; } //目标层有任务起始层 if (carToLayer == FromLayer && TaskType > 0) { carOK = false; break; } //目标层有任务目标层 if (carToLayer == ToLayer && TaskType > 0) { carOK = false; break; } } } } return(carOK); }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { switch (stateItem.ItemName) { case "TaskFinished01": case "TaskFinished02": object[] obj = ObjectUtil.GetObjects(stateItem.State); if (obj == null) { return; } string TaskNo = ConvertStringChar.BytesToString(obj); { //存储过程处理 if (TaskNo.Length > 0) { byte[] b = new byte[30]; ConvertStringChar.stringToByte("", 30).CopyTo(b, 0); WriteToService(stateItem.Name, stateItem.ItemName, b); Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo); DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) }; bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param); } //上报总控WCS,下架完成 } break; case "CarAlarm01": case "CarAlarm02": object obj1 = ObjectUtil.GetObject(stateItem.State); if (obj1 == null) { return; } if (obj1.ToString() != "0") { string strError = ""; DataRow[] drs = dtDeviceAlarm.Select(string.Format("Flag=2 and AlarmCode={0}", obj1.ToString())); if (drs.Length > 0) { strError = drs[0]["AlarmCode"].ToString(); } else { strError = "穿梭车未知错误!"; } Logger.Error(strError); } break; case "ElevatorAlarm": object obj2 = ObjectUtil.GetObject(stateItem.State); if (obj2 == null) { return; } if (obj2.ToString() != "0") { string strError = ""; DataRow[] drs = dtDeviceAlarm.Select(string.Format("Flag=3 and AlarmCode={0}", obj2.ToString())); if (drs.Length > 0) { strError = drs[0]["AlarmCode"].ToString(); } else { strError = "提升机未知错误!"; } Logger.Error(strError); } break; case "Run": blRun = (int)stateItem.State == 1; if (blRun) { tmWorkTimer.Start(); Logger.Info("提升机联机"); } else { tmWorkTimer.Stop(); Logger.Info("提升机脱机"); } break; default: break; } return; }
//获取小车让车可去的空闲的层 private int GetNoTaskLayer(DataTable dt, string carNo) { int NoTaskLayer = 0; for (int k = 1; k < 11; k++) { NoTaskLayer = k; bool isExist = false; for (int i = 0; i < dt.Rows.Count; i++) { string DeviceNo = dt.Rows[i]["DeviceNo"].ToString(); string serviceName = dt.Rows[i]["ServiceName"].ToString(); if (DeviceNo != carNo) { //读取小车状态 object[] obj = ObjectUtil.GetObjects(WriteToService(serviceName, "CarStatus" + carNo)); object[] obj1 = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "WriteFinished")); object[] obj2 = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "TaskAddress")); int TaskFlag = int.Parse(obj1[0].ToString()); int Layer = int.Parse(obj[3].ToString()); int FromLayer = int.Parse(obj[5].ToString()); int FromColumn = int.Parse(obj[4].ToString()); int ToLayer = int.Parse(obj[9].ToString()); int Column = int.Parse(obj[2].ToString()); int ToColumn = int.Parse(obj[8].ToString()); int TaskType = int.Parse(obj[12].ToString()); if (TaskFlag == 1) { FromLayer = int.Parse(obj[5].ToString()); FromColumn = int.Parse(obj[4].ToString()); ToLayer = int.Parse(obj2[8].ToString()); } if (k == 1) { if (FromColumn > 0 && FromLayer == k) { isExist = true; } if (ToLayer == k && ToColumn > 0) { isExist = true; } if (Layer == k) { isExist = true; } } else { if (FromLayer == k || ToLayer == k || Layer == k) { isExist = true; } } if (isExist) { break; } } } if (isExist) { continue; } else { break; } } return(NoTaskLayer); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tmWorker(object sender, ElapsedEventArgs e) { try { if (!blRun) { tmWorkTimer.Stop(); return; } tmWorkTimer.Stop(); DataTable dtAisle = bll.FillDataTable("CMD.SelectAisleElevator", new DataParameter[] { new DataParameter("{0}", string.Format("WarehoseCode='{0}'", Program.WarehouseCode)) }); for (int i = 0; i < dtAisle.Rows.Count; i++) { string serviceName = dtAisle.Rows[i]["ServiceName2"].ToString(); string AisleNo = dtAisle.Rows[i]["AisleNo"].ToString(); string filter = string.Format("WarehoseCode='{0}' and AisleNo='{1}'", Program.WarehouseCode, AisleNo); DataTable dtTask = GetTask(AisleNo); DataTable dtCar = bll.FillDataTable("CMD.SelectAisleCar", new DataParameter[] { new DataParameter("{0}", filter) }); for (int j = 0; j < dtCar.Rows.Count; j++) { //读取小车状态 string carNo = dtCar.Rows[j]["DeviceNo2"].ToString(); carNo = carNo.Substring(carNo.Length - 2, 2); object[] obj = ObjectUtil.GetObjects(WriteToService(serviceName, "CarStatus" + carNo)); int Column = int.Parse(obj[2].ToString()); int Layer = int.Parse(obj[3].ToString()); //如果小车空闲、在出入库站台位置,先找入库任务 if (Check_Car_Status_IsOk(carNo, serviceName)) { filter = string.Format("AisleNo='{0}'", AisleNo); bool IsSent = false; //Column=0表示在入库站台位置 if (Layer == 1 && Column <= 0) { //先找入库任务 IsSent = FindInTask(dtCar, dtTask, carNo, obj); if (IsSent) { continue; } //再找出库任务 IsSent = FindOutTask(dtCar, dtTask, carNo, obj); if (IsSent) { continue; } } else { //先找出库任务 IsSent = FindOutTask(dtCar, dtTask, carNo, obj); if (IsSent) { continue; } //再找入库任务 IsSent = FindInTask(dtCar, dtTask, carNo, obj); if (IsSent) { continue; } } if (!IsSent && Column <= 0) { //小车空闲,需要避开 //找出其他车所在层以及目标层 //如果其他车都空闲,则不需要避开 //if(GetOtherCarNoTask(dt,carNo)) // return; int ToLayer = GetNoTaskLayer(dtCar, carNo); if (ToLayer > 0) { Send2PLC2(serviceName, carNo, "001001" + (1000 + ToLayer).ToString().Substring(1, 3)); } } } } } } finally { tmWorkTimer.Start(); } }
private void tmCarWorker(object sender, System.Timers.ElapsedEventArgs e) { try { tmCar.Stop(); int[] carInfo = new int[6]; object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", "01_CarInfo")); for (int j = 0; j < 6; j++) { carInfo[j] = Convert.ToInt16(obj[j]) - 48; } obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", "01_CarTaskInfo")); string TaskNo = Util.ConvertStringChar.BytesToString(obj); Car car1 = new Car(); car1.CarNo = 1; car1.Load = carInfo[0]; car1.Status = carInfo[2]; car1.TaskType = carInfo[3]; car1.ErrCode = carInfo[4]; car1.Action = carInfo[5]; car1.TaskNo = TaskNo; Cars.CarInfo(car1); obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", "02_CarInfo")); for (int j = 0; j < 6; j++) { carInfo[j] = Convert.ToInt16(obj[j]) - 48; } obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", "02_CarTaskInfo")); TaskNo = Util.ConvertStringChar.BytesToString(obj); Car car2 = new Car(); car2.CarNo = 2; car2.Load = carInfo[0]; car2.Status = carInfo[2]; car2.TaskType = carInfo[3]; car2.ErrCode = carInfo[4]; car2.Action = carInfo[5]; car2.TaskNo = TaskNo; Cars.CarInfo(car2); obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", "03_CarInfo")); for (int j = 0; j < 6; j++) { carInfo[j] = Convert.ToInt16(obj[j]) - 48; } obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("CarPLC", "03_CarTaskInfo")); TaskNo = Util.ConvertStringChar.BytesToString(obj); Car car3 = new Car(); car3.CarNo = 3; car3.Load = carInfo[0]; car3.Status = carInfo[2]; car3.TaskType = carInfo[3]; car3.ErrCode = carInfo[4]; car3.Action = carInfo[5]; car3.TaskNo = TaskNo; Cars.CarInfo(car3); } catch (Exception ex) { Logger.Error(ex.Message); } finally { tmCar.Start(); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { switch (stateItem.ItemName) { case "101_TaskNo": object[] obj = ObjectUtil.GetObjects(stateItem.State); if (obj == null) { return; } string TaskNo = obj[0].ToString() + obj[1].ToString().PadLeft(4, '0') + obj[2].ToString().PadLeft(4, '0'); if (TaskNo.Length > 0) { string StationNo = stateItem.ItemName.Substring(0, 3); string PalletBarcode = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(stateItem.Name, StationNo + "_RPalletCode"))); try { DataParameter[] param = new DataParameter[] { new DataParameter("{0}", "State='2',Covey_FinishDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", TaskNo)) }; bll.ExecNonQueryTran("WCS.UpdateTaskState", param); Logger.Info("任务号:" + TaskNo + " 聊箱号:" + PalletBarcode + " 到达入库站台:" + StationNo); } catch (Exception ex) { Logger.Error("InStockToStationProcess出错,原因:" + ex.Message); } } break; case "TaskNo": string ReadTaskNo = stateItem.State.ToString(); //下达输送线入库任务 try { DataParameter[] parameter = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskType='11'and WCS_Task.State='0' and TaskNo='{0}'", ReadTaskNo)) }; DataTable dt = bll.FillDataTable("WCS.SelectTask", parameter); if (dt.Rows.Count > 0) { string ConveyID = dt.Rows[0]["ConveyFromStation"].ToString(); string PalletCode = dt.Rows[0]["PalletCode"].ToString(); string Destination = dt.Rows[0]["ConveyToStation"].ToString(); int[] iTaskNo = new int[3]; iTaskNo[0] = int.Parse(ReadTaskNo.Substring(0, 2)); iTaskNo[1] = int.Parse(ReadTaskNo.Substring(2, 4)); iTaskNo[2] = int.Parse(ReadTaskNo.Substring(6, 4)); WriteToService(ConveyServer, ConveyID + "_WTaskNo", iTaskNo); WriteToService(ConveyServer, ConveyID + "_WPalletCode", PalletCode); WriteToService(ConveyServer, ConveyID + "_Destination", Destination); //目的地 if (WriteToService(ConveyServer, ConveyID + "_WriteFinished", 1)) { bll.ExecNonQuery("WCS.UpdateTaskState", new DataParameter[] { new DataParameter("{0}", "State=1,Convey_StartDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", ReadTaskNo)) }); Logger.Info("任务号:" + ReadTaskNo + " 料箱号:" + PalletCode + " 已下输送线:" + ConveyID + " 目的地址:" + Destination); } } } catch (Exception ex) { Logger.Error("InStockToStationProcess出错,下达输送入库任务出错,原因:" + ex.Message); } break; } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { /* * 一楼入库货位申请 */ try { string FromStation = ""; string writeItem = ""; string ToStation = ""; string TaskID = ""; object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null || obj.ToString() == "0") { return; } string BarCode = ""; //读取PLC,获得产品编码 switch (stateItem.ItemName) { case "01_1_218_1": FromStation = "210"; ToStation = "218"; writeItem = "01_2_218_"; BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_01", "01_1_218_2"))); break; case "01_1_110_1": FromStation = "101"; ToStation = "110"; writeItem = "01_2_110_"; BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_01", "01_1_110_2"))); break; case "01_1_126_1": FromStation = "124"; ToStation = "126"; writeItem = "01_2_126_"; BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_01", "01_1_126_2"))); break; case "01_1_131": //空托盘组盘入 PalletBillDal Billdal = new PalletBillDal(); TaskID = Billdal.CreatePalletInBillTask(true); //空托盘组入库单,生成Task. FromStation = "124"; ToStation = "131"; writeItem = "01_2_131_"; break; case "PllateInRequest": break; } string strWhere = ""; if (TaskID == "") { strWhere = string.Format("PRODUCT_BARCODE='{0}'", BarCode); } else { strWhere = string.Format("TASK_ID='{0}'", TaskID); } TaskDal dal = new TaskDal(); //分配货位,返回 0:TaskID,1:货位 string[] CellValue = dal.AssignCell(strWhere, ToStation);//货位申请 //返回任务号9999 string TaskNo = dal.InsertTaskDetail(CellValue[0]); SysStationDal sysDal = new SysStationDal(); //获取task_detail行走路线item_no=3的信息,也就是堆垛机取货入库的动作 DataTable dt = sysDal.GetSationInfo(CellValue[1], "11", "3"); DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", CellValue[0])); //更新任务开始执行 dal.UpdateTaskState(CellValue[0], "1"); //更新Product_State 货位 ProductStateDal StateDal = new ProductStateDal(); StateDal.UpdateProductCellCode(CellValue[0], CellValue[1]); //更新货位申请起始地址及目标地址。 dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CellValue[0])); //0:任务号 1:目标地址 2:货物类型 int[] ServiceW = new int[3]; ServiceW[0] = int.Parse(TaskNo); // ServiceW[1] = int.Parse(dt.Rows[0]["STATION_NO"].ToString()); if (stateItem.ItemName == "01_1_131") { ServiceW[2] = 2; } else { ServiceW[2] = 1; } //PLC写入任务 WriteToService("StockPLC_01", writeItem + "1", ServiceW); if (stateItem.ItemName == "01_1_131") { WriteToService("StockPLC_01", writeItem + "2", 1); } else { byte[] b = new byte[110]; Common.ConvertStringChar.stringToByte(dtTask.Rows[0]["PALLET_CODE"].ToString(), 110).CopyTo(b, 0); //写入RFID WriteToService("StockPLC_01", writeItem + "2", b); //标识位置1 WriteToService("StockPLC_01", writeItem + "3", 1); } BillDal Bdal = new BillDal(); Bdal.UpdateBillMasterStart(dtTask.Rows[0]["BILL_NO"].ToString(), ServiceW[2] == 1 ? true : false); dal.UpdateTaskDetailStation(ToStation, dt.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", CellValue[0]));//更新货位到达入库站台, } catch (Exception e) { Logger.Error("THOK.XC.Process.Process_01.StockInRequestProcess:" + e.Message); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tmWorker(object sender, ElapsedEventArgs e) { try { tmWorkTimer.Stop(); DataParameter[] parameter = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_TASK.WarehouseCode = '{0}' and ((WCS_TASK.TaskType in('11') and WCS_TASK.State='2') or (WCS_TASK.TaskType in('12','13') and WCS_TASK.State='0'))", Program.WarehouseCode)) }; DataTable dt = bll.FillDataTable("WCS.SelectTask", parameter); DataTable dtAisle = bll.FillDataTable("CMD.SelectAisleDevice", new DataParameter[] { new DataParameter("{0}", string.Format("S1.WarehouseCode = '{0}'", Program.WarehouseCode)) }); for (int i = 0; i < dtAisle.Rows.Count; i++) { //查找可用设备 string DeviceNo = dtAisle.Rows[i]["DeviceNo"].ToString(); string ServiceName = dtAisle.Rows[i]["ServiceName"].ToString(); //没有可用设备 if (DeviceNo.Trim().Length <= 0) { continue; } //设备状态不符合 if (!Check_Device_Status_IsOk(ServiceName)) { continue; } //查找入库任务>2的先执行 string filter = string.Format("AisleNo='{0}' and TaskType='11' and State in('1','2')", dtAisle.Rows[i]["AisleNo"].ToString()); DataRow[] drs = dt.Select(filter, "State"); if (drs.Length > InTaskCount) { if (drs[0]["State"].ToString() == "2") { DataRow dr = drs[0]; Send2PLC(dr); continue; } //找到任务再找可以执行的设备 } else //再按优先等级排序 { filter = string.Format("AisleNo='{0}' and TaskType in('12','13') and State in('0')", dtAisle.Rows[i]["AisleNo"].ToString()); drs = dt.Select(filter, "TaskLevel,TaskNo"); if (drs.Length > 0) { if (drs[0]["TaskType"].ToString() == "13") { DataRow dr = drs[0]; Send2PLC(dr); continue; } else { int stationNo = int.Parse(drs[0]["StationNo"].ToString().Substring(2, 1)); object[] obj = ObjectUtil.GetObjects(WriteToService(ServiceName, "OtherStatus")); //判断出库站台无货 if (obj[2 + stationNo].ToString() == "1") { DataRow dr = drs[0]; Send2PLC(dr); continue; } } } } filter = string.Format("AisleNo='{0}' and TaskType='11' and State in('2')", dtAisle.Rows[i]["AisleNo"].ToString()); drs = dt.Select(filter, "State"); if (drs.Length > 0) { DataRow dr = drs[0]; Send2PLC(dr); continue; } } } finally { tmWorkTimer.Start(); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { try { string TaskNo = ""; switch (stateItem.ItemName) { case "TaskFinish": object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null) { return; } string TaskFinish = obj.ToString(); if (TaskFinish.Equals("True") || TaskFinish.Equals("1")) { TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(stateItem.Name, "ReadTaskNo"))); DataParameter[] para = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskNo='{0}'", TaskNo)) }; DataTable dt = bll.FillDataTable("WCS.SelectTask", para); string TaskType = ""; if (dt.Rows.Count > 0) { TaskType = dt.Rows[0]["TaskType"].ToString(); } //存储过程处理 if (TaskNo != "") { Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo); //更新任务状态 List <string> comds = new List <string>(); List <DataParameter[]> paras = new List <DataParameter[]>(); comds.Add("WCS.Sp_TaskProcess"); para = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) }; paras.Add(para); bll.ExecTran(comds.ToArray(), paras); //清除堆垛机任务号 sbyte[] taskNo = new sbyte[20]; for (int i = 0; i < 20; i++) { taskNo[i] = 32; } //Util.ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0); WriteToService(stateItem.Name, "TaskNo", taskNo); Send2MJWcs(3, TaskNo); } } break; case "ACK": obj = ObjectUtil.GetObject(stateItem.State); if (obj == null) { return; } string ack = obj.ToString(); if (ack.Equals("True") || ack.Equals("1")) { WriteToService(stateItem.Name, "STB", 0); } break; case "AlarmCode": obj = ObjectUtil.GetObject(stateItem.State); if (obj == null) { return; } string DeviceNo = stateItem.Name.Substring(3, 4); string AlarmCode = obj.ToString(); string AlarmDesc = ""; if (AlarmCode != "0") { DataRow[] drs = dtDeviceAlarm.Select(string.Format("AlarmCode={0}", AlarmCode)); if (drs.Length > 0) { AlarmDesc = drs[0]["AlarmDesc"].ToString(); } else { AlarmDesc = "堆垛机未知错误!"; } //更新任务报警 TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(stateItem.Name, "ReadTaskNo"))); if (TaskNo.Length > 0) { DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo), new DataParameter("@AlarmCode", obj), new DataParameter("@AlarmDesc", AlarmDesc) }; bll.ExecNonQueryTran("WCS.UpdateTaskDeviceAlarm", param); Send2MJWcs(2, TaskNo); } Logger.Error("设备编号" + DeviceNo + "发生报警,代号:" + obj.ToString() + ";描述:" + AlarmDesc); } DataParameter[] paramb = new DataParameter[] { new DataParameter("@AlarmCode", obj), new DataParameter("@DeviceNo", DeviceNo) }; bll.ExecNonQueryTran("WCS.UpdateDeviceAlarm", paramb); //上报设备状态 SendDeviceStatus(stateItem.Name, AlarmDesc); break; case "Run": blRun = (int)stateItem.State == 1; if (blRun) { tmWorkTimer.Start(); Logger.Info("堆垛机联机"); } else { tmWorkTimer.Stop(); Logger.Info("堆垛机脱机"); } break; default: break; } } catch (Exception ex) { Logger.Error("CraneProcess StateChanged方法出错,原因:" + ex.Message); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { switch (stateItem.ItemName) { case "TaskFinished01": case "TaskFinished02": object[] obj = ObjectUtil.GetObjects(stateItem.State); if (obj == null) { return; } string TaskNo = ConvertStringChar.BytesToString(obj); //存储过程处理 if (TaskNo.Length > 0) { DataParameter[] para = new DataParameter[] { new DataParameter("{0}", string.Format("Task.TaskNo='{0}'", TaskNo)) }; DataTable dt = bll.FillDataTable("WCS.SelectElevatorTask", para); if (dt.Rows.Count > 0) { string TaskType = dt.Rows[0]["TaskType"].ToString(); if (TaskType == "12") { bll.ExecNonQuery("WCS.UpdateCellEmpty", new DataParameter[] { new DataParameter("@CellCode", dt.Rows[0]["CellCode"].ToString()) }); bll.ExecNonQuery("WCS.UpdateTaskByFilter", new DataParameter[] { new DataParameter("{0}", "State=11,Car_FinishDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", TaskNo)) }); } else { DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) }; bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param); } } byte[] b = new byte[30]; ConvertStringChar.stringToByte("", 30).CopyTo(b, 0); WriteToService(stateItem.Name, stateItem.ItemName, b); Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo); } break; case "Run": blRun = (int)stateItem.State == 1; if (blRun) { tmWorkTimer.Start(); Logger.Info("换层提升机联机"); } else { tmWorkTimer.Stop(); Logger.Info("换层提升机脱机"); } break; default: break; } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { try { object obj = ObjectUtil.GetObject(stateItem.State); //if (obj == null) // return; switch (stateItem.ItemName) { case "CraneTaskFinished": obj = ObjectUtil.GetObject(stateItem.State); if (obj.ToString() == "2") { string TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(stateItem.Name, "CraneTaskNo"))); //存储过程处理 Logger.Info(stateItem.ItemName + "完成标志,任务号:" + TaskNo); sbyte[] taskNo = new sbyte[10]; Util.ConvertStringChar.stringToBytes("", 10).CopyTo(taskNo, 0); Context.ProcessDispatcher.WriteToService(stateItem.Name, "TaskNo", taskNo); //更新任务状态 DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo) }; bll.ExecNonQueryTran("WCS.Sp_TaskProcess", param); WriteToService(stateItem.Name, "ReplyFinished", 1); } break; case "Run": blRun = (int)stateItem.State == 1; if (blRun) { tmWorkTimer.Start(); Logger.Info("堆垛机联机"); } else { tmWorkTimer.Stop(); Logger.Info("堆垛机脱机"); } break; default: break; } } catch (System.Data.SqlClient.SqlException e) { //如果是存储过程名称是PROC_NAME,而且State是数据库中设置的一个值 如:66 //则该异常就是我们需要特殊处理的一个异常 if (e.Procedure.Equals("Sp_CreateInTask") && e.State == 1) { Logger.Error("Dispatching.Process.StockInToStationProcess:" + e.Message); } } catch (Exception e) { Logger.Error("Dispatching.Process.StockInToStationProcess:" + e.Message); } }
/// <summary> /// /// </summary> /// <param name="craneNo"></param> private void CraneIn(int craneNo) { // 判断堆垛机的状态 自动 空闲 try { //切换入库优先 dCrnStatus[craneNo].io_flag = 0; //判断堆垛机 if (!Check_Crane_Status_IsOk(craneNo)) { return; } } catch (Exception e) { //Logger.Debug("Crane out 状态检查错误:" + e.Message.ToString()); return; } string serviceName = "CranePLC" + craneNo; int[] craneInfo = new int[6]; object[] obj = ObjectUtil.GetObjects(WriteToService(serviceName, "CraneInfo")); obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo")); string plcTaskNo = Util.ConvertStringChar.BytesToString(obj); string CraneNo = "0" + craneNo.ToString(); //获取任务,排序优先等级、任务时间 DataParameter[] parameter = new DataParameter[] { new DataParameter("{0}", string.Format("((WCS_Task.TaskType='11' and WCS_Task.State='0') or (WCS_Task.TaskType='14' and WCS_Task.State='5')) and WCS_Task.CraneNo='{0}'", CraneNo)) }; DataTable dt = bll.FillDataTable("WCS.SelectTask", parameter); //出库 if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; string TaskNo = dr["TaskNo"].ToString(); string BillID = dr["BillID"].ToString(); int CraneErrCode = byte.Parse(dr["CraneErrCode"].ToString()); byte taskType = byte.Parse(dt.Rows[0]["TaskType"].ToString().Substring(1, 1)); string fromStation = dt.Rows[0]["FromStation"].ToString(); string toStation = dt.Rows[0]["ToStation"].ToString(); //如果重入,需要重新下任务需判断堆垛机任务号跟当前要下的任务号是否一致,如不一致不能下达 if (plcTaskNo != "" && TaskNo != plcTaskNo.Trim()) { return; } if (plcTaskNo.Length > 0) { if (CraneErrCode == 5 || CraneErrCode == 15) { taskType = 5; } } byte[] cellAddr = new byte[8]; cellAddr[0] = taskType; cellAddr[1] = 0; //0-不允许伸叉,1-允许伸叉 cellAddr[2] = byte.Parse(fromStation.Substring(0, 3)); cellAddr[3] = byte.Parse(fromStation.Substring(3, 3)); cellAddr[4] = byte.Parse(fromStation.Substring(6, 3)); cellAddr[5] = byte.Parse(toStation.Substring(0, 3)); cellAddr[6] = byte.Parse(toStation.Substring(3, 3)); cellAddr[7] = byte.Parse(toStation.Substring(6, 3)); sbyte[] palletBarcode = new sbyte[8]; Util.ConvertStringChar.stringToBytes(dr["PalletCode"].ToString(), 8).CopyTo(palletBarcode, 0); sbyte[] taskNo = new sbyte[10]; Util.ConvertStringChar.stringToBytes(dr["TaskNo"].ToString(), 10).CopyTo(taskNo, 0); WriteToService(serviceName, "TaskAddress", cellAddr); WriteToService(serviceName, "PalletCode", palletBarcode); WriteToService(serviceName, "TaskNo", taskNo); WriteToService(serviceName, "ProductType", 1); if (WriteToService(serviceName, "WriteFinished", 1)) { string State = "1"; if (taskType == 4) { State = "6"; } //更新任务状态为执行中 bll.ExecNonQuery("WCS.UpdateTaskTimeByTaskNo", new DataParameter[] { new DataParameter("@State", State), new DataParameter("@TaskNo", TaskNo) }); //bll.ExecNonQuery("WCS.UpdateBillStateByBillID", new DataParameter[] { new DataParameter("@State", 3), new DataParameter("@BillID", BillID) }); } Logger.Info("任务:" + dr["TaskNo"].ToString() + "已下发给" + craneNo + "堆垛机;起始地址:" + fromStation + ",目标地址:" + toStation); } }
/// <summary> /// /// </summary> /// <param name="craneNo"></param> private void CraneOut(int craneNo) { // 判断堆垛机的状态 自动 空闲 //Logger.Debug("判断堆垛机" + piCrnNo.ToString() + "能否出库"); try { //切换入库优先 dCrnStatus[craneNo].io_flag = 1; //判断堆垛机 if (!Check_Crane_Status_IsOk(craneNo)) { //Logger.Info("堆垛机状态不符合出库"); return; } } catch (Exception e) { Logger.Debug("Crane out 状态检查错误:" + e.Message.ToString()); return; } string serviceName = "CranePLC" + craneNo; int[] craneInfo = new int[6]; object[] obj = ObjectUtil.GetObjects(WriteToService(serviceName, "CraneInfo")); obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(serviceName, "CraneTaskNo")); string plcTaskNo = Util.ConvertStringChar.BytesToString(obj); string StationLoad = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService("ConveyorPLC1", "OutStationLoad")).ToString(); //判断出库站台无货 if (StationLoad.Equals("False") || StationLoad.Equals("0")) { Logger.Info("出库站台有货不符合堆垛机出库"); return; } //判断出库计数器 //object objCount = ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService("ConveyorPLC2", "NoBackPalletCount")); //int count = int.Parse(objCount.ToString()); //if (count > BalanceCounter) // return; string CraneNo = "0" + craneNo.ToString(); //获取任务,排序优先等级、任务时间 DataParameter[] parameter = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskType in ('12','13','14') and WCS_Task.State='0' and WCS_Task.CraneNo='{0}'", CraneNo)) }; DataTable dt = bll.FillDataTable("WCS.SelectTask", parameter); //出库 if (dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; //string carNo = dr["CarNo"].ToString(); string TaskNo = dr["TaskNo"].ToString(); string BillID = dr["BillID"].ToString(); int CraneErrCode = byte.Parse(dr["CraneErrCode"].ToString()); byte taskType = byte.Parse(dt.Rows[0]["TaskType"].ToString().Substring(1, 1)); string fromStation = dt.Rows[0]["FromStation"].ToString(); string toStation = dt.Rows[0]["ToStation"].ToString(); if (plcTaskNo != "" && TaskNo != plcTaskNo.Trim()) { return; } if (plcTaskNo.Length > 0) { if (CraneErrCode == 6 || CraneErrCode == 16) { taskType = 6; } } byte[] cellAddr = new byte[8]; cellAddr[0] = taskType; cellAddr[1] = 0; //0-不允许伸叉,1-允许伸叉 cellAddr[2] = byte.Parse(fromStation.Substring(0, 3)); cellAddr[3] = byte.Parse(fromStation.Substring(3, 3)); cellAddr[4] = byte.Parse(fromStation.Substring(6, 3)); cellAddr[5] = byte.Parse(toStation.Substring(0, 3)); cellAddr[6] = byte.Parse(toStation.Substring(3, 3)); cellAddr[7] = byte.Parse(toStation.Substring(6, 3)); sbyte[] palletBarcode = new sbyte[8]; Util.ConvertStringChar.stringToBytes(dr["PalletCode"].ToString(), 8).CopyTo(palletBarcode, 0); sbyte[] taskNo = new sbyte[10]; Util.ConvertStringChar.stringToBytes(dr["TaskNo"].ToString(), 10).CopyTo(taskNo, 0); WriteToService(serviceName, "TaskAddress", cellAddr); WriteToService(serviceName, "PalletCode", palletBarcode); WriteToService(serviceName, "TaskNo", taskNo); WriteToService(serviceName, "ProductType", 1); if (WriteToService(serviceName, "WriteFinished", 1)) { //更新任务状态为执行中 bll.ExecNonQuery("WCS.UpdateTaskTimeByTaskNo", new DataParameter[] { new DataParameter("@State", 1), new DataParameter("@TaskNo", TaskNo) }); //bll.ExecNonQuery("WCS.UpdateBillStateByBillID", new DataParameter[] { new DataParameter("@State", 3), new DataParameter("@BillID", BillID) }); } Logger.Info("任务:" + dr["TaskNo"].ToString() + "已下发给" + craneNo + "堆垛机;起始地址:" + fromStation + ",目标地址:" + toStation); } }
private string GetLedMessage(string LedNo, string ItemNo, StateItem item) { string strMsg = ""; try { string Stock = "外盘:"; if (int.Parse(ItemNo) % 2 == 0) { Stock = "内盘:"; } string PalletCode = ""; string CellCode = " 位:"; string CraneErrorNo = "0"; if (int.Parse(LedNo) % 2 == 0 && int.Parse(ItemNo) % 2 == 0) { int CarNo = int.Parse(LedNo) / 2; CraneErrorNo = ObjectUtil.GetObject(WriteToService("CranePLC" + CarNo, "nAlarmCode")).ToString(); } if (CraneErrorNo != "0") { string ErrMsg = "堆垛机未知错误"; DataRow[] drs = dtCraneError.Select(string.Format("warncode='{0}'", CraneErrorNo)); if (drs.Length > 0) { ErrMsg = drs[0]["WARNDESC"].ToString(); } strMsg = ErrMsg; } else { object[] obj = ObjectUtil.GetObjects(WriteToService(StockPLC, ItemNo + "_TaskNo")); byte[] berr = new byte[1]; berr[0] = byte.Parse(obj[26].ToString()); string sTaskno = Util.ConvertStringChar.BytesToString(obj).PadLeft(27, ' '); string errorNo = Util.ConvertStringChar.BytesToString(berr); if (errorNo != "0" && errorNo.Length != 0) { PalletCode = sTaskno.Substring(10, 8).Trim(); strMsg = Stock + (PalletCode.Length > 0 ? PalletCode : "") + " " + dicStockWarning[errorNo]; if (item.ItemName.IndexOf("_ErrCode") >= 0 && ItemNo == item.ItemName.Split('_')[0]) { Logger.Error("输送线:" + ItemNo + (PalletCode.Length > 0 ? "托盘编号:" + PalletCode : "") + dicStockWarning[errorNo]); } } else { PalletCode = sTaskno.Substring(10, 8).Trim(); if (PalletCode.Length > 0) { CellCode = " 位:" + sTaskno.Substring(18, 8).Trim(); } strMsg = Stock + PalletCode + CellCode; } } } catch (Exception ex) { Logger.Error("LEDProcess中GetLedMessage异常:" + ex.Message); } return(strMsg); }
private void CarStateChange(string Objstate, string CarNO, string CarItem, string WriteItem) { string CarNo = ""; if (Objstate == "2") //送货完成 { TaskDal dal = new TaskDal(); #region 送货完成,写入站台 object[] obj1 = ObjectUtil.GetObjects(WriteToService("StockPLC_02", CarItem + "_1")); //小车任务号,状态 object[] obj2 = ObjectUtil.GetObjects(WriteToService("StockPLC_02", CarItem + "_2")); //读取小车位置,目标地址 DataRow[] drsAddress = dtCarAddress.Select(string.Format("CAR_ADDRESS >'{0}' and CAR_ADDRESS<'{1}'", long.Parse(obj2[1].ToString()) - MaxDifferenceValue, long.Parse(obj2[1].ToString()) + MaxDifferenceValue)); if (drsAddress.Length > 0) { string strStationNo = drsAddress[0]["STATION_NO"].ToString(); string strItemName = ""; string strItemState = "02_1_" + strStationNo; if (strStationNo == "340" || strStationNo == "360") { strItemName = "StockOutCarFinishProcess"; } else { if (strStationNo == "301" || strStationNo == "305" || strStationNo == "309" || strStationNo == "313" || strStationNo == "317" || strStationNo == "323") { strItemName = "PalletToCarStationProcess"; } } if (strItemName != "") { WriteToProcess(strItemName, strItemState, obj1[0].ToString()); } } string FinshedTaskType = ""; if (dtCar == null) { return; } DataRow[] drexist = dtCar.Select(string.Format("CAR_NO='{0}' and STATE=1", CarNo));//获取小车开始执行完毕之后 if (drexist.Length > 0) { FinshedTaskType = drexist[0]["TASK_TYPE"].ToString(); dtCar.Rows.Remove(drexist[0]); } #endregion DataRow[] drs = dtCar.Select(string.Format("CAR_NO='{0}' and STATE=0", CarNo)); //有待分配的任务 if (drs.Length > 0) { #region 待分配的任务 DataRow dr = drs[0]; dr.BeginEdit(); dr["STATE"] = 1; dr.EndEdit(); int CurPostion = 0; int ToPostion = 0; string FromStation = ""; string ToStation = ""; string TargetCode = ""; if (dr["TASK_TYPE"].ToString() == "21") { CurPostion = int.Parse(dr["IN_STATION_ADDRESS"].ToString()); ToPostion = int.Parse(dr["STATION_NO_ADDRESS"].ToString()); FromStation = dr["IN_STATION"].ToString(); ToStation = dr["STATION_NO"].ToString(); } else { CurPostion = int.Parse(dr["STATION_NO_ADDRESS"].ToString()); ToPostion = int.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); FromStation = dr["STATION_NO"].ToString(); ToStation = dr["OUT_STATION_1"].ToString(); if (!dBillUseTarget.ContainsKey(dr["FORDERBILLNO"].ToString())) { dBillUseTarget.Add(dr["FORDERBILLNO"].ToString(), false); dBillTargetCode.Add(dr["FORDERBILLNO"].ToString(), ""); } if (dBillUseTarget[dr["FORDERBILLNO"].ToString()]) //已经使用过两次 { if (dBillTargetCode[dr["FORDERBILLNO"].ToString()] == "370") { ToPostion = int.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_1"].ToString(); } else { ToPostion = int.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_2"].ToString(); } } else { //制丝线1 正常走360,390拆盘有故障的时候,走340 if (dr["TARGET_CODE"].ToString().Trim() == "01") { int objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_390")).ToString()); if (objstate == 0) { ToPostion = int.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_2"].ToString(); TargetCode = "390"; } else { objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_370")).ToString()); if (objstate == 0) { ToPostion = int.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_1"].ToString(); TargetCode = "370"; } } } else //制丝线02,03 走340 如果370拆盘坏掉,走360至390处拆盘 { int objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_370")).ToString()); if (objstate == 0) { ToPostion = int.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_1"].ToString(); TargetCode = "370"; } else { objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_390")).ToString()); if (objstate == 0) { ToStation = dr["OUT_STATION_2"].ToString(); ToPostion = int.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); TargetCode = "390"; } } } if (dBillTargetCode[dr["FORDERBILLNO"].ToString()] != "" && dBillTargetCode[dr["FORDERBILLNO"].ToString()] != TargetCode) { dBillUseTarget[dr["FORDERBILLNO"].ToString()] = true; dBillTargetCode[dr["FORDERBILLNO"].ToString()] = TargetCode; } else { dBillTargetCode[dr["FORDERBILLNO"].ToString()] = TargetCode; } } } int[] WriteValue = new int[2]; WriteValue[0] = CurPostion; WriteValue[1] = ToPostion; int TaskNo = int.Parse(dr["TASK_NO"].ToString()); int ProductType = int.Parse(dr["PRODUCT_TYPE"].ToString()); int[] WriteTaskValue = new int[2]; WriteTaskValue[0] = TaskNo; WriteTaskValue[1] = ProductType; string barcode = ""; string palletcode = ""; if (dr["PRODUCT_CODE"].ToString() != "0000") // { barcode = dr["PRODUCT_BARCODE"].ToString(); palletcode = dr["PALLET_CODE"].ToString(); } byte[] b = new byte[190]; Common.ConvertStringChar.stringToByte(barcode, 80).CopyTo(b, 0); Common.ConvertStringChar.stringToByte(palletcode, 110).CopyTo(b, 80); WriteToService("StockPLC_02", dr["WriteItem"].ToString() + "_1", WriteTaskValue); //任务号。 WriteToService("StockPLC_02", dr["WriteItem"].ToString() + "_2", WriteValue); //地址。 WriteToService("StockPLC_02", dr["WriteItem"].ToString() + "_3", b); WriteToService("StockPLC_02", dr["WriteItem"].ToString() + "_4", 1); dal.UpdateTaskDetailCar(FromStation, ToStation, "1", dr["CAR_NO"].ToString(), string.Format("TASK_ID='{0}' and ITEM_NO='{1}'", dr["TASK_ID"], dr["ITEM_NO"])); #endregion } else //小车空闲,且没任务。 { #region 小车空闲,且没任务。 按顺序查找任务 long CurPostion = 0; long ToPostion = -1; string FromStation = ""; string ToStation = ""; string TargetCode = ""; DataRow[] drsNotCar = dtCar.Select("CAR_NO='' and STATE=0", "Index"); if (drsNotCar.Length > 0) { for (int i = 0; i < drs.Length; i++) { DataRow dr = drs[i]; if (dr["TASK_TYPE"].ToString() == "21") { CurPostion = long.Parse(dr["IN_STATION_ADDRESS"].ToString()); ToPostion = long.Parse(dr["STATION_NO_ADDRESS"].ToString()); FromStation = dr["IN_STATION"].ToString(); ToStation = dr["STATION_NO"].ToString(); } else { CurPostion = long.Parse(dr["STATION_NO_ADDRESS"].ToString()); //判断使用哪个出口? ToPostion = long.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_1"].ToString(); FromStation = dr["STATION_NO"].ToString(); ToPostion = -1; //判断二楼能否出库 bool blnCan = false; blnCan = dal.ProductCanToCar(dr["FORDERBILLNO"].ToString(), dr["FORDER"].ToString(), dr["IS_MIX"].ToString(), true, blnOutOrder); if (blnCan) { if (!dBillUseTarget.ContainsKey(dr["FORDERBILLNO"].ToString())) { dBillUseTarget.Add(dr["FORDERBILLNO"].ToString(), false); dBillTargetCode.Add(dr["FORDERBILLNO"].ToString(), ""); } if (dBillUseTarget[dr["FORDERBILLNO"].ToString()]) //已经使用过两次 { if (dBillTargetCode[dr["FORDERBILLNO"].ToString()] == "370") { ToPostion = long.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_1"].ToString(); } else { ToPostion = long.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_2"].ToString(); } } else { if (dr["TARGET_CODE"].ToString().Trim() == "01") { //读取370拆盘有无故障 int objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_390")).ToString()); if (objstate == 0) { ToPostion = long.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_2"].ToString(); TargetCode = "390"; } else { //读取390拆盘有无故障 objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_370")).ToString()); if (objstate == 0) { ToPostion = long.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_2"].ToString(); TargetCode = "370"; } } } else { int objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_370")).ToString()); if (objstate == 0) { ToPostion = long.Parse(dr["OUT_STATION_1_ADDRESS"].ToString()); ToStation = dr["OUT_STATION_1"].ToString(); TargetCode = "370"; } else { objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_390")).ToString()); if (objstate == 0) { ToStation = dr["OUT_STATION_2"].ToString(); ToPostion = long.Parse(dr["OUT_STATION_2_ADDRESS"].ToString()); TargetCode = "390"; } } } if (dBillTargetCode[dr["FORDERBILLNO"].ToString()] != "" && dBillTargetCode[dr["FORDERBILLNO"].ToString()] != TargetCode) { dBillUseTarget[dr["FORDERBILLNO"].ToString()] = true; dBillTargetCode[dr["FORDERBILLNO"].ToString()] = TargetCode; } else { dBillTargetCode[dr["FORDERBILLNO"].ToString()] = TargetCode; } } } } if (ToPostion != -1) { long[] WriteValue = new long[2]; WriteValue[0] = CurPostion; WriteValue[1] = ToPostion; int TaskNo = int.Parse(dr["TASK_NO"].ToString()); int ProductType = int.Parse(dr["PRODUCT_TYPE"].ToString()); int[] WriteTaskValue = new int[2]; WriteTaskValue[0] = TaskNo; WriteTaskValue[1] = ProductType; string barcode = ""; string palletcode = ""; if (dr["PRODUCT_CODE"].ToString() != "0000") // { barcode = dr["PRODUCT_BARCODE"].ToString(); palletcode = dr["PALLET_CODE"].ToString(); } byte[] b = new byte[190]; Common.ConvertStringChar.stringToByte(barcode, 80).CopyTo(b, 0); Common.ConvertStringChar.stringToByte(palletcode, 110).CopyTo(b, 80); WriteToService("StockPLC_02", WriteItem + "_1", WriteTaskValue); //任务号。 WriteToService("StockPLC_02", WriteItem + "_2", WriteValue); //地址。 WriteToService("StockPLC_02", WriteItem + "_3", b); WriteToService("StockPLC_02", WriteItem + "_4", 1); dal.UpdateTaskDetailCar(FromStation, ToStation, "1", dr["CAR_NO"].ToString(), string.Format("TASK_ID='{0}' and ITEM_NO='{1}'", dr["TASK_ID"], dr["ITEM_NO"])); break; } } } #endregion #region 小车空闲,且找不到任务,则移动到最大目的地址的下一个工位 if (ToPostion == -1) { obj2 = ObjectUtil.GetObjects(WriteToService("StockPLC_02", CarItem + "_2"));//读取小车位置 //判断当前位 DataTable dtOrder = GetCarOrder(int.Parse(obj2[0].ToString())); DataRow[] drMax = dtOrder.Select("state=1", "ToStationOrder desc"); //按照最大目的地址倒排。最大目的地址大于当前位置,则下任务给小车移动到最大目的地址+1个工位。 if (drMax.Length > 0) { if ((int)drMax[0]["ToStation"] > int.Parse(obj2[1].ToString())) { string strNextStation = GetNextStation(obj2[1].ToString()); long[] WriteValue = new long[2]; WriteValue[0] = long.Parse(obj2[0].ToString());; WriteValue[1] = long.Parse(strNextStation);//下任务给小车移动到最大目的地址+1个工位。; int TaskNo = 9999; int ProductType = 5; int[] WriteTaskValue = new int[2]; WriteTaskValue[0] = TaskNo; WriteTaskValue[1] = ProductType; string barcode = ""; string palletcode = ""; byte[] b = new byte[190]; Common.ConvertStringChar.stringToByte(barcode, 80).CopyTo(b, 0); Common.ConvertStringChar.stringToByte(palletcode, 110).CopyTo(b, 80); WriteToService("StockPLC_02", WriteItem + "_1", WriteTaskValue); //任务号。 WriteToService("StockPLC_02", WriteItem + "_2", WriteValue); //地址。 WriteToService("StockPLC_02", WriteItem + "_3", b); WriteToService("StockPLC_02", WriteItem + "_4", 1); } } } #endregion } } else { #region 烟包接货完成,处理目前位置与目的地之间的空闲小车 if (Objstate == "1") // { object[] obj = ObjectUtil.GetObjects(WriteToService("StockPLC_02", CarItem + "_2")); //读取小车位置 //判断当前位置 DataTable dtOrder = GetCarOrder(int.Parse(obj[0].ToString())); DataRow[] drMax = dtOrder.Select(string.Format("state=0 and CurStation>={0} and CurStation<={1}", obj[1], obj[2]), "orderNo desc"); //按照最大目的地址倒排。最大目的地址大于当前位置,则下任务给小车移动到最大目的地址+1个工位。 if (drMax.Length > 0) { for (int i = 0; i < drMax.Length; i++) { string strNextStation = GetNextStation(obj[2].ToString()); long[] WriteValue = new long[2]; WriteValue[0] = long.Parse(drMax[i]["CurStation"].ToString()); WriteValue[1] = long.Parse(strNextStation);//下任务给小车移动到最大目的地址+1个工位。; int TaskNo = 9999; int ProductType = 5; int[] WriteTaskValue = new int[2]; WriteTaskValue[0] = TaskNo; WriteTaskValue[1] = ProductType; string barcode = ""; string palletcode = ""; byte[] b = new byte[190]; Common.ConvertStringChar.stringToBytes(barcode, 80).CopyTo(b, 0); Common.ConvertStringChar.stringToBytes(palletcode, 110).CopyTo(b, 80); WriteToService("StockPLC_02", drMax[i]["WriteItem"].ToString() + "_1", WriteTaskValue); //任务号。 WriteToService("StockPLC_02", drMax[i]["WriteItem"].ToString() + "_2", WriteValue); //地址。 WriteToService("StockPLC_02", drMax[i]["WriteItem"].ToString() + "_3", b); WriteToService("StockPLC_02", drMax[i]["WriteItem"].ToString() + "_4", 1); } } } #endregion } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null) { return; } if (stateItem.ItemName.IndexOf("nAlarmCode") >= 0) { int CraneNo = int.Parse(stateItem.Name.Replace("CranePLC", "")) * 2; ShowLedMessage(CraneNo.ToString(), stateItem); return; } string ItemNo = stateItem.ItemName.Split('_')[0]; ShowLedMessage(GetLedNo(int.Parse(ItemNo)), stateItem); try { if (stateItem.ItemName.IndexOf("TaskNo") >= 0 && (ItemNo == "102" || ItemNo == "106" || ItemNo == "110" || ItemNo == "114" || ItemNo == "118" || ItemNo == "103" || ItemNo == "107" || ItemNo == "111" || ItemNo == "115" || ItemNo == "119")) { string Tasks = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(stateItem.State)); Tasks = Tasks.PadRight(26, ' '); string TaskNo = Tasks.Substring(0, 10).Trim(); if (TaskNo.Length > 0) { BLL.BLLBase bll = new BLL.BLLBase(); DataTable dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TaskID='{0}'", TaskNo)) }); if (dtTask.Rows.Count > 0) { string PalletCode = dtTask.Rows[0]["PALLETID"].ToString(); switch (ItemNo) { case "102": case "106": case "110": case "114": case "118": //更新WCS_Task入库状态 bll.ExecNonQuery("WCS.UpdateWCSTaskStateByStatus", new DataParameter[] { new DataParameter("{0}", "2"), new DataParameter("{1}", TaskNo), new DataParameter("{2}", 1) }); Logger.Info("入库任务:" + TaskNo + "托盘编号:" + PalletCode + "到达入库端!"); break; case "103": case "107": case "111": case "115": case "119": //更新出库完成 bll.ExecNonQueryTran("WCS.SpTaskFinished", new DataParameter[] { new DataParameter("VTaskNo", TaskNo) }); Logger.Info("出库任务:" + TaskNo + "托盘编号:" + PalletCode + "完成任务!"); break; } } } } } catch (Exception ex) { Logger.Error("LEDProcess中StateChanged出现异常" + ex.Message); } }
void Miniload_OnDataChanged(object sender, DataChangedEventArgs e) { try { if (e.State == null) { return; } string miniloadNo = e.ServerName.Replace("MiniloadServer", ""); GetMiniload(miniloadNo); if (e.ItemName.IndexOf("Mode") >= 0) { dicMiniload[miniloadNo].Mode = int.Parse(e.State.ToString()); } else if (e.ItemName.IndexOf("State1") >= 0) { dicMiniload[miniloadNo].State1 = int.Parse(e.State.ToString()); } else if (e.ItemName.IndexOf("Fork1") >= 0) { dicMiniload[miniloadNo].Fork1 = int.Parse(e.State.ToString()); } else if (e.ItemName.IndexOf("TaskNo1") >= 0) { dicMiniload[miniloadNo].TaskNo1 = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(e.States)); } else if (e.ItemName.IndexOf("State2") >= 0) { dicMiniload[miniloadNo].State2 = int.Parse(e.State.ToString()); } else if (e.ItemName.IndexOf("Fork2") >= 0) { dicMiniload[miniloadNo].Fork2 = int.Parse(e.State.ToString()); } else if (e.ItemName.IndexOf("TaskNo2") >= 0) { dicMiniload[miniloadNo].TaskNo2 = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(e.States)); } else if (e.ItemName.IndexOf("AlarmCode") >= 0) { dicMiniload[miniloadNo].AlarmCode = int.Parse(e.State.ToString()); } else if (e.ItemName.IndexOf("Station") >= 0) { dicMiniload[miniloadNo].Station = e.States; } Miniloads.MiniloadInfo(dicMiniload[miniloadNo]); } catch (Exception ex) { MCP.Logger.Error("Miniload监控界面中Miniload_OnDataChanged出现异常" + ex.Message); } }
private void tmCraneWorker(object sender, System.Timers.ElapsedEventArgs e) { try { tmCraneErr.Stop(); for (int i = 1; i <= dtCrane.Rows.Count; i++) { if (dtCrane.Rows[i - 1]["ISENABLED"].ToString() == "0") { continue; } string serviceName = "CranePLC" + i; int ErrCode = int.Parse(ObjectUtil.GetObject(context.ProcessDispatcher.WriteToService(serviceName, "nAlarmCode")).ToString()); if (ErrCode == 0) { continue; } if (ErrCode == 505) { string plcTaskNo = ConvertStringChar.BytesToString(ObjectUtil.GetObjects(context.ProcessDispatcher.WriteToService(serviceName, "ReadTaskNo"))); DataTable dtTask = bll.FillDataTable("WCS.SelectWmsTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}' and ASRSID='{1}'", plcTaskNo, i)) }); if (dtTask.Rows.Count > 0) { string TaskType = dtTask.Rows[0]["TASKTYPE"].ToString(); string plcPalletCode = dtTask.Rows[0]["PALLETID"].ToString(); DataTable dtErr = bll.FillDataTable("WCS.SelectWmsSend", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}'", plcTaskNo)) }); if (dtErr.Rows.Count > 0) { string Taskstatus = dtErr.Rows[0]["TASKSTATUS"].ToString(); if (Taskstatus == "4") { //crane.ErrCode == 505,重入异常 if (TaskType == "OB") { continue; } bll.ExecNonQueryTran("WCS.SPCancelTask", new DataParameter[] { new DataParameter("VTASKNO", plcTaskNo) }); Logger.Info("入库任务:" + plcTaskNo + "托盘编号:" + plcPalletCode + "取消!"); DataTable dtTaskNew = bll.FillDataTable("WCS.SelectWmsTask", new DataParameter[] { new DataParameter("{0}", string.Format("PALLETID='{0}' AND TASKSTATUS='0' AND ASRSID='{1}'", plcPalletCode, i)) }); if (dtTaskNew.Rows.Count > 0) { string TaskNo = dtTaskNew.Rows[0]["TASKID"].ToString(); sbyte[] staskNo = new sbyte[20]; Util.ConvertStringChar.stringToBytes(TaskNo, 12).CopyTo(staskNo, 0); Util.ConvertStringChar.stringToBytes(plcPalletCode, 8).CopyTo(staskNo, 12); string strDLocation = dtTaskNew.Rows[0]["DLOCATION"].ToString(); int[] Location = new int[6]; Location[0] = 0; Location[1] = 0; Location[2] = 0; Location[3] = int.Parse(strDLocation.Split('-')[0]); Location[4] = int.Parse(strDLocation.Split('-')[1]); int ToRow = int.Parse(strDLocation.Split('-')[2]); if (ToRow > 1) { ToRow += 1; } Location[5] = ToRow; context.ProcessDispatcher.WriteToService(serviceName, "Address", Location); context.ProcessDispatcher.WriteToService(serviceName, "WriteTask", staskNo); if (context.ProcessDispatcher.WriteToService(serviceName, "WriteFinish", true)) { bll.ExecNonQueryTran("WCS.SPReciveWmsTask", new DataParameter[] { new DataParameter("VTASKNO", TaskNo) }); //更新WCSTask状态为3 bll.ExecNonQuery("WCS.UpdateWCSTaskState", new DataParameter[] { new DataParameter("{0}", 3), new DataParameter("{1}", TaskNo) }); Logger.Info("入库任务:" + TaskNo + " 托盘编号:" + plcPalletCode + " 位:" + strDLocation + " 已下发给" + i + "堆垛机"); } else { Logger.Error("入库任务:" + TaskNo + " 托盘编号:" + plcPalletCode + " 无法写入堆垛机" + i); } } } } } } } } catch (Exception ex) { Logger.Error("MainServer中tmCraneWorker出现异常:" + ex.Message); } finally { tmCraneErr.Start(); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null) { return; } string TaskFinish = obj.ToString(); if (TaskFinish.Equals("True") || TaskFinish.Equals("1")) { try { //测试下发到达指定入库站台 //sbyte[] test = new sbyte[20]; //Util.ConvertStringChar.stringToBytes("0000000000B001", 20).CopyTo(test, 0); //WriteToService("TranLine", "Barcode", test); //WriteToService("TranLine", "SlideNum", Instation); //if (Instation == 1) // Instation = 3; //else // Instation = 1; //return; string taskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService(stateItem.Name, "Barcode"))); string Barcode = taskNo.PadRight(20, ' ').Substring(10, 10).Trim(); sbyte[] staskNo = new sbyte[20]; if (Barcode == "NoRead" || Barcode.Length <= 0) { Util.ConvertStringChar.stringToBytes("0000000000" + Barcode, 20).CopyTo(staskNo, 0); WriteToService("TranLine", "Barcode", staskNo); WriteToService("TranLine", "SlideNum", 99); return; } //判断是否还有货位可以存放 string F = Barcode.Substring(0, 1).ToLower(); string AreaCode = "002"; int SlideNum = 2; string StationNo = "02"; string AisleNo = "02"; string CraneNo = ""; if (F == "c") { AreaCode = "003"; SlideNum = 3; StationNo = "03"; AisleNo = "03"; CraneNo = "02"; DataTable dtSlide = bll.FillDataTable("WCS.SelectSlideTask"); if (dtSlide.Rows.Count > 0) { if (dtSlide.Rows[0]["StationNo"].ToString() == "03") { SlideNum = 1; StationNo = "01"; } } } DataParameter[] param = new DataParameter[] { new DataParameter("{0}", string.Format("PalletCode='{0}' and ((WCS_TASK.TaskType in ('11','16') and WCS_TASK.State='0') or (WCS_TASK.TaskType='14' and WCS_TASK.State='8'))", Barcode)) }; DataTable dt = bll.FillDataTable("WCS.SelectTask", param); if (dt.Rows.Count > 0) { taskNo = dt.Rows[0]["TaskNo"].ToString(); //如果是盘点任务,因为盘点回原库位,所以按照库位指定入库站台 if (dt.Rows[0]["TaskType"].ToString() == "14" && dt.Rows[0]["State"].ToString() == "8") { string CellCode = dt.Rows[0]["CellCode"].ToString(); if (CellCode.Length > 0) { if (CellCode.Substring(9, 1) == "2") { SlideNum = 1; StationNo = "01"; } else { SlideNum = 3; StationNo = "03"; } } else { Logger.Error("盘点任务货位丢失,请核对"); return; } } else { //判断此条码有没有在库位上存在或在途 if (BarcodeIsExist(Barcode, staskNo)) { return; } //判断有没有可用货位 dt = bll.FillDataTable("WCS.SelectHasCell", new DataParameter[] { new DataParameter("@AreaCode", AreaCode) }); if (int.Parse(dt.Rows[0][0].ToString()) == 0) { Util.ConvertStringChar.stringToBytes("", 20).CopyTo(staskNo, 0); WriteToService("TranLine", "Barcode", staskNo); WriteToService("TranLine", "SlideNum", 98); Logger.Error("没有空余的货位可以入库!"); return; } } } else { if (BarcodeIsExist(Barcode, staskNo)) { return; } //产生空周转箱入库任务 param = new DataParameter[] { new DataParameter("@PalletCode", Barcode) }; dt = bll.FillDataTable("WCS.Sp_CreatePalletInTask", param); if (dt.Rows.Count > 0) { taskNo = dt.Rows[0][0].ToString(); } } //盘点时可能存在问题,当只有一个货位的盘点时, //并且是深度为1的货位,这时紧跟的盘点任务不能补到入库站台1, //不然一起入库回不到原库位,所以可能等深度为1的上架后再下发到入库站台的任务 Util.ConvertStringChar.stringToBytes(taskNo + Barcode, 20).CopyTo(staskNo, 0); WriteToService("TranLine", "Barcode", staskNo); WriteToService("TranLine", "SlideNum", SlideNum); //更新状态 param = new DataParameter[] { new DataParameter("@StationNo", StationNo), new DataParameter("@AisleNo", AisleNo), new DataParameter("@AreaCode", AreaCode), new DataParameter("@CraneNo", CraneNo), new DataParameter("@TaskNo", taskNo) }; bll.ExecNonQuery("WCS.UpdateTaskInStockRequest", param); Logger.Info("任务号:" + taskNo + " 托盘:" + Barcode + " 开始入库,去往入库口:" + SlideNum); } catch (Exception ex) { Logger.Error("入库请求出错,错误内容:" + ex.Message); } } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { try { object obj = ObjectUtil.GetObject(stateItem.State); if (obj == null) { return; } string TaskFinish = obj.ToString(); if (TaskFinish.Equals("True") || TaskFinish.Equals("1")) { //读取产品品种 //Logger.Info("1"); string CellCode = ""; string ProductCode = ""; object[] product = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(stateItem.Name, "ProductInfo")); int key = int.Parse(product[0].ToString()); string ProductNo = dicProductNo[key]; string ProductType = product[1].ToString(); if (ProductType == "1") { DataTable dt = bll.FillDataTable("CMD.SelectProduct", new DataParameter[] { new DataParameter("{0}", string.Format("ProductNo='{0}'", ProductNo)) }); if (dt.Rows.Count > 0) { ProductCode = dt.Rows[0]["ProductCode"].ToString(); } } else { ProductCode = "0001"; } //判断有无等待的此品种入库任务,如有,不再产生任务 DataTable dtTask = bll.FillDataTable("WCS.SelectTask", new DataParameter[] { new DataParameter("{0}", string.Format("WCS_TASK.TaskType='11' and WCS_TASK.State='0' and WCS_TASK.ProductCode='{0}'", ProductCode)) }); if (dtTask.Rows.Count > 0) { return; } DataParameter[] param = new DataParameter[] { new DataParameter("@CraneNo", "01"), new DataParameter("@ProductCode", ProductCode), new DataParameter("@TimeDiff", TimeDiff), new DataParameter("@CellCode", CellCode), new DataParameter("@WorkMode", Program.mainForm.WorkMode), new DataParameter("@WorkModeId", Program.mainForm.WorkModeId) }; bll.FillDataTable("WCS.Sp_CreateInTask", param); ////如果工作模式是储存且不是托盘组入库,需产生一个托盘组出库任务 //if (Program.mainForm.WorkMode == 1 && ProductCode != "0001") //{ // CellCode = ""; // Logger.Info("开始产生空托盘出库"); // param = new DataParameter[] // { // new DataParameter("@CraneNo", "01"), // new DataParameter("@ProductCode", "0001"), // new DataParameter("@CellCode",CellCode), // new DataParameter("@Valid",2), // new DataParameter("@WorkMode",Program.mainForm.WorkMode), // new DataParameter("@WorkModeId",Program.mainForm.WorkModeId) // }; // bll.FillDataTable("WCS.Sp_CreateOutTask", param); // Logger.Info("空托盘出库已产生"); //} //清除申请标识 //WriteToService("ConveyorPLC", "_CarReply", 50); } } catch (System.Data.SqlClient.SqlException e) { //如果是存储过程名称是PROC_NAME,而且State是数据库中设置的一个值 如:66 //则该异常就是我们需要特殊处理的一个异常 if (e.Procedure.Equals("Sp_CreateInTask") && e.State == 1) { Logger.Error("Dispatching.Process.StockInToStationProcess:" + e.Message); } else if (e.Procedure.Equals("Sp_CreateOutTask") && e.State == 1) { Logger.Error("Dispatching.Process.StockInToStationProcess:" + e.Message); } } catch (Exception e) { Logger.Error("Dispatching.Process.StockInToStationProcess:" + e.Message); } }
protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher) { object[] obj = ObjectUtil.GetObjects(stateItem.State); if (obj == null) { return; } if (obj.ToString().Trim().Length <= 0) { return; } string PalletBarcode = Util.ConvertStringChar.BytesToString(obj); if (PalletBarcode.Trim().Length <= 0) { return; } string StationNo = ""; int state = 1; string AisleNo = stateItem.Name.Substring(5, 2); if (stateItem.ItemName == "RequestBarCode") { int WriteFinished = 2; int count = bll.GetRowCount("WCS_Task", string.Format("PalletBarcode='{0}' and AisleNo='{1}' and State in('0','1','2')", PalletBarcode, AisleNo)); if (count > 0) { WriteFinished = 1; } WriteToService(stateItem.Name, "RequestFinished", WriteFinished); if (WriteFinished == 2) { Logger.Error("条码:" + PalletBarcode + " 分配错误巷道" + AisleNo); } return; } else { switch (stateItem.ItemName) { case "InLocation01": StationNo = "SX-" + stateItem.Name.Substring(5, 2) + "-00"; state = 1; break; case "InLocation02": StationNo = "SX-" + stateItem.Name.Substring(5, 2) + "-01"; state = 2; break; case "OutLocation01": StationNo = "SX-" + stateItem.Name.Substring(5, 2) + "-00"; state = 6; break; case "OutLocation02": StationNo = "SX-" + stateItem.Name.Substring(5, 2) + "-02"; state = 7; break; } try { if (stateItem.ItemName.StartsWith("InLocation")) { if (bll.GetRowCount("WCS_Task", string.Format("PalletBarcode='{0}' and AisleNo='{1}' and State in('0','1','2')", PalletBarcode, AisleNo)) > 0) { DataParameter[] param = new DataParameter[] { new DataParameter("@PalletBarcode", PalletBarcode), new DataParameter("@AisleNo", AisleNo), new DataParameter("@State", state) }; bll.ExecNonQueryTran("WCS.UpdateTaskStateByBarcode", param); } else { Logger.Error("托盘/箱号:" + PalletBarcode + "到达站台:" + StationNo + " 到达错误站台!"); return; } } Logger.Info("托盘/箱号:" + PalletBarcode + "到达站台:" + StationNo); } catch (Exception ex) { Logger.Error("InOutLocationProcess出错,原因:" + ex.Message); } } }