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.

211 lines
5.9 KiB
C#

using NPOI.SS.Formula.Functions;
using Rs.DataAccess;
using Rs.Framework;
using Rs.MotionPlat.Entitys.Trays;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Rs.MotionPlat.Commom
{
/// <summary>
/// 中转吸头管理类
/// 中转吸头共有16个吸头
/// </summary>
public class TransitNozzleManager
{
private TransitNozzle[] nozzles;
private TransitNozzleManager() {
nozzles = new TransitNozzle[8];
for(int i=0;i<8; i++)
{
nozzles[i] = new TransitNozzle() {
NozzleIndex = i + 1,
IsHasProduct = false,
SN=""
};
}
}
private static TransitNozzleManager instance;
public static TransitNozzleManager Instance
{
get
{
if(instance==null)
{
instance = new TransitNozzleManager();
}
return instance;
}
}
public TransitNozzle Nozzle(int nozzleIndex)
{
nozzleIndex = nozzleIndex > 16 ? nozzleIndex - 8 : nozzleIndex;
return nozzles[nozzleIndex - 1];
}
/// <summary>
/// 获取含有产品的吸嘴
/// </summary>
/// <returns></returns>
public List<TransitNozzle> GetHasProductNozzles()
{
return nozzles.Where(n => n.IsHasProduct).ToList();
}
/// <summary>
/// 重置所有的穴位状态
/// </summary>
public void ResetStatus()
{
foreach (TransitNozzle nozzle in nozzles)
{
nozzle.IsHasProduct = false;
nozzle.FromIndex = 0;
nozzle.FromType = TurnoverType.Unknown;
nozzle.ToType= TurnoverType.Unknown;
nozzle.ToIndex = 0;
}
}
}
/// <summary>
/// 中转吸嘴
/// </summary>
public class TransitNozzle
{
public void AddProduct(TestTraySlot testTraySlot)
{
IsHasProduct = true;
SN = testTraySlot.SN;
FromIndex = testTraySlot.Index-1;
FromType = TurnoverType.Tester;
}
public void AddProduct(TurnoverTraySlot turnoverTraySlot)
{
IsHasProduct = true;
SN=turnoverTraySlot.SN;
FromIndex = turnoverTraySlot.Index-1;
FromType = TurnoverType.Turnover;
}
public void AddProduct(TurnoverInfo task)
{
IsHasProduct = true;
SN = task.SN;
FromIndex = task.FromIndex;
FromType = task.FromType;
ToIndex= task.ToIndex;
ToType= task.ToType;
ToFloor= task.ToFloor;
Task.Run(() => {
SqliteHelper db = new SqliteHelper();
string updateSql = $"update TrayStatus set status=1 where trayname='TurnoverNozzle' and slotindex={NozzleIndex}";
//db.ExecuteNonQuery(updateSql);
});
}
public void Clear(bool closeVac=false)
{
IsHasProduct = false;
SN = "";
if(closeVac )
{
CloseVac();
}
Task.Run(() => {
SqliteHelper db = new SqliteHelper();
string updateSql = $"update TrayStatus set status=0 where trayname='TurnoverNozzle' and slotindex={NozzleIndex}";
db.ExecuteNonQuery(updateSql);
});
}
public void ResetStaus()
{
IsHasProduct = false;
FromIndex = 0;
FromType = TurnoverType.Unknown;
ToType = TurnoverType.Unknown;
ToIndex = 0;
}
/// <summary>
/// 吸嘴索引
/// </summary>
public int NozzleIndex { get; set; }
/// <summary>
/// 是否有产品
/// </summary>
public bool IsHasProduct { get; set; }
/// <summary>
/// 产品的SN
/// </summary>
public string SN { get; set; }
public int FromIndex { get; set; }
public TurnoverType FromType { get; set; }
public int FromFloor { get; set; }
public int ToIndex { get; set; }
public TurnoverType ToType { get; set; }
public int ToFloor { get; set; }
/// <summary>
/// 是否有真空信号
/// </summary>
/// <returns></returns>
public bool HasVacSignal()
{
if(Ops.IsOn($"周转{NozzleIndex}号吸嘴真空吸检测",false))
return true;
return false;
}
/// <summary>
/// 关闭真空吸
/// </summary>
public void CloseVac(int waittime=0)
{
if (waittime > 0)
{
Thread.Sleep(waittime);
}
Ops.Off($"周转{NozzleIndex}号吸嘴真空吸");
MessageQueue.Instance.Insert($"关闭周转{NozzleIndex}号吸嘴真空吸");
}
/// <summary>
/// 打开真空吸
/// </summary>
public void OpenVac(int waittime = 0)
{
if (waittime > 0)
{
Thread.Sleep(waittime);
}
Ops.On($"周转{NozzleIndex}号吸嘴真空吸");
MessageQueue.Instance.Insert($"打开周转{NozzleIndex}号吸嘴真空吸");
}
/// <summary>
/// 打开真空破
/// </summary>
public void OpenBreak()
{
VacManager.TransitNozzleVacBreak(EVacOperator.Open, true,NozzleIndex);
}
/// <summary>
/// 关闭真空破
/// </summary>
public void CloseBreak()
{
VacManager.TransitNozzleVacBreak(EVacOperator.Open, true, NozzleIndex);
}
}
}