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;
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!