示例#1
0
        private async Task <Tuple <bool, LeftMaterialServiceErrorCodeEnum> > LeftMaterialInFlow()
        {
            return(await Task.Factory.StartNew(() =>
            {
                IWareHouseClient WareHouse = new LefModulaWareHouseClient("LEFT_MATERIAL_IN");

                int S_House_ProductType = 0;
                var ret_prod_type = ControlDevice.GetHouseProductType(ref S_House_ProductType);
                if (ret_prod_type == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_prod_type, LeftMaterialServiceErrorCodeEnum.IN_GETPRODUCTTYPE);
                }

                int S_House_MaterialType = 0;
                var ret_material_type = ControlDevice.GetHouseMaterialType(ref S_House_MaterialType);
                if (ret_material_type == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_material_type, LeftMaterialServiceErrorCodeEnum.IN_GETMATERIALTYPE);
                }

                var ret_movein = WareHouse.MoveInTray(S_House_ProductType, S_House_MaterialType);
                if (ret_movein == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_movein, LeftMaterialServiceErrorCodeEnum.IN_MOVEINTRAY);
                }

                bool S_House_TrayInposition = false;
                while (S_House_TrayInposition == false)
                {
                    var ret_inposition_info = ControlDevice.GetHouseTrayInposition(ref S_House_TrayInposition);
                    if (ret_inposition_info == false)
                    {
                        WareHouse.ReleaseWriterLock();
                        return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_inposition_info, LeftMaterialServiceErrorCodeEnum.IN_GETTRAYINPOSITION);
                    }

                    SendLeftMaterialServiceStateMessage(
                        new LeftMaterialServiceState
                    {
                        State = LeftMaterialServiceStateEnum.WARN,
                        Message = "等待料库托盘到位",
                        ErrorCode = LeftMaterialServiceErrorCodeEnum.NORMAL
                    });

                    var ret_reset = false;
                    ControlDevice.GetHouseFCSReset(ref ret_reset);
                    if (ret_reset == true)
                    {
                        WareHouse.ReleaseWriterLock();
                        return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_reset, LeftMaterialServiceErrorCodeEnum.IN_TRAYINPOSITIONRESET);
                    }
                }

                Thread.Sleep(500);

                int S_House_ProductPosition = 0;
                int S_House_TrayPosition = 0;
                int S_House_Quantity = 0;

                var ret_warehouse_info = WareHouse.GetPositionInfo(S_House_ProductType, S_House_MaterialType,
                                                                   out S_House_ProductPosition, out S_House_TrayPosition, out S_House_Quantity);
                if (ret_warehouse_info == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_warehouse_info, LeftMaterialServiceErrorCodeEnum.IN_GETTRAYPOSITION);
                }

                var ret_warehouse_product_position = ControlDevice.SetHouseProductPostion(S_House_ProductPosition);
                if (ret_warehouse_product_position == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_warehouse_product_position, LeftMaterialServiceErrorCodeEnum.IN_SETPRODUCTPOS);
                }

                var ret_warehouse_tray_position = ControlDevice.SetHouseTrayPostion(S_House_TrayPosition);
                if (ret_warehouse_tray_position == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_warehouse_tray_position, LeftMaterialServiceErrorCodeEnum.IN_SETTRAYPOS);
                }

                var ret_warehouse_quantity = ControlDevice.SetHouseQuantity(S_House_Quantity);
                if (ret_warehouse_quantity == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_warehouse_quantity, LeftMaterialServiceErrorCodeEnum.IN_SETQUANTITY);
                }

                var ret_confirm_materialtype_position = ControlDevice.SetHouseConfirmMaterialType(S_House_MaterialType);
                if (ret_confirm_materialtype_position == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_confirm_materialtype_position, LeftMaterialServiceErrorCodeEnum.IN_SETMATERIALTYPECONFIRM);
                }

                var ret_req_fin = ControlDevice.SetHouseRequestFCSFin(true);
                if (ret_req_fin == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_req_fin, LeftMaterialServiceErrorCodeEnum.IN_SETREQUESTFIN);
                }

                bool S_House_RequestInfoFCS = false;

                while (S_House_RequestInfoFCS == false)
                {
                    var ret_req_info = ControlDevice.GetHouseRequestInfoFCS(ref S_House_RequestInfoFCS);
                    if (ret_req_info == false)
                    {
                        WareHouse.ReleaseWriterLock();
                        return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_req_info, LeftMaterialServiceErrorCodeEnum.IN_GETREQINFO);
                    }

                    SendLeftMaterialServiceStateMessage(
                        new LeftMaterialServiceState
                    {
                        State = LeftMaterialServiceStateEnum.WARN,
                        Message = "等待料库动作完成",
                        ErrorCode = LeftMaterialServiceErrorCodeEnum.NORMAL
                    });

                    var reset = false;
                    ControlDevice.GetHouseFCSReset(ref reset);
                    if (reset == true)
                    {
                        WareHouse.ReleaseWriterLock();
                        return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_req_info, LeftMaterialServiceErrorCodeEnum.IN_REQINFORESET);
                    }
                }

                var ret_data_input = WareHouse.WriteBackData(S_House_ProductType, S_House_MaterialType, false);
                if (ret_data_input == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_data_input, LeftMaterialServiceErrorCodeEnum.IN_WRITEDATA);
                }

                var ret_info_fin = ControlDevice.SetHouseRequestInfoFCSFin(true);
                if (ret_info_fin == false)
                {
                    WareHouse.ReleaseWriterLock();
                    return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(ret_info_fin, LeftMaterialServiceErrorCodeEnum.IN_SETREQINFOFIN);
                }

                WareHouse.ReleaseWriterLock();
                return new Tuple <bool, LeftMaterialServiceErrorCodeEnum>(true, LeftMaterialServiceErrorCodeEnum.NORMAL);
            }));
        }