Ejemplo n.º 1
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             * 二层小车进入缓存站台
            */
            object obj = ObjectUtil.GetObject(stateItem.State);

            if (obj == null || obj.ToString() == "0")
                return;
            string WriteItem = "";
            try
            {
                switch (stateItem.ItemName)
                {

                    case "02_1_475":
                        WriteItem = "02_2_475";
                        break;
                    case "02_1_440":
                        WriteItem = "02_2_440";
                        break;
                    case "02_1_412":
                        WriteItem = "02_2_412";
                        break;
                }
                string TaskNo = obj.ToString().PadLeft(4, '0');
                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);
                if (!string.IsNullOrEmpty(strValue[0]))
                {
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=5", strValue[0]), "2"); //更新
                    ChannelDal cDal = new ChannelDal();
                    cDal.UpdateOutChannelTime(strValue[0]);

                    WriteToService("StockPLC_02", WriteItem, 1);
                }

                //读取码盘机是否处于,申请位;
                string SeparateItem = "";
                object objSeparate = ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_372_1"));
                if (objSeparate.ToString() != "0")
                    SeparateItem = "02_1_372_1";
                else
                {

                    objSeparate = ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_392_1"));
                    if (objSeparate.ToString() != "0")
                        SeparateItem = "02_1_392_1";
                }
                if (SeparateItem != "")
                {
                    WriteToProcess("StockOutSeparateProcess", SeparateItem, 1);
                }

            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.StockOutCacheProcess,原因:" + e.Message);
            }
        }
Ejemplo n.º 2
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  stateItem.ItemName :
             *  空托盘组,从小车站台到达入库站台。
             *  stateItem.State :参数 - 任务号。
            */
            object obj = ObjectUtil.GetObject(stateItem.State);
            if (obj == null || obj.ToString() == "0")
                return;

            string TaskNo = obj.ToString().PadLeft(4, '0');
            try
            {
                switch (stateItem.ItemName)
                {
                    case "02_1_302":
                        break;
                    case "02_1_306":
                        break;
                    case "02_1_310":
                        break;
                    case "02_1_314":
                        break;
                    case "02_1_318":
                        break;
                    case "02_1_324":
                        break;
                    default:
                        break;
                }
                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);

                if (!string.IsNullOrEmpty(strValue[1]))
                {
                    DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strValue[0]));
                    string CellCode = dtTask.Rows[0]["CELL_CODE"].ToString();
                    //更新小车站台到达入库站台任务完成。
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO='3'", strValue[0]), "2");
                    SysStationDal sysdal = new SysStationDal();
                    DataTable dtstation = sysdal.GetSationInfo(CellCode, "21","4");
                    //更新调度堆垛机的起始位置及目标地址。
                    dal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), CellCode, "0", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO=4", strValue[0]));

                    DataTable dt = dal.CraneTaskIn(string.Format("TASK.TASK_ID='{0}' and ITEM_NO='4'", strValue[0]));
                    if (dt.Rows.Count > 0)
                    {
                        WriteToProcess("CraneProcess", "CraneInRequest", dt);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.PalletToStationProcess, 原因:" + e.Message);
            }
        }
Ejemplo n.º 3
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             * 二楼空托盘组入库
             * 生成入库单,入库作业。
            */
            try
            {
                object[] obj = ObjectUtil.GetObjects(stateItem.State);
                if (obj[0] == null || obj[0].ToString() == "0")
                    return;

                int PalletCount = int.Parse(obj[1].ToString());
                string TaskID = "";

                //判断是否还有出库任务
                TaskDal dal = new TaskDal();
                int TaskOutCount = dal.CarTaskInfo();

                if (PalletCount >= 4 || TaskOutCount <= 4)
                {
                    //获取托盘组入库下达排程任务而小车未接货的任务号,防止托盘组数量变化引起触发
                    TaskID = dal.GetPalletInTask();
                    string strWhere = "";
                    if (TaskID == "")
                    {
                        PalletBillDal Billdal = new PalletBillDal();
                        TaskID = Billdal.CreatePalletInBillTask(false);

                        strWhere = string.Format("TASK_ID='{0}'", TaskID);
                        string[] CellValue = dal.AssignCellTwo(strWhere);//货位申请
                        string TaskNo = dal.InsertTaskDetail(CellValue[0]);

                        dal.UpdateTaskState(CellValue[0], "1");//更新任务开始执行

                        ProductStateDal StateDal = new ProductStateDal();
                        //更新Product_State 货位
                        StateDal.UpdateProductCellCode(CellValue[0], CellValue[1]);

                        //更新货位申请起始地址及目标地址。
                        dal.UpdateTaskDetailStation("357", "359", "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CellValue[0]));
                    }
                    strWhere = string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=2 AND DETAIL.STATE=0 ", TaskID);
                    DataTable dt = dal.TaskCarDetail(strWhere);
                    WriteToProcess("CarProcess", "CarInRequest", dt);
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.PalletInRequestProcess:" + e.Message);
            }
        }
Ejemplo n.º 4
0
        /*  处理事项:
         *  倒库烟包 122
         */
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {
                object sta = ObjectUtil.GetObject(stateItem.State);
                if (sta == null || sta.ToString() == "0")
                    return;
                string[] str = new string[3];
                str[0] = "4";
                str[1] = "";
                str[2] = "";

                TaskDal dal = new TaskDal(); //更具任务号,获取TaskID及BILL_NO
                string[] strInfo = dal.GetTaskInfo(sta.ToString().PadLeft(4, '0'));
                DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0]));
                DataTable dtProductInfo = dal.GetProductInfoByTaskID(strInfo[0]);
                //线程停止
                while (FormDialog.ShowDialog(str, dtProductInfo) != "")
                {
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strInfo[0]), "2");
                    dal.UpdateTaskState(strInfo[0], "2");

                    BillDal billdal = new BillDal();
                    billdal.UpdateInBillMasterFinished(strInfo[1],"1");

                    string writeItem = "01_2_122_";

                    int[] ServiceW = new int[3];
                    ServiceW[0] = int.Parse(strInfo[1]); //任务号
                    ServiceW[1] = 131;//目的地址
                    ServiceW[2] = 4;

                    WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务

                    WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务
                    break;
                }
               ;//线程继续。
            }
            catch (Exception ex)
            {
                Logger.Error("THOK.XC.Process.Process_01.MoveOutToStationProcess:" + ex.Message);
            }
        }
Ejemplo n.º 5
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             * 二楼出库条码校验
             *
            */
            try
            {
                object obj = ObjectUtil.GetObjects(stateItem.State);
                if (obj == null || obj.ToString() == "0")
                    return;

                string TaskNo = obj.ToString().PadLeft(4, '0');
                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);

                string WriteItem = "";
                string ReadItem = "";
                switch (stateItem.ItemName)
                {
                    case "02_1_340_1":
                        WriteItem = "02_2_340";
                        ReadItem = "02_1_340_";
                        break;
                    case "02_1_360_1":
                        WriteItem = "02_2_360";
                        ReadItem = "02_1_360_";
                        break;

                }
                object objCheck = ObjectUtil.GetObject(WriteToService("StockPLC_02", ReadItem + "2"));
                if (objCheck.ToString() == "0")
                {
                    string BarCode = Common.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(WriteToService("StockPLC_02", ReadItem+"3")));
                    dal.UpdateTaskCheckBarCode(strValue[0], BarCode);
                }
                WriteToService("StockPLC_02", WriteItem + "_3", 1);

            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.CheckProcess,原因:" + e.Message);
            }
        }
        /*  处理事项:
             *  空托盘组出库到达158,200
            */
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {

                object obj = ObjectUtil.GetObject(stateItem.State);
                if (obj == null || obj.ToString() == "0")
                    return;

                string writeItem = "";
                switch (stateItem.ItemName)
                {
                    case "01_1_158_2":
                        writeItem = "01_1_158_3";
                        break;
                    case "01_1_200_2":
                        writeItem = "01_1_200_3";
                        break;
                }
                string TaskNo = ((short)obj).ToString().PadLeft(4, '0');
                //根据任务号,获取TaskID及BILL_NO
                TaskDal dal = new TaskDal();
                string[] strInfo = dal.GetTaskInfo(TaskNo);
                if (!string.IsNullOrEmpty(strInfo[0]))
                {
                    //更新路线状态
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strInfo[0]), "2");
                    dal.UpdateTaskState(strInfo[0], "2");
                    //更新BillMaster状态完成
                    BillDal billdal = new  BillDal();
                    billdal.UpdateInBillMasterFinished(strInfo[1],"0");
                    //通知电控,空托盘组到达158,200
                    WriteToService("StockPLC_01", writeItem, 1);
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_01.PalletOutToStationProcess:" + e.Message);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// �̵�
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCheckScan_Click(object sender, EventArgs e)
        {
            object obj= ObjectUtil.GetObject(Context.ProcessDispatcher.WriteToService("StockPLC_01", "01_1_195"));
            if (obj == null || obj.ToString() == "0")
                return;
            string strTaskNo = obj.ToString().PadLeft(4, '0');

            if ( int.Parse(obj.ToString()) >= 9800 && int.Parse(obj.ToString()) < 9999) //�̵�
            {
                string[] str = new string[3];

                str[0] = "6";

                str[1] = "";
                str[2] = "";
                TaskDal dal = new TaskDal(); //��������ţ���ȡTaskID��BILL_NO
                string[] strInfo = dal.GetTaskInfo(strTaskNo);
                DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0]));
                DataTable dtProductInfo = dal.GetProductInfoByTaskID(strInfo[0]);
                //�߳�ֹͣ
                string strValue = "";
                while ((strValue = FormDialog.ShowDialog(str, dtProductInfo)) != "")
                {
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strInfo[0]), "2");
                    string writeItem = "01_2_195_";

                    DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0]));

                    DataRow dr = dtTask.Rows[0];
                    SysStationDal sysdal = new SysStationDal();
                    DataTable dtstation = sysdal.GetSationInfo(dr["CELL_CODE"].ToString(), "11","3");

                    if (strValue != "1")
                    {
                        CellDal celldal = new CellDal();
                        celldal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "����ɨ�費һ��");
                    }

                    int[] ServiceW = new int[3];
                    ServiceW[0] = int.Parse(strInfo[1]); //�����
                    ServiceW[1] = int.Parse(dtstation.Rows[0]["STATION_NO"].ToString());//Ŀ�ĵ�ַ
                    ServiceW[2] = 1;

                    Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC�����
                    Context.ProcessDispatcher.WriteToService("StockPLC_01", writeItem + "3", 1); //PLC�����

                    dal.UpdateTaskDetailStation("195", dtstation.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=3", strInfo[0]));//���»�λ�������վ̨��
                    dal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), dr["CELL_CODE"].ToString(), "0", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO=4", strInfo[0]));//���µ��ȶѶ������ʵλ�ü�Ŀ���ַ��
                    break;
                }
            }
        }
Ejemplo n.º 8
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*
             * 一楼入库到达入库站台。
            */
            try
            {
                object obj =  ObjectUtil.GetObject(stateItem.State);
                if (obj == null || obj.ToString() == "0")
                    return;

                switch (stateItem.ItemName)
                {
                    case "01_1_136":
                        break;
                    case "01_1_148":
                        break;
                    case "01_1_152":
                        break;
                    case "01_1_170":
                        break;
                    case "01_1_178":
                        break;
                    case "01_1_186":
                        break;
                }
                //电控系统返回任务号9999
                string TaskNo = obj.ToString().PadLeft(4, '0');
                TaskDal taskDal = new TaskDal();
                string[] TaskInfo = taskDal.GetTaskInfo(TaskNo);
                DataTable dt = taskDal.TaskInfo(string.Format("TASK_ID='{0}'", TaskInfo[0]));
                if (dt.Rows.Count > 0)
                {
                    DataRow dr = dt.Rows[0];
                    string taskType = dt.Rows[0]["TASK_TYPE"].ToString();
                    string ItemNo = "0";
                    string NextItemNo="1";
                    string CellCode = "";
                    switch(taskType)
                    {
                        //入库
                        case "11":
                            ItemNo = "2";
                            NextItemNo = "3";
                            CellCode = dr["CELL_CODE"].ToString();
                            break;
                        //盘点
                        case "13":
                            ItemNo = "3";
                            NextItemNo = "4";
                            CellCode = dr["CELL_CODE"].ToString();
                            break;
                        //移库
                        case "14":
                            ItemNo = "2";
                            NextItemNo = "3";
                            CellCode = dr["NEWCELL_CODE"].ToString();
                            break;
                    }
                    //更新路线完成状态
                    taskDal.UpdateTaskDetailState(string.Format("TASK_NO='{0}' AND ITEM_NO='{1}'", TaskNo, ItemNo), "2");

                    SysStationDal sysdal = new SysStationDal();
                    DataTable dtstation = sysdal.GetSationInfo(CellCode, "11","3");
                    //更新调度堆垛机的起始位置及目标地址。
                    taskDal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), CellCode, "0", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO={1}", TaskInfo[0],NextItemNo));

                    string strWhere = string.Format("TASK_NO='{0}'AND DETAIL.STATE='0' and ITEM_NO='{1}'", TaskNo, NextItemNo);
                    DataTable dtInCrane = taskDal.CraneTaskIn(strWhere);
                    if (dtInCrane.Rows.Count > 0)
                        WriteToProcess("CraneProcess", "CraneInRequest", dtInCrane);
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_01.StockInStationProcess:" + e.Message);
            }
        }
Ejemplo n.º 9
0
        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
            }
        }
Ejemplo n.º 10
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  堆垛机任务处理
             *  出库任务传入Task 需要产生TaskDetail,并更新起始位置及目的地。
             *  入库任务传入TaskDetail
             *  Init - 初始化。
             *      FirstBatch - 生成第一批入库请求任务。
             *      StockInRequest - 根据请求,生成入库任务。
             *
             *  stateItem.State :参数 - 请求的卷烟编码。
            */
            try
            {
                switch (stateItem.ItemName)
                {
                    case "StockOutRequest": //开始出库,主动调用。
                        DataTable[] dtSend = (DataTable[])stateItem.State;
                        if (dtSend[1] != null)
                        {
                            InsertCraneQuene(dtSend[1]);
                        }
                        InsertCraneQuene(dtSend[0]);
                        CraneThreadStart();//线程调度堆垛机

                        break;
                    case "StockOutToCarStation": //烟包经过扫描,正确烟包更新为3,错误更新为4.
                        string[] strdd = (string[])stateItem.State;
                        if (dtCrane != null)
                        {
                            DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", strdd[0]));
                            if (drs.Length > 0)
                            {
                                TaskDal tdal = new TaskDal();
                                tdal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=1", drs[0]["TASK_ID"].ToString()), "2");

                                ProductStateDal psdal = new ProductStateDal();
                                psdal.UpdateOutBillNo(strdd[0]);
                                dtCrane.Rows.Remove(drs[0]);

                            }
                            CraneThreadStart(); //更新完成之后,线程调用堆垛机,避免堆垛机因调度原因而是堆垛机没有任务。
                        }
                        break;

                    case "CraneInRequest":  //货物到达入库站台,调用堆垛机
                        DataTable dtInCrane = (DataTable)stateItem.State;
                        InsertCraneQuene(dtInCrane);
                        SendTelegram(dtInCrane.Rows[0]["CRANE_NO"].ToString(), dtInCrane.Rows[0]);
                        break;
                    case "ACP":
                        ACP(stateItem.State);
                        break;
                    case "CSR":
                        CSR(stateItem.State);
                        break;
                    case "ACK":
                        ACK(stateItem.State);
                        break;
                    case "DUM":
                        THOK.CRANE.TelegramData tgd = new CRANE.TelegramData();
                        THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming();
                        string str = tf.DataFraming("00000", tgd, tf.TelegramDUA);
                        WriteToService("Crane", "DUA", str);
                        break;
                    case "DUU":
                        WriteToService("Crane", "DUM", "<00000CRAN30THOK01DUM0000000>");
                        break;
                    case "NCK":
                        NCK(stateItem.State);
                        break;
                    case "DEC":
                        DEC(stateItem.State);
                        break;

                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_Crane.CraneProcess,原因:" + e.Message);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 发送报文,并返回发送成功。
        /// </summary>
        /// <param name="CraneNo"></param>
        /// <param name="TaskID"></param>
        /// <returns></returns>
        private bool SendTelegram(string CraneNo, DataRow  drTaskID)
        {
            bool blnSend = false;
            //判断dCraneState[CraneNo] 是否空闲;
            if (!dCraneState.ContainsKey(CraneNo))
            {
                dCraneState.Add(CraneNo, "");
                SendTelegramCRQ(CraneNo);
            }

            if (string.IsNullOrEmpty(dCraneState[CraneNo]))  //等待堆垛机应答。
            {
                if (dCraneWait[CraneNo] == null && drTaskID != null)
                {
                    dCraneWait[CraneNo] = drTaskID;
                    return false;
                }
                return false;

            }
            if (dCraneState[CraneNo] == "1") //堆垛机正忙。
                return true;
            TaskDal dal = new TaskDal();
            DataRow drTaskCrane = null;
            if (drTaskID==null && dtCrane!=null) //出库任务调用堆垛机
            {
                //读取二楼出库站台是否有烟包,PLC
                //按照任务等级,任务时间,产品形态,
                DataRow[] drs = dtCrane.Select(string.Format("CRANE_NO='{0}' and STATE=0 and TASK_TYPE in ('12','22','13','14')", CraneNo), "TASK_LEVEL,TASK_DATE,BILL_NO,IS_MIX,PRODUCT_CODE,TASK_ID");
                for (int i = 0; i < drs.Length; i++)
                {
                    //判断能否出库
                    if (drs[i]["TASK_TYPE"].ToString() == "22") //二楼出库,判断能否出库
                    {
                        bool blnCan = dal.ProductCanToCar(drs[i]["FORDERBILLNO"].ToString(), drs[i]["FORDER"].ToString(), drs[i]["IS_MIX"].ToString());  //判断能否出库
                        if (!blnCan)
                            continue;
                    }
                    drTaskCrane=drs[i];
                    break;
                }

            }
            else  //根据任务编号发送报文。
            {
                drTaskCrane = drTaskID;
            }
            if (drTaskCrane != null)
            {
                if (dCraneState[CraneNo] == "0")
                {
                    string TaskType=drTaskCrane["TASK_TYPE"].ToString();
                    string ItemNo=drTaskCrane["ITEM_NO"].ToString();
                    if (TaskType.Substring(1, 1) == "2" || (TaskType.Substring(1, 1) == "3" && ItemNo == "1") || (TaskType.Substring(1, 1) == "4" && ItemNo == "1" && drTaskCrane["CRANE_NO"].ToString() != drTaskCrane["NEW_CRANE_NO"].ToString()))
                    {
                        object t = ObjectUtil.GetObject(WriteToService(drTaskCrane["SERVICE_NAME"].ToString(), drTaskCrane["ITEM_NAME_1"].ToString()));//读取当前出库站台是否有货位
                        if (t.ToString() != "0")
                        {
                            blnSend = false;
                            return blnSend;
                        }
                    }
                    if (drTaskCrane["ITEM_NO"].ToString() == "1")
                    {

                        string strTaskDetailNo = dal.InsertTaskDetail(drTaskCrane["TASK_ID"].ToString());

                        DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", drTaskCrane["TASK_ID"]));
                        if (drs.Length > 0)
                        {
                            drs[0].BeginEdit();
                            drs[0]["TASK_NO"] = strTaskDetailNo;
                            drs[0]["ASSIGNMENT_ID"] = strTaskDetailNo.PadLeft(8, '0');
                            drs[0].EndEdit();
                            dtCrane.AcceptChanges();
                        }
                    }
                    SendTelegramARQ(drTaskCrane, true);//发送报文
                    blnSend = true;
                }
            }

            return blnSend;
        }
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  stateItem.ItemName :
             *
             *  stateItem.State :参数 - 任务号。
            */
            object obj = stateItem.State;

            if (obj == null || obj.ToString() == "0")
                return;

            string TaskNo = obj.ToString().PadLeft(4, '0');
            string FromStation = "";
            string WriteItem = "";
            string ToStation = "";
            try
            {
                switch (stateItem.ItemName)
                {
                    case "02_1_301":
                        FromStation = "301";
                        ToStation = "302";
                        WriteItem = "02_2_301";
                        break;
                    case "02_1_305":
                        FromStation = "305";
                        ToStation = "306";
                        WriteItem = "02_2_305";
                        break;
                    case "02_1_309":
                        FromStation = "309";
                        ToStation = "310";
                        WriteItem = "02_2_309";
                        break;
                    case "02_1_313":
                        FromStation = "313";
                        ToStation = "314";
                        WriteItem = "02_2_313";
                        break;
                    case "02_1_317":
                        FromStation = "317";
                        ToStation = "318";
                        WriteItem = "02_2_317";
                        break;
                    case "02_1_323":
                        FromStation = "323";
                        ToStation = "324";
                        WriteItem = "02_2_323";
                        break;

                }
                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);
                DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strValue[0]));
                if (!string.IsNullOrEmpty(strValue[0]))
                {
                    string strWhere = string.Format("TASK_ID='{0}' AND ITEM_NO=2", strValue[0]);
                    dal.UpdateTaskDetailState(strWhere, "2"); //更新小车任务完成
                    strWhere = string.Format("TASK_ID='{0}' AND ITEM_NO=3", strValue[0]);
                    dal.UpdateTaskDetailStation(FromStation, ToStation, "1", strWhere);//更新货物到达入库站台明细
                    int[] writestate = new int[3];
                    writestate[0] = int.Parse(TaskNo);
                    writestate[1] = int.Parse(ToStation);
                    writestate[2] = 2;

                    string barcode = "";
                    string palletcode = "";
                    if (dt.Rows[0]["PRODUCT_CODE"].ToString() != "0000") //
                    {
                        writestate[2] = 1;
                        barcode = dt.Rows[0]["PRODUCT_BARCODE"].ToString();
                        palletcode = dt.Rows[0]["PALLET_CODE"].ToString();
                    }
                    WriteToService("StockPLC_02", WriteItem + "_1", writestate);
                    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 + "_2", b);

                    WriteToService("StockPLC_02", WriteItem + "_3", 1);
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.PalletToCarStationProcess,原因:" + e.Message);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 堆垛机状态。
        /// </summary>
        /// <param name="state"></param>
        private void CSR(object state)
        {
            Dictionary<string, string> msg = (Dictionary<string, string>)state;
            if (!dCraneState.ContainsKey(msg["CraneNo"]))
            {
                dCraneState.Add(msg["CraneNo"], "");
            }
            if (msg["ReturnCode"] == "000")
            {
                lock (dCraneState)
                {
                    if (msg["AssignmenID"] == "00000000" && msg["CraneMode"] == "1")
                    {

                        dCraneState[msg["CraneNo"]] = "0";

                        if (dCraneWait[msg["CraneNo"]] != null)
                        {
                            SendTelegram(msg["CraneNo"], dCraneWait[msg["CraneNo"]]);
                        }
                        else
                        {
                            SendTelegram(msg["CraneNo"], null);
                        }
                    }
                    else
                        dCraneState[msg["CraneNo"]] = "1";
                }
            }
            else
            {
                lock (dCraneState)
                {
                    dCraneState[msg["CraneNo"]] = "1";
                }
                Logger.Error(string.Format("堆垛机{0}返回错误代码{1}{2}", msg["CraneNo"], msg["ReturnCode"], ""));

                #region 堆垛机错误而停止,重新选择出库批次
                if (msg["ReturnCode"] == "000")
                {
                    DataRow dr = null;
                    TaskDal dal = new TaskDal();
                    if (dtCrane != null)
                    {
                        DataRow[] drs = dtCrane.Select(string.Format("SQUENCE_NO='{0}'", msg["SequenceNo"]));
                        if (drs.Length > 0)
                        {
                            dr = drs[0];
                        }
                    }
                    if (dr == null)
                    {
                        //根据流水号,获取资料
                        DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.SQUENCE_NO='{0}' AND DETAIL.CRANE_NO IS NOT NULL", msg["SequenceNo"]));
                        if (dt.Rows.Count > 0)
                            dr = dt.Rows[0];
                    }
                    if (dr != null)
                    {

                        string ErrMsg = "";
                        DataRow[] drMsgs = dtErrMesage.Select(string.Format("CODE='{0}'", dr["ERR_CODE"].ToString()));
                        if (drMsgs.Length > 0)
                            ErrMsg = drMsgs[0]["DESCRIPTION"].ToString();

                        string strBillNo = "";
                        string[] strMessage = new string[4];
                        strMessage[0] = "9";
                        strMessage[1] = dr["TASK_ID"].ToString();
                        strMessage[2] = "错误代码:" + dr["ERR_CODE"] + ",错误内容:" + ErrMsg;
                        strMessage[3] = msg["CraneNo"];

                        DataTable dtProductInfo = dal.GetProductInfoByTaskID(dr["TASK_ID"].ToString());

                        while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "")
                        {
                            if (strBillNo != "1")
                            {
                                BillDal bdal = new BillDal();
                                string strNewBillNo = strBillNo;
                                //产生新的出库单
                                string strOutTaskID = bdal.CreateCancelBillOutTask(dr["TASK_ID"].ToString(), dr["BILL_NO"].ToString(), strNewBillNo, msg["CraneNo"]);
                                DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID));
                                WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask);

                                //取消当前单据的出货记录
                                CellDal cdal = new CellDal();
                                cdal.UpdateCellUnLock(dr["CELL_CODE"].ToString());
                                dal.UpdateTaskState(dr["TASK_ID"].ToString(), "3");
                                break;

                            }
                            else
                            {
                                break;
                            }
                        }

                    }
                    if (msg["AssignmenID"] == "00000000")
                    {
                        lock (dCraneState)
                        {
                            dCraneState[msg["CraneNo"]] = "0";
                        }
                    }
                }
                #endregion

            }
            SendACK(msg);
            CraneErrWriteToPLC(msg["CraneNo"], int.Parse(msg["ReturnCode"]));
        }
Ejemplo n.º 14
0
        /// <summary>
        ///接收删除指令返回值
        /// </summary>
        /// <param name="state"></param>
        private void DEC(object state)
        {
            Dictionary<string, string> msg = (Dictionary<string, string>)state;
            if (msg["ReturnCode"] == "000") //序列号出错,重新发送报文
            {
                TaskDal dal = new TaskDal();
                DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.CRANE_NO='{0}' AND ASSIGNMENT_ID='{1}'", msg["CraneNo"], msg["AssignmenID"]));
                DataRow dr = null;
                if (dt.Rows.Count > 0)
                    dr = dt.Rows[0];
                if (dr != null)
                {
                    #region 错误处理

                    if (dr["ERR_CODE"].ToString() == "111") //入库,货位有货,重新分配货位
                    {

                        CellDal cdal = new CellDal();
                        cdal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "货位有货,系统无记录");

                        string[] strValue = dal.AssignNewCell(string.Format("TASK_ID='{0}'",dr["TASK_ID"].ToString()), dr["CRANE_NO"].ToString());//货位申请
                        ProductStateDal StateDal = new ProductStateDal();
                        StateDal.UpdateProductCellCode(strValue[0], strValue[1]); //更新Product_State 货位

                        SysStationDal sysdal = new SysStationDal();
                        DataTable dtstation = sysdal.GetSationInfo(strValue[1], dr["TASK_TYPE"].ToString(), dr["ITEM_NO"].ToString());
                        dal.UpdateTaskDetailCrane(dtstation.Rows[0]["STATION_NO"].ToString(), strValue[1], "1", dtstation.Rows[0]["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO={1}", strValue[0], dr["ITEM_NO"].ToString()));//更新调度堆垛机的其实位置及目标地址。

                        dr.BeginEdit();
                        dr["CELLSTATION"] = "30" + strValue[1] + "01";
                        dr.EndEdit();
                        SendTelegramARQ(dr, false);
                        //if (dtCrane != null)
                        //{
                        //    DataRow[] drs = dtCrane.Select(string.Format("ASSIGNMENT_ID='{0}'", msg["AssignmenID"]));
                        //    if (drs.Length > 0)
                        //        dtCrane.Rows.Remove(drs[0]);
                        //}
                    }
                    else if (dr["ERR_CODE"].ToString() == "113")//出库,货位无货,
                    {

                        string ErrMsg = "";
                        DataRow[] drMsgs = dtErrMesage.Select(string.Format("CODE='{0}'", dr["ERR_CODE"].ToString()));
                        if (drMsgs.Length > 0)
                            ErrMsg = drMsgs[0]["DESCRIPTION"].ToString();

                        string strBillNo = "";
                        string[] strMessage = new string[3];
                        strMessage[0] = "8";
                        strMessage[1] =dr["TASK_ID"].ToString();
                        strMessage[2] = "错误代码:" + dr["ERR_CODE"] + ",错误内容:" + ErrMsg;

                        DataTable dtProductInfo = dal.GetProductInfoByTaskID(dr["TASK_ID"].ToString());

                        while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "")
                        {
                            BillDal bdal = new BillDal();
                            string strNewBillNo = strBillNo;

                            string strOutTaskID = bdal.CreateCancelBillOutTask(dr["TASK_ID"].ToString(), dr["BILL_NO"].ToString(), strNewBillNo);

                            DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID));

                            WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask);
                            CellDal cdal = new CellDal();
                            cdal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "货位无货,系统有记录");
                            break;
                        }
                    }
                }

                #endregion
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 发送报文,并返回发送成功。
        /// </summary>
        /// <param name="CraneNo"></param>
        /// <param name="TaskID"></param>
        /// <returns></returns>
        private bool SendTelegram(string CraneNo, DataRow  drTaskID)
        {
            bool blnSend = false;
            //判断dCraneState[CraneNo] 是否空闲;
            if (!dCraneState.ContainsKey(CraneNo))
            {
                dCraneState.Add(CraneNo, "");
                SendTelegramCRQ(CraneNo);
            }

            //状态在没有收到CSR的时候,dCraneState[CraneNo]=""
            if (string.IsNullOrEmpty(dCraneState[CraneNo]))  //等待堆垛机应答。
            {
                if (dCraneWait[CraneNo] == null && drTaskID != null)
                {
                    dCraneWait[CraneNo] = drTaskID;
                    return false;
                }
                return false;
            }
            //堆垛机正忙。
            if (dCraneState[CraneNo] == "1")
                return true;

            //堆垛机空闲,自行找任务执行
            TaskDal dal = new TaskDal();
            DataRow drTaskCrane = null;

            //出库任务调用堆垛机,drTaskID无任务,自行找出任务
            if (drTaskID==null && dtCrane!=null)
            {
                //读取二楼出库站台是否有烟包,PLC
                //按照任务等级,任务时间,产品形态,
                //FORDERBILLNO 如果有校验不合格,需另外批次替代,产生的新出库单,原始出库单号FORDERBILLNO,排序不会乱掉
                DataRow[] drs = dtCrane.Select(string.Format("CRANE_NO='{0}' and STATE=0 and TASK_TYPE in ('12','22','13','14')", CraneNo), "TASK_LEVEL,TASK_DATE,BILL_NO,IS_MIX,PRODUCT_CODE,TASK_ID");
                for (int i = 0; i < drs.Length; i++)
                {
                     //如果是二楼出库,判断当前任务的产品是不是
                    if (drs[i]["TASK_TYPE"].ToString() == "22")
                    {

                        //判断是否能出库
                        bool blnCan = dal.ProductCanToCar(drs[i]["FORDERBILLNO"].ToString(), drs[i]["FORDER"].ToString(), drs[i]["IS_MIX"].ToString(), false, blnOutOrder);  //判断能否出库
                        if (!blnCan)
                            continue;
                    }
                    drTaskCrane=drs[i];
                    break;
                }
            }
            else  //根据任务编号发送报文。
            {
                drTaskCrane = drTaskID;
            }

            if (drTaskCrane != null)
            {
                if (dCraneState[CraneNo] == "0")
                {
                    string TaskType=drTaskCrane["TASK_TYPE"].ToString();
                    //Task_Detail ITEM_NO字段
                    //TaskType:13盘点 14移库
                    string ItemNo=drTaskCrane["ITEM_NO"].ToString();
                    //正常1,2楼出库、1楼盘点移库(非同巷道)
                    if (TaskType.Substring(1, 1) == "2" || (TaskType == "13" && ItemNo == "1") || (TaskType == "14" && ItemNo == "1" && drTaskCrane["CRANE_NO"].ToString() != drTaskCrane["NEW_CRANE_NO"].ToString()))
                    {
                        //读取出库站台有无货物,如有直接返回
                        object t = ObjectUtil.GetObject(WriteToService(drTaskCrane["SERVICE_NAME"].ToString(), drTaskCrane["ITEM_NAME_1"].ToString()));//读取当前出库站台是否有货位
                        if (t.ToString() != "0")
                        {
                            blnSend = false;
                            return blnSend;
                        }
                    }
                    //出库任务,以堆垛机为第一步路线
                    if (ItemNo == "1")
                    {
                        //产生TASK_DETAIL明细,并返回TASKNO
                        string strTaskDetailNo = dal.InsertTaskDetail(drTaskCrane["TASK_ID"].ToString());

                        DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", drTaskCrane["TASK_ID"]));
                        if (drs.Length > 0)
                        {
                            drs[0].BeginEdit();
                            drs[0]["TASK_NO"] = strTaskDetailNo;
                            drs[0]["ASSIGNMENT_ID"] = strTaskDetailNo.PadLeft(8, '0');
                            drs[0].EndEdit();
                            dtCrane.AcceptChanges();
                        }
                    }
                    SendTelegramARQ(drTaskCrane, true);//发送报文
                    blnSend = true;
                }
            }

            return blnSend;
        }
Ejemplo n.º 16
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             * 二层小车进入缓存站台
            */

            object obj = ObjectUtil.GetObject(stateItem.State);

            if (obj == null || obj.ToString() == "0")
                return;

            string WriteItem = "";
            string ChannelNo = "";
            object objChannel;
            string strReadItem = "";
            try
            {
                switch (stateItem.ItemName)
                {

                    case "02_1_378_1":
                        WriteItem = "02_2_378";
                        ChannelNo = "415";
                        strReadItem = "02_1_378_2";
                        break;
                    case "02_1_381_1":
                        WriteItem = "02_2_381";
                        ChannelNo = "431";
                        strReadItem = "02_1_381_2";
                        break;
                    case "02_1_383_1":
                        WriteItem = "02_2_383";
                        ChannelNo = "438";
                        strReadItem = "02_1_383_2";
                        break;
                    case "02_1_385_1":
                        WriteItem = "02_2_385";
                        ChannelNo = "461";
                        strReadItem = "02_1_385_2";
                        break;
                    case "02_1_387_1":
                        WriteItem = "02_2_387";
                        ChannelNo = "465";
                        strReadItem = "02_1_387_2";
                        break;
                    case "02_1_389_1":
                        WriteItem = "02_2_389";
                        ChannelNo = "471";
                        strReadItem = "02_1_389_2";
                        break;
                }
                string TaskNo = obj.ToString().PadLeft(4, '0');
                objChannel = ObjectUtil.GetObject(WriteToService("StockPLC_02", strReadItem));

                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);

                if (!string.IsNullOrEmpty(strValue[0]))
                {
                     ChannelDal Cdal = new ChannelDal();

                     ChannelNo = Cdal.GetChannelFromTask(TaskNo, strValue[1]);

                     dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=5", strValue[0]), "2"); //更新
                     if (objChannel.ToString() == ChannelNo) //返回正确的缓存道。
                     {
                         int value = Cdal.UpdateInChannelTime(strValue[0], strValue[1], ChannelNo);
                         WriteToService("StockPLC_02", WriteItem + "_1", value);
                         WriteToService("StockPLC_02", WriteItem + "_2", 1);
                     }
                     else
                     {
                         int value = Cdal.UpdateInChannelAndTime(strValue[0], strValue[1], objChannel.ToString());
                         WriteToService("StockPLC_02", WriteItem + "_1", value);
                         WriteToService("StockPLC_02", WriteItem + "_2", 2);
                     }
                }

            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.StockOutInCacheProcess,原因:" + e.Message);
            }
        }
Ejemplo n.º 17
0
        private void ACP(object state)
        {
            Dictionary<string, string> msg = (Dictionary<string, string>)state;
            TaskDal dal = new TaskDal();
            if (!dCraneState.ContainsKey(msg["CraneNo"]))
            {
                dCraneState.Add(msg["CraneNo"], "");
            }
            DataRow dr = null;
            if (dtCrane != null)
            {
                DataRow[] drs = dtCrane.Select(string.Format("SQUENCE_NO='{0}'", msg["SequenceNo"]));
                if (drs.Length > 0)
                {
                    dr = drs[0];
                }
            }
            //如果在datatbale中找不到,再从数据库里查找
            if (dr == null)
            {
                //根据流水号,获取资料
                DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.SQUENCE_NO='{1}' AND DETAIL.CRANE_NO='{0}'", msg["CraneNo"], msg["SequenceNo"]));
                if (dt.Rows.Count > 0)
                    dr = dt.Rows[0];

            }
            string TaskType = "";
            string TaskID = "";
            string ItemNo = "";
            if (dr != null)
            {
                TaskType = dr["TASK_TYPE"].ToString();
                TaskID = dr["TASK_ID"].ToString();
                ItemNo = dr["ITEM_NO"].ToString();
            }
            if (msg["ReturnCode"] == "000")
            {
                #region 正常处理流程

                if (dr != null)
                {
                    //判断暂存的任务是否是当前完成的任务,如果是清空暂存
                    if (dCraneWait[msg["CraneNo"]] != null)
                    {
                        if (dCraneWait[msg["CraneNo"]]["TASK_ID"].ToString() == TaskID)
                        {
                            dCraneWait[msg["CraneNo"]] = null;
                        }
                    }

                    string strWhere = string.Format("TASK_ID='{0}' and ITEM_NO='{1}'", TaskID, ItemNo);
                    //出库,一楼盘点出库
                    if (TaskType.Substring(1, 1) == "2" || (TaskType == "13" && ItemNo == "1"))
                    {
                        if (TaskType == "12") //一楼出库
                        {
                            CellDal Cdal = new CellDal();
                            //货位解锁
                            Cdal.UpdateCellOutFinishUnLock(dr["CELL_CODE"].ToString());
                            //更新PRODUCTSTATE 出库单号
                            ProductStateDal psdal = new ProductStateDal();
                            psdal.UpdateOutBillNo(TaskID);

                        }
                        if(TaskType=="12" || TaskType=="13")
                            dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                        string ToStation;
                        if (TaskType == "22")
                            ToStation =  dr["MEMO"].ToString();
                        else
                            ToStation =  dr["TARGET_CODE"].ToString();

                        //更新TASK_DETAIL FROM_STATION TO_STATION STATE
                        dal.UpdateTaskDetailStation(dr["STATION_NO"].ToString(), ToStation, "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", TaskID));

                        int[] WriteValue = new int[3];
                        WriteValue[0] = int.Parse(dr["TASK_NO"].ToString());
                        if (TaskType == "22")
                            WriteValue[1] = int.Parse(dr["MEMO"].ToString());
                        else
                            WriteValue[1] = int.Parse(dr["TARGET_CODE"].ToString());

                        WriteValue[2] = int.Parse(dr["PRODUCT_TYPE"].ToString());

                        string Barcode = dr["PRODUCT_BARCODE"].ToString();
                        string 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);
                        //到达出库站台,再下任务给PLC
                        WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_1", WriteValue);
                        WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_2", b);
                        WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_3", 1);
                    }
                    //入库完成,更新Task任务完成。
                    else if (TaskType.Substring(1, 1) == "1" || (TaskType == "13" && dr["ITEM_NO"].ToString() == "4"))
                    {
                        dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                        dal.UpdateTaskState(TaskID, "2");//更新任务状态。
                        if (TaskType == "11")
                        {
                            CellDal Cdal = new CellDal();
                            Cdal.UpdateCellInFinishUnLock(TaskID);//入库完成,更新货位。
                        }

                        BillDal billdal = new BillDal();
                        string isBill = "1";
                        if (dr["PRODUCT_CODE"].ToString() == "0000")
                            isBill = "0";
                        billdal.UpdateInBillMasterFinished(dr["BILL_NO"].ToString(), isBill);//更新表单

                    }
                    else if (TaskType == "14")
                    {
                        #region 移库
                        //如果目标地址与源地址不同巷道
                        if (dr["CRANE_NO"].ToString() != dr["NEW_CRANE_NO"].ToString())
                        {
                            dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                            if (ItemNo == "1")
                            {
                                //更新货位信息
                                CellDal Cdal = new CellDal();
                                Cdal.UpdateCellOutFinishUnLock(dr["CELL_CODE"].ToString());
                                //更新TASK_DETAIL FROM_STATION TO_STATION STATE
                                dal.UpdateTaskDetailStation(dr["STATION_NO"].ToString(), dr["NEW_TARGET_CODE"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=2", TaskID));

                                //下达给PLC任务
                                int[] WriteValue = new int[3];
                                WriteValue[0] = int.Parse(dr["TASK_NO"].ToString());
                                WriteValue[1] = int.Parse(dr["NEW_TARGET_CODE"].ToString());
                                WriteValue[2] = int.Parse(dr["PRODUCT_TYPE"].ToString());

                                string Barcode = dr["PRODUCT_BARCODE"].ToString();
                                string 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(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_1", WriteValue);

                                WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_2", b);
                                WriteToService(dr["SERVICE_NAME"].ToString(), dr["ITEM_NAME_2"].ToString() + "_3", 1);

                                BillDal billdal = new BillDal();
                                billdal.UpdateBillMasterStart(dr["BILL_NO"].ToString(), true);//更新表单

                            }
                            else
                            {
                                dal.UpdateTaskState(TaskID, "2");//更新任务状态。

                                CellDal Cdal = new CellDal();
                                Cdal.UpdateCellInFinishUnLock(dr["NEWCELL_CODE"].ToString());

                                BillDal billdal = new BillDal();
                                string isBill = "1";
                                if (dr["PRODUCT_CODE"].ToString() == "0000")
                                    isBill = "0";
                                billdal.UpdateInBillMasterFinished(dr["BILL_NO"].ToString(), isBill);//更新表单

                            }

                        }
                        else   //相同巷道
                        {
                            dal.UpdateTaskDetailState(strWhere, "2"); //更新堆垛机状态
                            dal.UpdateTaskState(TaskID, "2");//更新任务状态。

                            CellDal Cdal = new CellDal();
                            Cdal.UpdateCellRemoveFinish(dr["NEWCELL_CODE"].ToString(), dr["CELL_CODE"].ToString()); //入库完成,更新货位。
                            Cdal.UpdateCellOutFinishUnLock(dr["CELL_CODE"].ToString());

                            BillDal billdal = new BillDal();
                            string isBill = "1";
                            if (dr["PRODUCT_CODE"].ToString() == "0000")
                                isBill = "0";
                            //更新WMS单据状态
                            billdal.UpdateInBillMasterFinished(dr["BILL_NO"].ToString(), isBill);//更新表单

                        }
                        #endregion
                    }
                    lock (dCraneState)
                    {
                        dCraneState[msg["CraneNo"]] = "0";
                    }
                    //移除完成的任务
                    if (dtCrane != null)
                    {
                        DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", TaskID));
                        if (drs.Length > 0)
                        {
                            dtCrane.Rows.Remove(drs[0]);
                        }
                    }

                    //查找发送下条报文。
                    GetNextTaskID(msg["CraneNo"], TaskType);
                }
                #endregion
            }
            else
            {
                string ErrMsg = "";
                DataRow[] drMsgs = dtErrMesage.Select(string.Format("CODE='{0}'", msg["ReturnCode"]));
                if (drMsgs.Length > 0)
                    ErrMsg = drMsgs[0]["DESCRIPTION"].ToString();

                dal.UpdateCraneErrCode(TaskID, ItemNo, msg["ReturnCode"]);//更新堆垛机错误编号
                Logger.Error(string.Format("堆垛机{0}返回错误代码{1}:{2}", msg["CraneNo"], msg["ReturnCode"], ErrMsg));

            }
            SendACK(msg);
            CraneErrWriteToPLC(msg["CraneNo"], int.Parse(msg["ReturnCode"]));
        }
Ejemplo n.º 18
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             * 二层出库拆盘完成
             *  stateItem.State :参数 - 请求的卷烟编码。
            */

            object obj = ObjectUtil.GetObject(stateItem.State);

            if (obj == null || obj.ToString() == "0")
                return;

            string WriteItem="";
            string FromStation = "";
            string strTaskItem = "";
            object objTaskNo;
            try
            {
                switch (stateItem.ItemName)
                {
                    case "02_1_372_1":
                        FromStation = "372";
                        WriteItem = "02_2_372";
                        strTaskItem = "02_1_372_2";

                        break;
                    case "02_1_392_1":
                        FromStation = "392";
                        WriteItem = "02_2_392";
                        strTaskItem = "02_1_392_2";
                        break;
                }
                objTaskNo = ObjectUtil.GetObject(WriteToService("StockPLC_02", strTaskItem));
                string TaskNo = objTaskNo.ToString().PadLeft(4, '0');
                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);
                if (!string.IsNullOrEmpty(strValue[0]))
                {

                    bool blnvalue = dal.SeparateTaskDetailStart(strValue[0]); //判断该任务是否开始执行
                    if (!blnvalue)
                    {
                        ChannelDal cdal = new ChannelDal();
                        string strChannelNo = cdal.InsertChannel(strValue[0], strValue[1]);//分配缓存道
                        if (strChannelNo != "")
                        {
                            dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=4", strValue[0]), "2");
                            WriteToService("StockPLC_02", WriteItem + "_1", int.Parse(strChannelNo));
                            WriteToService("StockPLC_02", WriteItem + "_2", 1);
                            dal.UpdateTaskDetailStation(FromStation, strChannelNo, "1", string.Format("TASK_ID='{0}' AND ITEM_NO=5", strValue[0]));
                        }
                    }

                }

            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.StockOutSeparateProcess,原因:" + e.Message);
            }
        }
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  stateItem.ItemName :
             *  Init - 初始化。
             *      FirstBatch - 生成第一批入库请求任务。
             *      StockInRequest - 根据请求,生成入库任务。
             *
             *  stateItem.State :参数 - 请求的卷烟编码。
            */
              //烟包托盘到达出库站台,根据返回的任务号,判断是否正常烟包:
               // 1、正常烟包,更新原有CranProcess的datatable将状态更改为3,并更改数据库状态。调用WriteToProcess(穿梭车Process).
               // 2、错误烟包,写入移库单,产生任务,调用调用WriteToProcess(穿梭车Process)。写入出库单,产生任务,并下达出库任务。
            object[] obj = ObjectUtil.GetObjects(stateItem.State);
            if (obj[0] == null || obj[0].ToString() == "0")
                return;

            try
            {
                string ToStation = "";
                string FromStation = "";
                string ReadItem2 = "";
                switch (stateItem.ItemName)
                {
                    case "02_1_304_1":
                        FromStation = "303";
                        ToStation = "304";
                        ReadItem2 = "02_1_304_2";
                        break;
                    case "02_1_308_1":
                        FromStation = "307";
                        ToStation = "308";
                        ReadItem2 = "02_1_308_2";
                        break;
                    case "02_1_312_1":
                        FromStation = "311";
                        ToStation = "313";
                        ReadItem2 = "02_1_312_2";
                        break;
                    case "02_1_316_1":
                        FromStation = "315";
                        ToStation = "316";
                        ReadItem2 = "02_1_316_2";
                        break;
                    case "02_1_320_1":
                        FromStation = "319";
                        ToStation = "320";
                        ReadItem2 = "02_1_320_2";
                        break;
                    case "02_1_322_1":
                        FromStation = "321";
                        ToStation = "322";
                        ReadItem2 = "02_1_322_2";
                        break;
                }

               string StationState ="";

                TaskDal dal = new TaskDal();
                string[] strTask = dal.GetTaskInfo(obj[0].ToString().PadLeft(4, '0'));

                if (!string.IsNullOrEmpty(strTask[0]))
                {
                    //更新
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strTask[0]), "2");

                    DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strTask[0]));
                    string CellCode = dtTask.Rows[0]["CELL_CODE"].ToString();
                    CellDal Celldal = new CellDal();

                    //TaskID
                    StationState = strTask[0];

                    //校验正确烟包
                    if (obj[1].ToString() == "1")
                    {
                        WriteToProcess("CraneProcess", "StockOutToCarStation", StationState);

                        //解除货位锁定
                        Celldal.UpdateCellOutFinishUnLock(CellCode);
                        ProductStateDal psdal = new ProductStateDal();
                        psdal.UpdateOutBillNo(strTask[0]); //更新出库单
                        //获取任务记录
                        DataTable dt = dal.TaskCarDetail(string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=3 AND DETAIL.STATE=0 ", strTask[0]));
                        //调度小车;
                        WriteToProcess("CarProcess", "CarOutRequest", dt);
                    }
                    else //校验错误烟包
                    {
                        //返回读取到的RFID
                        string NewPalletCode = Common.ConvertStringChar.BytesToString((object[])ObjectUtil.GetObjects(WriteToService("StockPLC_02", ReadItem2)));

                        DataTable dtProductInfo = dal.GetProductInfoByTaskID(strTask[0]);

                        string strBillNo = "";
                        string[] strMessage = new string[3];
                        //strMessage[0] 弹出窗口类别,5是校验窗口
                        strMessage[0] = "5";
                        strMessage[1] = strTask[0];
                        strMessage[2] = NewPalletCode;

                        //弹出校验不合格窗口,人工选择处理方式
                        //strBillNo返回1 继续出库,否则返回替代的入库批次
                        while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "")
                        {
                            string strNewBillNo = strBillNo;
                            if (string.IsNullOrEmpty(strNewBillNo))
                            {
                                if (strNewBillNo == "1")
                                {
                                    WriteToProcess("CraneProcess", "StockOutToCarStation", StationState); //更新堆垛机任务明细为完成状态。
                                    Celldal.UpdateCellOutFinishUnLock(CellCode);//解除货位锁定
                                    ProductStateDal psdal = new ProductStateDal();
                                    psdal.UpdateOutBillNo(strTask[0]); //更新出库单

                                    DataTable dtCar = dal.TaskCarDetail(string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=3 AND DETAIL.STATE=0 ", strTask[0])); //获取任务ID
                                    WriteToProcess("CarProcess", "CarOutRequest", dtCar);  //调度小车;
                                }
                                else
                                {
                                    //生成二楼退库单
                                    BillDal bdal = new BillDal();
                                    //产生WMS退库单以及WCS任务,并生成TaskDetail。
                                    string CancelTaskID = bdal.CreateCancelBillInTask(strTask[0], strTask[1]);
                                    //更新货位错误标志。
                                    Celldal.UpdateCellNewPalletCode(CellCode, NewPalletCode);
                                    //更新退库申请货位完成。
                                    dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CancelTaskID));
                                    //更新出库任务完成
                                    dal.UpdateTaskState(strTask[0], "2");

                                    string strWhere = string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=2 AND DETAIL.STATE=0 ", CancelTaskID);
                                    DataTable dt = dal.TaskCarDetail(strWhere);
                                    //写入调小车的源地址目标地址
                                    if (dt.Rows.Count > 0)
                                    {
                                        SysStationDal sysdal = new SysStationDal();
                                        DataTable dtCarStation = sysdal.GetCarSationInfo(CellCode, "22");
                                        dt.Rows[0].BeginEdit();
                                        dt.Rows[0]["IN_STATION_ADDRESS"] = dtCarStation.Rows[0]["IN_STATION_ADDRESS"];
                                        dt.Rows[0]["IN_STATION"] = dtCarStation.Rows[0]["IN_STATION"];
                                        dt.Rows[0].EndEdit();
                                    }
                                    //调度穿梭车入库。
                                    WriteToProcess("CarProcess", "CarInRequest", dt);
                                    //创建替代入库批次的WMS单据,WCS出库任务
                                    string strOutTaskID = bdal.CreateCancelBillOutTask(strTask[0], strTask[1], strNewBillNo);
                                    DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID));
                                    //调度穿梭车出库
                                    WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask);

                                    //延迟
                                    int i = 0;
                                    while (i < 100)
                                    {
                                        i++;
                                    }

                                    //StationState:原任务TASKID,更新堆垛机Process 状态为2.
                                    WriteToProcess("CraneProcess", "StockOutToCarStation", StationState);
                                    //插入替换批次记录
                                    DataTable dtNewProductInfo = dal.GetProductInfoByTaskID(strOutTaskID);
                                    dal.InsertChangeProduct(dtProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtProductInfo.Rows[0]["PRODUCT_CODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_CODE"].ToString());
                                }
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.StockOutToCarStationProcess:" + e.Message);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dt"></param>
        private void InsertdtCar(DataTable dt)
        {
            if (dtCar == null)
            {
                dtCar = new DataTable();
                dtCar = dt.Clone();
                DataColumn dcIndex = new DataColumn("Index", Type.GetType("System.Int16"));
                dtCar.Columns.Add(dcIndex);
            }
            if (dt.Rows.Count == 0)
                return;

            //插入

            //调用小车任务插入缓存表

            object[] obj = new object[dt.Columns.Count + 1];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow[] drsExist = dtCar.Select(string.Format("TASK_ID='{0}'", dt.Rows[i]["TASK_ID"]));
                if (drsExist.Length > 0)
                    continue;

                dt.Rows[i].ItemArray.CopyTo(obj, 0);
                obj[dt.Columns.Count] = OrderIndex + i;
                dtCar.Rows.Add(obj);

            }
            dtCar.AcceptChanges();
            DataRow[] drsTask = dtCar.Select(string.Format("TASK_ID='{0}'", dt.Rows[0]["TASK_ID"]));
            if (drsTask.Length > 0)
            {
                DataRow dr = drsTask[0];

                long CurPostion = 0;
                long ToPostion = 0;
                string FromStation = "";
                string ToStation = "";
                string TargetCode = "";
                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();
                }

                TaskDal dal = new TaskDal();

                DataTable dtorder = GetCarOrder(CurPostion);
                DataRow[] drsOrder = dtorder.Select("", "orderNo desc");
                for (int i = 0; i < drsOrder.Length; i++)
                {
                    if (drsOrder[i]["State"].ToString() == "0") //小车空闲
                    {
                        #region 小车空闲
                        if (dr["TASK_TYPE"].ToString() == "22")
                        {
                            ToPostion = -1;

                            //判断二楼能否出库
                            bool 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")
                                    {
                                        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)
                                            {
                                                ToPostion = long.Parse(dr["OUT_STATION_2_ADDRESS"].ToString());
                                                ToStation = dr["OUT_STATION_2"].ToString();
                                                TargetCode = "390";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        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
                                        {
                                            objstate = int.Parse(ObjectUtil.GetObject(WriteToService("StockPLC_02", "02_1_370")).ToString());
                                            if (objstate == 0)
                                            {
                                                ToStation = dr["OUT_STATION_1"].ToString();
                                                ToPostion = long.Parse(dr["OUT_STATION_1_ADDRESS"].ToString());
                                                TargetCode = "370";
                                            }
                                        }
                                    }

                                    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", drsOrder[i]["WriteItem"].ToString() + "_1", WriteTaskValue);//任务号。
                            WriteToService("StockPLC_02", drsOrder[i]["WriteItem"].ToString() + "_2", WriteValue);//地址。
                            WriteToService("StockPLC_02", drsOrder[i]["WriteItem"].ToString() + "_3", b);
                            WriteToService("StockPLC_02", drsOrder[i]["WriteItem"].ToString() + "_4", 1);

                            dr.BeginEdit();
                            dr["CAR_NO"] = drsOrder[i]["CAR_NO"].ToString();
                            dr["STATE"] = 1;
                            dr.EndEdit();

                            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
                    }
                    else
                    {
                        #region 小车不空闲,但是目的地小于当前位置
                        if (int.Parse(drsOrder[i]["ToStation"].ToString()) < CurPostion) //小车不空闲,但是目的地小于当前位置
                        {
                            if (dtCar.Select(string.Format("STATE=0 and CAR_NO='{0}'", drsOrder[i]["CAR_NO"].ToString())).Length == 0) //判断当前小车,是否已经有分配未执行的任务,则给小车分配任务
                            {
                                //判断二楼能否出库
                                bool blnCan = false;
                                if (dr["TASK_TYPE"].ToString() == "21")
                                    blnCan = true;
                                else
                                    blnCan = dal.ProductCanToCar(dr["FORDERBILLNO"].ToString(), dr["FORDER"].ToString(), dr["IS_MIX"].ToString(), true, blnOutOrder);
                                if (blnCan)
                                {
                                    dr.BeginEdit();
                                    dr["CAR_NO"] = drsOrder[i]["CAR_NO"];
                                    dr["WriteItem"] = drsOrder[i]["WriteItem"];
                                    dr.EndEdit();
                                    break;
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
        }
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
            * 二层出库到开包线
            *
               */

                object obj = ObjectUtil.GetObject(stateItem.State);
                if (obj == null || obj.ToString() == "0")
                    return;
                try
                {
                    string TaskNo = obj.ToString().PadLeft(4, '0');
                    TaskDal dal = new TaskDal();
                    string[] strValue = dal.GetTaskInfo(TaskNo);
                    string WriteItem = "";
                    string ReadItem = "";
                    string PackLine = "";
                    if (!string.IsNullOrEmpty( strValue[0]))
                    {

                        switch (stateItem.ItemName)
                        {
                            case "02_1_250_1":
                                WriteItem = "02_2_250";
                                ReadItem = "02_1_250_2";
                                PackLine = "制丝1号线";
                                break;
                            case "02_1_251_1":
                                WriteItem = "02_2_251";
                                ReadItem = "02_1_251_2";
                                PackLine = "制丝2号线";
                                break;
                            case "02_1_252_1":
                                WriteItem = "02_2_252";
                                ReadItem = "02_1_252_2";
                                PackLine = "制丝3号线";
                                break;
                            case "02_1_253_1":
                                WriteItem = "02_2_253";
                                ReadItem = "02_1_253_2";
                                PackLine = "制丝1号线";
                                break;
                            case "02_1_254_1":
                                WriteItem = "02_2_254";
                                ReadItem = "02_1_254_2";
                                PackLine = "制丝2号线";
                                break;
                            case "02_1_255_1":
                                WriteItem = "02_2_255";
                                ReadItem = "02_1_255_2";
                                PackLine = "制丝3号线";
                                break;
                        }
                        object objCheck = ObjectUtil.GetObject(WriteToService("StockPLC_02", ReadItem ));
                        if (objCheck.ToString() == "0")
                        {
                            Logger.Error(PackLine + "校验出错,请人工处理。");
                        }
                        dal.UpdateTaskState(strValue[0], "2");

                        BillDal bDal = new BillDal();
                        bDal.UpdateOutBillMasterFinished(strValue[1]);

                        WriteToService("StockPLC_02", WriteItem, 1);

                    }

                }
                catch (Exception e)
                {
                    Logger.Error("THOK.XC.Process.Process_02.StockOutToUnpackLineProcess,原因:" + e.Message);
                }
        }
Ejemplo n.º 22
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     TaskDal taskDal = new TaskDal();
     DataTable dt = taskDal.TaskOutToDetail();
     DataTable dt2 = null;
     //if (IndexStar == 0)
     //{
     //    string strWhere = string.Format("TASK_TYPE IN ({0}) AND DETAIL.STATE IN ({1})  AND DETAIL.CRANE_NO IS NOT NULL ", "11,21,12,13,14", "0,1");
     //    dt2 = taskDal.CraneTaskIn(strWhere);
     //    strWhere = string.Format("TASK_TYPE IN ({0}) AND DETAIL.STATE IN ({1}) AND DETAIL.CRANE_NO IS NOT NULL ", "22", "0,1,2");
     //    DataTable dtout = taskDal.CraneTaskIn(strWhere);
     //    dt2.Merge(dtout);
     //}
     DataTable[] dtSend = new DataTable[2];
     dtSend[0] = dt;
     dtSend[1] = dt2;
     Context.Processes["CraneProcess"].Start();
     Context.ProcessDispatcher.WriteToProcess("CraneProcess", "StockOutRequest", dtSend);
     IndexStar++;
 }
Ejemplo n.º 23
0
        /// <summary>
        /// 发送报文后,堆垛机发送接收确认。
        /// </summary>
        /// <param name="state"></param>
        private void ACK(object state)
        {
            Dictionary<string, string> msg = (Dictionary<string, string>)state;
            DataRow dr = null;
            TaskDal dal = new TaskDal();
            if (dtCrane != null)
            {
                DataRow[] drs = dtCrane.Select(string.Format("SQUENCE_NO='{0}'", msg["SequenceNo"]));
                if (drs.Length > 0)
                {
                    dr = drs[0];
                }
            }
            if (dr == null)
            {
                //根据流水号,获取资料
                DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.SQUENCE_NO='{0}' AND DETAIL.CRANE_NO IS NOT NULL", msg["SequenceNo"]));
                if (dt.Rows.Count > 0)
                    dr = dt.Rows[0];
            }

            #region 缓存数据存在
            if (dr != null)
            {
                string TaskType = dr["TASK_TYPE"].ToString();
                string ItemNo = dr["ITEM_NO"].ToString();
                BillDal bdal = new BillDal();
                if (TaskType.Substring(1, 1) == "2" || (TaskType == "13" && ItemNo == "1") || (TaskType == "14" && ItemNo == "1" && dr["CRANE_NO"].ToString() != dr["NEW_CRANE_NO"].ToString()))
                {

                    dal.UpdateTaskState(dr["TASK_ID"].ToString(), "1");
                    dal.UpdateTaskDetailCrane(dr["CELL_CODE"].ToString(), dr["STATION_NO"].ToString(), "1", dr["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO={1}", dr["TASK_ID"], dr["ITEM_NO"]));
                    //更新BILL_MASTER 单据状态作业中
                    bdal.UpdateBillMasterStart(dr["BILL_NO"].ToString(), dr["PRODUCT_CODE"].ToString() == "0000" ? false : true);

                }
                else if (TaskType == "14" && ItemNo == "1" && dr["CRANE_NO"].ToString() == dr["NEW_CRANE_NO"].ToString())
                {
                    //出库任务 更新任务状态:任务执行中
                    dal.UpdateTaskState(dr["TASK_ID"].ToString(), "1");
                    dal.UpdateTaskDetailCrane(dr["CELL_CODE"].ToString(), dr["NEWCELL_CODE"].ToString(), "1", dr["CRANE_NO"].ToString(), string.Format("TASK_ID='{0}' AND ITEM_NO={1}", dr["TASK_ID"], dr["ITEM_NO"]));
                    bdal.UpdateBillMasterStart(dr["BILL_NO"].ToString(), true);
                }
                else
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' and ITEM_NO={1}", dr["TASK_ID"], dr["ITEM_NO"]), "1");

                if (dtCrane != null)
                {
                    DataRow []drs=dtCrane.Select(string.Format("TASK_ID='{0}'",dr["TASK_ID"]));
                    if(drs.Length>0)
                    {
                        drs[0].BeginEdit();
                        drs[0]["state"]="1";
                        drs[0].EndEdit();
                        dtCrane.AcceptChanges();
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 24
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  stateItem.ItemName :
             *  Init - 初始化。
             *      FirstBatch - 生成第一批入库请求任务。
             *      StockInRequest - 根据请求,生成入库任务。
             *
             *  stateItem.State :参数 - 请求的卷烟编码。
            */
            object obj =stateItem.State;

            if (obj == null || obj.ToString() == "0")
                return;

            string FromStation="";
            string ToStation="";
            string WriteItem = "";
            try
            {
                switch (stateItem.ItemName)
                {
                    case "02_1_340":
                        FromStation = "340";
                        ToStation = "372";
                        WriteItem = "02_2_340";
                        break;
                    case "02_1_360":
                        FromStation = "360";
                        ToStation = "392";
                        WriteItem = "02_2_360";
                        break;

                }

                string TaskNo = obj.ToString().PadLeft(4, '0');
                TaskDal dal = new TaskDal();
                string[] strValue = dal.GetTaskInfo(TaskNo);
                if (!string.IsNullOrEmpty(strValue[0]))
                {
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=3", strValue[0]), "2");

                    //
                    DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strValue[0]));
                    if (dt.Rows.Count > 0)
                    {
                        int[] WriteValue = new int[3];
                        WriteValue[0] = int.Parse(TaskNo);
                        WriteValue[1] = int.Parse(FromStation);
                        WriteValue[2] = int.Parse(ToStation);

                        WriteToService("StockPLC_02", WriteItem + "_1", WriteValue);

                        string barcode = dt.Rows[0]["PRODUCT_BARCODE"].ToString();
                        string palletcode = dt.Rows[0]["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 + "_2", b);
                        WriteToService("StockPLC_02", WriteItem + "_3", 1);
                    }
                    dal.UpdateTaskDetailStation(FromStation, ToStation, "1", string.Format("TASK_ID='{0}' AND ITEM_NO=4", strValue[0]));
                }
            }

            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_02.StockOutCarFinishProcess,原因:" + e.Message);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 堆垛机状态。
        /// </summary>
        /// <param name="state"></param>
        private void CSR(object state)
        {
            Dictionary<string, string> msg = (Dictionary<string, string>)state;
            if (!dCraneState.ContainsKey(msg["CraneNo"]))
            {
                dCraneState.Add(msg["CraneNo"], "");
            }
            //如果返回错误代码是000时,CraneMode=1表示堆垛机是自动状态,CraneMode 1: automatic 2: stopped 3: manual
            if (msg["ReturnCode"] == "000")
            {
                lock (dCraneState)
                {
                    if (msg["AssignmenID"] == "00000000" && msg["CraneMode"] == "1")
                    {
                        //此堆垛机状态为空闲
                        dCraneState[msg["CraneNo"]] = "0";

                        if (dCraneWait[msg["CraneNo"]] != null)
                        {
                            SendTelegram(msg["CraneNo"], dCraneWait[msg["CraneNo"]]);
                        }
                        else
                        {
                            SendTelegram(msg["CraneNo"], null);
                        }
                    }
                    else
                        dCraneState[msg["CraneNo"]] = "1";
                }
            }
            else
            {
                TaskDal dal = new TaskDal();
                DataRow dr = null;
                if (dtCrane != null)
                {
                    DataRow[] drs = dtCrane.Select(string.Format("ASSIGNMENT_ID='{0}'", msg["AssignmenID"]));
                    if (drs.Length > 0)
                    {
                        dr = drs[0];
                    }
                }
                //如果在datatbale中找不到,再从数据库里查找
                if (dr == null)
                {
                    //根据流水号,获取资料
                    DataTable dt = dal.CraneTaskIn(string.Format("DETAIL.ASSIGNMENT_ID='{1}' AND DETAIL.CRANE_NO='{0}'", msg["CraneNo"], msg["AssignmenID"]));
                    if (dt.Rows.Count > 0)
                        dr = dt.Rows[0];

                }
                string TaskID = "";
                string ItemNo = "";
                if (dr != null)
                {
                    TaskID = dr["TASK_ID"].ToString();
                    ItemNo = dr["ITEM_NO"].ToString();

                    string ErrMsg = "";
                    DataRow[] drMsgs = dtErrMesage.Select(string.Format("CODE='{0}'", msg["ReturnCode"]));
                    if (drMsgs.Length > 0)
                        ErrMsg = drMsgs[0]["DESCRIPTION"].ToString();
                    Logger.Error(string.Format("堆垛机{0}返回错误代码{1}:{2}", msg["CraneNo"], msg["ReturnCode"], ErrMsg));

                    dal.UpdateCraneErrCode(TaskID, ItemNo, msg["ReturnCode"]);//更新堆垛机错误编号
                }

            }
            SendACK(msg);
            CraneErrWriteToPLC(msg["CraneNo"], int.Parse(msg["ReturnCode"]));
        }
Ejemplo n.º 26
0
        /*  处理事项:
            *  抽检,补料,盘点  烟包到达,195
            */
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {
                object sta = ObjectUtil.GetObject(stateItem.State);

                if (sta==null || sta.ToString() == "0")
                    return;
                string[] str = new string[3];
                if (((short)sta) >= 9000 && ((short)sta) <= 9299) //补料
                    str[0] = "1";
                else if (((short)sta) >= 9300 && ((short)sta) <= 9499)//抽检
                    str[0] = "2";
                else if (((short)sta) >= 9800 && ((short)sta) < 9999) //盘点
                    str[0] = "6";
                str[1] = "";
                str[2] = "";

                //根据任务号,获取TaskID及BILL_NO
                TaskDal dal = new TaskDal();
                string[] strInfo = dal.GetTaskInfo(sta.ToString().PadLeft(4, '0'));
                DataTable dt = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0]));
                DataTable dtProductInfo = dal.GetProductInfoByTaskID(strInfo[0]);
                //线程停止
                string strValue = "";
                while ((strValue = FormDialog.ShowDialog(str, dtProductInfo)) != "")
                {
                    dal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=2", strInfo[0]), "2");
                    string writeItem = "01_2_195_";
                    if (str[0] == "1" || str[0] == "2")  //抽检,补料
                    {
                        dal.UpdateTaskState(strInfo[0], "2");

                        BillDal billdal = new BillDal();
                        billdal.UpdateInBillMasterFinished(strInfo[1],"1");

                        int[] ServiceW = new int[3];
                        ServiceW[0] = int.Parse(strInfo[1]); //任务号
                        ServiceW[1] = 131;//目的地址
                        ServiceW[2] = 4;

                        WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务

                        WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务
                    }
                    else  //盘点
                    {
                        DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strInfo[0]));

                        DataRow dr = dtTask.Rows[0];
                        SysStationDal sysdal = new SysStationDal();
                        DataTable dtstation = sysdal.GetSationInfo(dr["CELL_CODE"].ToString(), "11", "3");

                        if (strValue != "1")
                        {
                            CellDal celldal = new CellDal();
                            celldal.UpdateCellErrFlag(dr["CELL_CODE"].ToString(), "条码扫描不一致");
                        }

                        int[] ServiceW = new int[3];
                        ServiceW[0] = int.Parse(strInfo[1]); //任务号
                        ServiceW[1] = int.Parse(dtstation.Rows[0]["STATION_NO"].ToString());//目的地址
                        ServiceW[2] = 1;

                        WriteToService("StockPLC_01", writeItem + "1", ServiceW); //PLC写入任务
                        WriteToService("StockPLC_01", writeItem + "2", 1); //PLC写入任务

                        dal.UpdateTaskDetailStation("195", dtstation.Rows[0]["STATION_NO"].ToString(), "1", string.Format("TASK_ID='{0}' AND ITEM_NO=3", strInfo[0]));//更新货位到达入库站台,

                    }

                   //线程继续。
                    break;
                }

            }
            catch (Exception ex)
            {
                Logger.Error("THOK.XC.Process.Process_01.CheckOutToStationProcess:" + ex.Message);
            }
        }
Ejemplo n.º 27
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            /*  处理事项:
             *
             *  堆垛机任务处理
             *  出库任务传入Task 需要产生TaskDetail,并更新起始位置及目的地。
             *  入库任务传入TaskDetail
             *  Init - 初始化。
             *      FirstBatch - 生成第一批入库请求任务。
             *      StockInRequest - 根据请求,生成入库任务。
             *
             *  stateItem.State :参数 - 请求的卷烟编码。
            */
            try
            {
                switch (stateItem.ItemName)
                {
                    //开始出库,主动调用。
                    case "StockOutRequest":
                        DataTable[] dtSend = (DataTable[])stateItem.State;
                        if (dtSend[1] != null)
                        {
                            InsertCraneQuene(dtSend[1]);
                        }
                        InsertCraneQuene(dtSend[0]);
                        //线程调度堆垛机
                        CraneThreadStart();
                        break;

                    //二楼出库RFID校验,Task_Detail ItemNo=1 状态更新为2,确认检验完成后,才可下下一产品的下一任务
                    case "StockOutToCarStation":
                        string  strdd = (string)stateItem.State;
                        if (dtCrane != null)
                        {
                            DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", strdd));
                            if (drs.Length > 0)
                            {
                                dtCrane.Rows.Remove(drs[0]);
                            }

                            TaskDal tdal = new TaskDal();
                            //ItemNo=1 状态更新为2
                            tdal.UpdateTaskDetailState(string.Format("TASK_ID='{0}' AND ITEM_NO=1", strdd), "2");

                            //更新完成之后,线程调用堆垛机,避免堆垛机因调度原因而是堆垛机没有任务。
                            CraneThreadStart();
                        }
                        break;
                    //货物到达入库站台,调用堆垛机
                    case "CraneInRequest":
                        DataTable dtInCrane = (DataTable)stateItem.State;
                        InsertCraneQuene(dtInCrane);
                        SendTelegram(dtInCrane.Rows[0]["CRANE_NO"].ToString(), dtInCrane.Rows[0]);
                        break;
                    case "ACP":
                        ACP(stateItem.State);
                        break;
                    case "CSR":
                        CSR(stateItem.State);
                        break;
                    case "ACK":
                        ACK(stateItem.State);
                        break;
                    case "DUM":
                        SendDUA();
                        break;
                    case "DUU":
                        SendDUM();
                        break;
                    case "NCK":
                        NCK(stateItem.State);
                        break;
                    case "DEC":
                        DEC(stateItem.State);
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                Logger.Error("THOK.XC.Process.Process_Crane.CraneProcess,原因:" + e.Message);
            }
        }
Ejemplo n.º 28
0
        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);
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// blnValue=true 正常发送ARQ报文,如果目标地址有货,报警,并要重新指定新货位,blnValue=false
        /// </summary>
        /// <param name="dr"></param>
        /// <param name="blnValue"></param>
        private void SendTelegramARQ(DataRow dr,bool blnValue)
        {
            THOK.CRANE.TelegramData tgd = new CRANE.TelegramData();
            tgd.CraneNo = dr["CRANE_NO"].ToString();
            tgd.AssignmenID = dr["ASSIGNMENT_ID"].ToString();
            if (!blnValue)
            {
                tgd.AssignmentType = "DE";
            }
            string TaskType = dr["TASK_TYPE"].ToString();
            string ItemNo = dr["ITEM_NO"].ToString();

            if (TaskType.Substring(1, 1) == "4" && ItemNo == "1" && dr["CRANE_NO"].ToString() == dr["NEW_CRANE_NO"].ToString())
            {
                tgd.StartPosition = dr["CRANESTATION"].ToString();
                tgd.DestinationPosition = dr["NEW_TO_STATION"].ToString();
            }
            else
            {
                if (TaskType.Substring(1, 1) == "1" || (TaskType.Substring(1, 1) == "4" && ItemNo == "3") || TaskType.Substring(1, 1) == "3" && ItemNo == "4") //入库
                {
                    tgd.StartPosition = dr["CRANESTATION"].ToString();
                    tgd.DestinationPosition = dr["CELLSTATION"].ToString();
                }
                else //出库
                {
                    tgd.StartPosition = dr["CELLSTATION"].ToString();
                    tgd.DestinationPosition = dr["CRANESTATION"].ToString();
                }
            }

            THOK.CRANE.TelegramFraming tf = new CRANE.TelegramFraming();
            string QuenceNo = GetNextSQuenceNo();
            string str = tf.DataFraming("1" + QuenceNo, tgd, tf.TelegramARQ);
            WriteToService("Crane", "ARQ", str);

            DataRow[] drs = dtCrane.Select(string.Format("TASK_ID='{0}'", dr["TASK_ID"]));
            if (drs.Length > 0)
            {
                drs[0].BeginEdit();
                drs[0]["SQUENCE_NO"] = QuenceNo;
                drs[0].EndEdit();
                dtCrane.AcceptChanges();

                dr.BeginEdit();
                dr["SQUENCE_NO"] = QuenceNo;
                dr.EndEdit();
            }
            lock (dCraneState)
            {
                dCraneState[dr["CRANE_NO"].ToString()] = "1";
            }

            //更新发送报文。
            TaskDal dal = new TaskDal();
            dal.UpdateCraneQuenceNo(dr["TASK_ID"].ToString(), dr["SQUENCE_NO"].ToString(), ItemNo); //更新堆垛机序列号。并更新为1
        }
Ejemplo n.º 30
0
        /// <summary>
        /// У�鴦��
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVerficate_Click(object sender, EventArgs e)
        {
            string ServiceName = "StockPLC_02";
            string[] ItemName = new string[6];
            ItemName[0] = "02_1_304_1";
            ItemName[1] = "02_1_308_1";
            ItemName[2] = "02_1_312_1";
            ItemName[3] = "02_1_316_1";
            ItemName[4] = "02_1_320_1";
            ItemName[5] = "02_1_322_1";
            for (int i = 0; i < ItemName.Length; i++)
            {
                object[] obj = ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(ServiceName, ItemName[i]));
                if (obj[0] == null || obj[0].ToString() == "0")
                    continue;
                if (obj[1].ToString() == "1")
                    continue;

                string ToStation = "";
                string FromStation = "";
                string ReadItem2 = "";

                switch (ItemName[i])
                {
                    case "02_1_304_1":
                        FromStation = "303";
                        ToStation = "304";
                        ReadItem2 = "02_1_304_2";
                        break;
                    case "02_1_308_1":
                        FromStation = "307";
                        ToStation = "308";
                        ReadItem2 = "02_1_308_2";
                        break;
                    case "02_1_312_1":
                        FromStation = "311";
                        ToStation = "313";
                        ReadItem2 = "02_1_312_2";
                        break;
                    case "02_1_316_1":
                        FromStation = "315";
                        ToStation = "316";
                        ReadItem2 = "02_1_316_2";
                        break;
                    case "02_1_320_1":
                        FromStation = "319";
                        ToStation = "320";
                        ReadItem2 = "02_1_320_2";
                        break;
                    case "02_1_322_1":
                        FromStation = "321";
                        ToStation = "322";
                        ReadItem2 = "02_1_322_2";
                        break;

                }

                TaskDal dal = new TaskDal();
                string[] strTask = dal.GetTaskInfo(obj[0].ToString().PadLeft(4, '0'));
                if (!string.IsNullOrEmpty(strTask[0]))
                {
                    string NewPalletCode = THOK.XC.Process.Common.ConvertStringChar.BytesToString((object[])ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService("StockPLC_02", ReadItem2)));
                    string[] StationState = new string[2];
                    CellDal Celldal = new CellDal(); //���»�λ��������RFID�������־��
                    DataTable dtProductInfo = dal.GetProductInfoByTaskID(strTask[0]);
                    DataTable dtTask = dal.TaskInfo(string.Format("TASK_ID='{0}'", strTask[0]));
                    string CellCode = dtTask.Rows[0]["CELL_CODE"].ToString();
                    string strBillNo = "";
                    string[] strMessage = new string[3];
                    strMessage[0] = "5";
                    strMessage[1] = strTask[0];
                    strMessage[2] = NewPalletCode;
                    ProductStateDal psdal = new ProductStateDal();
                    if (psdal.ExistsPalletCode(dtTask.Rows[0]["PALLET_CODE"].ToString())) //�Ѿ������������
                        continue;
                    while ((strBillNo = FormDialog.ShowDialog(strMessage, dtProductInfo)) != "")
                    {

                        string strNewBillNo = strBillNo;
                        if (string.IsNullOrEmpty(strNewBillNo))
                        {
                            if (strNewBillNo == "1")
                            {
                                StationState[0] = obj[0].ToString();//�����;
                                StationState[1] = "3";

                                //this.Context.Processes["CraneProcess"].Start();
                              Context.ProcessDispatcher.WriteToProcess("CraneProcess", "StockOutToCarStation", StationState); //���¶Ѷ��Process ״̬Ϊ3.

                                Celldal.UpdateCellOutFinishUnLock(CellCode);//��������

                                psdal.UpdateOutBillNo(strTask[0]); //���³��ⵥ

                                DataTable dtCar = dal.TaskCarDetail(string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=3 AND DETAIL.STATE=0 ", strTask[0])); //��ȡ����ID
                                Context.ProcessDispatcher.WriteToProcess("CarProcess", "CarOutRequest", dtCar);  //��������
                            }
                            else
                            {
                                //���ɶ�¥�˿ⵥ
                                BillDal bdal = new BillDal();
                                string CancelTaskID = bdal.CreateCancelBillInTask(strTask[0], strTask[1]);//�����˿ⵥ����������ϸ��
                                Celldal.UpdateCellNewPalletCode(CellCode, NewPalletCode);//���»�λ�����־��

                                dal.UpdateTaskDetailStation(FromStation, ToStation, "2", string.Format("TASK_ID='{0}' AND ITEM_NO=1", CancelTaskID)); //���������λ��ɡ�
                                dal.UpdateTaskState(strTask[0], "2");//���³����������

                                string strWhere = string.Format("WCS_TASK.TASK_ID='{0}' AND ITEM_NO=2 AND DETAIL.STATE=0 ", CancelTaskID);
                                DataTable dt = dal.TaskCarDetail(strWhere);
                                Context.ProcessDispatcher.WriteToProcess("CarProcess", "CarInRequest", dt);//���ȴ�����⡣

                                string strOutTaskID = bdal.CreateCancelBillOutTask(strTask[0], strTask[1], strNewBillNo);
                                DataTable dtOutTask = dal.CraneTaskOut(string.Format("TASK_ID='{0}'", strOutTaskID));

                                Context.ProcessDispatcher.WriteToProcess("CraneProcess", "CraneInRequest", dtOutTask);
                                int jj = 0;
                                while (jj < 100)  //�ӳ�
                                {
                                    jj++;
                                }
                                StationState[0] = strTask[0];//TaskID;
                                StationState[1] = "4";
                                Context.ProcessDispatcher.WriteToProcess("CraneProcess", "StockOutToCarStation", StationState); //���¶Ѷ��Process ״̬Ϊ4.
                                DataTable dtNewProductInfo = dal.GetProductInfoByTaskID(strOutTaskID);
                                dal.InsertChangeProduct(dtProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtProductInfo.Rows[0]["PRODUCT_CODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_BARCODE"].ToString(), dtNewProductInfo.Rows[0]["PRODUCT_CODE"].ToString());

                            }
                        }

                        break;
                    }
                }
            }
        }