Exemple #1
0
        /// <summary>
        /// 更新采集单元数据
        /// </summary>
        /// <param name="mdl"></param>
        /// <param name="curUnit"></param>
        /// <returns></returns>
        public int  UpdateAcqUnitData(ref AcqLineItemMDL mdl)
        {
            int ret = -1;

            try
            {
                AcqLineDAL acqDal = new AcqLineDAL();

                ProductDal pdal = new ProductDal();


                //获取PN编码
                //
                ProductionMDL productmdl = pdal.GetProductInfo(mdl.PLID, mdl.EMS);


                //存在产品编码
                if (mdl == null || mdl.PN == string.Empty)
                {
                    mdl.PN = "N/A";
                }

                mdl.PN = productmdl.PN;

                ////判断是存在有历史数据,有更新区间信息
                ////有历史数据

                if (acqDal.AcqUintExist2(mdl.PLID, mdl.EMS, mdl.UNITID) > 0)
                {
                    //获取当前区间的计数
                    //int percount = GetLastRangCount(mdl);

                    AcqLineItemMDL lastItem = GetLastUnit(mdl);
                    //加一个脉冲信号
                    lastItem.PR_COUNT += 1;
                    //加一个脉冲信号

                    CLog.WriteStationLog("PRE_COUNT", mdl.UNITID + "-" + lastItem.PR_COUNT.ToString());

                    //更新结束时间 和 当前开始时段的时间信息
                    mdl.TID        = lastItem.TID;
                    mdl.TGNAME     = lastItem.TGNAME;
                    mdl.PR_COUNT   = lastItem.PR_COUNT;
                    mdl.START_TIME = lastItem.START_TIME;
                    mdl.END_TIME   = DateTime.Now;

                    mdl.TIME_LENGTH = TimeRange.ExecDateDiffSecond(lastItem.START_TIME, mdl.END_TIME);

                    mdl.UPDATE_TIME = mdl.END_TIME;

                    ret = acqDal.UpdateAcqLineUint(mdl);
                }
                else///当前时段的新项目
                {
                    int uintSeq = acqDal.IsUionAcqUint(mdl.UNITID, mdl.PLID);

                    mdl.START_TIME = DateTime.Now;
                    mdl.END_TIME   = mdl.START_TIME;

                    //型号发生变化重新计数 同时表示换型了
                    if (uintSeq > 0)
                    {
                        uintSeq += 1;

                        string strSeq = String.Format("{0:D2}", uintSeq);
                        mdl.SetTID(mdl.START_TIME, mdl.PLID, mdl.TGNAME, strSeq);
                    }

                    // mdl.UPDATE_TIME = DateTime.Now;


                    if (productmdl != null || productmdl.OP != 0)
                    {
                        mdl.START_TIME = DateTime.Now.AddSeconds(-productmdl.OP);
                    }
                    else
                    {
                        mdl.START_TIME = DateTime.Now;
                    }

                    mdl.TIME_LENGTH = TimeRange.ExecDateDiffSecond(mdl.START_TIME, mdl.END_TIME);

                    //更新上一个区间产品的时间
                    AcqLineDAL updateDal = new AcqLineDAL();
                    updateDal.UpdateAclineUnitByLastUnit(DateTime.Now, mdl.PLID);


                    // modify by guozq  2018/3/26
                    //添加采集数据
                    ret = acqDal.AddAcqLine1(mdl);
                }
            }
            catch
            {
                throw;
            }

            return(ret);
        }
Exemple #2
0
        private void TestAcq()
        {
            int ems = 29;


            for (int i = 0; i < 20; i++)
            {
                Thread.Sleep(100);

                if (i == 10)
                {
                    ems += 1;
                    Thread.Sleep(500);
                }

                if (i == 15)
                {
                    ems += 1;
                    Thread.Sleep(500);
                }

                AcqLineItemMDL acqlineMDL = new AcqLineItemMDL();

                EMSUnit unit = null;

                acqlineMDL.PLID = "01";
                //  TimeRange range = plineCaculator.GetTimeRangByAcqTime(DateTime.Now);

                ///采集数据创建并设置唯一编号


                acqlineMDL.TGNAME = "01";
                acqlineMDL.SetTID(DateTime.Now, acqlineMDL.PLID, "01", "01");
                acqlineMDL.PR_COUNT    = 1;
                acqlineMDL.EMS         = ems;
                acqlineMDL.UPDATE_TIME = DateTime.Now;
                //AddTraceInfo(acqlineMDL, "ST440", 11);

                //判断计算器时间
                if (plineCaculator == null)
                {
                    plineCaculator = new ProductLineCaculator();
                    plineCaculator.ReloadPlanUnits();
                    ///初始化EMS编号
                    // ems = ReadEMS();

                    unit = new EMSUnit(ems, DateTime.Now);

                    plineCaculator.ems = unit;
                }



                unit = new EMSUnit(ems, DateTime.Now);



                //检查是否需要重新加载计算区间
                plineCaculator.CheckReload(DateTime.Now, unit);

                DateTime acqTime = DateTime.Now;

                //获取当前数据输入的采集区间
                TimeRange range = plineCaculator.GetTimeRangByAcqTime(DateTime.Now);

                ///采集数据创建并设置唯一编号
                acqlineMDL.TGNAME = range.SEQ;
                acqlineMDL.SetTID(DateTime.Now, acqlineMDL.PLID, range.SEQ, "01");
                acqlineMDL.PR_COUNT    = 1;
                acqlineMDL.EMS         = ems;
                acqlineMDL.UPDATE_TIME = DateTime.Now;



                //更新采集数据
                // plineCaculator.UpdateAcqData(ref acqlineMDL, index, curCount);
                plineCaculator.UpdateAcqUnitData(ref acqlineMDL);

                CLog.WriteStationLog("ST400", string.Format("更新数据完成:{0}的计算数量已提交", acqlineMDL.PR_COUNT));


                if (plineCaculator.IsChangedEMS(ems))
                {
                    //处理换型记录
                    plineCaculator.ProcessAcqLineData(acqlineMDL.PLID, acqlineMDL.UNITID, unit);

                    CLog.WriteStationLog("ST400", string.Format("换型:{0}", acqlineMDL.PLID));
                    ////更改换型时间
                    //AcqLineDAL updateDal = new AcqLineDAL();
                    //updateDal.UpdateAclineUnitByLastUnit(DateTime.Now, acqlineMDL.PLID);
                }
                else
                {
                    //plineCaculator.LoadEMSTime(unit.SetTime);
                    plineCaculator.LoadEMSTime(DateTime.Now);
                }
            }
        }