refactor: 将Framework库和RT、UI放在同一个解决方案中。
This commit is contained in:
+1652
File diff suppressed because it is too large
Load Diff
+65
@@ -0,0 +1,65 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL
|
||||
{
|
||||
public class JelRobotMessage : AsciiMessage
|
||||
{
|
||||
public string Data { get; set; }
|
||||
public string ErrorText { get; set; }
|
||||
}
|
||||
|
||||
public class JelRobotConnection : SerialPortConnectionBase
|
||||
{
|
||||
//private bool _isAckMode = false;//should read from config file
|
||||
|
||||
private string _cachedBuffer = string.Empty;
|
||||
private List<byte> _lstCacheBuffer = new List<byte>();
|
||||
|
||||
public JelRobotConnection(string portName, int baudRate = 9600, int dataBits = 8, Parity parity = Parity.None, StopBits stopBits = StopBits.One)
|
||||
: base(portName, baudRate, dataBits, parity, stopBits, "", true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool SendMessage(byte[] message)
|
||||
{
|
||||
_lstCacheBuffer.Clear();
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
public override bool SendMessage(string message)
|
||||
{
|
||||
_cachedBuffer = string.Empty;
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
|
||||
protected override MessageBase ParseResponse(string rawmsg)
|
||||
{
|
||||
_cachedBuffer += rawmsg;
|
||||
JelRobotMessage msg = new JelRobotMessage();
|
||||
|
||||
if (_cachedBuffer == ">")
|
||||
{
|
||||
msg.IsAck = true;
|
||||
msg.Data = _cachedBuffer.Replace(">", "").Replace("\r", "");
|
||||
_cachedBuffer = string.Empty;
|
||||
}
|
||||
else if (_cachedBuffer.Contains("\r"))
|
||||
{
|
||||
msg.IsAck = true;
|
||||
msg.IsResponse = true;
|
||||
msg.Data = _cachedBuffer.Replace(">", "").Replace("\r", "");
|
||||
_cachedBuffer = string.Empty;
|
||||
}
|
||||
//else if(_cachedBuffer.Contains("\r"))
|
||||
//{
|
||||
// msg.IsAck = true;
|
||||
// msg.Data = rawmsg.Replace(">", "").Replace("\r", "");
|
||||
// _cachedBuffer = string.Empty;
|
||||
//}
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.JEL
|
||||
{
|
||||
public abstract class JelRobotHandler:HandlerBase
|
||||
{
|
||||
public JelRobot Device { get; }
|
||||
|
||||
protected string _command;
|
||||
protected string _parameter;
|
||||
protected JelRobotHandler(JelRobot device, string command, string parameter = null)
|
||||
: base(BuildMessage(device.BodyNumber, command, parameter))
|
||||
{
|
||||
Device = device;
|
||||
_command = command;
|
||||
_parameter = parameter;
|
||||
Name = command;
|
||||
}
|
||||
protected JelRobotHandler(string command)
|
||||
: base(command)
|
||||
{
|
||||
_command = command;
|
||||
}
|
||||
private static string BuildMessage(int bodyno, string command, string parameter)
|
||||
{
|
||||
return $"${bodyno}{command}{parameter}\r";
|
||||
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
JelRobotMessage response = msg as JelRobotMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public class JelRobotReadHandler: JelRobotHandler
|
||||
{
|
||||
|
||||
public JelRobotReadHandler(JelRobot device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
|
||||
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
|
||||
LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
JelRobotMessage response = msg as JelRobotMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
Device.ParseData(_command,_parameter,response.Data);
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class JelRobotSetHandler : JelRobotHandler
|
||||
{
|
||||
|
||||
public JelRobotSetHandler(JelRobot device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
|
||||
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
|
||||
LOG.Write($"{device.Name} execute read command {command} {temp} in byte.");
|
||||
}
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
JelRobotMessage response = msg as JelRobotMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public class JelRobotMoveHandler : JelRobotHandler
|
||||
{
|
||||
public JelRobotMoveHandler(JelRobot device, string command, string parameter = null)
|
||||
: base(device, command, parameter)
|
||||
{
|
||||
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
|
||||
LOG.Write($"{device.Name} execute move command {command} {temp} in byte.");
|
||||
}
|
||||
}
|
||||
|
||||
public class JelRobotRawCommandHandler : JelRobotHandler
|
||||
{
|
||||
public JelRobotRawCommandHandler(JelRobot device, string command)
|
||||
: base(command)
|
||||
{
|
||||
|
||||
LOG.Write($"{device.Name} execute move command {command} in byte.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class JelRobotCompaundCommandHandler : JelRobotHandler
|
||||
{
|
||||
public JelRobotCompaundCommandHandler(JelRobot device, string cmdNo, string parameter = null)
|
||||
: base(device, $"G{cmdNo}", parameter)
|
||||
{
|
||||
string temp = string.IsNullOrEmpty(parameter) ? parameter : "";
|
||||
LOG.Write($"{device.Name} execute compaund command {cmdNo} {temp} in byte.");
|
||||
}
|
||||
|
||||
public override bool HandleMessage(MessageBase msg, out bool transactionComplete)
|
||||
{
|
||||
JelRobotMessage response = msg as JelRobotMessage;
|
||||
ResponseMessage = msg;
|
||||
|
||||
if (response.IsAck)
|
||||
{
|
||||
//if (_command == "G")
|
||||
// Device.CurrentCompoundCommandStatus = JelCommandStatus.None;
|
||||
|
||||
SetState(EnumHandlerState.Acked);
|
||||
//transactionComplete = true;
|
||||
//return true;
|
||||
}
|
||||
if (response.IsResponse)
|
||||
{
|
||||
SetState(EnumHandlerState.Completed);
|
||||
if (response.Data.Contains("END"))
|
||||
{
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
if (response.Data.Contains("ERR"))
|
||||
{
|
||||
Device.HandlerError(response.Data);
|
||||
transactionComplete = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
transactionComplete = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user