using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace M423project
|
{
|
public class ProductStep
|
{
|
public int DetectID { get; set; }
|
public int Step { get; set; }
|
public ProductStep(int detectID)
|
{
|
DetectID = detectID;
|
Step = 0;
|
}
|
}
|
public class StepContol
|
{
|
static object _stepLock = new object();
|
private volatile List<ProductStep> _stepList = new List<ProductStep>();
|
|
public int Count { get { return _stepList.Count(); } }
|
|
public void RemoveUnload()
|
{
|
lock (_stepLock)
|
{
|
//List<int> listRemove = new List<int>();
|
//for (int i = 0; i < _stepList.Count; i++)
|
//{
|
// if (_stepList[i].Step == 3)
|
// {
|
// listRemove.Add(i);
|
// }
|
|
//}
|
//foreach (int i in listRemove)
|
// _stepList.RemoveAt(i);
|
|
_stepList.RemoveAll(u => u.Step == 3);
|
}
|
}
|
|
public void IncStep()
|
{
|
//lock (this)
|
//{
|
// foreach (var x in _stepList)
|
// {
|
// x.Step++;
|
// }
|
//}
|
|
lock (_stepLock)
|
{
|
_stepList.ForEach(u => u.Step++);
|
}
|
}
|
|
public void AddProductStep(int detectID)
|
{
|
//lock (this)
|
//{
|
// _stepList.Add(new ProductStep(detectID));
|
//}
|
|
lock (_stepLock)
|
{
|
_stepList.Add(new ProductStep(detectID));
|
}
|
}
|
|
public int GetDetectHeightID()
|
{
|
//lock (this)
|
//{
|
// int id = -1;
|
// for (int i = 0; i < _stepList.Count; i++)
|
// {
|
// if (_stepList[i].Step == 0)
|
// {
|
// id = _stepList[i].DetectID;
|
// break;
|
// }
|
// }
|
// return id;
|
//}
|
|
return _stepList.FirstOrDefault(u => u.Step == 0)?.DetectID ?? -1;
|
}
|
|
public int GetDetectSizeStepID()
|
{
|
//lock (this)
|
//{
|
// int id = -1;
|
// for (int i = 0; i < _stepList.Count; i++)
|
// {
|
// if (_stepList[i].Step == 2)
|
// {
|
// id = _stepList[i].DetectID;
|
// break;
|
// }
|
// }
|
// return id;
|
//}
|
|
return _stepList.FirstOrDefault(u => u.Step == 2)?.DetectID ?? -1;
|
}
|
|
public int GetUnloadStepID()
|
{
|
//lock (this)
|
//{
|
// int id = -1;
|
// for (int i = 0; i < _stepList.Count; i++)
|
// {
|
// if (_stepList[i].Step == 3)
|
// {
|
// id = _stepList[i].DetectID;
|
// break;
|
// }
|
// }
|
// return id;
|
//}
|
|
return _stepList.FirstOrDefault(u => u.Step == 3)?.DetectID ?? -1;
|
}
|
|
public void Clear()
|
{
|
_stepList.Clear();
|
}
|
|
public override string ToString()
|
{
|
StringBuilder sb = new StringBuilder();
|
sb.Append(string.Format("StepControl Count:{0}", _stepList.Count));
|
foreach (var x in _stepList)
|
{
|
sb.Append(" [");
|
sb.Append(x.DetectID.ToString());
|
sb.Append(",");
|
sb.Append(x.Step.ToString());
|
sb.Append("]");
|
|
}
|
return sb.ToString();
|
}
|
|
#region Add by Patrick 2018-07-12
|
/// <summary>
|
/// 获取下料机械手臂下料完成时的两块电池的ID号
|
/// </summary>
|
/// <returns></returns>
|
public List<int> GetUnloadStep2IDs()
|
{
|
//lock (this)
|
{
|
return _stepList.OrderByDescending(p => p.Step).Take(2).Select(p => p.DetectID).ToList();
|
}
|
}
|
|
/// <summary>
|
/// 获取下料机械手臂下料完成时的电池的ID号
|
/// </summary>
|
/// <returns></returns>
|
public int GetUnloadBatteryID()
|
{
|
////lock (this)
|
//{
|
// var st = _stepList.OrderByDescending(p => p.Step).FirstOrDefault();
|
// if (st != null)
|
// {
|
// return st.DetectID;
|
// }
|
// else
|
// {
|
// return 0;
|
// }
|
|
// //return _stepList.OrderByDescending(p => p.Step).FirstOrDefault().DetectID;
|
//}
|
|
return _stepList.OrderByDescending(p => p.Step).FirstOrDefault().DetectID;
|
}
|
|
public void RemoveById(int id)
|
{
|
lock (_stepLock)
|
{
|
_stepList.RemoveAll(p => p.DetectID == id);
|
}
|
}
|
#endregion
|
}
|
}
|