Sic07/FrameworkLocal/RTEquipmentLibrary/HardwareUnits/Aligners/HiWinAligner/HwAlignerGuideHandler.cs

64 lines
1.8 KiB
C#
Raw Permalink Normal View History

2023-02-02 14:23:32 +08:00
using MECF.Framework.Common.Communications;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Aligners.HwAligner
{
public abstract class HwAlignerGuideHandler : HandlerBase
{
public HwAlignerGuide Device { get; }
protected HwAlignerGuideHandler(HwAlignerGuide device, string commandvalue)
: base(BuildMessage(commandvalue))
{
Device = device;
}
private static byte[] BuildMessage(string commandvalue)
{
List<byte> liCmd = Encoding.ASCII.GetBytes(commandvalue).ToList<byte>();
liCmd.Add(0x0d); //CR
liCmd.Add(0x0a); //LF 不可颠倒
return liCmd.ToArray();
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HwAlignerGuideMessage;
ResponseMessage = msg;
handled = true;
return true;
}
}
public class HwAlignerGuideSetAHandler : HwAlignerGuideHandler
{
public HwAlignerGuideSetAHandler(HwAlignerGuide device, string name, string commandvalue, int timeout = 30)
: base(device, commandvalue)
{
AckTimeout = TimeSpan.FromSeconds(timeout);
CompleteTimeout = TimeSpan.FromSeconds(timeout);
Name = name;
}
public override bool HandleMessage(MessageBase msg, out bool handled)
{
var result = msg as HwAlignerGuideMessage;
if (!result.IsResponse)
{
handled = true;
return false;
}
handled = Device.PraseDataA(Name, result.Data,out bool returnIfo);
return returnIfo;
}
}
}