Example #1
0
        /// <summary>
        /// 循环体内容
        /// </summary>
        public override void LoopContent()
        {
            if (!Config.EnableAngleRecording)
            {
                return;
            }

            YawAngle        = Config.AngleRecordingSource == AngleSource.PLC ? Const.OpcDatasource.YawAngle_Plc : Const.GnssInfo.YawAngle;
            PitchAngle      = Config.AngleRecordingSource == AngleSource.PLC ? Const.OpcDatasource.PitchAngle_Plc : Const.GnssInfo.PitchAngle;
            WalkingPosition = Config.AngleRecordingSource == AngleSource.PLC ? Const.OpcDatasource.WalkingPositionLeft_Plc : Const.GnssInfo.WalkingPosition;
            InAction        = Math.Abs(YawAngle) > _angleThres;
            if (_actionStarted)
            {
                FileDate = DateTime.Now;
            }
            WheelLeftBeyond  = Const.OpcDatasource.WheelLeftBeyondStack;
            WheelRightBeyond = Const.OpcDatasource.WheelRightBeyondStack;
            _yawStorage.Push(YawAngle);
            _pitchStorage.Push(PitchAngle);
            _walkStorage.Push(WalkingPosition);
            double first = _yawStorage.First(), last = _yawStorage.Last();

            YawAngleDiff = first - last;

            //假如目录不存在,创建
            if (!Directory.Exists(_filePath))
            {
                Directory.CreateDirectory(_filePath);
            }
            //假如文件不存在,则首先写入表头
            if (!File.Exists(_fileName))
            {
                File.AppendAllLines(_fileName, new string[] { _columnHeader });
            }
            if (!File.Exists(_fileNameExt))
            {
                File.AppendAllLines(_fileNameExt, new string[] { _columnHeaderExt });
            }
            ////假如有一边出垛边,则开始记录
            //if (Const.OpcDatasource.WheelLeftBeyondStack == 1 || Const.OpcDatasource.WheelRightBeyondStack == 1)
            //    _recording = true;
            //假如斗轮开始转动,则开始记录
            if (Const.OpcDatasource.WheelTurningBackwards == 1)
            {
                _recording = true;
            }
            //是否记录同时由悬皮状态以及斗轮是否转动决定
            if (_recording && Const.OpcDatasource.BeltStatus == 1 && Const.OpcDatasource.WheelTurningBackwards == 1)
            {
                DateTime now = DateTime.Now;
                string   stamp = DateTimeHelper.GetTimeStampBySeconds(), fileDateStr = _fileDate.ToString("yyyyMMddHHmmss");
                //记录所有数据
                File.AppendAllLines(_fileNameExt, new string[] { string.Format(_columnTemplateExt, now, WalkingPosition, PitchAngle, YawAngle, Const.RadarInfo.SurfaceAngleWheelLeft, Const.RadarInfo.SurfaceAngleWheelRight, Const.OpcDatasource.WheelPowerPolished, Const.OpcDatasource.PileHeight, Const.RadarInfo.RadiusAverageLeft, Const.RadarInfo.RadiusAverageRight) });
                if (_beyondLeftReached)
                {
                    File.AppendAllLines(_fileName, new string[] { string.Format(_columnTemplate, stamp, WalkingPosition, PitchAngle, YawAngle, string.Empty, string.Empty, string.Empty, "left", 1) });
                    _dataService.InsertAngleRecord(Config.MachineName, fileDateStr, WalkingPosition, PitchAngle, YawAngle, 1, 1, now);
                }
                if (_beyondRightReached)
                {
                    File.AppendAllLines(_fileName, new string[] { string.Format(_columnTemplate, stamp, WalkingPosition, PitchAngle, string.Empty, string.Empty, YawAngle, string.Empty, "right", 1) });
                    _dataService.InsertAngleRecord(Config.MachineName, fileDateStr, WalkingPosition, PitchAngle, YawAngle, 2, 2, now);
                }
                if (_manualTurnSignal == TurnSignal.Left)
                {
                    File.AppendAllLines(_fileName, new string[] { string.Format(_columnTemplate, stamp, _walkStorage.Last(), _pitchStorage.Last(), string.Empty, last, string.Empty, string.Empty, "left", 2) });
                    _dataService.InsertAngleRecord(Config.MachineName, fileDateStr, WalkingPosition, PitchAngle, YawAngle, 3, 1, now);
                }
                else if (_manualTurnSignal == TurnSignal.Right)
                {
                    File.AppendAllLines(_fileName, new string[] { string.Format(_columnTemplate, stamp, _walkStorage.Last(), _pitchStorage.Last(), string.Empty, string.Empty, string.Empty, last, "right", 2) });
                    _dataService.InsertAngleRecord(Config.MachineName, fileDateStr, WalkingPosition, PitchAngle, YawAngle, 4, 2, now);
                }
            }
        }