Commit e0d5952c LN

预扫码增加超时判断

1 个父辈 8a38b111
此文件类型无法预览

using Asa;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AgvClient
{
public static bool CurrCancelState = true ;
private static string ServerIp = ConfigAppSettings.GetValue(Setting_Init.AgvServerIp);
private static Asa.AgvClient 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()
{
try
{
LogUtil.info("开始 Init agvclient");
if (!isInit)
{
isInit = true;
agvClient = new Asa.AgvClient(ServerIp);
agvClient.CancelState = true;
agvClient.Log += AgvClient_Log;
agvClient.Arrive += AgvClient_Arrive;
agvClient.Ready += AgvClient_Ready;
agvClient.CloseDoor += AgvClient_CloseDoor;
}
actionMap = new Dictionary<string, Asa.ClientAction>();
LogUtil.info(" 开始 agvClient.Connect");
agvClient.Connect();
foreach (string str in NodeList)
{
SetStatus(str);
}
}
catch (Exception ex)
{
LogUtil.error("初始化agvClient " + ServerIp + " 出错:", ex);
}
}
public static void SetCancelState(bool isCancel)
{
if (agvClient == null)
{
return;
}
CurrCancelState = isCancel;
agvClient.CancelState = isCancel;
}
public static void SetStatus(string id, string shelfId = "", ClientAction action = ClientAction.None, ClientLevel level = ClientLevel.Low,bool isMust=false)
{
if (!isMust && level.Equals(ClientLevel.Low))
{
if (actionMap.ContainsKey(id))
{
ClientAction currA = actionMap[id]; //相同状态就设置一次
if (currA.Equals(action))
{
return;
}
}
}
string mark = "";
if (shelfId != "")
{
int index = shelfId.IndexOf(',');
if (index > 0)
{
//紧急出料模块,料架离开时,mark=紧急料或者分配料,rfid=料架号
mark = shelfId.Substring(index + 1, shelfId.Length - index - 1);
shelfId = shelfId.Substring(0, index);
}
}
agvClient.SetStatus(id,mark, shelfId, action, level);
UpdateAction(id, action);
}
private static void AgvClient_CloseDoor(string id, string rfid)
{
LogUtil.info("收到 AgvClient_CloseDoor [" + id + "] [" + rfid + "] 更新状态 ");
UpdateAction(id, ClientAction.CloseDoor);
Task.Factory.StartNew(delegate
{
Thread.Sleep(5000);
if (GetAction(id).Equals(ClientAction.CloseDoor))
{
SetStatus(id);
LogUtil.error("收到 AgvClient_CloseDoor [" + id + "] [" + rfid + "] 5秒后,更新状态为None ");
}
});
}
private static void AgvClient_Ready(string id, string rfid)
{
UpdateAction(id, ClientAction.Ready);
// RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Ready [" + id + "] [" + rfid + "] ");
FeedingEquip equip = getFeedEquip(id);
if (equip == null)
{
LogUtil.error("收到 AgvClient_Ready [" + id + "] [" + rfid + "] 未找到对应的设备 ,暂不处理");
return;
}
equip.AgvReady(id, rfid);
}
private static void AgvClient_Arrive(string id, string rfid)
{
UpdateAction(id, ClientAction.Arrive);
// RFIDData data = new RFIDData(content);
LogUtil.info("收到 AgvClient_Arrive [" + id + "] [" + rfid + "] ");
FeedingEquip equip = getFeedEquip(id);
if (equip == null)
{
LogUtil.error("收到 AgvClient_Ready [" + id + "] [" + rfid + "] 未找到对应的设备 ,暂不处理 ");
return;
}
equip.AgvArrive(id, rfid);
}
private static FeedingEquip getFeedEquip(string nodeId)
{
foreach (FeedingEquip feed in LineManager.Line.FeedingEquipMap.Values)
{
if (feed.Config.AgvInName.Equals(nodeId) || feed.Config.AgvOutName.Equals(nodeId))
{
return feed;
}
}
return null;
}
internal static bool ISConnected()
{
if (agvClient == null)
{
return false;
}
return agvClient.IsConn;
}
public static bool SetToNone(string id, string shelfId = "")
{
ClientAction currA = GetAction(id);
if (currA.Equals(ClientAction.None) || currA.Equals(ClientAction.NeedLeave) || currA.Equals(ClientAction.NeedEnter))
{
SetStatus(id, shelfId, ClientAction.None);
return true;
}
return false;
}
public static bool NeedEnter(string id, string shelfId="", ClientLevel level = ClientLevel.Low)
{
ClientAction currA = GetAction(id);
if (currA.Equals(ClientAction.None) || currA.Equals(ClientAction.NeedLeave) || currA.Equals(ClientAction.NeedEnter))
{
SetStatus(id, shelfId, ClientAction.NeedEnter, level);
return true;
}
return false;
}
public static bool NeedLeave(string id, string shelfId="",ClientLevel level=ClientLevel.Low)
{
ClientAction currA = GetAction(id);
if (currA.Equals(ClientAction.None) || currA.Equals(ClientAction.NeedLeave) || currA.Equals(ClientAction.NeedEnter))
{
SetStatus(id, shelfId, ClientAction.NeedLeave, level);
return true;
}
return false;
}
private static bool isLog = ConfigAppSettings.GetIntValue(Setting_Init.Agv_Log_Open).Equals(1);
private static void AgvClient_Log(string s)
{
try
{
if (isLog)
{
LogUtil.info(" AGV " + ServerIp + " Log : " + s);
}
}
catch (Exception ex)
{
LogUtil.error("AgvClient_Log 出错:" + ex.ToString());
}
}
public static Asa.ClientAction GetAction(string NodeName)
{
if (actionMap.ContainsKey(NodeName))
{
return actionMap[NodeName];
}
return Asa.ClientAction.None;
}
public static void UpdateAction(string name, Asa.ClientAction action)
{
if (actionMap.ContainsKey(name))
{
actionMap[name] = action;
}
else
{
actionMap.Add(name, action);
}
}
public static void Dispose()
{
try
{
if (agvClient != null)
{
agvClient.Close();
}
}
catch (Exception ex)
{
LogUtil.error("释放 agvClient " + 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";
//}
}
...@@ -879,10 +879,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -879,10 +879,11 @@ namespace OnlineStore.DeviceLibrary
InLog("料盘移栽" + MoveInfo.SLog + ":提升轴下降到料盘不溢出(" + (currPositon - Config.Height_ChangeValue * 30) + "):" + targetPosition+",速度"+Config.BatchAxis_P4Speed); InLog("料盘移栽" + MoveInfo.SLog + ":提升轴下降到料盘不溢出(" + (currPositon - Config.Height_ChangeValue * 30) + "):" + targetPosition+",速度"+Config.BatchAxis_P4Speed);
BatchAxis.AbsMove(MoveInfo, targetPosition, Config.BatchAxis_P4Speed); BatchAxis.AbsMove(MoveInfo, targetPosition, Config.BatchAxis_P4Speed);
} }
private Task YuScanTask = null;
private void YuScanCode() private void YuScanCode()
{ {
bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1); bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1);
YuScanTask = null;
//TODO 此处需要等待空托盘 //TODO 此处需要等待空托盘
if (MoveInfo.ShelfNoTray.Equals(false) && isScan) if (MoveInfo.ShelfNoTray.Equals(false) && isScan)
{ {
...@@ -892,7 +893,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -892,7 +893,7 @@ namespace OnlineStore.DeviceLibrary
List<string> bijiaoList = new List<string>(LastCodeList); List<string> bijiaoList = new List<string>(LastCodeList);
try try
{ {
Task<List<string>> scanTask = Task.Factory.StartNew(delegate YuScanTask = Task.Factory.StartNew(delegate
{ {
Thread.Sleep(100); Thread.Sleep(100);
NextCodeList = CodeManager.CameraScan(Config.GetCameraList(), Name.Trim()+"预扫码"); NextCodeList = CodeManager.CameraScan(Config.GetCameraList(), Name.Trim()+"预扫码");
...@@ -949,56 +950,64 @@ namespace OnlineStore.DeviceLibrary ...@@ -949,56 +950,64 @@ namespace OnlineStore.DeviceLibrary
{ {
if (CylinderIsOk(IO_Type.SL_MoveCylinder_Take, IO_Type.SL_MoveCylinder_Give)) if (CylinderIsOk(IO_Type.SL_MoveCylinder_Take, IO_Type.SL_MoveCylinder_Give))
{ {
MoveInfo.NextMoveStep(LineMoveStep.FI_18_ScanCode); if (YuScanTask == null || YuScanTask.IsCompleted)
bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1); {
ClearTimeoutAlarm("预扫码结束超时");
MoveInfo.NextMoveStep(LineMoveStep.FI_18_ScanCode);
bool isScan = ConfigAppSettings.GetIntValue(Setting_Init.NeedScanCode).Equals(1);
LastCodeList = new List<string>(); LastCodeList = new List<string>();
ScanCodeTask = null; ScanCodeTask = null;
if (NextCodeList.Count > 0) if (NextCodeList.Count > 0)
{ {
InLog("料盘移栽" + MoveInfo.SLog + ":开始扫码:使用预扫码"); InLog("料盘移栽" + MoveInfo.SLog + ":开始扫码:使用预扫码");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
LastCodeList = new List<string>(NextCodeList); LastCodeList = new List<string>(NextCodeList);
NextCodeList = new List<string>(); NextCodeList = new List<string>();
MoveInfo.NextMoveStep(LineMoveStep.FI_20_CylinderTake); MoveInfo.NextMoveStep(LineMoveStep.FI_20_CylinderTake);
lastcode = CodeManager.ProcessCode(LastCodeList); lastcode = CodeManager.ProcessCode(LastCodeList);
InLog("料盘移栽" + MoveInfo.SLog + ":上料横移取料端"); InLog("料盘移栽" + MoveInfo.SLog + ":上料横移取料端");
CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take); CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
} }
else if (isScan) else if (isScan)
{
InLog("料盘移栽" + MoveInfo.SLog + ":开始扫码");
MoveInfo.OneWaitCanEndStep = true;
MoveInfo.WaitList.Add(WaitResultInfo.WaitFeedScanCode());
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(7000));
try
{ {
ScanCodeTask = Task.Factory.StartNew(delegate InLog("料盘移栽" + MoveInfo.SLog + ":开始扫码");
MoveInfo.OneWaitCanEndStep = true;
MoveInfo.WaitList.Add(WaitResultInfo.WaitFeedScanCode());
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(7000));
try
{ {
LastCodeList = CodeManager.CameraScan(Config.GetCameraList(), Name); ScanCodeTask = Task.Factory.StartNew(delegate
bool hasRightCode = CodeManager.HasRightCode(LastCodeList.ToArray());
if (!hasRightCode)
{ {
LastCodeList = CodeManager.CameraScan(Config.GetCameraList(), Name, false, 3000); LastCodeList = CodeManager.CameraScan(Config.GetCameraList(), Name);
} bool hasRightCode = CodeManager.HasRightCode(LastCodeList.ToArray());
lastcode = CodeManager.ProcessCode(LastCodeList); if (!hasRightCode)
return LastCodeList; {
}); LastCodeList = CodeManager.CameraScan(Config.GetCameraList(), Name, false, 3000);
}
lastcode = CodeManager.ProcessCode(LastCodeList);
return LastCodeList;
});
}
catch (Exception ex)
{
LogUtil.error("" + MoveInfo.SLog + ":扫码出错:", ex);
}
//finally
//{
// MoveInfo.EndStepWait();
//}
} }
catch (Exception ex) else
{ {
LogUtil.error("" + MoveInfo.SLog + ":扫码出错:", ex); InLog("料盘移栽" + MoveInfo.SLog + ":不需要扫码");
} }
//finally
//{
// MoveInfo.EndStepWait();
//}
} }
else else if (MoveInfo.IsTimeOut(60))
{ {
InLog("料盘移栽" + MoveInfo.SLog + ":不需要扫码"); MoveTimeOut(MoveInfo, "预扫码结束超时");
} }
} }
else else
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!