Commit 31e0cf72 顾剑亮

debug

1 个父辈 c94edc52
......@@ -54,6 +54,7 @@
<Compile Include="Job\SendFullJob.cs" />
<Compile Include="Server.cs" />
<Compile Include="Job\StandbyJob.cs" />
<Compile Include="WorkManage.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj">
......
......@@ -56,7 +56,7 @@ namespace BLL
}
catch (Exception ex)
{
LogOut.Error("CallProcess " + info.Name, ex);
Common.log.Error("CallProcess " + info.Name, ex);
}
finally
{
......@@ -111,7 +111,7 @@ namespace BLL
int idx = Common.agvInfos.FindIndex(s => s.IP == ip);
if (idx > -1) AgvOnline?.Invoke(idx);
}
LogOut.Debug(string.Format("{0}[{1}] 脱机", info.Name, info.IP));
Common.log.Debug(string.Format("{0}[{1}] 脱机", info.Name, info.IP));
}
}
......
......@@ -5,16 +5,19 @@ namespace BLL
{
public class ChargeJob : IJob
{
private string _name;
private AgvInfo _info;
private MissionJob move;
private string mission;
private JobStep<ChargeStep> chargeStep;
private int currBattery;
public ChargeJob()
public ChargeJob(string name)
{
IsEnd = false;
_name = name;
chargeStep = new JobStep<ChargeStep>(ChargeStep.None);
LogOut.Debug("加载ChargeJob");
Common.log.Debug("加载ChargeJob");
}
public bool IsEnd { get; private set; }
......@@ -45,7 +48,7 @@ namespace BLL
{
if (_info.Battery == _info.BatteryMax)
{
chargeStep.Msg = _info.Name + "电量达到" + _info.BatteryMax;
chargeStep.Msg = _info.Name + " 电量达到" + _info.BatteryMax;
chargeStep.NextStep(ChargeStep.End);
}
else if (_info.Battery > _info.BatteryMin)
......@@ -60,8 +63,9 @@ namespace BLL
}
else if (chargeStep.Equals(ChargeStep.End))
{
IsEnd = true;
MiR_API.Del_Mission(_info.IP, _info.Authorization);
chargeStep.Msg = _info.Name + "充电工作结束,回待机位";
chargeStep.Msg = _info.Name + " 充电工作结束,回待机位";
return new StandbyJob();
}
......@@ -73,12 +77,12 @@ namespace BLL
/// </summary>
private void SendCharge()
{
mission = Common.MISSION_CHARGE + _info.Name;
_info.Place = mission;
mission = Common.MISSION_CHARGE + _name;
_info.Place = _name;
move = new MissionJob(mission);
move.Execute(_info);
chargeStep.NextStep(ChargeStep.MoveStation);
chargeStep.Msg = _info.Name + "发送任务" + mission;
chargeStep.Msg = string.Format("{0} 去{1},[{2}]", _info.Name, _info.Place, mission);
}
/// <summary>
......@@ -87,11 +91,11 @@ namespace BLL
private void PassDoor4D()
{
mission = Common.MISSION_PASS_DOOR_4D;
_info.Place = mission;
_info.Place = "Goto4D";
move = new MissionJob(mission);
move.Execute(_info);
chargeStep.NextStep(ChargeStep.PassDoor);
chargeStep.Msg = _info.Name + "发送任务" + mission;
chargeStep.Msg = string.Format("{0} 去4D车间,[{1}]", _info.Name, mission);
}
/// <summary>
......@@ -101,7 +105,7 @@ namespace BLL
{
if (_info.Battery > currBattery)
{
chargeStep.Msg = _info.Name + "到达充电位,准备充电";
chargeStep.Msg = _info.Name + " 到达充电位,准备充电";
chargeStep.NextStep(ChargeStep.Charging);
}
}
......
......@@ -59,7 +59,7 @@ namespace BLL
{
_times = 0;
log = string.Format("MissionJob To:{0},[{1}]发送成功", _info.Name, _mission);
LogOut.Debug(log);
Common.log.Debug(log);
_getTime = DateTime.Now;
missionStep.NextStep(MissionStep.Working);
}
......@@ -67,7 +67,7 @@ namespace BLL
{
_times++;
log = string.Format("MissionJob To:{0},[{1}]发送失败{2}次", _info.Name, _mission, _times);
LogOut.Warn(log);
Common.log.Warn(log);
}
}
......@@ -88,7 +88,7 @@ namespace BLL
if (rtn)
{
log = string.Format("MissionJob To:{0},[{1}]任务状态{2}", _info.Name, _mission, state);
LogOut.Debug(log);
Common.log.Debug(log);
if (state == MissionState.Done.ToString())
missionStep.NextStep(MissionStep.End);
else if (state == MissionState.Aborted.ToString())
......@@ -101,14 +101,14 @@ namespace BLL
else
{
log = string.Format("MissionJob To:{0},[{1}]获取状态失败", _info.Name, _mission);
LogOut.Warn(log);
Common.log.Warn(log);
}
}
}
private void Error()
{
LogOut.Debug(string.Format("MissionJob To:{0},[{1}]重新发送", _info.Name, _mission));
Common.log.Debug(string.Format("MissionJob To:{0},[{1}]重新发送", _info.Name, _mission));
MiR_API.Clear_Error(_info.IP, _info.Authorization);
MiR_API.Del_Mission(_info.IP, _info.Authorization);
missionStep.NextStep(MissionStep.Send);
......
......@@ -13,8 +13,9 @@ namespace BLL
public StandbyJob()
{
IsEnd = false;
standbyStep = new JobStep<StandbyStep>(StandbyStep.None);
LogOut.Debug("加载StandbyJob");
Common.log.Debug("加载StandbyJob");
}
public bool IsEnd { get; private set; }
......@@ -41,7 +42,7 @@ namespace BLL
if (move.IsEnd)
{
standbyStep.NextStep(StandbyStep.End);
standbyStep.Msg = _info.Name + "到达待机位";
standbyStep.Msg = _info.Name + " 到达待机位";
_getTime = DateTime.Now;
}
}
......@@ -49,7 +50,7 @@ namespace BLL
{
if (_info.Battery <= _info.BatteryMin)
{
standbyStep.Msg = _info.Name + "电量小于" + _info.BatteryMin + ",执行充电任务";
standbyStep.Msg = _info.Name + " 电量小于" + _info.BatteryMin + ",执行充电任务";
return new ChargeJob();
}
else
......@@ -57,7 +58,7 @@ namespace BLL
TimeSpan span = DateTime.Now - _getTime;
if (span.TotalMinutes >= 2)
{
standbyStep.Msg = _info.Name + "在待机位停留超过2分钟,执行充电任务";
standbyStep.Msg = _info.Name + " 在待机位停留超过2分钟,执行充电任务";
return new ChargeJob();
}
else
......@@ -77,11 +78,11 @@ namespace BLL
private void SendStandby()
{
mission = Common.MISSION_STANDBY + _info.Name;
_info.Place = mission;
_info.Place = "待机位";
move = new MissionJob(mission);
move.Execute(_info);
standbyStep.NextStep(StandbyStep.MoveStandby);
standbyStep.Msg = _info.Name + "发送任务" + mission;
standbyStep.Msg = string.Format("{0} 去待机位,[{1}]", _info.Name, mission);
}
/// <summary>
......@@ -90,11 +91,11 @@ namespace BLL
private void PassDoor4D()
{
mission = Common.MISSION_PASS_DOOR_4D;
_info.Place = mission;
_info.Place = "Goto4D";
move = new MissionJob(mission);
move.Execute(_info);
standbyStep.NextStep(StandbyStep.PassDoor);
standbyStep.Msg = _info.Name + "发送任务" + mission;
standbyStep.Msg = string.Format("{0} 去4D车间,[{1}]", _info.Name, mission);
}
......
......@@ -42,11 +42,11 @@ namespace BLL
_client = new List<Client>();
timerListenClient = new Timer(ListenClient, null, 50, Timeout.Infinite);
LogOut.Info("AGV服务启动");
Common.log.Info("AGV服务启动");
}
catch (Exception ex)
{
LogOut.Error("Start", ex);
Common.log.Error("Start", ex);
}
}
......@@ -59,7 +59,7 @@ namespace BLL
_client[i].Clear();
if (timerListenClient != null)
timerListenClient.Dispose();
LogOut.Info("AGV服务关闭");
Common.log.Info("AGV服务关闭");
}
/// <summary>
......@@ -224,7 +224,7 @@ namespace BLL
Client client = new Client { IP = ip, IsConn = true, Socket = socket };
_client.Add(client);
client.ListenNet = new Timer(ListenNet, _client.Count - 1, 100, 100);
LogOut.Info(string.Format("[{0}] 已连接", client.IP));
Common.log.Info(string.Format("[{0}] 已连接", client.IP));
}
catch (SocketException)
{
......@@ -232,7 +232,7 @@ namespace BLL
}
catch (Exception ex)
{
LogOut.Error("ListenClient", ex);
Common.log.Error("ListenClient", ex);
}
}
......@@ -257,9 +257,9 @@ namespace BLL
ClientNode node = Decode(buff);
if (node == null)
LogOut.Info("命令解析失败: " + HexBuff(buff));
Common.log.Info("命令解析失败: " + HexBuff(buff));
else
LogOut.Info("From Server: " + node.ToText());
Common.log.Info("From Server: " + node.ToText());
UpdateNode(client, node);
}
else
......@@ -268,13 +268,13 @@ namespace BLL
if (time > 10000)
{
Offline(client);
LogOut.Info("[" + client.IP + "] 超过10s没有收到数据,关闭连接");
Common.log.Info("[" + client.IP + "] 超过10s没有收到数据,关闭连接");
}
}
}
catch (Exception ex)
{
LogOut.Error("ListenNet", ex);
Common.log.Error("ListenNet", ex);
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace BLL
{
public static class WorkManage
{
public static string GetChargingName(AgvInfo info)
{
string name = null;
if (Common.chargingPile == null) return name;
//空闲充电桩
for (int i = 0; i < Common.chargingPile.Count; i++)
{
if (Common.chargingPile[i].Employ == "")
{
int idx = Array.FindIndex(Common.chargingPile[i].User, s => s == info.Name);
if (idx > -1)
{
name = Common.chargingPile[i].Name;
return name;
}
}
}
if (info.Battery <= info.BatteryMin)
{
}
return name;
}
}
}
......@@ -23,15 +23,9 @@ namespace ClientTest
private void FrmMain_Load(object sender, EventArgs e)
{
client = new AgvClient("127.0.0.1");
client.Log += Client_Log;
client.Connect();
}
private void Client_Log(string s)
{
TxtLog.AppendText(s + "\r\n");
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
client.Close();
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
......@@ -19,9 +20,7 @@ namespace Clinet
private Timer timerListen;
private List<ClientNode> _node;
private const int PORT = 12000; //端口
public delegate void LogEvent(string s);
public event LogEvent Log;
private readonly log4net.ILog LOG;
/// <summary>
/// 小车动作事件
......@@ -45,9 +44,10 @@ namespace Clinet
public event ActionEvent EnterShelf;
public AgvClient(string serverIP)
public AgvClient(string serverIP, string logName = "AgvClient")
{
_ip = serverIP;
LOG = log4net.LogManager.GetLogger(logName);
_node = new List<ClientNode>();
ThreadPool.SetMaxThreads(6, 6); //线程池最大数量
}
......@@ -69,7 +69,7 @@ namespace Clinet
timerSend.Dispose();
if (timerListen != null)
timerListen.Dispose();
Log?.Invoke("AGV客户端关闭");
LOG.Info("AGV客户端关闭");
}
public void SetStatus(string name, string mark = "", string rfid = "", ClientAction action = ClientAction.None, ClientLevel level = ClientLevel.Low)
......@@ -79,7 +79,7 @@ namespace Clinet
{
ClientNode node = new ClientNode(name, mark, rfid, action, level);
_node.Add(node);
Log?.Invoke("SetStatus " + node.ToText());
LOG.Info("SetStatus " + node.ToText());
}
else
{
......@@ -87,7 +87,7 @@ namespace Clinet
_node[idx].RFID = rfid;
_node[idx].Action = action;
_node[idx].Level = level;
Log?.Invoke("SetStatus " + _node[idx].ToText());
LOG.Info("SetStatus " + _node[idx].ToText());
}
}
......@@ -97,7 +97,7 @@ namespace Clinet
if (idx == -1)
{
_node.Add(node.ToCopy());
Log?.Invoke("SetStatus " + node.ToText());
LOG.Info("SetStatus " + node.ToText());
}
else
{
......@@ -105,7 +105,7 @@ namespace Clinet
_node[idx].RFID = node.RFID;
_node[idx].Action = node.Action;
_node[idx].Level = node.Level;
Log?.Invoke("SetStatus " + _node[idx].ToText());
LOG.Info("SetStatus " + _node[idx].ToText());
}
}
......@@ -120,13 +120,13 @@ namespace Clinet
if (IsConn)
{
countRecon = 0;
Log?.Invoke("连接AGV服务器成功");
LOG.Info("连接AGV服务器成功");
timerSend = new Timer(SendStatus, null, 50, 2000);
timerListen = new Timer(ListenNet, null, 50, 100);
}
else
{
Log?.Invoke("连接服务器失败" + ++countRecon + "次");
LOG.Info("连接服务器失败" + ++countRecon + "次");
}
}
......@@ -147,7 +147,7 @@ namespace Clinet
}
catch (Exception ex)
{
Log?.Invoke(ex.Message);
LOG.Error("Open", ex);
}
}
......@@ -165,16 +165,22 @@ namespace Clinet
ClientNode node = Decode(buff);
if (node == null)
Log?.Invoke("命令解析失败: " + HexBuff(buff));
{
LOG.Info("命令解析失败: " + HexBuff(buff));
}
else
Log?.Invoke("From Server: " + node.ToText());
Resolve(node);
{
LOG.Info("来自服务器: " + node.ToText());
Resolve(node);
node.Action = ClientAction.Received;
Send(Encode(node));
}
}
}
catch (Exception ex)
{
IsConn = false;
Log?.Invoke(ex.Message);
LOG.Error("ListenNet", ex);
}
}
......@@ -197,19 +203,19 @@ namespace Clinet
switch (node.Action)
{
case ClientAction.Arrive:
Log?.Invoke("触发Arrive事件");
LOG.Info("触发Arrive事件");
Arrive?.Invoke(node.Name, node.RFID);
break;
case ClientAction.Ready:
Log?.Invoke("触发Ready事件");
LOG.Info("触发Ready事件");
Ready?.Invoke(node.Name, node.RFID);
break;
case ClientAction.CloseDoor:
Log?.Invoke("触发CloseDoor事件");
LOG.Info("触发CloseDoor事件");
CloseDoor?.Invoke(node.Name, node.RFID);
break;
case ClientAction.EnterShelf:
Log?.Invoke("触发EnterShelf事件");
LOG.Info("触发EnterShelf事件");
EnterShelf?.Invoke(node.Name, node.RFID);
break;
}
......@@ -220,125 +226,82 @@ namespace Clinet
{
if (!IsConn)
{
Log?.Invoke("Send 服务器没有连接");
LOG.Info("Send 服务器没有连接");
return false;
}
try
{
//Log?.Invoke("Send: " + HexBuff(buff));
LOG.Debug("Send: " + HexBuff(buff));
client.Send(buff);
return true;
}
catch (Exception ex)
{
Log?.Invoke(ex.Message);
LOG.Error("Send", ex);
return false;
}
}
//private byte[] Encode(ClientNode node)
//{
// byte[] name = Encoding.UTF8.GetBytes(node.Name);
// byte[] mark = Encoding.UTF8.GetBytes(node.Mark);
// byte[] rfid = Encoding.UTF8.GetBytes(node.RFID);
// int count = name.Length + mark.Length + rfid.Length + 7;
// int idx = 0;
// byte[] buff = new byte[count];
// buff[idx++] = 0xAB;
// buff[idx++] = Convert.ToByte(name.Length);
// Array.Copy(name, 0, buff, idx, name.Length);
// idx += name.Length;
// buff[idx++] = Convert.ToByte(mark.Length);
// Array.Copy(mark, 0, buff, idx, mark.Length);
// idx += mark.Length;
// buff[idx++] = Convert.ToByte(rfid.Length);
// Array.Copy(rfid, 0, buff, idx, rfid.Length);
// idx += rfid.Length;
// buff[idx++] = (byte)node.Action;
// buff[idx++] = Convert.ToByte(node.Level);
// buff[idx++] = 0xBA;
// return buff;
//}
private byte[] Encode(ClientNode node)
{
List<string> arr = new List<string>
try
{
System.Reflection.PropertyInfo[] info = node.GetType().GetProperties();
string[] arr = new string[info.Length];
for (int i = 0; i < info.Length; i++)
arr[i] = string.Format("\"{0}\":\"{1}\"", info[i].Name, info[i].GetValue(node));
string json = "{" + string.Join(",", arr) + "}";
LOG.Info("编码json " + json);
byte[] buff = Encoding.UTF8.GetBytes(json);
return buff;
}
catch (Exception ex)
{
"name:\"" + node.Name + "\"",
"mark:\"" + node.Mark + "\"",
"rfid:\"" + node.RFID + "\"",
"action:\"" + node.Action.ToString() + "\"",
"level:\"" + node.Level.ToString() + "\""
};
string s = "{" + string.Join(",", arr) + "}";
byte[] buff = Encoding.UTF8.GetBytes(s);
return buff;
LOG.Error("Encode", ex);
return null;
}
}
//private ClientNode Decode(byte[] buff)
//{
// int idx = 0;
// if (buff[idx++] != 0xAB) return null;
// byte[] temp1 = new byte[buff[idx++]];
// Array.Copy(buff, idx, temp1, 0, temp1.Length);
// string name = Encoding.UTF8.GetString(temp1);
// idx += temp1.Length;
// temp1 = new byte[buff[idx++]];
// Array.Copy(buff, idx, temp1, 0, temp1.Length);
// string mark = Encoding.UTF8.GetString(temp1);
// idx += temp1.Length;
// temp1 = new byte[buff[idx++]];
// Array.Copy(buff, idx, temp1, 0, temp1.Length);
// string rfid = Encoding.UTF8.GetString(temp1);
// idx += temp1.Length;
// ClientAction action = (ClientAction)buff[idx++];
// ClientLevel level = (ClientLevel)buff[idx++];
// ClientNode node = new ClientNode(name, mark, rfid, action, level);
// if (buff[idx] != 0xBA)
// return null;
// return node;
//}
private ClientNode Decode(byte[] buff)
{
string json = Encoding.UTF8.GetString(buff);
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> dic = (Dictionary<string, object>)serializer.DeserializeObject(json);
if (dic == null) return null;
ClientNode node = new ClientNode();
if (dic.TryGetValue("name", out object value))
node.Name = value.ToString();
if (dic.TryGetValue("mark", out value))
node.Mark = value.ToString();
if (dic.TryGetValue("rfid", out value))
node.RFID = value.ToString();
if (dic.TryGetValue("action", out value))
try
{
if (Enum.TryParse(value.ToString(), out ClientAction action))
node.Action = action;
string json = Encoding.UTF8.GetString(buff);
LOG.Info("解码json " + json);
JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, object> dic = (Dictionary<string, object>)serializer.DeserializeObject(json);
if (dic == null) return null;
ClientNode node = new ClientNode();
System.Reflection.PropertyInfo[] info = node.GetType().GetProperties();
for (int i = 0; i < info.Length; i++)
{
if (!dic.TryGetValue(info[i].Name, out object value))
continue;
switch (info[i].Name)
{
case "Action":
Enum.TryParse(value.ToString(), out ClientAction action);
value = action;
break;
case "Level":
Enum.TryParse(value.ToString(), out ClientLevel level);
value = level;
break;
}
info[i].SetValue(node, value);
}
return node;
}
if (dic.TryGetValue("level", out value))
catch (Exception ex)
{
if (Enum.TryParse(value.ToString(), out ClientLevel level))
node.Level = level;
LOG.Error("Decode", ex);
return null;
}
return node;
}
private string HexBuff(byte[] buff)
{
string s = "";
......@@ -356,7 +319,7 @@ namespace Clinet
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(ip, pattern);
if (!rtn)
{
Log?.Invoke("非法的IP地址" + ip);
LOG.Info("非法的IP地址" + ip);
return false;
}
......@@ -368,151 +331,18 @@ namespace Clinet
ping.Dispose();
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
Log?.Invoke("Ping " + ip + " 请求没有响应");
LOG.Info("Ping " + ip + " 请求没有响应");
return false;
}
return true;
}
catch (Exception ex)
{
Log?.Invoke(ex.Message);
LOG.Error("CheckIP", ex);
return false;
}
}
}
/// <summary>
/// 客户端的动作
/// </summary>
public enum ClientAction : byte
{
/// <summary>
/// 没有动作
/// </summary>
None = 0,
/// <summary>
/// 包装料仓关门
/// </summary>
CloseDoor = 1,
/// <summary>
/// 可以进入料架,Arrive事件使用,让小车开始对接
/// </summary>
MayEnter = 2,
/// <summary>
/// 可以出去料架,Arrive事件使用,让小车开始对接
/// </summary>
MayLeave = 3,
/// <summary>
/// 需要进入料架
/// </summary>
NeedEnter = 4,
/// <summary>
/// 需要出去料架
/// </summary>
NeedLeave = 5,
/// <summary>
/// 完成进入料架
/// </summary>
FinishEnter = 6,
/// <summary>
/// 完成出去料架
/// </summary>
FinishLeave = 7,
/// <summary>
/// 小车到达,到达包装料仓门口,等待开门
/// </summary>
Arrive = 8,
/// <summary>
/// 小车已准备,已对接上流水线
/// </summary>
Ready = 9,
/// <summary>
/// 包装料仓只能入料不能出料
/// </summary>
EnterShelf = 10,
/// <summary>
/// 不允许
/// </summary>
MayNot = 11
}
/// <summary>
/// 客户端的优先级
/// </summary>
public enum ClientLevel : byte
{
/// <summary>
/// 低
/// </summary>
Low = 0,
/// <summary>
/// 中等
/// </summary>
Middle = 1,
/// <summary>
/// 高
/// </summary>
High = 2
}
public class ClientNode
{
/// <summary>
/// 节点名称
/// </summary>
public string Name { set; get; }
/// <summary>
/// 标记,用于包装料仓
/// </summary>
public string Mark { set; get; }
/// <summary>
/// 当前架子的RFID
/// </summary>
public string RFID { set; get; }
/// <summary>
/// 动作
/// </summary>
public ClientAction Action { set; get; }
/// <summary>
/// 优先级
/// </summary>
public ClientLevel Level { set; get; }
public ClientNode()
{
}
public ClientNode(string name, string mark, string rfid, ClientAction action, ClientLevel level)
{
Name = name;
Mark = mark;
RFID = rfid;
Action = action;
Level = level;
}
/// <summary>
/// 所有属性的文本形式
/// </summary>
/// <returns></returns>
public string ToText()
{
string s = string.Format("Name={0}, Action={1}, Level={2}, Mark={3}, RFID={4}", Name, Action, Level, Mark, RFID);
return s;
}
public ClientNode ToCopy()
{
ClientNode node = new ClientNode(Name, Mark, RFID, Action, Level);
return node;
}
}
}
using System;
namespace Clinet
{
/// <summary>
/// 客户端的动作
/// </summary>
public enum ClientAction : byte
{
/// <summary>
/// 没有动作
/// </summary>
None = 0,
/// <summary>
/// 包装料仓关门
/// </summary>
CloseDoor = 1,
/// <summary>
/// 可以进入料架,Arrive事件使用,让小车开始对接
/// </summary>
MayEnter = 2,
/// <summary>
/// 可以出去料架,Arrive事件使用,让小车开始对接
/// </summary>
MayLeave = 3,
/// <summary>
/// 需要进入料架
/// </summary>
NeedEnter = 4,
/// <summary>
/// 需要出去料架
/// </summary>
NeedLeave = 5,
/// <summary>
/// 完成进入料架
/// </summary>
FinishEnter = 6,
/// <summary>
/// 完成出去料架
/// </summary>
FinishLeave = 7,
/// <summary>
/// 小车到达,到达包装料仓门口,等待开门
/// </summary>
Arrive = 8,
/// <summary>
/// 小车已准备,已对接上流水线
/// </summary>
Ready = 9,
/// <summary>
/// 包装料仓只能入料不能出料
/// </summary>
EnterShelf = 10,
/// <summary>
/// 不允许
/// </summary>
MayNot = 11,
/// <summary>
/// 已收到应答
/// </summary>
Received
}
}
\ No newline at end of file
using System;
namespace Clinet
{
/// <summary>
/// 客户端的优先级
/// </summary>
public enum ClientLevel : byte
{
/// <summary>
/// 低
/// </summary>
Low = 0,
/// <summary>
/// 中等
/// </summary>
Middle = 1,
/// <summary>
/// 高
/// </summary>
High = 2
}
}
\ No newline at end of file
using System;
namespace Clinet
{
public class ClientNode
{
/// <summary>
/// 节点名称
/// </summary>
public string Name { set; get; }
/// <summary>
/// 标记,用于包装料仓
/// </summary>
public string Mark { set; get; }
/// <summary>
/// 当前架子的RFID
/// </summary>
public string RFID { set; get; }
/// <summary>
/// 动作
/// </summary>
public ClientAction Action { set; get; }
/// <summary>
/// 优先级
/// </summary>
public ClientLevel Level { set; get; }
public ClientNode()
{
}
public ClientNode(string name, string mark, string rfid, ClientAction action, ClientLevel level)
{
Name = name;
Mark = mark;
RFID = rfid;
Action = action;
Level = level;
}
/// <summary>
/// 所有属性的文本形式
/// </summary>
/// <returns></returns>
public string ToText()
{
System.Reflection.PropertyInfo[] info = typeof(ClientNode).GetProperties();
string[] arr = new string[info.Length];
for (int i = 0; i < info.Length; i++)
arr[i] = string.Format("\"{0}\":\"{1}\"", info[i].Name, info[i].GetValue(this));
return string.Join(",", arr);
//string s = string.Format("Name={0}, Action={1}, Level={2}, Mark={3}, RFID={4}", Name, Action, Level, Mark, RFID);
//return s;
}
public ClientNode ToCopy()
{
ClientNode node = new ClientNode(Name, Mark, RFID, Action, Level);
return node;
}
}
}
\ No newline at end of file
......@@ -31,8 +31,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
......@@ -43,7 +48,13 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AgvClient.cs" />
<Compile Include="ClientAction.cs" />
<Compile Include="ClientLevel.cs" />
<Compile Include="ClientNode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.12" targetFramework="net46" />
</packages>
\ No newline at end of file
using System;
namespace Model
{
public class ChargingPile
{
/// <summary>
/// 充电桩名称
/// </summary>
public string Name { private set; get; }
/// <summary>
/// 当前使用者
/// </summary>
public string Employ { set; get; }
/// <summary>
/// 可以使用的小车
/// </summary>
public string[] User { set; get; }
public int Battery { set; get; }
public ChargingPile(string name)
{
Name = name;
Employ = "";
User = null;
Battery = 0;
}
}
}
......@@ -5,9 +5,11 @@ namespace Model
{
public static class Common
{
public static LogOut log;
public static List<AgvInfo> agvInfos;
public static bool fleetSend;
public static List<ClientNode> nodeInfos;
public static List<ChargingPile> chargingPile;
public const string MISSION_CHARGE = "AutoCharge";
public const string MISSION_STANDBY = "MoveStandby";
......@@ -15,5 +17,9 @@ namespace Model
public const string MISSION_PASS_DOOR_4D = "PassDoorInto4D";
public const string MISSION_PASS_DOOR_4C = "PassDoorInto4C";
public static readonly string PATH_AGV_NAME = Environment.CurrentDirectory + "\\Config\\AgvName.csv";
public static readonly string PATH_AGV_MISSION = Environment.CurrentDirectory + "\\Config\\AgvMission.csv";
public static readonly string PATH_CHARGING_PILE = Environment.CurrentDirectory + "\\Config\\ChargingPile.txt";
}
}
......@@ -48,8 +48,8 @@ namespace Model
{
_msg = value;
string s = string.Format("{0} (step={1})", _msg, _step.ToString());
//LogOut.Info(s);
LogOut.UIShow(s);
//Common.log.Info(s);
Common.log.UIShow(s);
}
}
......
......@@ -2,18 +2,17 @@
namespace Model
{
public static class LogOut
public class LogOut
{
private static log4net.ILog LOG;
public static System.Windows.Forms.TextBox LogBox { set; get; }
private readonly log4net.ILog log;
public System.Windows.Forms.TextBox LogBox { set; get; }
public static void Init(string name)
public LogOut(string name)
{
LOG = log4net.LogManager.GetLogger(name);
log = log4net.LogManager.GetLogger(name);
}
public static void UIShow(string s)
public void UIShow(string s)
{
if (LogBox == null) return;
string time = string.Format("[{0:HH:mm:ss}] ", DateTime.Now);
......@@ -21,29 +20,29 @@ namespace Model
LogBox.ScrollToCaret();
}
public static void Error(string s, Exception ex)
public void Error(string s, Exception ex)
{
LOG.Error(s, ex);
log.Error(s, ex);
}
public static void Debug(string s)
public void Debug(string s)
{
LOG.Debug(s);
log.Debug(s);
}
public static void Info(string s)
public void Info(string s)
{
LOG.Info(s);
log.Info(s);
}
public static void Fatal(string s, Exception ex)
public void Fatal(string s, Exception ex)
{
LOG.Fatal(s, ex);
log.Fatal(s, ex);
}
public static void Warn(string s)
public void Warn(string s)
{
LOG.Warn(s);
log.Warn(s);
}
......
......@@ -56,6 +56,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AgvInfo.cs" />
<Compile Include="ChargingPile.cs" />
<Compile Include="Client.cs" />
<Compile Include="IJob.cs" />
<Compile Include="JobStep.cs" />
......
......@@ -20,7 +20,7 @@ namespace AGVControl
private void FrmMain_Load(object sender, EventArgs e)
{
LogOut.LogBox = TxtLog;
Common.log.LogBox = TxtLog;
}
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
namespace AGVControl
{
......@@ -20,22 +19,44 @@ namespace AGVControl
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Model.LogOut.Init("AGVControl_SMD");
Model.LogOut.Info("=====程序开始=====");
Common.log = new LogOut("AGVControl_SMD");
Common.log.Info("=====程序开始=====");
ReadChargingPile();
Application.Run(new FrmMain());
Model.LogOut.Info("=====程序结束=====\r\n");
Common.log.Info("=====程序结束=====\r\n");
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Model.LogOut.Error("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject);
Common.log.Error("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject);
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
Model.LogOut.Error("Application_ThreadException", e.Exception);
Common.log.Error("Application_ThreadException", e.Exception);
}
/// <summary>
/// 读取充电桩配置
/// </summary>
private static void ReadChargingPile()
{
Common.chargingPile = new List<ChargingPile>();
string[] lines = System.IO.File.ReadAllLines(Common.PATH_CHARGING_PILE, System.Text.Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].StartsWith("//")) continue;
string[] str = lines[i].Split(',');
if (str.Length <= 1) continue;
ChargingPile pile = new ChargingPile(str[0]) { User = new string[str.Length - 1] };
Array.Copy(str, 1, pile.User, 0, pile.User.Length);
Common.chargingPile.Add(pile);
}
Common.log.Info("读取配置文件 " + Common.PATH_CHARGING_PILE);
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!