|
|
using Rs.Camera;
|
|
|
using Rs.Framework;
|
|
|
using Rs.Motion.GugaoEcat;
|
|
|
using Rs.Motion.GugaoPulse;
|
|
|
using Rs.Motion;
|
|
|
using Rs.MotionPlat.Flow;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using Rs.Motion.Base;
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip;
|
|
|
using Rs.Controls;
|
|
|
using System.Threading;
|
|
|
using System.Diagnostics;
|
|
|
using System.Windows.Forms;
|
|
|
using Rs.MotionPlat.Flow.SubFlow;
|
|
|
using Rs.DataAccess;
|
|
|
using System.Data;
|
|
|
using System.Reflection;
|
|
|
using System.ComponentModel;
|
|
|
using System.IO;
|
|
|
using Rs.MotionPlat.Entitys;
|
|
|
|
|
|
namespace Rs.MotionPlat.Commom
|
|
|
{
|
|
|
public class Ops
|
|
|
{
|
|
|
public static bool Pause { get; set; } = false;
|
|
|
public static void Init()
|
|
|
{
|
|
|
|
|
|
GlobalVar.NeedCheckEnvironment = true;
|
|
|
InitDb();
|
|
|
SysConfigParam.Init();
|
|
|
int errNum = 0;
|
|
|
|
|
|
//Task.Run(() => {
|
|
|
if (!GlobalVar.VirtualAxis)
|
|
|
{
|
|
|
|
|
|
VisionHelper.Init();
|
|
|
|
|
|
#region 初始化固高卡
|
|
|
ErrorCode errCode = GugaoPulseCardManager.Instance.Init();
|
|
|
if (errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
errNum++;
|
|
|
MessageQueue.Instance.Warn($"Gugao motion card load fail {errCode}");
|
|
|
LogHelper.Debug($"Gugao motion card load fail {errCode}");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("Gugao motion card load success");
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 初始化IO
|
|
|
IoManager.Instance.Init();
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
//使能所有轴卡
|
|
|
AxisControl.AllEnable();
|
|
|
SafeControl.Instance.Init();
|
|
|
|
|
|
AxisControl.AllStop();
|
|
|
if (errNum == 0)
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("Init finished");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Warn("Init fail");
|
|
|
}
|
|
|
LightManger.Instance.SetStatus(ELightStatus.YellowBlink);
|
|
|
On("照明灯");
|
|
|
Off("光源1");
|
|
|
Off("光源2");
|
|
|
}
|
|
|
NozzleManager.Init();
|
|
|
TrayRunPointManager.Init();
|
|
|
TrayPointManager.LoadPoint();
|
|
|
|
|
|
MonitorSystemButton.Instance.Start();
|
|
|
|
|
|
DischargeFlow.Instance.Init();
|
|
|
GrrFlow.Instance.Init();
|
|
|
SysConfigParam.Update("EnableVirtuleBarCode", "False");
|
|
|
Task.Run(() => {
|
|
|
TestFixtureManager.Instance.StartLister();
|
|
|
if (GlobalVar.IsSimTest)
|
|
|
{
|
|
|
SimulateTesterManager.Instance.Init();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
static void InitDb()
|
|
|
{
|
|
|
SqliteHelper db = new SqliteHelper();
|
|
|
Type type = typeof(GlobalVar);
|
|
|
PropertyInfo[] pis = type.GetProperties();
|
|
|
foreach (PropertyInfo propertyInfo in pis)
|
|
|
{
|
|
|
ParameterInitAttribute initAttr = (ParameterInitAttribute)propertyInfo.GetCustomAttribute(typeof(ParameterInitAttribute));
|
|
|
if(initAttr != null)
|
|
|
{
|
|
|
string querySql = $"select * from SysParameter where fieldname='{propertyInfo.Name}'";
|
|
|
DataTable dt = db.GetDataTable(querySql);
|
|
|
if (dt == null || dt.Rows.Count == 0)
|
|
|
{
|
|
|
string insertSql = $"insert into SysParameter(fieldname,fieldtype,fieldvalue,Desc,category,enable) values('{propertyInfo.Name}','{initAttr.FieldType}','{initAttr.FieldValue}','{initAttr.Desc}','{initAttr.Category}',1)";
|
|
|
db.ExecuteNonQuery(insertSql);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public static void Start()
|
|
|
{
|
|
|
//先检测门禁
|
|
|
//if(IoManager.Instance.ReadIn("后安全门禁")==0 && !GlobalVar.DisableDoor)
|
|
|
if(SafeDoorCheck.Check())
|
|
|
{
|
|
|
bool run = true;
|
|
|
if (run)
|
|
|
{
|
|
|
Task.Run(() => {
|
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Homed || MachineManage.Instance.MachineStatus == EMachineStatus.Stop)
|
|
|
{
|
|
|
MachineManage.Instance.SetLocalMachineStatus(EMachineStatus.Working);
|
|
|
LightManger.Instance.SetStatus(ELightStatus.Green);
|
|
|
if(GlobalVar.TestMode=="GRR" || GlobalVar.TestMode=="AUDIT")
|
|
|
{
|
|
|
GrrFlow.Instance.Start();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DischargeFlow.Instance.Start();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void Stop(bool isWarning=false)
|
|
|
{
|
|
|
if(MachineManage.Instance.MachineStatus== EMachineStatus.Working)
|
|
|
{
|
|
|
LightManger.Instance.SetStatus(ELightStatus.Yellow);
|
|
|
if (GlobalVar.TestMode == "GRR" || GlobalVar.TestMode == "AUDIT")
|
|
|
{
|
|
|
GrrFlow.Instance.Stop();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
DischargeFlow.Instance.Stop();
|
|
|
}
|
|
|
if (isWarning)
|
|
|
{
|
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.Warning;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MachineManage.Instance.MachineStatus = EMachineStatus.Stop;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else if(MachineManage.Instance.MachineStatus== EMachineStatus.Homing)
|
|
|
{
|
|
|
foreach (IAxis axis in AxisControl.GetAllAxis())
|
|
|
{
|
|
|
axis.Abort_Go_Home();
|
|
|
}
|
|
|
HomeFlow.Instance.CancleHome();
|
|
|
MachineManage.Instance.SetLocalMachineStatus(EMachineStatus.HomeFail);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void GoHome()
|
|
|
{
|
|
|
if (MachineManage.Instance.MachineStatus == EMachineStatus.Homed
|
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.NotInit
|
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.NotHomed
|
|
|
|| MachineManage.Instance.MachineStatus == EMachineStatus.Stop
|
|
|
|| MachineManage.Instance.MachineStatus== EMachineStatus.HomeFail
|
|
|
)
|
|
|
{
|
|
|
if(SafeDoorCheck.Check())
|
|
|
{
|
|
|
HomeFlow.Instance.StartGoHome();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
MessageQueue.Instance.Warn($"device state {MachineManage.Instance.MachineStatus} cann't home!");
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 检测轴是否报警
|
|
|
/// </summary>
|
|
|
/// <param name="axis"></param>
|
|
|
/// <returns></returns>
|
|
|
public static List<IAxis> AxiesAlarm(params IAxis[] axies)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
bool bAlarm = false;
|
|
|
List<IAxis> axes= new List<IAxis>();
|
|
|
foreach (IAxis axis in axies)
|
|
|
{
|
|
|
errCode = axis.GetAlarmStatus(out bAlarm);
|
|
|
if (errCode == ErrorCode.Ok)
|
|
|
{
|
|
|
if(bAlarm)
|
|
|
axes.Add(axis);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
axes.Add(axis);
|
|
|
}
|
|
|
}
|
|
|
return axes;
|
|
|
}
|
|
|
public static bool IsStop(params string[] axies)
|
|
|
{
|
|
|
foreach (var axisname in axies)
|
|
|
{
|
|
|
if (!IsStop(AxisControl.GetAxis(axisname)))
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
public static bool IsStop(params IAxis[] axies)
|
|
|
{
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
axis.IsStop(out bool bStop);
|
|
|
if (!bStop)
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 判断轴是否运动到位
|
|
|
/// </summary>
|
|
|
/// <param name="axies"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool IsInPosition(params IAxis[] axies)
|
|
|
{
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
axis.IsInPosition(out bool bArrived);
|
|
|
if (!bArrived)
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
//public static MoveResult IsStop( IAxis axis)
|
|
|
//{
|
|
|
// ErrorCode errCode = ErrorCode.Ok;
|
|
|
// MoveResult mr = new MoveResult();
|
|
|
// errCode = axis.GetAlarmStatus(out bool bAlarm);
|
|
|
// if (errCode == ErrorCode.Ok)
|
|
|
// {
|
|
|
// mr.IsAlarm= bAlarm;
|
|
|
// errCode = axis.IsStop(out bool bStop);
|
|
|
// if(errCode== ErrorCode.Ok)
|
|
|
// {
|
|
|
// mr.IsStop= bStop;
|
|
|
// }
|
|
|
// }
|
|
|
// mr.Result = errCode;
|
|
|
// return mr ;
|
|
|
//}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 轴是否运动到位
|
|
|
/// </summary>
|
|
|
/// <param name="axies"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool IsArrived(params string[] axies)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
foreach (var axisname in axies)
|
|
|
{
|
|
|
errCode = AxisControl.GetAxis(axisname).IsArrived(out bool isArrived);
|
|
|
if(errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else if(!isArrived)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 轴是否运动到位
|
|
|
/// </summary>
|
|
|
/// <param name="axies"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool IsArrived(params IAxis[] axies)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
errCode = axis.IsArrived(out bool isArrived);
|
|
|
if (errCode > ErrorCode.Ok)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else if (!isArrived)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool IsHomed(params string[] axies)
|
|
|
{
|
|
|
foreach (var axisname in axies)
|
|
|
{
|
|
|
if (!IsHomed(AxisControl.GetAxis(axisname)))
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool IsHomed(params IAxis[] axies)
|
|
|
{
|
|
|
foreach (var axis in axies)
|
|
|
{
|
|
|
if (axis.HomeStatus != EHomeStatus.Finished)
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static void On(string ioName)
|
|
|
{
|
|
|
IoManager.Instance.WriteOut(ioName, 1);
|
|
|
}
|
|
|
|
|
|
public static void Off(string ioName)
|
|
|
{
|
|
|
IoManager.Instance.WriteOut(ioName, 0);
|
|
|
}
|
|
|
|
|
|
public static bool IsOn(string ioName,bool needRecheck=true)
|
|
|
{
|
|
|
int num = 0;
|
|
|
short val = 0;
|
|
|
if (needRecheck)
|
|
|
{
|
|
|
while (num < 3)
|
|
|
{
|
|
|
val = IoManager.Instance.ReadIn(ioName);
|
|
|
if (val == 0)
|
|
|
{
|
|
|
num++;
|
|
|
Thread.Sleep(20);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
num = 0;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
val = IoManager.Instance.ReadIn(ioName);
|
|
|
}
|
|
|
return val == 1;
|
|
|
}
|
|
|
|
|
|
public static bool IsOff(string ioName,bool needRecheck = true)
|
|
|
{
|
|
|
int num = 0;
|
|
|
short val = 0;
|
|
|
if(needRecheck)
|
|
|
{
|
|
|
while (num < 3)
|
|
|
{
|
|
|
val = IoManager.Instance.ReadIn(ioName);
|
|
|
if (val == 1)
|
|
|
{
|
|
|
num++;
|
|
|
Thread.Sleep(20);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
num = 0;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
val = IoManager.Instance.ReadIn(ioName);
|
|
|
}
|
|
|
return val == 0;
|
|
|
//return IoManager.Instance.ReadIn(ioName) == 0;
|
|
|
}
|
|
|
|
|
|
public static bool IsOutOn(string ioName)
|
|
|
{
|
|
|
return IoManager.Instance.ReadOut(ioName) == 1;
|
|
|
}
|
|
|
|
|
|
public static bool IsOutOff(string ioName)
|
|
|
{
|
|
|
return IoManager.Instance.ReadOut(ioName) == 0;
|
|
|
}
|
|
|
|
|
|
public static void Quit()
|
|
|
{
|
|
|
LightManger.Instance.CloseAll();
|
|
|
Off("启动灯");
|
|
|
Off("停止灯");
|
|
|
AxisControl.AllDisable();
|
|
|
HikCamera.Instance.Deinit();
|
|
|
}
|
|
|
|
|
|
public static bool AllZHomed()
|
|
|
{
|
|
|
if(AxisControl.NozzleZ1.HomeStatus!= EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ2.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ3.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.NozzleZ4.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
|
|
|
if (AxisControl.StockZ1.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.StockZ2.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
if (AxisControl.StockZ3.HomeStatus != EHomeStatus.Finished) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public static bool AllZStoped()
|
|
|
{
|
|
|
if (!IsStop(AxisControl.NozzleZ1)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ2)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ3)) return false;
|
|
|
if (!IsStop(AxisControl.NozzleZ4)) return false;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查有没有轴报警
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static bool CheckHasAlarm()
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static double GetCurPosition(string axisName)
|
|
|
{
|
|
|
IAxis axis=AxisControl.GetAxis(axisName);
|
|
|
return GetCurPosition(axis);
|
|
|
}
|
|
|
|
|
|
public static double GetCurPosition(IAxis axis)
|
|
|
{
|
|
|
double pos = 0.0;
|
|
|
if (axis == null) return 0;
|
|
|
if (axis.Config.EnableEncoder == 1)
|
|
|
{
|
|
|
if (axis.Config.AxisName.IndexOf("Nozzle") >= 0)
|
|
|
{
|
|
|
axis.GetPrfPosition(out pos);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
axis.GetEncoderPosition(out pos);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
axis.GetPrfPosition(out pos);
|
|
|
}
|
|
|
return pos;
|
|
|
}
|
|
|
|
|
|
public static void HomeAndGoStartPos(string axisName)
|
|
|
{
|
|
|
Task.Run(() => {
|
|
|
IAxis axis = AxisControl.GetAxis(axisName);
|
|
|
axis.Home();
|
|
|
MessageQueue.Instance.Insert("stat home");
|
|
|
Thread.Sleep(10);
|
|
|
Stopwatch timeout = new Stopwatch();
|
|
|
timeout.Restart();
|
|
|
while (axis.HomeStatus != EHomeStatus.Finished)
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("homing");
|
|
|
Thread.Sleep(10);
|
|
|
}
|
|
|
|
|
|
timeout.Stop();
|
|
|
if (axis.HomeStatus == EHomeStatus.Finished)
|
|
|
{
|
|
|
MessageQueue.Instance.Insert("go to start pos");
|
|
|
Thread.Sleep(100);
|
|
|
timeout.Restart();
|
|
|
ErrorCode errCode = axis.MovePos(SysConfigParam.GetValue<double>($"{axisName}StartPos"), GlobalVar.WholeSpeed);
|
|
|
while (!Ops.IsStop(axisName) && timeout.ElapsedMilliseconds < 5000)
|
|
|
{
|
|
|
Thread.Sleep(10);
|
|
|
}
|
|
|
}
|
|
|
timeout.Stop();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 是否已回原并在起始位
|
|
|
/// </summary>
|
|
|
/// <param name="axisName"></param>
|
|
|
public static bool IsHomedAndNearStartPos(string axisName)
|
|
|
{
|
|
|
IAxis axis = AxisControl.GetAxis(axisName);
|
|
|
if(axis.HomeStatus==EHomeStatus.Finished)
|
|
|
{
|
|
|
double curPos = GetCurPosition(axisName);
|
|
|
double startPos = SysConfigParam.GetValue<double>($"{axisName}StartPos");
|
|
|
if (Math.Abs(curPos - startPos) <= 0.02)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public static bool Go(string axisName,double targetPos, int speedPercent = 0) {
|
|
|
return Go(AxisControl.GetAxis(axisName),targetPos, speedPercent);
|
|
|
}
|
|
|
|
|
|
public static bool Go(IAxis axis, double targetPos,int speedPercent = 0)
|
|
|
{
|
|
|
ErrorCode errCode = ErrorCode.Ok;
|
|
|
if(speedPercent==0)
|
|
|
speedPercent=GlobalVar.WholeSpeed;
|
|
|
errCode = axis.MovePos(targetPos,speedPercent);
|
|
|
if(errCode == ErrorCode.Ok || GlobalVar.VirtualAxis)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Msg.ShowError($"轴{axis.Config.AxisName}运动异常,ret={errCode}");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断轴是否在原点
|
|
|
/// </summary>
|
|
|
/// <param name="axisName"></param>
|
|
|
/// <returns></returns>
|
|
|
public static bool IsInOrg(string axisName)
|
|
|
{
|
|
|
IAxis axis=AxisControl.GetAxis(axisName);
|
|
|
axis.GetOrgStatus(out bool isInOrg);
|
|
|
if (isInOrg)
|
|
|
return true;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|