示例#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);
            }));
        }
示例#2
0
        public void Start()
        {
            SendLeftMaterialServiceStateMessage(
                new LeftMaterialServiceState {
                State = LeftMaterialServiceStateEnum.INFO, Message = "左侧料库服务启动!", ErrorCode = LeftMaterialServiceErrorCodeEnum.NORMAL
            });


            Temp_S_House_RequestFCS_Last = false;

            bool ret = false;

            #region 初始化
            bool temp_S_House_RequestFCS_Last = false;
            ret = ControlDevice.GetHouseRequestFCS(ref temp_S_House_RequestFCS_Last);
            if (ret == false)
            {
                while (ret == false)
                {
                    ret = ControlDevice.SetHouseFCSAlarm(true);
                    SendLeftMaterialServiceStateMessage(
                        new LeftMaterialServiceState {
                        State = LeftMaterialServiceStateEnum.ERROR, Message = "初始化连接,请检查网络连接与配置后复位!", ErrorCode = LeftMaterialServiceErrorCodeEnum.INI_GETREQ
                    });
                    Thread.Sleep(1000);
                }


                bool dev_reset = false;
                while (dev_reset == false)
                {
                    ControlDevice.GetHouseFCSReset(ref dev_reset);
                    SendLeftMaterialServiceStateMessage(
                        new LeftMaterialServiceState {
                        State = LeftMaterialServiceStateEnum.WARN, Message = "初始化失败,等待设备的复位信号", ErrorCode = LeftMaterialServiceErrorCodeEnum.NORMAL
                    });
                    Thread.Sleep(1000);
                }
            }
            Temp_S_House_RequestFCS_Last = temp_S_House_RequestFCS_Last;

            #endregion

            while (!token.IsCancellationRequested)
            {
                //料库请求
                var ret_tuple = LeftMaterialFlow().Result;
                if (ret_tuple.Item1 == false)
                {
                    ret = false;
                    while (ret == false)
                    {
                        ret = ControlDevice.SetHouseFCSAlarm(true);
                        SendLeftMaterialServiceStateMessage(
                            new LeftMaterialServiceState {
                            State = LeftMaterialServiceStateEnum.ERROR, Message = "左侧料库请求调用失败,请检查后复位!", ErrorCode = ret_tuple.Item2
                        });
                        Thread.Sleep(1000);
                    }

                    bool dev_reset = false;
                    while (dev_reset == false)
                    {
                        ControlDevice.GetHouseFCSReset(ref dev_reset);
                        SendLeftMaterialServiceStateMessage(
                            new LeftMaterialServiceState {
                            State = LeftMaterialServiceStateEnum.WARN, Message = "左侧料库请求调用失败,等待设备的复位信号", ErrorCode = LeftMaterialServiceErrorCodeEnum.NORMAL
                        });
                        Thread.Sleep(1000);
                    }

                    SendLeftMaterialServiceStateMessage(
                        new LeftMaterialServiceState {
                        State = LeftMaterialServiceStateEnum.WARN, Message = "左侧料库请求调用失败,设备复位", ErrorCode = LeftMaterialServiceErrorCodeEnum.NORMAL
                    });
                }
                else
                {
                }
                Thread.Sleep(1000);
            }
        }