Commit 96725a1a LN

1

1 个父辈 e371218f
......@@ -39,7 +39,8 @@
<Reference Include="Asa.IOModule.AIOBOX">
<HintPath>..\..\dll\Asa.IOModule.AIOBOX.dll</HintPath>
</Reference>
<Reference Include="Client">
<Reference Include="Client, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\dll\Client.dll</HintPath>
</Reference>
<Reference Include="CodeLibrary">
......
......@@ -276,6 +276,15 @@ namespace OnlineStore.DeviceLibrary
ol_noshelfWatch.Stop();
IOManager.CIOMove(IO_Type.OutL_InStopDown, IO_VALUE.LOW);
}
//如果入口无料架即可进入
if (IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW))
{
AgvClient.NeedEnter(Config.InL_AgvName, "");
}else
{
AgvClient.ConnotEnter(Config.InL_AgvName, "");
}
}
private DateTime il_lastCallAgvTime = DateTime.Now;
private Stopwatch il_outstopCheckWarch = new Stopwatch();
......@@ -295,8 +304,8 @@ namespace OnlineStore.DeviceLibrary
il_lastCallAgvTime = DateTime.Now;
//StopIOMove(IO_Type.InL_OutStopDown, StopDownMS);
LogUtil.info(" 入库线体出口有料架,呼叫agv小车[" + Config.InL_AgvName + "] ");
AgvClient.NeedLeave(Config.InL_AgvName);
LogUtil.info(" 入库线体出口有料架"+ LastOutShelfId + ",呼叫agv小车[" + Config.InL_AgvName + "] [NeedLeave] ");
AgvClient.NeedLeave(Config.InL_AgvName,LastOutShelfId);
}
}
else if (span.TotalMilliseconds > StopDownMS)
......
......@@ -125,7 +125,8 @@ namespace OnlineStore.DeviceLibrary
public string GetRunInfo()
{
return "进料流水线:入口处料架 ["+LastInShelfId+"] 出口处料架 ["+LastOutShelfId+"]";
return "进料入口料架: "+LastInShelfId+" 进料出口料架: "+LastOutShelfId+"\r\n"+
"进料出口"+Config.InL_AgvName+":"+AgvClient.GetAction(Config.InL_AgvName)+" 出料进口" + Config.OutL_AgvName + ":"+ AgvClient.GetAction(Config.OutL_AgvName) + "";
}
#endregion
}
......

using Asa;
using Asa.RFID;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AgvClient
{
private static string ServerIp = ConfigAppSettings.GetValue(Setting_Init.AgvServerIp);
private static Asa.Client agvClient;
public static Dictionary<string, string> actionMap = new Dictionary<string, string>();
public static List<string> NodeList = new List<string>();
private static bool isInit = false;
public static void Init()
{
try
{
if (!isInit)
{
isInit = true;
agvClient = new Asa.Client(ServerIp);
agvClient.Log += AgvClient_Log;
agvClient.Arrive += AgvClient_Arrive;
agvClient.CanEnter += AgvClient_CanEnter;
agvClient.Ready += AgvClient_Ready;
}
lastNeedLeave = "";
lastNeedEnter = "";
actionMap = new Dictionary<string, string>();
foreach (string key in NodeList)
{
actionMap.Add(key, AGVAction.None);
}
agvClient.Connect(NodeList.ToArray());
}
catch (Exception ex)
{
LogUtil.error("初始化agvClient " + ServerIp + " 出错:", ex);
}
}
private static void AgvClient_Ready(string id, byte[] content)
{
UpdateAction(id, AGVAction.Ready);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + data.ToData() + "] ");
if (id.Equals(LineManager.Config.OutL_AgvName))
{
// MayEnter("C2");
if (IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW))
{
agvClient.MayEnter(id);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + data.ToData() + "] 调用 MayEnter ");
}
}
else if (id.Equals(LineManager.Config.InL_AgvName))
{
if (IOManager.IOValue(IO_Type.InL_OutStopCheck).Equals(IO_VALUE.HIGH))
{
LineManager.VMILine.StopIOMove(IO_Type.InL_OutStopDown);
agvClient.MayLeave(id);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + data.ToData() + "] ,下降 InL_OutStopDown 600ms,调用 MayLeave ");
}
}
}
private static void AgvClient_CanEnter(string id, byte[] content)
{
UpdateAction(id, AGVAction.CanEnter);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_CanEnter [" + id + "] [" + data.ToData() + "] ");
if (id.Equals(LineManager.Config.OutL_AgvName))
{
bool result = IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW);
if (IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW))
{
agvClient.IsEnter(id);
}
}
else if (id.Equals(LineManager.Config.InL_AgvName))
{
}
}
private static void AgvClient_Arrive(string id, byte[] content)
{
UpdateAction(id, AGVAction.Arrive);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Arrive [" + id + "] [" + data.ToData() + "] ");
}
public static bool ISConnected()
{
if (agvClient == null)
{
return false;
}
return agvClient.IsConn;
}
public static void SendRFID(string NodeName, string rfid)
{
agvClient.SendRFID(NodeName, rfid);
}
private static string lastNeedEnter = "";
public static void NeedEnter(string NodeName, string shelfID, bool NeedClearLast = false)
{
if (NeedClearLast)
{
lastNeedEnter = "";
}
if (lastNeedEnter.Equals(NodeName + shelfID))
{
//return;
}
bool result = agvClient.NeedEnter(NodeName);
if (result)
{
lastNeedEnter = NodeName + shelfID;
LogUtil.info(" agvClient 料架需要进入:NeedEnter[" + NodeName + shelfID + "],呼叫成功");
}
else
{
LogUtil.info(" agvClient 料架需要进入:NeedEnter[" + NodeName + shelfID + "],呼叫失败,等待重新呼叫");
}
}
private static string lastNeedLeave = "";
public static void NeedLeave(string NodeName, string shelfID, bool NeedClearLast = false)
{
if (NeedClearLast)
{
lastNeedLeave = "";
}
if (lastNeedLeave.Equals(NodeName + shelfID))
{
// return;
}
bool result = agvClient.NeedLeave(NodeName);
if (result)
{
lastNeedLeave = NodeName + shelfID;
LogUtil.info(" agvClient 料架需要离开:NeedLeave[" + NodeName + shelfID + "],呼叫成功");
}
else
{
LogUtil.info(" agvClient 料架需要离开:NeedLeave[" + NodeName + shelfID + "],呼叫失败,等待重新呼叫");
}
}
public static void MayEnter(string NodeName)
{
agvClient.MayEnter(NodeName);
}
public static void FinishEnter(string NodeName)
{
agvClient.FinishEnter(NodeName);
}
public static void MayLeave(string NodeName)
{
agvClient.MayLeave(NodeName);
}
public static void IsEnter(string NodeName, bool result)
{
if (result)
{
agvClient.IsEnter(NodeName);
}
}
private static void AgvClient_Log(string s)
{
try
{
bool isLog = ConfigAppSettings.GetIntValue(Setting_Init.Agv_Log_Open).Equals(1);
if (isLog)
{
LogUtil.info(" AGV " + ServerIp + " Log : " + s);
}
}
catch (Exception ex)
{
LogUtil.error("AgvClient_Log 出错:" + ex.ToString());
}
}
public static string GetAction(string NodeName)
{
if (actionMap.ContainsKey(NodeName))
{
return actionMap[NodeName];
}
return AGVAction.None;
}
public static void UpdateAction(string name, string action)
{
if (actionMap.ContainsKey(name))
{
actionMap[name] = action;
}
else
{
actionMap.Add(name, action);
}
}
public static void Dispose()
{
try
{
lastNeedLeave = "";
lastNeedEnter = "";
if (agvClient != null)
{
agvClient.Close();
}
}
catch (Exception ex)
{
LogUtil.error("agvClient.Close " + ServerIp + " 出错:", ex);
}
}
}
public class AGVAction
{
public static string None = "None";
public static string Arrive = "Arrive";
public static string CanEnter = "CanEnter";
public static string GetRFID = "GetRFID";
public static string Ready = "Ready";
}
}
......@@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
......@@ -14,8 +15,8 @@ namespace OnlineStore.DeviceLibrary
public class AgvClient
{
private static string ServerIp = ConfigAppSettings.GetValue(Setting_Init.AgvServerIp);
private static Asa.Client agvClient;
public static Dictionary<string, string> actionMap = new Dictionary<string, string>();
private static Asa.Client2 agvClient;
public static Dictionary<string, Asa.ClientAction> actionMap = new Dictionary<string, Asa.ClientAction>();
public static List<string> NodeList = new List<string>();
private static bool isInit = false;
public static void Init()
......@@ -25,19 +26,24 @@ namespace OnlineStore.DeviceLibrary
if (!isInit)
{
isInit = true;
agvClient = new Asa.Client(ServerIp);
agvClient = new Asa.Client2(ServerIp);
agvClient.Log += AgvClient_Log;
agvClient.Arrive += AgvClient_Arrive;
agvClient.CanEnter += AgvClient_CanEnter;
// agvClient.CanEnter += AgvClient_CanEnter;
agvClient.Ready += AgvClient_Ready;
agvClient.GetRFID += AgvClient_GetRFID;
}
actionMap = new Dictionary<string, string>();
actionMap = new Dictionary<string, Asa.ClientAction>();
foreach (string key in NodeList)
{
actionMap.Add(key, AGVAction.None);
actionMap.Add(key, Asa.ClientAction.None);
}
agvClient.Connect(NodeList.ToArray());
agvClient.Connect();
foreach (string str in NodeList)
{
SetStatus(str);
}
}
catch (Exception ex)
......@@ -46,20 +52,41 @@ namespace OnlineStore.DeviceLibrary
}
}
private static void AgvClient_GetRFID(string name, byte[] content)
{
}
public static void SetStatus(string id,string shelfId="",ClientAction action=ClientAction.None,ClientLevel level=ClientLevel.Low)
{
agvClient.SetStatus(id, shelfId, action, level);
UpdateAction(id, action);
}
private static void AgvClient_Ready(string id, byte[] content)
{
UpdateAction(id, AGVAction.Ready);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + data.ToData() + "] ");
UpdateAction(id, Asa.ClientAction.Ready);
if (id.Equals(LineManager.Config.OutL_AgvName))
{
// MayEnter("C2");
if (IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW))
{
agvClient.MayEnter(id);
SetStatus(id, "", ClientAction.MayEnter);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + data.ToData() + "] 调用 MayEnter ");
Task.Factory.StartNew(delegate
{
//两秒后改为离开状态
Thread.Sleep(5000);
SetStatus(id, "", ClientAction.FinishEnter);
Thread.Sleep(2000);
SetStatus(id, "", ClientAction.None);
});
}
}
......@@ -68,42 +95,60 @@ namespace OnlineStore.DeviceLibrary
if (IOManager.IOValue(IO_Type.InL_OutStopCheck).Equals(IO_VALUE.HIGH))
{
LineManager.VMILine.StopIOMove(IO_Type.InL_OutStopDown);
agvClient.MayLeave(id);
//agvClient.MayLeave(id);
SetStatus(id, "", ClientAction.MayLeave);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + data.ToData() + "] ,下降 InL_OutStopDown 600ms,调用 MayLeave ");
Task.Factory.StartNew(delegate
{
//两秒后改为离开状态
Thread.Sleep(5000);
SetStatus(id, "", ClientAction.FinishEnter);
Thread.Sleep(2000);
SetStatus(id, "", ClientAction.None);
});
}
}
}
private static void AgvClient_Arrive(string id, byte[] content)
{
UpdateAction(id, Asa.ClientAction.Arrive);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Arrive [" + id + "] [" + data.ToData() + "] ");
}
private static void AgvClient_CanEnter(string id, byte[] content)
public static bool ConnotEnter(string id,string shelfId)
{
UpdateAction(id, AGVAction.CanEnter);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_CanEnter [" + id + "] [" + data.ToData() + "] ");
if (id.Equals(LineManager.Config.OutL_AgvName))
ClientAction currA = GetAction(id);
if (currA.Equals(ClientAction.None) || currA.Equals(ClientAction.FinishLeave) || currA.Equals(ClientAction.FinishEnter))
{
bool result = IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW);
if (IOManager.IOValue(IO_Type.OutL_InCheck).Equals(IO_VALUE.LOW))
{
agvClient.IsEnter(id);
}
SetStatus(id, shelfId, ClientAction.None);
return true;
}
else if (id.Equals(LineManager.Config.InL_AgvName))
return false;
}
public static bool NeedEnter(string id, string shelfId)
{
ClientAction currA = GetAction(id);
if (currA.Equals(ClientAction.None) || currA.Equals(ClientAction.FinishLeave) || currA.Equals(ClientAction.FinishEnter))
{
SetStatus(id, shelfId, ClientAction.NeedEnter);
return true;
}
return false;
}
private static void AgvClient_Arrive(string id, byte[] content)
public static bool NeedLeave(string id, string shelfId)
{
UpdateAction(id, AGVAction.Arrive);
RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Arrive [" + id + "] [" + data.ToData() + "] ");
ClientAction currA = GetAction(id);
if (currA.Equals(ClientAction.None) || currA.Equals(ClientAction.FinishLeave) || currA.Equals(ClientAction.FinishEnter))
{
SetStatus(id, shelfId, ClientAction.NeedLeave);
return true;
}
return false;
}
public static bool ISConnected()
{
if (agvClient == null)
......@@ -116,36 +161,7 @@ namespace OnlineStore.DeviceLibrary
{
agvClient.SendRFID(NodeName, rfid);
}
public static void NeedEnter(string NodeName)
{
agvClient.NeedEnter(NodeName);
}
public static void NeedLeave(string NodeName)
{
agvClient.NeedLeave(NodeName);
}
public static void MayEnter(string NodeName)
{
agvClient.MayEnter(NodeName);
}
public static void FinishEnter(string NodeName)
{
agvClient.FinishEnter(NodeName);
}
public static void MayLeave(string NodeName)
{
agvClient.MayLeave(NodeName);
}
public static void IsEnter(string NodeName, bool result)
{
if (result)
{
agvClient.IsEnter(NodeName);
}
}
}
private static void AgvClient_Log(string s)
{
try
......@@ -162,15 +178,15 @@ namespace OnlineStore.DeviceLibrary
}
}
public static string GetAction(string NodeName)
public static Asa.ClientAction GetAction(string NodeName)
{
if (actionMap.ContainsKey(NodeName))
{
return actionMap[NodeName];
}
return AGVAction.None;
return Asa.ClientAction.None;
}
public static void UpdateAction(string name, string action)
public static void UpdateAction(string name, Asa.ClientAction action)
{
if (actionMap.ContainsKey(name))
{
......@@ -184,7 +200,7 @@ namespace OnlineStore.DeviceLibrary
public static void Dispose()
{
try
{
{
if (agvClient != null)
{
agvClient.Close();
......@@ -195,13 +211,5 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error("agvClient.Close " + ServerIp + " 出错:", ex);
}
}
}
public class AGVAction
{
public static string None = "None";
public static string Arrive = "Arrive";
public static string CanEnter = "CanEnter";
public static string GetRFID = "GetRFID";
public static string Ready = "Ready";
}
}
}
......@@ -54,10 +54,10 @@
<level value="Error" />
<appender-ref ref="TheRFID" />
</logger>
<!-- <root> -->
<!-- <level value="Info" /> -->
<!-- <appender-ref ref="RollingLogFileAppender" /> -->
<!-- </root> -->
<root>
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
......
......@@ -60,12 +60,12 @@
this.btnInLineRun = new System.Windows.Forms.Button();
this.btnOutL = new System.Windows.Forms.Button();
this.groupBox5 = new System.Windows.Forms.GroupBox();
this.txtShelfId = new System.Windows.Forms.TextBox();
this.txtname = new System.Windows.Forms.TextBox();
this.btnNeedEntry = new System.Windows.Forms.Button();
this.btnNeedLeave = new System.Windows.Forms.Button();
this.btnDis = new System.Windows.Forms.Button();
this.btnInit = new System.Windows.Forms.Button();
this.txtShelfId = new System.Windows.Forms.TextBox();
this.groupBox3.SuspendLayout();
this.panel1.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
......@@ -139,15 +139,15 @@
this.panel1.Controls.Add(this.chbDebug);
this.panel1.Controls.Add(this.btnVmiStop);
this.panel1.Controls.Add(this.chbAuto);
this.panel1.Location = new System.Drawing.Point(5, 18);
this.panel1.Location = new System.Drawing.Point(5, 15);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1121, 45);
this.panel1.Size = new System.Drawing.Size(1121, 48);
this.panel1.TabIndex = 273;
//
// lblInfo
//
this.lblInfo.AutoSize = true;
this.lblInfo.Location = new System.Drawing.Point(274, 14);
this.lblInfo.Location = new System.Drawing.Point(277, 5);
this.lblInfo.Name = "lblInfo";
this.lblInfo.Size = new System.Drawing.Size(56, 17);
this.lblInfo.TabIndex = 273;
......@@ -502,6 +502,16 @@
this.groupBox5.TabStop = false;
this.groupBox5.Text = "AGV调度通信";
//
// txtShelfId
//
this.txtShelfId.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtShelfId.Location = new System.Drawing.Point(354, 31);
this.txtShelfId.MaxLength = 4;
this.txtShelfId.Name = "txtShelfId";
this.txtShelfId.Size = new System.Drawing.Size(53, 26);
this.txtShelfId.TabIndex = 6;
this.txtShelfId.Text = "000";
//
// txtname
//
this.txtname.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
......@@ -556,16 +566,6 @@
this.btnInit.UseVisualStyleBackColor = true;
this.btnInit.Click += new System.EventHandler(this.btnInit_Click);
//
// txtShelfId
//
this.txtShelfId.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtShelfId.Location = new System.Drawing.Point(354, 31);
this.txtShelfId.MaxLength = 4;
this.txtShelfId.Name = "txtShelfId";
this.txtShelfId.Size = new System.Drawing.Size(53, 26);
this.txtShelfId.TabIndex = 6;
this.txtShelfId.Text = "000";
//
// FrmVMIClient
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
......
......@@ -367,13 +367,12 @@ namespace OnlineStore.VMILineClient
string agvName = "C2";
private void btnNeedLeave_Click(object sender, EventArgs e)
{
AgvClient.NeedLeave(txtname.Text, txtShelfId.Text);
AgvClient.SetStatus(txtname.Text, txtShelfId.Text,Asa.ClientAction.NeedLeave);
}
private void btnNeedEntry_Click(object sender, EventArgs e)
{
AgvClient.NeedEnter(txtname.Text);
{
AgvClient.SetStatus(txtname.Text, txtShelfId.Text,Asa.ClientAction.NeedEnter);
}
private void btnInit_Click(object sender, EventArgs e)
......
......@@ -53,8 +53,9 @@
<ApplicationIcon>DfIcon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="halcondotnet">
<HintPath>..\..\dll\halcondotnet.dll</HintPath>
<Reference Include="Client, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\dll\Client.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\dll\log4net.dll</HintPath>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!