From 6f92829951f3ec228b18df8c157239573edd9cb4 Mon Sep 17 00:00:00 2001 From: xcd <834800634@qq.com> Date: 星期三, 09 九月 2020 15:20:53 +0800 Subject: [PATCH] 1. 取消ImageSet中的HImage释放动作,转移到业务流程中 2. 拆分板卡的IO监听和轴状态,轴位置监听 --- src/Bro.Device.GTSCard/GTSCardDriver.cs | 95 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 85 insertions(+), 10 deletions(-) diff --git a/src/Bro.Device.GTSCard/GTSCardDriver.cs b/src/Bro.Device.GTSCard/GTSCardDriver.cs index c430886..a721273 100644 --- a/src/Bro.Device.GTSCard/GTSCardDriver.cs +++ b/src/Bro.Device.GTSCard/GTSCardDriver.cs @@ -99,6 +99,9 @@ { AllAxisOn(); + MonitorPosition(); + MonitorAxisStatus(); + base.Start(); } @@ -1131,7 +1134,6 @@ return axisMovingStatusesList; } - public List<IOItem> GetMonitorValues() { var result = new List<IOItem>(); @@ -1164,6 +1166,79 @@ return result; } + SpinWait _positionWait = new SpinWait(); + private async void MonitorPosition() + { + await Task.Run(() => + { + while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept && CurrentState != EnumHelper.DeviceState.DSUninit) + { + try + { + if (!IConfig.IsEnableMonitor) + return; + + AxisStatusList.ForEach(a => + { + int curPosition = (int)GetPrfPosition(a.AxisIndex); + + if (a.CurPosition != curPosition) + { + a.CurPosition = curPosition; + AxisPositionChanged(a.AxisIndex, curPosition); + } + }); + + _positionWait.SpinOnce(); + } + catch (Exception ex) + { + if (CurrentState == DeviceState.DSOpen) + { + LogAsync(DateTime.Now, $"{this.Name}鐩戝惉杞翠俊鎭紓甯�", ex.GetExceptionMessage()); + } + } + } + }); + } + + SpinWait _statusWait = new SpinWait(); + private async void MonitorAxisStatus() + { + await Task.Run(() => + { + while (CurrentState != EnumHelper.DeviceState.DSClose && CurrentState != EnumHelper.DeviceState.DSExcept && CurrentState != EnumHelper.DeviceState.DSUninit) + { + try + { + if (!IConfig.IsEnableMonitor) + return; + + AxisStatusList.ForEach(a => + { + int curStatus = GetAxisStatus(a.AxisIndex); + + if (a.AxisStatus != curStatus) + { + int temp = a.AxisStatus; + a.AxisStatus = curStatus; + AxisStatusChanged(a.AxisIndex, temp, curStatus); + } + }); + + _statusWait.SpinOnce(); + } + catch (Exception ex) + { + if (CurrentState == DeviceState.DSOpen) + { + LogAsync(DateTime.Now, $"{this.Name}鐩戝惉杞翠俊鎭紓甯�", ex.GetExceptionMessage()); + } + } + } + }); + } + public async override void Monitor() { await Task.Run(() => @@ -1176,9 +1251,9 @@ return; var newValues = GetMonitorValues(); - var newAxisMovingStatus = GetAxisMovingStatus(); + //var newAxisMovingStatus = GetAxisMovingStatus(); - if (newValues == null || newValues.Count == 0 || newAxisMovingStatus == null || newAxisMovingStatus.Count == 0) + if (newValues == null || newValues.Count == 0 ) continue; //Stopwatch sw = new Stopwatch(); @@ -1192,14 +1267,14 @@ MonitorCheckAndInvoke(tempNew, tempOld); } - if (AxisStatusList.Count == newAxisMovingStatus.Count) - { - var tempNew = new List<AxisMovingStatus>(newAxisMovingStatus);//clone - var tempOld = new List<AxisMovingStatus>(AxisStatusList); - AxisStatusCheck(tempNew, tempOld); - } + //if (AxisStatusList.Count == newAxisMovingStatus.Count) + //{ + // var tempNew = new List<AxisMovingStatus>(newAxisMovingStatus);//clone + // var tempOld = new List<AxisMovingStatus>(AxisStatusList); + // AxisStatusCheck(tempNew, tempOld); + //} - AxisStatusList = new List<AxisMovingStatus>(newAxisMovingStatus); + //AxisStatusList = new List<AxisMovingStatus>(newAxisMovingStatus); MonitorValues = new List<IOItem>(newValues); //sw.Stop(); -- Gitblit v1.8.0