123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using Aitex.Core.RT.Log;
- using MECF.Framework.Common.Communications;
- using System;
- using System.Collections.Generic;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.LoadPorts.TDKB
- {
- public class TDKBLoadPortMessage : AsciiMessage
- {
- public string CommandType { get; set; }
- public string Command { get; set; }
- public string Data { get; set; }
- }
- public class TDKBLoadPortConnection : SerialPortConnectionBase
- {
- private TDKBLoadPort _device;
- public TDKBLoadPortConnection(TDKBLoadPort device, string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
- : base(portName, baudRate, dataBits, parity, stopBits, "\r", true)
- {
- _device = device;
- IsEnableHandlerRetry = true;
- }
- protected override MessageBase ParseResponse(string rawMsg)
- {
- TDKBLoadPortMessage msg = new TDKBLoadPortMessage();
- msg.RawMessage = rawMsg;
- msg.IsAck = false;
- msg.IsResponse = false;
- msg.IsComplete = false;
- msg.IsResponse = false;
- msg.IsNak = false;
- msg.IsError = false;
- msg.CommandType = rawMsg.Split(':')[0].Replace("s00", "");
- msg.Command = Regex.Match(rawMsg, "(?<=:).*?(?=;)").Value;
- if (msg.CommandType.Contains("ACK")) msg.IsAck = true;
- if (msg.CommandType.Contains("NAK"))
- {
- msg.IsNak = true;
- _device.OnNak(rawMsg);
- _device.OnError($"Received NAK:{rawMsg}");
- }
- if (msg.CommandType.Contains("MOV")) msg.IsAck = true;
- if (msg.CommandType.Contains("GET")) msg.IsAck = true;
- if (msg.CommandType.Contains("INF"))
- {
- msg.IsEvent = true;
- }
- if (msg.CommandType.Contains("ABS"))
- {
- _device.OnAbs(rawMsg);
- msg.IsError = true;
- }
- if(!msg.CommandType.Contains("s00ACK:STATE"))
- LOG.Write($"{_device.LPModuleName} {Address} received message:{rawMsg}");
- return msg;
- }
- protected override void OnEventArrived(MessageBase msg)
- {
- TDKBLoadPortMessage message = msg as TDKBLoadPortMessage;
- string evtcontent = message.RawMessage;
-
-
- if (evtcontent.Contains("PODON"))
- {
- //_device.OnCarrierPresent();
- //_device.OnCarrierPlaced();
- }
- if (evtcontent.Contains("PODOF"))
- {
- _device.OnCarrierNotPlaced();
- _device.OnCarrierNotPresent();
- }
- if (evtcontent.Contains("ABNST"))
- {
- _device.OnCarrierNotPlaced();
- _device.OnCarrierPresent();
- }
- if (evtcontent.Contains("SMTON"))
- {
- _device.OnCarrierNotPlaced();
- _device.OnCarrierPresent();
- }
- if (evtcontent.Contains("MANSW"))
- {
- _device.OnSwitchKey1();
- }
- if (evtcontent.Contains("PRSIN"))
- {
- //_device.IsWaferProtrude = true;
- }
- if (evtcontent.Contains("PRSCL"))
- {
- //_device.IsWaferProtrude = false;
- }
- if(evtcontent.Contains("E84IO"))
- {
- _device.OnE84IOEvent(evtcontent);
- }
- if(evtcontent.Contains("E84ER"))
- {
- _device.OnE84Error(evtcontent);
- }
- if (evtcontent.Contains("E84EV"))
- {
- _device.OnE84Load(evtcontent);
- }
- if (evtcontent.Contains("E84ev"))
- {
- _device.OnE84Unload(evtcontent);
- }
- _device.OnEvent(out _);
- }
- }
- public class TDKBLoadPortTCPConnection : TCPPortConnectionBase
- {
- private TDKBLoadPort _device;
- public TDKBLoadPortTCPConnection(TDKBLoadPort device, string ipaddress)
- : base(ipaddress)
- {
- _device = device;
- }
- protected override MessageBase ParseResponse(string rawMsg)
- {
- TDKBLoadPortMessage msg = new TDKBLoadPortMessage();
- msg.RawMessage = rawMsg;
- msg.IsAck = false;
- msg.IsResponse = false;
- msg.IsComplete = false;
- msg.IsResponse = false;
- msg.IsNak = false;
- msg.IsError = false;
- msg.CommandType = rawMsg.Split(':')[0].Replace("s00","");
- msg.Command = Regex.Match(rawMsg, "(?<=:).*?(?=;)").Value;
- if (msg.CommandType.Contains("ACK")) msg.IsAck = true;
- if (msg.CommandType.Contains("NAK"))
- {
- msg.IsNak = true;
- _device.OnError($"Received NAK:{rawMsg}");
- }
- if (msg.CommandType.Contains("MOV")) msg.IsAck = true;
- if (msg.CommandType.Contains("GET")) msg.IsAck = true;
- if (msg.CommandType.Contains("INF"))
- {
- msg.IsEvent = true;
- }
- if (msg.CommandType.Contains("ABS"))
- {
- _device.OnAbs(rawMsg);
- msg.IsError = true;
- }
- LOG.Write($"{Address} received message:{rawMsg}");
- return msg;
- }
- protected override void OnEventArrived(MessageBase msg)
- {
- TDKBLoadPortMessage message = msg as TDKBLoadPortMessage;
- string evtcontent = message.RawMessage;
- if (evtcontent.Contains("PODON"))
- {
- //_device.OnCarrierPresent();
- //_device.OnCarrierPlaced();
- }
- if (evtcontent.Contains("PODOF"))
- {
- _device.OnCarrierNotPlaced();
- _device.OnCarrierNotPresent();
- }
- if (evtcontent.Contains("ABNST"))
- {
- _device.OnCarrierNotPlaced();
- _device.OnCarrierPresent();
- }
- if (evtcontent.Contains("SMTON"))
- {
- _device.OnCarrierNotPlaced();
- _device.OnCarrierPresent();
- }
- if (evtcontent.Contains("MANSW"))
- {
- _device.OnSwitchKey1();
- }
- if (evtcontent.Contains("PRSIN"))
- {
- _device.IsWaferProtrude = true;
- }
- if (evtcontent.Contains("PRSCL"))
- {
- _device.IsWaferProtrude = false;
- }
- if (evtcontent.Contains("E84IO"))
- {
- _device.OnE84IOEvent(evtcontent);
- }
- if (evtcontent.Contains("E84ER"))
- {
- _device.OnE84Error(evtcontent);
- }
- if (evtcontent.Contains("E84EV"))
- {
- _device.OnE84Load(evtcontent);
- }
- if (evtcontent.Contains("E84ev"))
- {
- _device.OnE84Unload(evtcontent);
- }
- }
- }
- }
|