Commit b8514908 张东亮

lineplace

1 个父辈 a29760e4
此文件类型无法预览
......@@ -51,7 +51,7 @@ namespace BLL
_server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_server.Bind(localEP);
_server.Listen(100);
Common.log.Info("Server Start");
Common.LogInfo("Server Start");
_loop = true;
_client = new List<Client>();
......@@ -79,7 +79,7 @@ namespace BLL
_server.Close();
_client = null;
Thread.Sleep(50);
Common.log.Info("Server Stop");
Common.LogInfo("Server Stop");
}
public bool ReadyEnter(string nodeName, string rfid = "")
......@@ -87,7 +87,7 @@ namespace BLL
int idx = FindClient(nodeName);
if (idx == -1)
{
Common.log.Info("ReadyEnter 没有找到" + nodeName);
Common.LogInfo("ReadyEnter 没有找到" + nodeName);
return false;
}
else
......@@ -103,7 +103,7 @@ namespace BLL
int idx = FindClient(nodeName);
if (idx == -1)
{
Common.log.Info("ReadyLeave 没有找到" + nodeName);
Common.LogInfo("ReadyLeave 没有找到" + nodeName);
return false;
}
else
......@@ -156,12 +156,12 @@ namespace BLL
_client.Add(client);
listen.Start(_client.Count - 1);
Common.log.Info(string.Format("[{0}] 已连接", client.IP));
Common.LogInfo(string.Format("[{0}] 已连接", client.IP));
}
catch (SocketException)
{
//关闭连接,退出阻塞Accept
Common.log.Info("服务端关闭连接,退出阻塞Accept");
Common.LogInfo("服务端关闭连接,退出阻塞Accept");
}
catch (Exception ex)
{
......@@ -197,7 +197,7 @@ namespace BLL
ClientNode node = Decode(buff);
if (node == null)
{
Common.log.Info("解码失败:" + HexBuff(buff));
Common.LogInfo("解码失败:" + HexBuff(buff));
}
else
{
......@@ -213,7 +213,7 @@ namespace BLL
if (time > 5000)
{
Offline(client);
Common.log.Info("[" + client.IP + "] 超过5s没有收到数据,关闭连接");
Common.LogInfo("[" + client.IP + "] 超过5s没有收到数据,关闭连接");
}
}
}
......@@ -273,7 +273,7 @@ namespace BLL
int idx = Common.nodeInfo.FindIndex(s => s.Name == node.Name);
if (idx == -1)
{
Common.log.Info("UpdateNode " + node.Name + " 不存在");
Common.LogInfo("UpdateNode " + node.Name + " 不存在");
return;
}
......@@ -288,7 +288,7 @@ namespace BLL
{
Common.nodeInfo[idx].Action = node.Action;
Common.nodeInfo[idx].RFID = node.RFID;
Common.log.Info(node.Name + "更新 " + node.ToText());
Common.LogInfo(node.Name + "更新 " + node.ToText());
NodeChanged?.Invoke(idx);
}
}
......@@ -363,7 +363,7 @@ namespace BLL
if (!_client[idx].IsConn)
{
Common.log.Info(ip + " 没有连接");
Common.LogInfo(ip + " 没有连接");
return false;
}
......
......@@ -20,7 +20,7 @@ namespace AGVControl
/// </summary>
public static List<Agv_Info> agvInfo;
public static List<string> linePlace;
public static System.Windows.Forms.TextBox logTextBox;
public static BLL.AgvServer server;
public static BLL.Control control;
......@@ -33,42 +33,57 @@ namespace AGVControl
public static Dictionary<string, string> agvProductionLine;
public static System.Configuration.Configuration appConfig;
public static readonly string CONFIG_PATH = AppDomain.CurrentDomain.BaseDirectory + "Config\\";
public static int logCnt = 0;
public static void LogInfo(string text)
{
if (logTextBox.InvokeRequired)
{
logTextBox.Invoke(new Action(() => LogInfo(text)));
return;
}
logCnt++;
if (logCnt > 200)
logTextBox.Text = "";
logTextBox.Text += string.Format("[{0}] {1}\r\n",DateTime.Now.ToString("HH:mm:ss") ,text);
}
public static void ReadLinePlace()
{
if (!System.IO.File.Exists(CONFIG_PATH + "LinePlace.txt"))
return;
string[] s = System.IO.File.ReadAllLines(CONFIG_PATH + "LinePlace.txt");
linePlace = new List<string>();
linePlace.AddRange(s);
}
//public static void AddLinePlace(string nodeName)
//{
// int idx = Common.nodeInfo.FindIndex(s => s.Name == nodeName);
// if(idx>-1)
// {
// if(Common.linePlace.ContainsKey(nodeName))
// {
// log.Info("AddLinePlace 节点" + nodeName + "已存在任务队列,无需重复添加");
// return;
// }
// Common.linePlace.Add(nodeName,Common.nodeInfo[idx].Level);
// Common.appConfig.AppSettings.Settings["nodesLevel"].Value = string.Join(",",linePlace.Values);
// Common.appConfig.AppSettings.Settings["nodesMission"].Value =string.Join(",",linePlace.Keys);
// Common.appConfig.Save();
// }
// else
// {
// log.Error("AddLinePlace 失败 节点"+ nodeName+"不存在");
// }
//}
//public static void RemoveLinePlace(string nodeName)
//{
// Common.linePlace.Remove(nodeName);
// Common.appConfig.AppSettings.Settings["nodesLevel"].Value = string.Join(",", linePlace.Values);
// Common.appConfig.AppSettings.Settings["nodesMission"].Value = string.Join(",", linePlace.Keys);
// Common.appConfig.Save();
//}
public static bool AddLinePlace(string nodeName)
{
int idx = Common.nodeInfo.FindIndex(s => s.Name == nodeName);
if (idx > -1)
{
if (Common.linePlace.Contains(nodeName))
{
LogInfo("AddLinePlace 节点" + nodeName + "已存在任务队列,无需重复添加");
return false;
}
Common.linePlace.Add(nodeName);
System.IO.File.WriteAllLines(CONFIG_PATH + "LinePlace.txt", linePlace);
return true;
}
else
{
log.Error("AddLinePlace 失败 节点" + nodeName + "不存在");
return false;
}
}
public static void RemoveLinePlace(string nodeName)
{
Common.linePlace.Remove(nodeName);
System.IO.File.WriteAllLines(CONFIG_PATH + "LinePlace.txt", linePlace);
}
public static void CheckAGVMissionState()
{
......@@ -79,7 +94,7 @@ namespace AGVControl
if (rtn)
{
agv.GetPlace(regValue);
Common.log.Info(string.Format("软件开启:{0} Get_Register PLC{1}={2} Place={3} PlaceState={4}", agv.Name, 20, regValue, agv.Place, agv.PlaceState));
Common.LogInfo(string.Format("软件开启:{0} Get_Register PLC{1}={2} Place={3} PlaceState={4}", agv.Name, 20, regValue, agv.Place, agv.PlaceState));
if (!agv.Place.Equals(""))
{
int idx = nodeInfo.FindIndex(s => s.Name == agv.Place);
......
......@@ -470,7 +470,7 @@ namespace BLL
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(ip, pattern);
if (!rtn)
{
Common.log.Info("非法的IP地址" + ip);
Common.LogInfo("非法的IP地址" + ip);
return false;
}
......@@ -482,7 +482,7 @@ namespace BLL
ping.Dispose();
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
Common.log.Info("Ping " + ip + " 请求没有响应");
Common.LogInfo("Ping " + ip + " 请求没有响应");
return false;
}
return true;
......
......@@ -3,6 +3,7 @@ using System.ServiceModel.Web;
using System.Runtime.Serialization;
using System.ServiceModel.Activation;
using System;
using AGVControl;
namespace BLL
{
......@@ -39,25 +40,32 @@ namespace BLL
public Result CreateEmptyRecycleTask(string line)
{
AGVControl.Common.log.Info("WebService Request emptyStation=" + line);
AGVControl.Common.LogInfo("WebService Request emptyStation=" + line);
Result res;
if (AGVControl.Common.agvProductionLine.TryGetValue(line, out string value))
{
res = new Result() { Succeed = "true", ResultData = "", ErrorMessage = "" };
AGVControl.Common.log.Info("WebService Response OK");
AGVControl.Common.LogInfo("WebService Response OK");
//加到任务
int idx = AGVControl.Common.nodeInfo.FindIndex(s => s.Name == value);
if (idx > -1)
AGVControl.Common.linePlace.Add(value);
//int idx = AGVControl.Common.nodeInfo.FindIndex(s => s.Name == value);
//if (idx > -1)
// AGVControl.Common.linePlace.Add(value);
//else
// AGVControl.Common.log.Error("CreateEmptyRecycleTask " + value + "不存在");
if(!Common.AddLinePlace(value))
AGVControl.Common.log.Error("CreateEmptyRecycleTask 节点【" + value + "】不存在");
else
AGVControl.Common.log.Error("CreateEmptyRecycleTask " + value + "不存在");
{
AGVControl.Common.LogInfo("CreateEmptyRecycleTask 节点【" + value + "】收到出空料架任务");
}
//System.IO.File.WriteAllLines(Common.CONFIG_PATH + "LinePlace.txt", Common.linePlace);
}
else
{
res = new Result() { Succeed = "false", ResultData = "", ErrorMessage = "Not find " + line };
AGVControl.Common.log.Info("WebService Response false");
AGVControl.Common.LogInfo("WebService Response false");
}
return res;
......@@ -75,7 +83,7 @@ namespace BLL
ClsWebService service = new ClsWebService();
_serviceHost = new WebServiceHost(service, new Uri(url));
_serviceHost.Open();
AGVControl.Common.log.Info("Web服务已开启");
AGVControl.Common.LogInfo("Web服务已开启");
}
catch (Exception ex)
{
......@@ -88,7 +96,7 @@ namespace BLL
try
{
_serviceHost.Close();
AGVControl.Common.log.Info("Web服务已关闭");
AGVControl.Common.LogInfo("Web服务已关闭");
}
catch (Exception ex)
{
......
......@@ -19,6 +19,7 @@ namespace AGVControl
public FrmMain()
{
InitializeComponent();
Common.logTextBox = TxtLog;
}
private void ShowConfig()
......@@ -37,6 +38,7 @@ namespace AGVControl
{
n = DgvNode.Rows.Add(Common.nodeInfo[i].ToRow());
DgvNode.Rows[n].HeaderCell.Value = (n + 1).ToString();
comboBox1.Items.Add(Common.nodeInfo[i].Name);
if (!Common.nodeInfo[i].Online)
DgvNode.Rows[n].DefaultCellStyle.ForeColor = Color.Red;
}
......@@ -138,7 +140,7 @@ namespace AGVControl
else if (e.ColumnIndex == 9) //清除缓存
{
//清除小车缓存
Common.log.Info(string.Format("手动清除缓存,{0} {1}", Common.agvInfo[e.RowIndex].Name, Common.agvInfo[e.RowIndex].Place));
Common.LogInfo(string.Format("手动清除缓存,{0} {1}", Common.agvInfo[e.RowIndex].Name, Common.agvInfo[e.RowIndex].Place));
string place = Common.agvInfo[e.RowIndex].Place;
Common.agvInfo[e.RowIndex].Place = "";
Common.agvInfo[e.RowIndex].RFID = "";
......@@ -176,7 +178,7 @@ namespace AGVControl
else if (e.ColumnIndex == 7) //清除缓存
{
//清除节点缓存
Common.log.Info(string.Format("手动清除缓存,{0} {1}", Common.nodeInfo[e.RowIndex].AgvName, Common.nodeInfo[e.RowIndex].Name));
Common.LogInfo(string.Format("手动清除缓存,{0} {1}", Common.nodeInfo[e.RowIndex].AgvName, Common.nodeInfo[e.RowIndex].Name));
string name = Common.nodeInfo[e.RowIndex].AgvName;
Common.nodeInfo[e.RowIndex].AgvName = "";
DgvNode.Rows[e.RowIndex].Cells[4].Value = "";
......@@ -237,41 +239,42 @@ namespace AGVControl
private void btnAddlinePlace_Click(object sender, EventArgs e)
{
//if (TxtPlace.Text == "")
//{
// MessageBox.Show("请输入节点名");
// return;
//}
//Common.AddLinePlace(TxtPlace.Text.ToUpper());
//dgvLinePlace.Rows.Clear();
//foreach (var item in Common.linePlace)
//{
// dgvLinePlace.Rows.Add(item.Key, item.Value);
//}
if (comboBox1.SelectedItem == null)
{
MessageBox.Show("请先选择任务节点!");
return;
}
Common.AddLinePlace(comboBox1.SelectedItem.ToString());
Common.LogInfo("手动添加【"+ comboBox1.SelectedItem.ToString() + "】出空料架任务");
dgvLinePlace.Rows.Clear();
foreach (var item in Common.linePlace)
{
dgvLinePlace.Rows.Add(item);
}
}
private void btnDeletelinePlace_Click(object sender, EventArgs e)
{
//if (TxtPlace.Text == "")
//{
// MessageBox.Show("请输入节点名");
// return;
//}
//Common.RemoveLinePlace(TxtPlace.Text.ToUpper());
//dgvLinePlace.Rows.Clear();
//foreach (var item in Common.linePlace)
//{
// dgvLinePlace.Rows.Add(item.Key, item.Value);
//}
if (comboBox1.SelectedItem == null)
{
MessageBox.Show("请先选择任务节点!");
return;
}
Common.RemoveLinePlace(comboBox1.SelectedItem.ToString());
dgvLinePlace.Rows.Clear();
foreach (var item in Common.linePlace)
{
dgvLinePlace.Rows.Add(item);
}
}
private void btnReadlinePlace_Click(object sender, EventArgs e)
{
//dgvLinePlace.Rows.Clear();
//foreach (var item in Common.linePlace)
//{
// dgvLinePlace.Rows.Add(item.Key, item.Value);
//}
dgvLinePlace.Rows.Clear();
foreach (var item in Common.linePlace)
{
dgvLinePlace.Rows.Add(item);
}
}
}
}
......@@ -174,9 +174,6 @@
<metadata name="Column8.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column20.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
......
......@@ -38,9 +38,9 @@ namespace AGVControl
return;
}
}
Common.logTextBox = new TextBox();
Common.log = log4net.LogManager.GetLogger("AgvServer");
Common.log.Info("=====程序开始=====");
Common.LogInfo("=====程序开始=====");
ReadConfig();
Common.ReadLinePlace();
......@@ -59,7 +59,7 @@ namespace AGVControl
Common.control.Stop();
Common.server.Stop();
Common.web.Close();
Common.log.Info("=====程序结束=====\r\n");
Common.LogInfo("=====程序结束=====\r\n");
}
private static void ReadConfig()
......
......@@ -77,7 +77,7 @@ namespace AsaPL
tRecon.Start();
tListen.Start();
tSend.Start();
LOG.Info("Connect");
LogInfo("Connect");
}
/// <summary>
......@@ -93,7 +93,7 @@ namespace AsaPL
_client.Close();
_client = null;
}
LOG.Info("Close");
LogInfo("Close");
}
/// <summary>
......@@ -118,7 +118,7 @@ namespace AsaPL
_node[idx].Action = action;
_node[idx].Level = level;
}
LOG.Info("SetStatus " + _node[idx].ToText());
LogInfo("SetStatus " + _node[idx].ToText());
}
/// <summary>
......@@ -127,7 +127,7 @@ namespace AsaPL
/// <param name="name"></param>
public void MayEnter(string name)
{
LOG.Info(name + " MayEnter");
LogInfo(name + " MayEnter");
ClientNode node = new ClientNode(name, "", ClientAction.MayEnter, ClientLevel.High);
byte[] buff = Encode(node);
bool bln = Send(buff);
......@@ -139,7 +139,7 @@ namespace AsaPL
/// <param name="name"></param>
public void MayLeave(string name)
{
LOG.Info(name + " MayLeave");
LogInfo(name + " MayLeave");
ClientNode node = new ClientNode(name, "", ClientAction.MayLeave, ClientLevel.High);
byte[] buff = Encode(node);
bool bln = Send(buff);
......@@ -151,7 +151,7 @@ namespace AsaPL
/// <param name="name"></param>
public void FinishEnter(string name)
{
LOG.Info(name + " FinishEnter");
LogInfo(name + " FinishEnter");
ClientNode node = new ClientNode(name, "", ClientAction.FinishEnter, ClientLevel.High);
byte[] buff = Encode(node);
bool bln = Send(buff);
......@@ -163,7 +163,7 @@ namespace AsaPL
/// <param name="name"></param>
public void FinishLeave(string name)
{
LOG.Info(name + " FinishLeave");
LogInfo(name + " FinishLeave");
ClientNode node = new ClientNode(name, "", ClientAction.FinishLeave, ClientLevel.High);
byte[] buff = Encode(node);
bool bln = Send(buff);
......@@ -184,11 +184,11 @@ namespace AsaPL
if (IsConn)
{
countRecon = 0;
LOG.Info("Server connection successful");
LogInfo("Server connection successful");
}
else
{
LOG.Info("Server connection failed " + ++countRecon + " times");
LogInfo("Server connection failed " + ++countRecon + " times");
}
}
Thread.Sleep(1000);
......@@ -202,7 +202,7 @@ namespace AsaPL
{
try
{
LOG.Info("Connect " + IP + ":" + PORT);
LogInfo("Connect " + IP + ":" + PORT);
if (CheckIP(IP))
{
_client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
......@@ -212,7 +212,7 @@ namespace AsaPL
_client.Connect(IPAddress.Parse(IP), PORT);
if (!_loop) return;
IsConn = true;
LOG.Info("Connect OK");
LogInfo("Connect OK");
}
}
catch (Exception ex)
......@@ -246,11 +246,11 @@ namespace AsaPL
ClientNode node = Decode(_buffer);
if (node == null)
{
LOG.Info("Command decoding failed: " + HexBuff(_buffer));
LogInfo("Command decoding failed: " + HexBuff(_buffer));
}
else
{
LOG.Info("From server: " + node.ToText());
LogInfo("From server: " + node.ToText());
Resolve(node);
}
}
......@@ -273,12 +273,12 @@ namespace AsaPL
{
if (result.Action == ClientAction.ReadyEnter)
{
LOG.Info("Trigger ReadyEnter Event");
LogInfo("Trigger ReadyEnter Event");
ReadyEnter?.Invoke(result.Name);
}
else if (result.Action == ClientAction.ReadyLeave)
{
LOG.Info("Trigger ReadyLeave Event");
LogInfo("Trigger ReadyLeave Event");
ReadyLeave?.Invoke(result.Name);
}
}
......@@ -324,7 +324,7 @@ namespace AsaPL
{
if (!IsConn)
{
LOG.Info("服务器没有连接");
LogInfo("服务器没有连接");
return false;
}
......@@ -418,7 +418,7 @@ namespace AsaPL
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(ip, pattern);
if (!rtn)
{
LOG.Info("Illegal IP address " + ip);
LogInfo("Illegal IP address " + ip);
return false;
}
......@@ -430,7 +430,7 @@ namespace AsaPL
ping.Dispose();
if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
{
LOG.Info("Ping " + ip + " request timeout");
LogInfo("Ping " + ip + " request timeout");
return false;
}
return true;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!