using Bro.Common.Base;
|
using Bro.Common.Helper;
|
using Bro.Common.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing.Design;
|
using System.Linq;
|
|
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; } = ",";
|
|
[Category("IO监听设置")]
|
[Description("IO监听操作配置集合")]
|
[TypeConverter(typeof(CollectionCountConvert))]
|
[Editor(typeof(ComplexCollectionEditor<MonitorSet>), typeof(UITypeEditor))]
|
public List<MonitorSet> MonitorSetCollection { get; set; } = new List<MonitorSet>();
|
|
[Category("IO监听设置")]
|
[Description("IO监听间隔,以ms为单位")]
|
public int ScanInterval { get; set; } = 100;
|
}
|
|
[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 int Para2 { get; set; } = 0;
|
|
/// <summary>
|
/// Paras不包含Para1,Para2内容
|
/// </summary>
|
public List<string> Datas { get; set; } = new List<string>();
|
|
public byte[] GetMsgBytes(string seperator, string endChar)
|
{
|
List<string> list = new List<string>() { ((int)Type).ToString("D2"), ID.ToString("D2") };
|
|
if (Type == RobotMsgType.Send)
|
{
|
list.Add(((int)Action).ToString("D2"));
|
|
list.Add(((int)Para1).ToString("D2"));
|
list.Add(Para2.ToString("D2"));
|
|
if (Datas == null)
|
{
|
Datas = new List<string>();
|
}
|
|
while (Datas.Count < 5)
|
{
|
Datas.Add("0");
|
}
|
|
list.AddRange(Datas.ConvertAll(s =>
|
{
|
string res = float.Parse(s).ToString("F7");
|
|
while (res.Length < 11)
|
{
|
res = "0" + res;
|
}
|
return res;
|
}));
|
}
|
|
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)int.Parse(datas[0]);
|
msg.ID = int.Parse(datas[1]);
|
|
if (msg.Type == RobotMsgType.Send)
|
{
|
msg.Action = (RobotMsgAction)int.Parse(datas[2]);
|
|
msg.Para1 = (RobotMsgParas)int.Parse(datas[3]);
|
msg.Para2 = int.Parse(datas[4]);
|
|
msg.Datas = datas.Skip(5).ToList();
|
}
|
|
return msg;
|
}
|
|
public string GetDisplayText()
|
{
|
string msg = $"序号:{ID},{Action.ToString()}_{Para1.ToString()}_{Para2.ToString()}_{(Datas.Count > 0 ? ("_" + string.Join(",", Datas)) : "")}";
|
return msg;
|
}
|
}
|
|
public enum RobotMsgType
|
{
|
Send = 1,
|
Rec = 2,
|
}
|
|
public enum RobotMsgAction
|
{
|
Move = 1,
|
Unload = 2,
|
Load = 3,
|
IO = 6,
|
Calibration = 9,
|
StandardPoint = 10,
|
}
|
|
public enum RobotMsgParas
|
{
|
None = 0,
|
Home = 1,
|
LineSnap = 2,
|
EmptyTray = 3,
|
FullTray = 4,
|
UnloadEmptyTraySnap = 5,
|
LoadFullTraySnap = 6,
|
Query = 7,
|
}
|
}
|