Esempio n. 1
0
        public bool ShowTrigger(Model.PSTData objPSTData)
        {
            if (objPSTData == null)
            {
                return(false);
            }
            if (objErrorDaoService == null)
            {
                objErrorDaoService = new ErrorDaoImp();
            }
            if (objErrorControllerService == null)
            {
                objErrorControllerService = new ErrorControllerImp();
            }

            int error = objErrorControllerService.GetErrorCode(objPSTData.machineChannel, objPSTData.machineCode, OpcTags.PST_L2_ErrCode);

            if (error != 0)
            {
                return(false);
            }
            TriggerData objTriggerData = new TriggerData();

            objTriggerData.MachineCode    = objPSTData.machineCode;
            objTriggerData.category       = TriggerData.triggerCategory.ERROR;
            objTriggerData.ErrorCode      = error.ToString();
            objTriggerData.TriggerEnabled = true;
            objErrorDaoService.UpdateTriggerActiveStatus(objTriggerData);
            return(true);
        }
        public bool CheckPSCommandDone(Model.PSData objPSData, PSTData objPSTData, EESData objEESData)
        {
            //Logger.WriteLogger(GlobalValues.PMS_LOG, "Entering CheckPSCommandDone: " + objPSData.machineCode + " >> dest_aisle: " + objPSData.destAisle);
            bool result = false;

            int counter = 1;
            OpcOperationsService opcd = null;

            int    commandType  = 0;
            string doneCheckTag = null;
            int    error        = 0;

            if (objPSTControllerService == null)
            {
                objPSTControllerService = new PSTControllerImp();
            }

            try
            {
                opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection());
                if (objErrorControllerService == null)
                {
                    objErrorControllerService = new ErrorControllerImp();
                }

                Thread.Sleep(3000);
                result = false;
                FindCommandTypeAndDoneTag(objPSData, out commandType, out doneCheckTag);


                do
                {
                    if (ShowTrigger(objPSData) || objPSTControllerService.ShowTrigger(objPSTData) || objEESControllerService.ShowTrigger(objEESData))
                    {
                        while (objErrorControllerService.GetTriggerActiveStatus(objPSData.machineCode))
                        {
                            Thread.Sleep(1000);
                        }
                        if (objErrorControllerService.GetTriggerAction(objPSData.machineCode) == 1)
                        {
                            DoTriggerAction(objPSData, objPSTData, objEESData, commandType);

                            Thread.Sleep(2000);
                        }
                    }

                    result = opcd.ReadTag <bool>(objPSData.machineChannel, objPSData.machineCode, doneCheckTag);

                    if (counter > 3)
                    {
                        Thread.Sleep(700);
                    }
                    counter += 1;
                } while (!result);
            }
            catch (Exception errMsg)
            {
                Logger.WriteLogger(GlobalValues.PMS_LOG, "Error in CheckPSCommandDone: " + objPSData.machineCode
                                   + " >> dest_aisle: " + objPSData.destAisle + "; error: " + errMsg.Message);
            }
            finally
            {
                //Logger.WriteLogger(GlobalValues.PMS_LOG, "Exitting CheckPSCommandDone: " + objPSData.machineCode + " >> dest_aisle: "
                //    + objPSData.destAisle + ", result =" + result);
                if (opcd != null)
                {
                    opcd.Dispose();
                }
            }
            return(result);
        }
        public bool CheckVLCCommandDone(Model.VLCData objVLCData)
        {
            Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objVLCData.queueId + ":--Entering 'CheckVLCCommandDone' ");
            bool result = false;

            bool isWaitingForCmdDoneOn = false;
            int  counter = 1;
            OpcOperationsService opcd = null;

            if (objQueueControllerService == null)
            {
                objQueueControllerService = new QueueControllerImp();
            }
            if (objErrorControllerService == null)
            {
                objErrorControllerService = new ErrorControllerImp();
            }
            if (objErrorDaoService == null)
            {
                objErrorDaoService = new ErrorDaoImp();
            }
            bool        triggerAlreadyEnabled = false;
            TriggerData objTriggerData        = null;

            try
            {
                opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection());

                Thread.Sleep(3000);
                result = false;
                //TimeSpan startTime = System.DateTime.Now.TimeOfDay;

                do
                {
                    triggerAlreadyEnabled = objErrorControllerService.GetTriggerActiveStatus(objVLCData.machineCode);
                    if (!triggerAlreadyEnabled)
                    {
                        objTriggerData = NeedToShowTrigger(objVLCData);
                    }
                    if (triggerAlreadyEnabled || objTriggerData.TriggerEnabled)
                    {
                        if (!triggerAlreadyEnabled)
                        {
                            objErrorDaoService.UpdateTriggerActiveStatus(objTriggerData);
                        }


                        while (objErrorControllerService.GetTriggerActiveStatus(objVLCData.machineCode))
                        {
                            /**checking transaction deleted or not****/
                            objQueueControllerService.CancelIfRequested(objVLCData.queueId);
                            /******/
                            Thread.Sleep(1000);
                        }
                        if (objQueueControllerService.NeedToOptimizePath(objVLCData.queueId))
                        {
                            break;
                        }
                        if (objErrorControllerService.GetTriggerAction(objVLCData.machineCode) == 1)
                        {
                            VLCMove(objVLCData);

                            Thread.Sleep(2000);
                        }
                    }


                    result = opcd.ReadTag <bool>(objVLCData.machineChannel, objVLCData.machineCode, OpcTags.VLC_CP_Done);

                    if (counter > 3)
                    {
                        counter = 1;
                        /**checking transaction deleted or not****/
                        objQueueControllerService.CancelIfRequested(objVLCData.queueId);
                        /******/
                        Thread.Sleep(700);
                    }
                    counter += 1;
                } while (!result);
            }
            catch (OperationCanceledException errMsg)
            {
                Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objVLCData.queueId + ": CM=" + objVLCData.machineCode + " --TaskCanceledException 'CheckVLCCommandDone':: " + errMsg.Message);
                throw new OperationCanceledException();
            }
            catch (Exception errMsg)
            {
                Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objVLCData.queueId + ":--Exception 'CheckVLCCommandDone':: " + errMsg.Message);
                if (errMsg is TaskCanceledException)
                {
                    throw new Exception();
                }
            }
            finally
            {
                if (opcd != null)
                {
                    opcd.Dispose();
                }
            }
            Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objVLCData.queueId + ":--Exitting 'CheckVLCCommandDone' ");
            return(result);
        }
        public TriggerData NeedToShowTrigger(VLCData objVLCData)
        {
            bool needToShow = false;

            if (objVLCDaoService == null)
            {
                objVLCDaoService = new VLCDaoImp();
            }

            int         checkCount     = 0;
            int         errorCode      = 0;
            TriggerData objTriggerData = new TriggerData();

            if (objErrorControllerService == null)
            {
                objErrorControllerService = new ErrorControllerImp();
            }
            int max_check_count = 10;


            using (OpcOperationsService opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection()))
            {
                do
                {
                    errorCode = objErrorControllerService.GetErrorCode(objVLCData.machineChannel, objVLCData.machineCode, OpcTags.VLC_L2_ErrCode);
                    if (errorCode > 0)
                    {
                        objTriggerData.category  = TriggerData.triggerCategory.ERROR;
                        objTriggerData.ErrorCode = errorCode.ToString();
                        needToShow = true;
                        break;
                    }

                    needToShow = !opcd.ReadTag <bool>(objVLCData.machineChannel, objVLCData.machineCode, OpcTags.VLC_Auto_Ready);
                    if (needToShow)
                    {
                        if (checkCount >= max_check_count)
                        {
                            objTriggerData.category = TriggerData.triggerCategory.MANUAL;
                            break;
                        }
                        checkCount++;
                        Thread.Sleep(1000);
                        continue;
                    }

                    needToShow = objVLCDaoService.IsVLCDisabled(objVLCData.machineCode);
                    if (needToShow)
                    {
                        objTriggerData.category = TriggerData.triggerCategory.DISABLE;
                        break;
                    }
                } while (needToShow && checkCount < max_check_count);
            }
            if (needToShow)
            {
                objTriggerData.MachineCode    = objVLCData.machineCode;
                objTriggerData.TriggerEnabled = true;
                Logger.WriteLogger(GlobalValues.PARKING_LOG, "Queue Id:" + objVLCData.queueId + ": VLC = " + objVLCData.machineCode + "--'NeedToShowTrigger For VLC' = " + needToShow);
            }
            return(objTriggerData);
        }
        public bool CheckPVLCommandDone(Model.PVLData objPVLData)
        {
            bool result = false;

            int counter = 1;
            OpcOperationsService opcd = null;

            int    commandType  = 0;
            string doneCheckTag = null;
            int    error        = 0;

            try
            {
                opcd = new OpcOperationsImp(OpcConnection.GetOPCServerConnection());
                if (objErrorControllerService == null)
                {
                    objErrorControllerService = new ErrorControllerImp();
                }
                if (objErrorDaoService == null)
                {
                    objErrorDaoService = new ErrorDaoImp();
                }
                Thread.Sleep(2000);
                result = false;
                FindCommandTypeAndDoneTag(objPVLData, out commandType, out doneCheckTag);


                do
                {
                    error = objErrorControllerService.GetErrorCode(objPVLData.machineChannel, objPVLData.machineCode, OpcTags.PVL_L2_ErrCode);
                    if (error > 0)
                    {
                        TriggerData objTriggerData = new TriggerData();
                        objTriggerData.MachineCode    = objPVLData.machineCode;
                        objTriggerData.category       = TriggerData.triggerCategory.ERROR;
                        objTriggerData.ErrorCode      = error.ToString();
                        objTriggerData.TriggerEnabled = true;
                        objErrorDaoService.UpdateTriggerActiveStatus(objTriggerData);


                        while (objErrorControllerService.GetTriggerActiveStatus(objPVLData.machineCode))
                        {
                            Thread.Sleep(1000);
                        }
                        if (objErrorControllerService.GetTriggerAction(objPVLData.machineCode) == 1)
                        {
                            DoTriggerAction(objPVLData, commandType);

                            Thread.Sleep(2000);
                        }
                    }

                    result = opcd.ReadTag <bool>(objPVLData.machineChannel, objPVLData.machineCode, doneCheckTag);

                    if (counter > 3)
                    {
                        Thread.Sleep(700);
                    }
                    counter += 1;
                } while (!result);
            }
            catch (Exception errMsg)
            {
                Console.WriteLine(errMsg.Message);
            }
            finally
            {
                if (opcd != null)
                {
                    opcd.Dispose();
                }
            }
            return(result);
        }