Esempio n. 1
0
        public static void GetFirstDataFromPLC()
        {
            try
            {
                UInt32     str     = 0;
                ArrayList  list    = null;
                string     openstr = "OK";
                object     readobj = null;
                PLCHisData plchis  = null;
                foreach (var adapter in RowConfig.EqpPoint)
                {
                    list = adapter.Value;
                    if (list != null)
                    {
                        RowDataPoint eqp = (RowDataPoint)list[0];
                        Plc          plc = PLCSingleton.CreatePLC(CpuType.S7300, eqp.IP, 0, 2); //new Plc(CpuType.S7300, "10.21.189.139", 0, 2);

                        try
                        {
                            openstr = plc.QMOpen();
                            if (openstr == "OK")
                            {
                                foreach (var V in list)
                                {
                                    eqp = (RowDataPoint)V;
                                    try
                                    {
                                        readobj = plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                        // str = (UInt32)plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                        if (readobj != null)
                                        {
                                            str = (UInt32)readobj;

                                            plchis = FrontData.dic[eqp.TagID];

                                            plchis.Value = str;
                                            plchis.TagID = eqp.TagID;
                                            plchis.type  = RowConfig.TagDic[plchis.TagID].type;

                                            plchis.refid = DTKAG.KAGCreateNewDT(eqp.TagID, plchis.type, str);
                                            plchis.Time  = DateTime.Now;

                                            if (eqp.TagID == EqpName.FillerStatusTagID)
                                            {
                                                plchis.formid = PersisDTFiller.CL1NewDTFiller("", "", "", str);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex.ToString());
                                    }
                                }
                                plc.Close();
                            }
                            else
                            {
                                SetEQPRealDataMax(eqp.EQP);
                                Log.Error("[PLC][Link Fail] IP Address is : " + eqp.IP);
                                Log.Error(openstr);
                            }
                            //  throw new InvalidAddressException("To few periods for DB address");
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }
Esempio n. 2
0
        //  int rv = 0;

        public static void Compare()
        {
            try
            {
                PLCHisData hisdata = null;
                foreach (var R in RealData.dic)
                {
                    if (R.Value == uint.MaxValue)  //判断是否断线
                    {
                        hisdata       = FrontData.dic[R.Key];
                        hisdata.refid = 0;
                        hisdata.Time  = DateTime.Now;
                        hisdata.Value = uint.MaxValue;
                    }
                    else
                    {
                        Log.Info("[JobDT] TagID: " + R.Key + "  Real Value  " + R.Value + "===" + FrontData.dic[R.Key].Value + "   HisData Value ");
                        if (R.Value == FrontData.dic[R.Key].Value)//设备状态没有变化
                        {
                            hisdata = FrontData.dic[R.Key];
                            TimeSpan span = DateTime.Now - hisdata.Time;
                            double   muni = span.TotalMinutes;
                            if (muni > 2)
                            {
                                DTKAG.PlusDT(hisdata.refid, muni);
                                hisdata.Time = DateTime.Now;
                                if (R.Key == EqpName.FillerStatusTagID)
                                {
                                    if (!string.IsNullOrEmpty(hisdata.formid))
                                    {
                                        DTFiller.DTPlusDuration(hisdata.formid, muni);
                                    }
                                }
                            }
                            //  hisdata.Value = R.Value;
                        }
                        else  //设备状态有变化
                        {
                            QMNCPLCS7.TraceDT.TraceCL1.CloseLoop();


                            hisdata = FrontData.dic[R.Key];
                            TimeSpan span = DateTime.Now - hisdata.Time;
                            double   muni = span.TotalMinutes;

                            DTKAG.PlusDTFinish(hisdata.refid, muni);                                    //结束上一状态

                            hisdata.refid = DTKAG.KAGCreateNewDT(hisdata.TagID, hisdata.type, R.Value); //创建新的状态
                            hisdata.Time  = DateTime.Now;                                               //更新 FrontData
                            hisdata.Value = R.Value;

                            if (R.Key == EqpName.FillerStatusTagID)  //如果是Filler 结束 FIller状态
                            {
                                if (!string.IsNullOrEmpty(hisdata.formid))
                                {
                                    DTFiller.DTPlusDurationFinish(hisdata.formid, muni);
                                    if (R.Value == 8)
                                    {
                                        hisdata.formid = QMNCPLCS7.TraceDT.PersisDTFiller.CL1NewDTFiller(EqpName.DepackStatusTagID, EqpName.Depack, "", RealData.dic[EqpName.FillerStatusTagID]);
                                    }
                                    else if (R.Value == 16)
                                    {
                                        QMNCPLCS7.TraceDT.TraceCL1.SetLoop();
                                        FuncAsyn.RunP1(QMNCPLCS7.TraceDT.TraceDownEqp.Run, hisdata.formid);
                                    }
                                    else if (R.Value == 128)
                                    {
                                    }
                                    else
                                    {
                                        hisdata.formid = QMNCPLCS7.TraceDT.PersisDTFiller.CL1NewDTFiller(EqpName.FillerStatusTagID, EqpName.Filler, "", RealData.dic[EqpName.FillerStatusTagID]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.ToString());
            }
        }