You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
6.7 KiB
C#

11 months ago
using Rs.DataAccess;
using Rs.MotionPlat.Commom;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Entitys.Trays
{
/// <summary>
/// 周转盘穴位类型
/// </summary>
public enum ETurnoverTraySlotType
{
/// <summary>
/// 待测穴位
/// </summary>
WaitTest,
/// <summary>
/// 已测穴位
/// </summary>
Tested
}
public enum ETurnoverTraySlotStatus
{
/// <summary>
/// 有产品
/// </summary>
Have,
/// <summary>
/// 无产品
/// </summary>
NotHave,
/// <summary>
/// 有产品且真空异常
/// </summary>
VacException,
/// <summary>
/// 所有
/// </summary>
All
}
/// <summary>
/// 周转盘状态管理类只有一个周转盘32个穴位
/// </summary>
public class TurnoverTrayManager
{
/// <summary>
/// 周转盘层数
/// </summary>
public int Floor { get; set; }
private TurnoverTraySlot[] slots;
public List<TurnoverTraySlot> Slots
{
get
{
return slots.ToList();
}
}
private TurnoverTrayManager() {
slots = new TurnoverTraySlot[16];
11 months ago
int index = 0;
for(int row=1;row<=4;row++)
{
for(int col=1;col<=4;col++)
11 months ago
{
slots[index] = new TurnoverTraySlot()
{
Row = row,
Index = index+1,
IsHasProduct = false,
SN = "",
FromIndex = 0,
SuckerNo = 0,
SlotType = (row%2==0) ? ETurnoverTraySlotType.Tested : ETurnoverTraySlotType.WaitTest
};
index++;
}
}
}
private static TurnoverTrayManager instance;
public static TurnoverTrayManager Instance
{
get
{
if(instance==null)
{
instance = new TurnoverTrayManager();
}
return instance;
}
}
public TurnoverTraySlot Slot(int slotIndex)
{
return slots[slotIndex - 1];
}
/// <summary>
/// 根据穴位中是否有产品获取待测穴位
/// </summary>
/// <returns></returns>
public List<TurnoverTraySlot> GetSlots(ETurnoverTraySlotType slotType,ETurnoverTraySlotStatus slotStatus)
{
List<TurnoverTraySlot> results = new List<TurnoverTraySlot>();
switch (slotStatus)
{
case ETurnoverTraySlotStatus.Have:
results = slots.Where(s => s.SlotType == slotType && s.IsHasProduct == true).ToList();
break;
case ETurnoverTraySlotStatus.NotHave:
results = slots.Where(s => s.SlotType == slotType && s.IsHasProduct == false).ToList();
break;
case ETurnoverTraySlotStatus.VacException:
results = slots.Where(s => s.SlotType == slotType && s.IsHasProduct == true && s.VacException==true).ToList();
break;
case ETurnoverTraySlotStatus.All:
results = slots.Where(s => s.SlotType == slotType).ToList();
break;
default:
break;
}
return results;
}
/// <summary>
/// 检测料盘中某一行是否有产品
/// </summary>
/// <param name="row"></param>
/// <returns></returns>
public bool HasProduct(ETrayRow row)
{
return slots.Where(s => s.Row == (int)row && s.IsHasProduct==true).Count() > 0;
}
public List<TurnoverTraySlot> GetAll()
{
return slots.ToList();
}
/// <summary>
/// 重置周转盘穴位状态
/// </summary>
public void ResetStatus()
{
foreach (TurnoverTraySlot slot in slots)
{
slot.IsHasProduct = false;
slot.FromIndex = 0;
slot.FromType = TurnoverType.Unknown;
}
}
}
public class TurnoverTraySlot:BaseTraySlot
{
/// <summary>
/// 穴位类型 0待测 1已测
/// </summary>
public ETurnoverTraySlotType SlotType { get; set; }
public void AddProduct(Nozzle nozzle)
{
IsHasProduct = true;
SN = nozzle.SN;
FromIndex = nozzle.FromIndex;
FromType = nozzle.FromType;
SuckerNo = nozzle.NozzleIndex;
Task.Run(() => {
SqliteHelper db = new SqliteHelper();
string updateSql = $"update TrayStatus set status=1 where trayname='TurnoverTray' and slotindex={Index}";
db.ExecuteNonQuery(updateSql);
});
}
public void AddProduct(TransitNozzle nozzle)
{
IsHasProduct = true;
SN = nozzle.SN;
FromIndex = nozzle.FromIndex;
FromType = nozzle.FromType;
SuckerNo = nozzle.NozzleIndex;
Task.Run(() => {
SqliteHelper db = new SqliteHelper();
string updateSql = $"update TrayStatus set status=1 where trayname='TurnoverTray' and slotindex={Index}";
db.ExecuteNonQuery(updateSql);
});
}
public void ClearProduct()
{
IsHasProduct = false;
SN = "";
FromIndex = 0;
FromType = TurnoverType.Unknown;
SuckerNo = 0;
Task.Run(() => {
SqliteHelper db = new SqliteHelper();
string updateSql = $"update TrayStatus set status=0 where trayname='TurnoverTray' and slotindex={Index}";
//db.ExecuteNonQuery(updateSql);
});
}
public bool HasVac()
{
if (Ops.IsOn($"周转盘{Index}号穴位真空吸检测"))
return true;
return false;
}
public void ResetStatus()
{
IsHasProduct = false;
FromIndex = 0;
FromType = TurnoverType.Unknown;
}
/// <summary>
/// 穴位真空异常
/// </summary>
public bool VacException { get; set; } = false;
}
}