首次上传
This commit is contained in:
+154
@@ -0,0 +1,154 @@
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Extensions;
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway.Errors
|
||||
{
|
||||
public class SunwayRobotAggregatedErrors : IBitTypeClass
|
||||
{
|
||||
#region Variables
|
||||
|
||||
private const int BIT_WIDTH = 16;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public SunwayRobotAggregatedErrors()
|
||||
{
|
||||
Input = new SunwayRobotInputErrors();
|
||||
Sensor = new SunwayRobotSensorErrors();
|
||||
AxisT = new SunwayRobotServoErrors();
|
||||
AxisR = new SunwayRobotServoErrors();
|
||||
AxisZ = new SunwayRobotServoErrors();
|
||||
Controller = new SunwayRobotControllerErrors();
|
||||
}
|
||||
|
||||
public SunwayRobotAggregatedErrors(string response)
|
||||
{
|
||||
if (!IsErrResponse(response, out var rawErr))
|
||||
throw new InvalidOperationException("the format of response string is incorrect.");
|
||||
|
||||
Input = int.TryParse(rawErr[0], NumberStyles.HexNumber, null, out var input)
|
||||
? input.ToBitTypeClass<SunwayRobotInputErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotInputErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
Sensor = int.TryParse(rawErr[1], NumberStyles.HexNumber, null, out var sensor)
|
||||
? sensor.ToBitTypeClass<SunwayRobotSensorErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotSensorErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
AxisT = int.TryParse(rawErr[2], NumberStyles.HexNumber, null, out var axisT)
|
||||
? axisT.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
AxisR = int.TryParse(rawErr[3], NumberStyles.HexNumber, null, out var axisR)
|
||||
? axisR.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
AxisZ = int.TryParse(rawErr[4], NumberStyles.HexNumber, null, out var axisZ)
|
||||
? axisZ.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
AxisW = int.TryParse(rawErr[5], NumberStyles.HexNumber, null, out var axisW)
|
||||
? axisW.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
AxisH = int.TryParse(rawErr[6], NumberStyles.HexNumber, null, out var axisH)
|
||||
? axisH.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotServoErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
Controller = int.TryParse(rawErr[7], NumberStyles.HexNumber, null, out var cont)
|
||||
? cont.ToBitTypeClass<SunwayRobotControllerErrors>(BIT_WIDTH)
|
||||
: 0xffff.ToBitTypeClass<SunwayRobotControllerErrors>(BIT_WIDTH); // 如果转换错误,全部置为错误,以防呆
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 输入错误
|
||||
/// </summary>
|
||||
public SunwayRobotInputErrors Input { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 传感器错误
|
||||
/// </summary>
|
||||
public SunwayRobotSensorErrors Sensor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// T轴错误
|
||||
/// </summary>
|
||||
public SunwayRobotServoErrors AxisT { get; }
|
||||
|
||||
/// <summary>
|
||||
/// R轴错误
|
||||
/// </summary>
|
||||
public SunwayRobotServoErrors AxisR { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Z轴错误
|
||||
/// </summary>
|
||||
public SunwayRobotServoErrors AxisZ { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Z轴错误
|
||||
/// </summary>
|
||||
public SunwayRobotServoErrors AxisW { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Z轴错误
|
||||
/// </summary>
|
||||
public SunwayRobotServoErrors AxisH { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 控制器错误
|
||||
/// </summary>
|
||||
public SunwayRobotControllerErrors Controller { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回整合的错误信息列表。
|
||||
/// </summary>
|
||||
public List<string> AggregateErrorMessages
|
||||
{
|
||||
get
|
||||
{
|
||||
var errs = new List<string>();
|
||||
errs.AddRange(Input.AggregateErrorMessages());
|
||||
errs.AddRange(Sensor.AggregateErrorMessages());
|
||||
|
||||
// 伺服轴的错误输出文本中加入轴名称
|
||||
errs.AddRange(AxisT.AggregateErrorMessages()
|
||||
.Select(x => string.Concat($"[{nameof(AxisT)}]", x)));
|
||||
errs.AddRange(AxisR.AggregateErrorMessages()
|
||||
.Select(x => string.Concat($"[{nameof(AxisR)}]", x)));
|
||||
errs.AddRange(AxisZ.AggregateErrorMessages()
|
||||
.Select(x => string.Concat($"[{nameof(AxisZ)}]", x)));
|
||||
errs.AddRange(AxisW.AggregateErrorMessages()
|
||||
.Select(x => string.Concat($"[{nameof(AxisW)}]", x)));
|
||||
errs.AddRange(AxisH.AggregateErrorMessages()
|
||||
.Select(x => string.Concat($"[{nameof(AxisH)}]", x)));
|
||||
|
||||
errs.AddRange(Controller.AggregateErrorMessages());
|
||||
|
||||
return errs;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public static bool IsErrResponse(string response, out string[] errArray)
|
||||
{
|
||||
errArray = response.Split(',');
|
||||
return errArray.Length == 8;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Interfaces;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway.Errors
|
||||
{
|
||||
public class SunwayRobotControllerErrors : IBitTypeClass
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Interfaces;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway.Errors
|
||||
{
|
||||
public class SunwayRobotInputErrors : IBitTypeClass
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Interfaces;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway.Errors
|
||||
{
|
||||
public class SunwayRobotSensorErrors : IBitTypeClass
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Interfaces;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway.Errors
|
||||
{
|
||||
public class SunwayRobotServoErrors : IBitTypeClass
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+1415
File diff suppressed because it is too large
Load Diff
+93
@@ -0,0 +1,93 @@
|
||||
using Aitex.Core.RT.Log;
|
||||
using MECF.Framework.Common.Communications;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway
|
||||
{
|
||||
public class SunwayRobotMessage : AsciiMessage
|
||||
{
|
||||
public string Data { get; set; }
|
||||
public string ErrorText { get; set; }
|
||||
}
|
||||
|
||||
public class SunwayRobotTCPConnection : TCPPortConnectionBase
|
||||
{
|
||||
private bool _isAckMode = false;//should read from config file
|
||||
|
||||
public SunwayRobotTCPConnection(string address, string endof)
|
||||
: base(address, endof, true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override bool SendMessage(string message)
|
||||
{
|
||||
return base.SendMessage(message);
|
||||
}
|
||||
|
||||
protected override void ActiveHandlerProceedMessage(MessageBase msg)
|
||||
{
|
||||
lock (_lockerActiveHandler)
|
||||
{
|
||||
if (_activeHandler != null)
|
||||
{
|
||||
if (msg.IsFormatError || !((SunwayRobotHandler)_activeHandler).HasResponse || (_activeHandler.HandleMessage(msg, out bool transactionComplete) && transactionComplete))
|
||||
{
|
||||
_activeHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override MessageBase ParseResponse(string rawText)
|
||||
{
|
||||
SunwayRobotMessage msg = new SunwayRobotMessage();
|
||||
msg.RawMessage = rawText;
|
||||
|
||||
if (rawText.Length <= 0)
|
||||
{
|
||||
LOG.Error($"empty response,");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
rawText = rawText.Replace("\r", "").Replace("\n", "");
|
||||
if (rawText.Contains("_ERR"))
|
||||
{
|
||||
msg.IsError = true;
|
||||
|
||||
var rewTextArray = rawText.Split(' ');
|
||||
msg.Data = rewTextArray[1];
|
||||
msg.IsComplete = true;
|
||||
}
|
||||
else if (rawText.Contains("_BG_RDY"))
|
||||
{
|
||||
if (!_isAckMode)
|
||||
{
|
||||
LOG.Error($"response format check failed, BG_RDY is not valid in Mode 1");
|
||||
msg.IsFormatError = true;
|
||||
return msg;
|
||||
}
|
||||
msg.Data = rawText;
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
}
|
||||
else if (rawText.Contains("_RDY"))
|
||||
{
|
||||
msg.Data = rawText;
|
||||
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.Data = rawText;
|
||||
msg.IsResponse = true;
|
||||
msg.IsAck = true;
|
||||
msg.IsComplete = true;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1745
File diff suppressed because it is too large
Load Diff
+114
@@ -0,0 +1,114 @@
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Attributes;
|
||||
using MECF.Framework.RT.EquipmentLibrary.Core.Interfaces;
|
||||
|
||||
namespace MECF.Framework.RT.EquipmentLibrary.HardwareUnits.Robots.Sunway
|
||||
{
|
||||
public class SunwayRobotStatus : IBitTypeClass
|
||||
{
|
||||
|
||||
#region Constructor
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否已接收巨集指令尚未被执行。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(0, "已接收巨集指令尚未被执行")]
|
||||
public bool IsCommandNotExecuted { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否正压力传感器被触发。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(1, "正压力传感器被触发")]
|
||||
public bool IsPosPressureSensorTriggered { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否负压力传感器被触发。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(2, "负压力传感器被触发")]
|
||||
public bool IsNegPressureSensorTriggered { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否电磁阀已被启动。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(3, "电磁阀已被启动")]
|
||||
public bool IsSolenoidValveTurnedOn { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否单轴或多轴马达发生错误。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(4, "单轴或多轴马达发生错误", true)]
|
||||
public bool IsMotorError { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否单个或多个极限开关被触发。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(5, "单个或多个极限开关被触发", true)]
|
||||
public bool IsEndLimitTriggered { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否单个或多个轴伺服马达归零未成功。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(6, "单个或多个轴伺服马达归零未成功", true)]
|
||||
public bool IsHomingFailed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保留位1。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(7, "保留位1")]
|
||||
public bool Reserved1 { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否指令正在执行中。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(8, "指令正在执行中")]
|
||||
public bool IsCommandExecuting { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否单个或多个轴正在移动中。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(9, "单个或多个轴正在移动中")]
|
||||
public bool IsMoving { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否单个或多个马达已被解除励磁。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(10, "单个或多个马达已被解除励磁中", true)]
|
||||
public bool IsServoOff { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否已回原点但RW轴未在原点位置。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(11, "已回原点但RW轴未在原点位置", true)]
|
||||
public bool IsHomedButRWAxis { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否已回原点并且处于缩回状态。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(12, "已回原点并且处于缩回状态")]
|
||||
public bool IsHomedAndRetracted { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保留位2。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(13, "保留位2")]
|
||||
public bool Reserved2 { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 返回是否控制器返回错误。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(14, "控制器返回错误", true)]
|
||||
public bool IsControllerError { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保留位3。
|
||||
/// </summary>
|
||||
[BitTypeClassProperty(15, "保留位3")]
|
||||
public bool Reserved3 { get; private set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user