Exemple #1
0
        //private Stopwatch mCosStopwatch;
        //private Stopwatch mSinStopwatch;
        //private Stopwatch mStepStopwatch;
        /// <summary>
        ///
        /// </summary>
        private void CosThreadPro()
        {
            ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
            List <Tagbase> vv  = mTagIdCach.ContainsKey("Sim:cos") ? mTagIdCach["Sim:cos"] : null;
            List <int>     vvr = mManualRecordTagCach.ContainsKey("Sim:cos") ? mManualRecordTagCach["Sim:cos"] : null;

            //mCosStopwatch = new Stopwatch();
            while (!mIsClosed)
            {
                mCosEvent.WaitOne();
                mCosEvent.Reset();

                if (mCosNeedReload)
                {
                    vv             = mTagIdCach.ContainsKey("Sim:cos") ? mTagIdCach["Sim:cos"] : null;
                    vvr            = mManualRecordTagCach.ContainsKey("Sim:cos") ? mManualRecordTagCach["Sim:cos"] : null;
                    mCosNeedReload = false;
                }

                //mCosStopwatch.Restart();
                //long ll = 0;
                double fval = Math.Cos(mNumber / 180.0 * Math.PI);
                if (vv != null)
                {
                    mTagService.SetTagValue(vv, ref fval, 0);
                    //ll = mCosStopwatch.ElapsedMilliseconds;
                    mTagService.SubmiteNotifyChanged();
                }

                if (vvr != null && vvr.Count > 0)
                {
                    TagValue tv = new TagValue()
                    {
                        Quality = 0, Time = DateTime.UtcNow, Value = fval
                    };
                    foreach (var vvv in vvr)
                    {
                        mTagHisValueService.SetTagHisValue(vvv, tv);
                    }
                }

                //mCosStopwatch.Stop();

                //LoggerService.Service.Info("SimDriver", "设置变量耗时:" + ll + " 其他耗时:" + (mCosStopwatch.ElapsedMilliseconds - ll) + " count:" + vv.Count);

                var ts = (DateTime.Now - mLastProcessTime).TotalMilliseconds;
                lock (mLockObj)
                {
                    if (ts > mMaxProcessTimeSpan)
                    {
                        mMaxProcessTimeSpan = ts;
                        //mSelfProcessTimeSpan = mCosStopwatch.ElapsedMilliseconds;
                    }
                }

                Interlocked.Increment(ref mFinishCount);
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        private void StepThreadPro()
        {
            ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
            List <Tagbase> vv  = mTagIdCach.ContainsKey("Sim:step") ? mTagIdCach["Sim:step"] : null;
            List <int>     vvr = mManualRecordTagCach.ContainsKey("Sim:step") ? mManualRecordTagCach["Sim:step"] : null;

            //mStepStopwatch = new Stopwatch();
            while (!mIsClosed)
            {
                mStepEvent.WaitOne();
                mStepEvent.Reset();

                if (mStepNeedReload)
                {
                    vv              = mTagIdCach.ContainsKey("Sim:step") ? mTagIdCach["Sim:step"] : null;
                    vvr             = mManualRecordTagCach.ContainsKey("Sim:step") ? mManualRecordTagCach["Sim:step"] : null;
                    mStepNeedReload = false;
                }

                //mStepStopwatch.Restart();
                if (vv != null)
                {
                    mTagService.SetTagValue(vv, ref mNumber, 0);
                    mTagService.SubmiteNotifyChanged();
                }

                if (vvr != null && vvr.Count > 0)
                {
                    TagValue tv = new TagValue()
                    {
                        Quality = 0, Time = DateTime.UtcNow, Value = mNumber
                    };
                    foreach (var vvv in vvr)
                    {
                        mTagHisValueService.SetTagHisValue(vvv, tv);
                    }
                }
                //mStepStopwatch.Stop();
                var ts = (DateTime.Now - mLastProcessTime).TotalMilliseconds;
                lock (mLockObj)
                {
                    if (ts > mMaxProcessTimeSpan)
                    {
                        mMaxProcessTimeSpan = ts;
                        //mSelfProcessTimeSpan = mStepStopwatch.ElapsedMilliseconds;
                    }
                }

                Interlocked.Increment(ref mFinishCount);
            }
        }
Exemple #3
0
        private void DateTimeThreadPro()
        {
            ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
            List <Tagbase> vv  = mTagIdCach.ContainsKey("Sim:datetime") ? mTagIdCach["Sim:datetime"] : null;
            List <int>     vvr = mManualRecordTagCach.ContainsKey("Sim:datetime") ? mManualRecordTagCach["Sim:datetime"] : null;

            while (!mIsClosed)
            {
                mDatetimeEvent.WaitOne();
                mDatetimeEvent.Reset();

                if (mDatetimeReload)
                {
                    vv              = mTagIdCach.ContainsKey("Sim:datetime") ? mTagIdCach["Sim:datetime"] : null;
                    vvr             = mManualRecordTagCach.ContainsKey("Sim:datetime") ? mManualRecordTagCach["Sim:datetime"] : null;
                    mDatetimeReload = false;
                }

                if (vv != null)
                {
                    DateTime dnow = DateTime.Now;
                    mTagService.SetTagValue(vv, ref dnow, 0);
                    mTagService.SubmiteNotifyChanged();
                }

                if (vvr != null && vvr.Count > 0)
                {
                    TagValue tv = new TagValue()
                    {
                        Quality = 0, Time = DateTime.UtcNow, Value = DateTime.Now
                    };
                    foreach (var vvv in vvr)
                    {
                        mTagHisValueService.SetTagHisValue(vvv, tv);
                    }
                }

                var ts = (DateTime.Now - mLastProcessTime).TotalMilliseconds;
                lock (mLockObj)
                {
                    if (ts > mMaxProcessTimeSpan)
                    {
                        mMaxProcessTimeSpan = ts;
                    }
                }

                Interlocked.Increment(ref mFinishCount);
            }
        }
Exemple #4
0
        private void ScanThreadPro()
        {
            ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray2);
            bool isNeedRepeat = false;

            while (!mIsClosed)
            {
                DateTime time = DateTime.Now;

                if (mFinishCount > 5 && mLastProcessTime.Second != time.Second)
                {
                    mFinishCount = 0;
                }
                else
                {
                    if (isNeedRepeat)
                    {
                        Thread.Sleep(300);

                        mMaxProcessTimeSpan = 0;
                        //mSelfProcessTimeSpan = 0;

                        mLastProcessTime = DateTime.Now;

                        mSinEvent.Set();
                        mCosEvent.Set();
                        mSquareEvent.Set();
                        mDatetimeEvent.Set();
                        mStepEvent.Set();
                        mSteppointEvent.Set();
                        isNeedRepeat = false;
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                    continue;
                }

                if (mMaxProcessTimeSpan > 1000)
                {
                    LoggerService.Service.Warn("Sim Driver", "出现阻塞 更新耗时:" + mMaxProcessTimeSpan + " ms");
                }
                //else if ((mNumber % 10 == 0))
                //{
                //    LoggerService.Service.Debug("Sim Driver", "上次更新数据耗时: " + mMaxProcessTimeSpan + " ms");
                //}

                mMaxProcessTimeSpan = 0;
                //mSelfProcessTimeSpan = 0;

                mLastProcessTime = time;

                mNumber++;
                mNumber   = mNumber >= (short)360 ? (short)0 : mNumber;
                mIsSecond = true;
                if (mNumber % 60 == 0)
                {
                    mBoolNumber = !mBoolNumber;
                }

                mSinEvent.Set();
                mCosEvent.Set();
                mSquareEvent.Set();
                mDatetimeEvent.Set();
                mStepEvent.Set();
                mSteppointEvent.Set();
                isNeedRepeat = true;
                Thread.Sleep(100);
            }
        }