123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using Aitex.Core.Common;
- using Aitex.Core.Common.DeviceData;
- using Aitex.Core.RT.DataCenter;
- using Aitex.Core.RT.Device;
- using Aitex.Core.RT.Event;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.OperationCenter;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.SubstrateTrackings;
- using MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robot;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Xml;
- using CyberX8_Core;
- using CyberX8_RT.Devices;
- using CyberX8_RT.Devices.EFEM;
- using CyberX8_RT.Devices.YASKAWA;
- using CyberX8_RT.Modules;
- namespace CyberX8_RT.Devices
- {
- sealed class MessageHandler : IMessageHandler
- {
- // Fields
- //
- private readonly IList<EfemMessage> _msgQueue = new List<EfemMessage>();
- private readonly EfemBase _efem;
- // Properties
- //
- public bool IsCompleted
- {
- get
- {
- if (_msgQueue.Count <= 0) return false;
- return EfemMessage.MsgHead.INF == _msgQueue[_msgQueue.Count - 1].Head;
- }
- }
- public event EventHandler<EfemActionArgs> CommandUpdated;
- public event EventHandler<EfemEventArgs> EventUpdated;
- public event EventHandler<EfemErrorArgs> ErrorOccurred;
- // Constructor
- //
- public MessageHandler(EfemBase device)
- {
- _efem = device;
- }
- public void Send(IEfemMessage msg)
- {
- // _efem.Comm.SendTo(msg);
- _msgQueue.Add(msg as EfemMessage);
- }
- public void ReceiveMessage(string sRec)
- {
- string[] msgs = sRec.Split('\r');
- foreach (var msg in msgs)
- {
- if (string.IsNullOrWhiteSpace(msg)) continue;
- EfemMessage rec_msg = msg.ToMessage();
- switch (rec_msg.Head)
- {
- case EfemMessage.MsgHead.ACK:
- _msgQueue.Add(rec_msg);
- OnCommandUpdated(new EfemActionArgs
- {
- Module = rec_msg.Module,
- CommandType = rec_msg.Operation,
- Status = ActionStatus.RecACK
- });
- break;
- case EfemMessage.MsgHead.INF:
- OnCommandUpdated(new EfemActionArgs
- {
- Module = rec_msg.Module,
- CommandType = rec_msg.Operation,
- Status = ActionStatus.RecINF
- });
- // 收到INF之后发送ACK确认
- string strACK = rec_msg.RawString.Replace("INF", "ACK");
- // _efem.Comm.SendTo(strACK);
- EfemMessage ack_msg = strACK.ToMessage();
- ack_msg.Direct = MsgDirection.To;
- _msgQueue.Add(ack_msg);
- OnCommandUpdated(new EfemActionArgs
- {
- Module = rec_msg.Module,
- CommandType = rec_msg.Operation,
- Status = ActionStatus.Completed,
- Data = rec_msg.Data.Count > 0 ? rec_msg.Data.First() : string.Empty
- });
- break;
- case EfemMessage.MsgHead.EVT:
- OnEventUpdated(new EfemEventArgs
- {
- EvtStr = rec_msg.ToParamString(),
- Module = rec_msg.Module,
- CommandType = rec_msg.Operation,
- DataList = rec_msg.Data
- });
- break;
- case EfemMessage.MsgHead.NAK:
- OnErrorOccurred(new EfemErrorArgs
- {
- Factor = rec_msg.Factor,
- Description = Constant.FactorString[rec_msg.Factor],
- CommandType = rec_msg.Operation,
- Module = rec_msg.Module,
- });
- break;
- case EfemMessage.MsgHead.CAN:
- OnErrorOccurred(new EfemErrorArgs
- {
- Factor = rec_msg.Factor,
- Description = Constant.FactorString.ContainsKey(rec_msg.Factor) ? Constant.FactorString[rec_msg.Factor] : rec_msg.Factor,
- Message = rec_msg.Data[0],
- CommandType = rec_msg.Operation,
- Module = rec_msg.Module,
- });
- break;
- case EfemMessage.MsgHead.ABS:
- OnErrorOccurred(new EfemErrorArgs
- {
- Factor = rec_msg.Factor,
- Description = $"{rec_msg.Data[0]}, {rec_msg.Data[1]}",
- CommandType = rec_msg.Operation,
- Module = rec_msg.Module,
- });
- break;
- }
- }
- }
- private void OnCommandUpdated(EfemActionArgs args)
- {
- CommandUpdated?.Invoke(this, args);
- }
- private void OnEventUpdated(EfemEventArgs args)
- {
- EventUpdated?.Invoke(this, args);
- }
- private void OnErrorOccurred(EfemErrorArgs args)
- {
- ErrorOccurred?.Invoke(this, args);
- }
- }
- sealed class SignalTower
- {
- // Fields
- //
- private readonly Dictionary<LightType, LightStatus> _lights = new Dictionary<LightType, LightStatus>(5);
- public SignalTower()
- {
- _lights.Add(LightType.RED, LightStatus.OFF);
- _lights.Add(LightType.YELLOW, LightStatus.OFF);
- _lights.Add(LightType.BLUE, LightStatus.OFF);
- _lights.Add(LightType.GREEN, LightStatus.OFF);
- _lights.Add(LightType.WHITE, LightStatus.OFF);
- _lights.Add(LightType.BUZZER1, LightStatus.OFF);
- DATA.Subscribe($"{ModuleName.EFEM}.SignalTower", () =>
- {
- return new AITSignalTowerData
- {
- IsGreenLightOn = _lights[LightType.GREEN] == LightStatus.ON,
- IsRedLightOn = _lights[LightType.RED] == LightStatus.ON,
- IsYellowLightOn = _lights[LightType.YELLOW] == LightStatus.ON,
- IsWhiteLightOn = _lights[LightType.WHITE] == LightStatus.ON,
- IsBlueLightOn = _lights[LightType.BLUE] == LightStatus.ON,
- IsBuzzerOn = _lights[LightType.BUZZER1] == LightStatus.ON,
- };
- },SubscriptionAttribute.FLAG.IgnoreSaveDB);
- }
- // Methods
- //
- public void ChangeLightStatus(LightType light, LightStatus st)
- {
- if (!_lights.ContainsKey(light))
- LOG.Write(eEvent.WARN_EFEM_COMMON_WARN, ModuleName.EFEM, $"NO {light} configured");
- _lights[light] = st;
- }
- }
- }
|