using Bro.Common.Base;
|
using Bro.Common.Helper;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
|
namespace Bro.Device.AuboRobot
|
{
|
[Device("AuboRobot", "奥博机器人", EnumHelper.DeviceAttributeType.InitialConfig)]
|
public class AuboRobotInitialConfig : InitialConfigBase
|
{
|
[Category("机器人设置")]
|
[Description("机器人通信IP")]
|
public string RobotIP { get; set; } = "0.0.0.0";
|
|
[Category("机器人设置")]
|
[Description("机器人通信端口")]
|
public int RobotPort { get; set; }
|
|
[Category("通信设置")]
|
[Description("反馈超时设置,单位ms")]
|
public int ReplyTimeout { get; set; } = 1000;
|
|
[Category("通信设置")]
|
[Description("协议文本结束字符")]
|
public string EndChar { get; set; } = "#";
|
|
[Category("通信设置")]
|
[Description("协议内容分隔字符")]
|
public string Seperator { get; set; } = ",";
|
}
|
|
[Device("AuboRobot", "奥博机器人", EnumHelper.DeviceAttributeType.OperationConfig)]
|
public class AuboRobotOperationConfig : OperationConfigBase
|
{
|
}
|
|
public class RobotMsg : IComplexDisplay
|
{
|
public RobotMsgType Type { get; set; } = RobotMsgType.Send;
|
|
public int ID { get; set; }
|
|
public RobotMsgAction Action { get; set; } = RobotMsgAction.Move;
|
|
public RobotMsgParas Para1 { get; set; } = RobotMsgParas.None;
|
|
public List<string> Paras { get; set; } = new List<string>();
|
|
public byte[] GetMsgBytes(string seperator, string endChar)
|
{
|
List<string> list = new List<string>() { Type.ToString(), ID.ToString() };
|
|
if (Type == RobotMsgType.Send)
|
{
|
list.Add(Action.ToString());
|
|
if (Para1 != RobotMsgParas.None)
|
{
|
list.Add(Para1.ToString());
|
}
|
|
list.AddRange(Paras);
|
}
|
|
string msg = string.Join(seperator, list);
|
|
return System.Text.Encoding.ASCII.GetBytes(msg + endChar);
|
}
|
|
public static RobotMsg GetRobotMsg(string data, string seperator)
|
{
|
string[] datas = data.Split(new string[] { seperator }, System.StringSplitOptions.RemoveEmptyEntries);
|
|
RobotMsg msg = new RobotMsg();
|
|
msg.Type = (RobotMsgType)Enum.Parse(typeof(RobotMsgType), datas[0]);
|
msg.ID = int.Parse(datas[1]);
|
|
if (msg.Type == RobotMsgType.Send)
|
{
|
msg.Action = (RobotMsgAction)Enum.Parse(typeof(RobotMsgAction), datas[2]);
|
|
if (int.TryParse(datas[3], out int para1))
|
{
|
msg.Para1 = RobotMsgParas.None;
|
|
for (int i = 3; i < datas.Length; i++)
|
{
|
msg.Paras.Add(datas[i]);
|
}
|
}
|
else
|
{
|
msg.Para1 = (RobotMsgParas)Enum.Parse(typeof(RobotMsgParas), datas[3]);
|
|
for (int i = 4; i < datas.Length; i++)
|
{
|
msg.Paras.Add(datas[i]);
|
}
|
}
|
}
|
|
return msg;
|
}
|
|
public string GetDisplayText()
|
{
|
string msg = $"序号:{ID},{Action.ToString()}_{Para1.ToString()}{(Paras.Count > 0 ? ("_" + string.Join(",", Paras)) : "")}";
|
return msg;
|
}
|
}
|
|
public enum RobotMsgType
|
{
|
Send,
|
Rec
|
}
|
|
public enum RobotMsgAction
|
{
|
Move,
|
State,
|
Adjust,
|
IO,
|
}
|
|
public enum RobotMsgParas
|
{
|
None,
|
LineSnap,
|
Line,
|
Robot,
|
LoadEmptyTraySnap,
|
LoadEmptyTrayDone,
|
LoadFullTraySnap,
|
LoadFullTrayDone,
|
EmptyTrayReady,
|
EmptyTrayEmpty,
|
FullTrayFull,
|
Query,
|
}
|
}
|