领胜LDS 键盘AOI检测项目
xcd
2020-07-03 3cba54c4ee8d29d33ed21a2c749a9d2f2d03e22d
src/Bro.Device.GTSCard/GTSCardDriver.cs
@@ -18,7 +18,7 @@
namespace Bro.Device.GTSCard
{
    [Device("GTSCard", "固高板卡", EnumHelper.DeviceAttributeType.Device)]
    public class GTSCardDriver : DeviceBase, IMonitor, IMotion
    public class GTSCardDriver : MotionCardBase
    {
        // 异常事件
        public Action<Exception> OnExceptionRaised;
@@ -42,7 +42,7 @@
            _isResetting = isReset;
        }
        public List<AxisInfo> GetCurrentAxisInfo(params string[] axisName)
        public override List<AxisInfo> GetCurrentAxisInfo(params string[] axisName)
        {
            throw new NotImplementedException();
        }
@@ -74,6 +74,11 @@
            AllMoveStop();
            AllAxisOff();
        }
        public override ResponseMessage Run(IOperationConfig config)
        {
            throw new NotImplementedException();
        }
        #endregion
        #region GTSCard
@@ -93,6 +98,7 @@
                throw new Exception("板卡载入配置文件异常,错误码:" + res);
            }
        }
        public bool AllAxisOn()
        {
@@ -153,7 +159,7 @@
        /// </summary>
        /// <param name="item">运动对象</param>
        /// <returns>运动控制+停止判断</returns>
        public ResponseMessage MoveToPoint(IOperationConfig opConfig)
        public override ResponseMessage MoveToPoint(IOperationConfig opConfig)
        {
            bool resultOK = false;
            var gtsOperationConfig = opConfig as GTSCardOperationConfig;
@@ -646,16 +652,17 @@
        /// <param name="cardNum">卡号</param>
        /// <param name="index">输出口,返回1-16</param>
        /// <param name="value">false表示输出,true表示关闭</param>
        public void WriteOut(short cardNum, short index, bool value)
        public override void WriteOutput(short cardNum, short index, IOValue value)
        {
            short outNum = (short)(index % 100 + 1);
            if (value)
            if ((int)value <= 1)
            {
                GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, 0);
                GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)value);
            }
            else
            {
                GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, 1);
                var currentValue = (int)MonitorValues.FirstOrDefault(u => u.IONum == outNum && u.IOType == IOType.OUTPUT).Value;
                GTSCardAPI.GT_SetDoBit(cardNum, GTSCardAPI.MC_GPO, outNum, (short)(currentValue == 1 ? 0 : 1));
            }
        }
@@ -680,10 +687,8 @@
        #endregion
        #region IMonitor
        public event Action<DateTime, string, IDevice, IMonitorSet> OnMonitorInvoke;
        public event Action<DateTime, IDevice, IWarningSet> OnMonitorAlarm;
        public List<IOItem> MonitorValues { get; set; } = new List<IOItem>();
        //public List<IOItem> MonitorValues { get; set; } = new List<IOItem>();
        public List<IOItem> GetMonitorValues()
@@ -702,14 +707,14 @@
                IOItem inItem = new IOItem()
                {
                    IONum = index,
                    Value = (inValue & (1 << index)) == 0 ? 1 : 0,
                    IOType = IOType.In
                    Value = (inValue & (1 << index)) == 0 ? IOValue.TRUE : IOValue.FALSE,
                    IOType = IOType.INPUT
                };
                IOItem outItem = new IOItem()
                {
                    IONum = index,
                    Value = (outValue & (1 << index)) == 0 ? 1 : 0,
                    IOType = IOType.Out
                    Value = (outValue & (1 << index)) == 0 ? IOValue.TRUE : IOValue.FALSE,
                    IOType = IOType.OUTPUT
                };
                result.Add(inItem);
                result.Add(outItem);
@@ -718,7 +723,7 @@
            return result;
        }
        public async void Monitor()
        public async override void Monitor()
        {
            await Task.Run(() =>
            {
@@ -736,8 +741,8 @@
                        sw.Start();
                        if (MonitorValues.Count == newValues.Count)
                        {
                            var tempNew = new List<IOItem>(newValues);//clone
                            var tempOld = new List<IOItem>(MonitorValues);
                            var tempNew = newValues.DeepSerializeClone();//clone
                            var tempOld = MonitorValues.DeepSerializeClone();
                            MonitorCheckAndInvoke(tempNew, tempOld);
                        }
                        MonitorValues = new List<IOItem>(newValues);
@@ -780,7 +785,7 @@
            foreach (var replyIOData in monitorSet.ReplyIODatas)
            {
                //写入IO输出
                if (replyIOData.IOType == IOType.Out)
                if (replyIOData.IOType == IOType.OUTPUT)
                {
                    GTSCardAPI.GT_SetDoBit((short)IConfig.CardNum, GTSCardAPI.MC_GPI, (short)replyIOData.IONum, (short)replyIOData.Value);
                }
@@ -797,15 +802,14 @@
            {
                MotionCardWarningSet warningSet = wSet as MotionCardWarningSet;
                bool isOn = ((tempNew.FirstOrDefault(u => u.IONum == warningSet.TriggerIndex && u.IOType == warningSet.WarningIOModel)?.Value >> warningSet.TriggerIndex) & 1) == (warningSet.TriggerValue ? 1 : 0);
                bool isOn = (((int)((tempNew.FirstOrDefault(u => u.IONum == warningSet.TriggerIndex && u.IOType == warningSet.WarningIOModel)?.Value)) >> warningSet.TriggerIndex) & 1) == (warningSet.TriggerValue ? 1 : 0);
                if (warningSet.CurrentStatus != isOn)
                {
                    warningSet.CurrentStatus = isOn;
                    warningSet.TriggerTime = DateTime.Now;
                    warningSet.WarningDescription = $"警报:{warningSet.Name}-触发索引:{warningSet.TriggerIndex}-{warningSet.WarningIOModel.GetEnumDescription()}:{warningSet.WarningCode}";
                    SaveAlarmCSVAsync(DateTime.Now, this.Name, warningSet);
                    OnMonitorAlarm?.BeginInvoke(DateTime.Now, this, warningSet, null, null);
                    ExcuteMonitorAlarm(DateTime.Now, this, warningSet);
                }
            });
            #endregion
@@ -824,7 +828,7 @@
                if (newIOItem?.Value != oldIOItem?.Value)
                {
                    if (monitorSet.TriggerValue == -999 || newIOItem.Value == monitorSet.TriggerValue)
                    if (monitorSet.TriggerValue == -999 || (int)newIOItem.Value == monitorSet.TriggerValue)
                    {
                        if (monitorSet.OpConfig == null)
                        {
@@ -836,14 +840,14 @@
                        //    return tempNew[index].Value;
                        //}).ToList();
                        OnMonitorInvoke?.BeginInvoke(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet, OnMethodInvoked, monitorSet);
                        ExcuteMonitorInvoke(DateTime.Now, monitorSet.InvokeDevice, this, monitorSet);
                    }
                }
            });
            #endregion
        }
        public void ResetAlarm()
        public override void ResetAlarm()
        {
            int axis_sts;
            uint clk;