Commit 36387ea6 LN

rfid加重连。阻挡下降优化。

1 个父辈 789d6116
...@@ -169,6 +169,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -169,6 +169,8 @@ namespace OnlineStore.DeviceLibrary
/// </summary> /// </summary>
internal override void StopMove() internal override void StopMove()
{ {
trayCheck2LowWait.Stop();
trayCheckWait.Stop();
//如果正在出库中,需要减去托盘号 //如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore)) if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
...@@ -463,6 +464,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -463,6 +464,8 @@ namespace OnlineStore.DeviceLibrary
#endregion #endregion
#region 托盘检测 #region 托盘检测
private Stopwatch trayCheckWait = new Stopwatch();
private Stopwatch trayCheck2LowWait = new Stopwatch();
private object lockObj = ""; private object lockObj = "";
private void StartCheckFixture() private void StartCheckFixture()
{ {
...@@ -472,28 +475,45 @@ namespace OnlineStore.DeviceLibrary ...@@ -472,28 +475,45 @@ namespace OnlineStore.DeviceLibrary
{ {
if (SecondMoveInfo.MoveType.Equals(LineMoveType.None).Equals(false)) if (SecondMoveInfo.MoveType.Equals(LineMoveType.None).Equals(false))
{ {
LogUtil.error(Name + " StartCheckFixture " + " 不在空闲中,直接返回 " ); LogUtil.error(Name + " StartCheckFixture " + " 不在空闲中,直接返回 ");
return; return;
} }
if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
{ {
SecondMoveInfo.NewMove(LineMoveType.CheckFixture); trayCheck2LowWait.Stop();
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_Stop2Down); if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, true))
CheckLog("托盘阻挡" + SecondMoveInfo.SLog + " 阻挡气缸1-1上升)"); {
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW); SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW)); SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_Stop2Down);
CheckLog("托盘阻挡" + SecondMoveInfo.SLog + " 阻挡气缸1-1上升)");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW));
}
} }
else if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH)) else
{ {
//托盘在第一个阻挡处 bool check2IsOk = TrayManager.checkWatch(trayCheck2LowWait, TrayManager.SwTrayWaitTime, false );
SecondMoveInfo.NewMove(LineMoveType.CheckFixture); if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH))
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down); {
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200)); if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, false ) && check2IsOk)
CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待 StopCylinder_Check1=0"); {
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200); trayCheckWait.Stop();
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH)); trayCheck2LowWait.Stop();
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW)); //托盘在第一个阻挡处
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime)); SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待 StopCylinder_Check1=0");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime));
}
}
else
{
trayCheckWait.Stop();
}
} }
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -154,7 +154,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -154,7 +154,8 @@ namespace OnlineStore.DeviceLibrary
internal override void StopMove() internal override void StopMove()
{ {
trayCheckWait.Stop(); trayCheck2LowWait.Stop();
trayCheckWait.Stop();
MoveInfo.EndMove(); MoveInfo.EndMove();
SecondMoveInfo.EndMove(); SecondMoveInfo.EndMove();
runStatus = LineRunStatus.Runing; runStatus = LineRunStatus.Runing;
......
...@@ -33,7 +33,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -33,7 +33,7 @@ namespace OnlineStore.DeviceLibrary
} }
internal DateTime lastStopDown = DateTime.Now; internal DateTime lastStopDown = DateTime.Now;
private Stopwatch trayCheckWait = new Stopwatch(); private Stopwatch trayCheckWait = new Stopwatch();
private Stopwatch trayCheck2LowWait = new Stopwatch();
private object lockObj = ""; private object lockObj = "";
private void StartCheckFixture() private void StartCheckFixture()
{ {
...@@ -50,7 +50,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -50,7 +50,8 @@ namespace OnlineStore.DeviceLibrary
//int num = TrayManager.GetTrayNum(DeviceID); //int num = TrayManager.GetTrayNum(DeviceID);
if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
{ {
if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, true) && canProcess) trayCheck2LowWait.Stop();
if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, false) && canProcess)
{ {
trayCheckWait.Stop(); trayCheckWait.Stop();
SecondMoveInfo.NewMove(LineMoveType.CheckFixture); SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
...@@ -59,30 +60,34 @@ namespace OnlineStore.DeviceLibrary ...@@ -59,30 +60,34 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW); IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW)); SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW));
} }
} }
else if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH) && (DateTime.Now - lastStopDown).TotalSeconds > 3) else
{ {
if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, true) && canProcess) bool check2Ok = TrayManager.checkWatch(trayCheck2LowWait, TrayManager.SwTrayWaitTime, false);
if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH) && (DateTime.Now - lastStopDown).TotalSeconds > 3)
{
if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, false) && check2Ok && canProcess)
{
trayCheckWait.Stop();
trayCheck2LowWait.Stop();
lastStopDown = DateTime.Now;
//托盘在第一个阻挡处
SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
LogUtil.info(Name + " [" + trayCount + "] 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0");
//CheckLog(" 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0" );
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime));
}
}
else
{ {
lastStopDown = DateTime.Now;
trayCheckWait.Stop(); trayCheckWait.Stop();
//托盘在第一个阻挡处
SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
LogUtil.info(Name + " [" + trayCount + "] 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0");
//CheckLog(" 托盘检测:" + SecondMoveInfo.SLog + "阻挡气缸1-1下降 ,等待 StopCylinder_Check1=0" );
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH, 1200);
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH));
SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
// SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(TrayManager.StopDownWaitTime));
} }
} }
else
{
trayCheckWait.Stop();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -216,7 +216,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -216,7 +216,10 @@ namespace OnlineStore.DeviceLibrary
} }
else if (watch.ElapsedMilliseconds >= targetMs) else if (watch.ElapsedMilliseconds >= targetMs)
{ {
watch.Stop(); if (isStop)
{
watch.Stop();
}
return true; return true;
} }
return false; return false;
......
...@@ -13,7 +13,7 @@ namespace Asa.RFID ...@@ -13,7 +13,7 @@ namespace Asa.RFID
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private System.Threading.Thread tScan; // private System.Threading.Thread tScan;
private bool loop; private bool loop;
private string IP = ""; private string IP = "";
private byte addr; private byte addr;
...@@ -49,7 +49,7 @@ namespace Asa.RFID ...@@ -49,7 +49,7 @@ namespace Asa.RFID
IsConnect = false; IsConnect = false;
try try
{ {
tScan.Abort(); // tScan.Abort();
}catch(Exception ex) }catch(Exception ex)
{ {
LOGGER.Info("Close tScan[" + IP + "] error :" + ex.ToString()); LOGGER.Info("Close tScan[" + IP + "] error :" + ex.ToString());
...@@ -104,8 +104,9 @@ namespace Asa.RFID ...@@ -104,8 +104,9 @@ namespace Asa.RFID
public void FindMode() public void FindMode()
{ {
loop = true; loop = true;
tScan = new System.Threading.Thread(new System.Threading.ThreadStart(Scan)); //tScan = new System.Threading.Thread(new System.Threading.ThreadStart(Scan));
tScan.Start(); //tScan.Start();
Task.Factory.StartNew(Scan);
} }
private void Scan() private void Scan()
...@@ -115,11 +116,23 @@ namespace Asa.RFID ...@@ -115,11 +116,23 @@ namespace Asa.RFID
bool rtn = FindRFID(); bool rtn = FindRFID();
if (rtn) if (rtn)
{ {
ReadRFID(); int result = ReadRFID();
byte[] bb = new byte[] { _buff[0], _buff[1], _buff[2] }; if (result.Equals(0))
string dataStr = byteToStr(bb, bb.Length); {
LOGGER.Info(IP + " Scan Data:" + dataStr); byte[] bb = new byte[] { _buff[0], _buff[1], _buff[2] };
Received?.Invoke(IP, bb); string dataStr = byteToStr(bb, bb.Length);
LOGGER.Info(IP + " Scan Data:" + dataStr);
Received?.Invoke(IP, bb);
}
else if (result.Equals(14))
{
LOGGER.Error(IP + " ReadRFID 返回 " + result + ", 需要重连,调用close ,等待100后重连");
Close();
System.Threading.Thread.Sleep(100);
Open();
FindMode();
break;
}
} }
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
} }
...@@ -183,24 +196,24 @@ namespace Asa.RFID ...@@ -183,24 +196,24 @@ namespace Asa.RFID
return false; return false;
} }
public byte[] Read(bool isNeedFind = false) //public byte[] Read(bool isNeedFind = false)
{ //{
if (isNeedFind) // if (isNeedFind)
{ // {
FindRFID(); // FindRFID();
} // }
if (IsExist) // if (IsExist)
{ // {
ReadRFID(); // ReadRFID();
return _buff; // return _buff;
} // }
else // else
{ // {
LOGGER.Info(IP + " Read: IsExist=false "); // LOGGER.Info(IP + " Read: IsExist=false ");
} // }
return null; // return null;
} //}
private void ReadRFID() private int ReadRFID()
{ {
try try
{ {
...@@ -232,17 +245,22 @@ namespace Asa.RFID ...@@ -232,17 +245,22 @@ namespace Asa.RFID
Array.Copy(data, 0, _buff, 0, data.Length); Array.Copy(data, 0, _buff, 0, data.Length);
string dataStr = byteToStr(data, data.Length); string dataStr = byteToStr(data, data.Length);
LOGGER.Info(IP + " ReadMultipleBlock: Length: " + data.Length + " Data:" + dataStr); LOGGER.Info(IP + " ReadMultipleBlock: Length: " + data.Length + " Data:" + dataStr);
}else if (ErrCode == 14)
{
LOGGER.Error(IP + " ReadMultipleBlock: ErrCode: " + ErrCode+",需要重连");
} }
else else
{ {
LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode); LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode);
} }
return ErrCode;
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error(IP + "ReadRFID Error:" + ex.ToString()); LOGGER.Error(IP + "ReadRFID Error:" + ex.ToString());
} }
return -1;
} }
private string byteToStr(byte[] data, int len) private string byteToStr(byte[] data, int len)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!