private void SetActualEvent(PlcEvent eventInfo)
        {
            if (eventInfo.Severity == Severity.Ignored)
            {
                return;
            }

            if (eventInfo.Severity == Severity.NoError) // remove error from active and last error
            {
                if (lastEventSubject.Value != null)
                {
                    if (lastEventSubject.Value.Source.Equals(eventInfo.Source))
                    {
                        lastEventSubject.OnNext(null);
                    }
                }
                if (activeEventSubject.Value.Any(e => e.Source.Equals(eventInfo.Source)))
                {
                    var activeEvents = activeEventSubject.Value
                                       .ToList();
                    activeEvents.RemoveAll(e => e.Source.Equals(eventInfo.Source));
                    activeEventSubject.OnNext(activeEvents.ToArray());
                }
            }
            else
            {
                lastEventSubject.OnNext(eventInfo); //set last event
                //update active events
                var activeEvents = activeEventSubject.Value
                                   .ToList();
                activeEvents.RemoveAll(e => e.Source.Equals(eventInfo.Source));
                activeEvents.Add(eventInfo);
                activeEventSubject.OnNext(activeEvents.ToArray());
            }
        }
        private PlcEvent CreateEvent([NotNull] object value, ErrorCodeSetting errorCodeSetting)
        {
            var isNotError = value.ToString().Equals(errorCodeSetting.NoErrorValue.ToString());

            var errorCodeDescription = errorCodeSetting.CodeDescriptions.FirstOrDefault(description => description.Value.ToString().Equals(value.ToString()));

            var ignored = errorCodeSetting.IgnoreNotDescribedValues && errorCodeDescription == null;

            var plcEvent = new PlcEvent()
            {
                Timestamp       = DateTime.Now,
                Source          = $"{errorCodeSetting.PlcName}::{errorCodeSetting.ErrorCodeAddress}",
                Value           = value,
                ExpectedValue   = errorCodeSetting.NoErrorValue,
                Description     = errorCodeDescription?.Description,
                LongDescription = errorCodeDescription?.LongDescription
            };

            if (isNotError)
            {
                plcEvent.Severity = Severity.NoError;
            }
            else if (ignored)
            {
                plcEvent.Severity = Severity.Ignored;
            }
            else
            {
                plcEvent.Severity = errorCodeDescription?.Severity ?? errorCodeSetting.DefaultSeverity;
            }

            return(plcEvent);
        }
예제 #3
0
 /// <summary>
 /// 事件自动触发处理,生成PLC上报数据
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="Args"></param>
 private void AutoSendDataHandler(object sender, PlcEvent Args)
 {
     if (Args.ACTION_ID != null && Args.EQUIP_CODE != null &&
         Args.ACTION_ID.Length > 0 && Args.EQUIP_CODE.Length > 0)
     {
         if (Args.Type == "RGV")
         {
             RGV_LOCATION node = new RGV_LOCATION();
             node.EQUIP_CODE          = Args.EQUIP_CODE;
             node.WC_CODE             = LindeStr;
             node.RGV_LOCATION_Column = Args.ACTION_ID;
             node.STATE       = sbyte.Parse(Args.Value.ToString());
             node.RGV_SPEED   = decimal.Parse(Args.ArrLabel);
             node.HAPPEN_TIME = DateTime.Now;
             RGVData SendData = new RGVData(node);
             lock (m_ShareData.m_lockrgvData)
             {
                 m_ShareData.rgvData.Add(SendData);
                 while (m_ShareData.rgvData.Count > m_ShareData.agvData_CountMax)
                 {
                     m_ShareData.rgvData.RemoveAt(0);
                 }
             }
         }
         else
         {
             MONITOR_INFO node = new MONITOR_INFO();
             node.ACTION_ID   = Args.ACTION_ID;
             node.EQUIP_CODE  = Args.EQUIP_CODE;
             node.HAPPEN_TIME = DateTime.Now;
             PLCData SendData = new PLCData(node);
             lock (m_ShareData.m_lockplcData)
             {
                 m_ShareData.plcData.Add(SendData);
                 while (m_ShareData.plcData.Count > m_ShareData.plcData_CountMax)
                 {
                     m_ShareData.plcData.RemoveAt(0);
                 }
             }
         }
     }
 }
예제 #4
0
        public static PlcEventDTO MapPlcEvent(PlcEvent plcEvent)
        {
            var plcEventDTO = new PlcEventDTO()
            {
                DateTime = plcEvent.DateTime.AddMilliseconds(plcEvent.Msec),
                Number = plcEvent.MessageNumber,
                Message = plcEvent.PlcMessage.Text,
                Code = plcEvent.CodeId,

                CodeString = plcEvent.PlcEventCode.Text,
                SeverityNumber = plcEvent.PlcEventCode.SeverityNumber,
                //Severity = plcEvent.PlcEventCode.Severity.Name,

                ShowValue = plcEvent.PlcEventCode.ShowValue == true,
                Value = plcEvent.Value,

                Group = plcEvent.PlcMessage.Group,
                //FactoryNumber = plcEvent.PLC.Factory.Number.Value,
                //PlcName = plcEvent.PLC.Description,
            };
            return plcEventDTO;
        }
 public void LogEvent(PlcEvent plcEvent)
 {
     databaseService.InsertIntoCollection(CollectionName, plcEvent);
 }