Esempio n. 1
0
File: OneIn.cs Progetto: 13TT/TEST2
 private void btn_tin_Click(object sender, EventArgs e)
 {
     //w.Write();
     //int a = w.Median();
     w.Account();
 }
Esempio n. 2
0
        /// <summary>
        /// 堆垛机PLC连接的处理逻辑
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="e"></param>
        private static void V_LoopWrite(object Sender, EArgOnHandle_Process e)
        {
            string plcID        = ((PLCProcesser)Sender).Name;
            string currentSRMNo = "";

            try
            {
                var arry_sts = Dic_SRM_STSClass.Where(item => item.Value.address.PLC == plcID).ToList();

                var  arry_pc = Dic_SRM_PS.Where(item => item.Value.address.PLC == plcID).ToList();
                bool f       = false;
                int  r       = 0;
                int  c       = 0;
                foreach (var pc in arry_pc)
                {
                    f = pc.Value.LoadFromPLC(e.PLCConn, 4);
                }

                int s_finish         = 0;
                int s_fault          = 1;
                int s_runMaintenance = 1;
                int s_run            = 1;
                int s_FrGrid         = 0;
                int s_FrTier         = 0;
                int s_pattern        = 0;

                int s_FrStand = 0;//站
                int s_FrLine  = 0;
                int s_FrGrids = 0;
                int s_FrTiers = 0;

                int    s_ToStand = 0;//站
                int    s_ToLine  = 0;
                int    s_ToGrid  = 0;
                int    s_ToTier  = 0;
                string str;

                var arry_res = Dic_SRM_Res.Where(item => item.Value.address.PLC == plcID).ToList();
                foreach (var res in arry_res)
                {
                    res.Value.LoadFromPLC(e.PLCConn);

                    //完成信号
                    s_finish = res.Value.s_finish;

                    //故障
                    s_fault = res.Value.s_fault;

                    //运行维护
                    s_runMaintenance = res.Value.s_runMaintenance;

                    //运行信号
                    s_run = res.Value.s_run;

                    //格
                    s_FrGrid = res.Value.s_FrGrid;

                    //层
                    s_FrTier = res.Value.s_FrTier;
                }

                #region 当前指令
                var arry_dd = Dic_SRM_Request.Where(item => item.Value.address.PLC == plcID).ToList();
                foreach (var s in arry_dd)
                {
                    s.Value.LoadFromPLC(e.PLCConn);
                    int s_serial = s.Value.s_serial;
                    s_pattern = s.Value.s_pattern; //模式

                    s_FrStand = s.Value.s_FrStand; //站
                    s_FrLine  = s.Value.s_FrLine;
                    s_FrGrids = s.Value.s_FrGrid;
                    s_FrTiers = s.Value.s_FrTier;

                    s_ToStand = s.Value.s_ToStand;//站
                    s_ToLine  = s.Value.s_ToLine;
                    s_ToGrid  = s.Value.s_ToGrid;
                    s_ToTier  = s.Value.s_ToTier;
                }
                #endregion

                var        arry_req = Dic_SRM_Request.Where(item => item.Value.address.PLC == plcID).ToList();
                WOrderInfo w        = new WOrderInfo();
                foreach (var s in arry_req)
                {
                    //currentSRMNo = s.Key;
                    //s.Value.LoadFromPLC(e.PLCConn);
                    r = s.Value.s_FrStand;
                    c = s.Value.s_ToStand;

                    #region 写入数据
                    if (s_finish == 1 && s_fault == 0 && s_runMaintenance == 0)
                    {
                        //判断当前指令是否有值
                        str = w.OrderInfo(s_pattern);
                        //更新数据库
                        if (str == "出库")
                        {
                            w.OutAccount(s_FrLine, s_FrGrids, s_FrTiers, s_ToStand);
                        }
                        else if (str == "入库")
                        {
                            w.InAccount(s_FrStand, s_ToLine, s_ToGrid, s_ToTier);
                        }

                        //判断指令排队序列
                        string strs = w.Write();

                        if (strs == "S")
                        {
                            w.ClearAccount();
                            //写入数据成功后  完成信号改为0
                            if (s.Value.WirteToPLC(e.PLCConn))
                            {
                                foreach (var h in PLCSystem_SRM.Dic_SRM_Res)
                                {
                                    h.Value.s_finish = 0;
                                    h.Value.WirteToPLC(e.PLCConn);
                                    int aaa = h.Value.s_finish;
                                }
                                //系统过账
                                w.Account();
                            }
                        }
                        if (strs == "N")
                        {
                            #region 清除数据
                            s.Value.s_serial  = 0;
                            s.Value.s_pattern = 0;
                            s.Value.s_FrStand = 0;
                            s.Value.s_FrLine  = 0;
                            s.Value.s_FrGrid  = 0;
                            s.Value.s_FrTier  = 0;

                            s.Value.s_ToStand = 0;
                            s.Value.s_ToLine  = 0;
                            s.Value.s_ToGrid  = 0;
                            s.Value.s_ToTier  = 0;
                            s.Value.WirteToPLC(e.PLCConn);
                            w.ClearAccount();
                            #endregion
                        }
                        #region 判断当前指令  格 层是否有值
                        //if (str == "写入")
                        //{
                        //    //执行order_info 中排队指令
                        //    w.Write();

                        //    //写入数据成功后  完成信号改为0
                        //    if (s.Value.WirteToPLC(e.PLCConn))
                        //    {
                        //        foreach (var h in PLCSystem_SRM.Dic_SRM_Res)
                        //        {
                        //            h.Value.s_finish = 0;
                        //            h.Value.WirteToPLC(e.PLCConn);
                        //            int aaa = h.Value.s_finish;
                        //        }
                        //        #region 清除数据
                        //        //s.Value.s_serial = 0;
                        //        //s.Value.s_pattern = 0;
                        //        //s.Value.s_FrStand = 0;
                        //        //s.Value.s_FrLine = 0;
                        //        //s.Value.s_FrGrid = 0;
                        //        //s.Value.s_FrTier = 0;

                        //        //s.Value.s_ToStand = 0;
                        //        //s.Value.s_ToLine = 0;
                        //        //s.Value.s_ToGrid = 0;
                        //        //s.Value.s_ToTier = 0;
                        //        //s.Value.WirteToPLC(e.PLCConn);
                        //        #endregion
                        //        //系统过账
                        //        w.Account();
                        //    }
                        //}

                        //if (str == "过账")
                        //{
                        //    s.Value.s_serial = 0;
                        //    s.Value.s_pattern = 0;
                        //    s.Value.s_FrStand = 0;
                        //    s.Value.s_FrLine = 0;
                        //    s.Value.s_FrGrid = 0;
                        //    s.Value.s_FrTier = 0;

                        //    s.Value.s_ToStand = 0;
                        //    s.Value.s_ToLine = 0;
                        //    s.Value.s_ToGrid = 0;
                        //    s.Value.s_ToTier = 0;

                        //    if (s.Value.WirteToPLC(e.PLCConn))
                        //    {
                        //        foreach (var h in PLCSystem_SRM.Dic_SRM_Res)
                        //        {
                        //            h.Value.s_finish = 0;
                        //            h.Value.WirteToPLC(e.PLCConn);
                        //            int aaa = h.Value.s_finish;
                        //        }
                        //        #region 完成后指令过账
                        //        w.ClearAccount();
                        //        #endregion
                        //    }
                        //}

                        #region 清除数据
                        //if (of1!=1)
                        //{
                        //    s.Value.s_serial = 0;
                        //    s.Value.s_pattern = 0;
                        //    s.Value.s_FrStand = 0;
                        //    s.Value.s_FrLine = 0;
                        //    s.Value.s_FrGrid = 0;
                        //    s.Value.s_FrTier = 0;

                        //    s.Value.s_ToStand = 0;
                        //    s.Value.s_ToLine = 0;
                        //    s.Value.s_ToGrid = 0;
                        //    s.Value.s_ToTier = 0;

                        //    if (s.Value.WirteToPLC(e.PLCConn))
                        //    {
                        //        foreach (var h in PLCSystem_SRM.Dic_SRM_Res)
                        //        {
                        //            h.Value.s_finish = 0;
                        //            h.Value.WirteToPLC(e.PLCConn);
                        //            int aaa = h.Value.s_finish;
                        //        }
                        //        #region 完成后指令过账
                        //        w.ClearAccount();
                        //        #endregion
                        //    }
                        //}
                        #endregion

                        #endregion
                    }
                    #endregion

                    #region 清除指令
                    //if (s_finish == 0)
                    //{
                    //    s.Value.s_serial = 0;
                    //    s.Value.s_pattern = 0;
                    //    s.Value.s_FrStand = 0;
                    //    s.Value.s_FrLine = 0;
                    //    s.Value.s_FrGrid = 0;
                    //    s.Value.s_FrTier = 0;

                    //    s.Value.s_ToStand = 0;
                    //    s.Value.s_ToLine = 0;
                    //    s.Value.s_ToGrid = 0;
                    //    s.Value.s_ToTier = 0;

                    //    if (s.Value.WirteToPLC(e.PLCConn))
                    //    {
                    //        foreach (var h in PLCSystem_SRM.Dic_SRM_Res)
                    //        {
                    //            h.Value.s_finish = 0;
                    //            h.Value.WirteToPLC(e.PLCConn);
                    //            int aaa = h.Value.s_finish;
                    //        }
                    //        #region 完成后指令过账
                    //        w.ClearAccount();
                    //        #endregion
                    //    }
                    //}
                    #endregion
                }

                if (s_fault == 1) //故障
                {
                    w.Fault();
                    foreach (var s in PLCSystem_SRM.Dic_SRM_Request)
                    {
                        s.Value.s_serial  = 0;
                        s.Value.s_pattern = 0;
                        s.Value.s_FrStand = 0;
                        s.Value.s_FrLine  = 0;
                        s.Value.s_FrGrid  = 0;
                        s.Value.s_FrTier  = 0;

                        s.Value.s_ToStand = 0;
                        s.Value.s_ToLine  = 0;
                        s.Value.s_ToGrid  = 0;
                        s.Value.s_ToTier  = 0;
                        s.Value.WirteToPLC(e.PLCConn);
                    }
                }

                e.result = true;
            }
            catch (Exception ex)
            {
                Program.Log_Agent_SRM.WriteLog(Enum_LogType.LogType_Error,
                                               Enum_LogGrade.LogGrade_Nin,
                                               Enum_LogMessageType.LogMsgType_Exception,
                                               string.Format("V_LoopWrite-[{0}]-[{1}]", plcID, currentSRMNo),
                                               ex.Message,
                                               ex.StackTrace);
                e.result = false;
            }
        }