Commit 36387ea6 LN

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

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