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; namespace Rs.MotionPlat.Commom { public class Ops { public static void Init() { SysConfigParam.Init(); int errNum = 0; Task.Run(() => { #region 初始化固高卡 ErrorCode errCode = GugaoPulseCardManager.Instance.Init(); if (errCode > ErrorCode.Ok) { errNum++; MessageQueue.Instance.Warn($"Gugao motion card load fail {errCode}"); } else { MessageQueue.Instance.Insert("Gugao motion card load success"); } #endregion #region 初始化ztm卡 errCode = ZtmCardManager.Instance.Init(); if (errCode > ErrorCode.Ok) { errNum++; MessageQueue.Instance.Warn($"rs motion card load fail {errCode}"); return; } else { MessageQueue.Instance.Insert("rs motion card load ok"); } #endregion #region 初始化IO IoManager.Instance.Init(); #endregion #region 链接相机 //链接相机 ECameraErrorCode ceCode = HikCamera.Instance.Init(); if (ceCode > ECameraErrorCode.Ok) { errNum++; MessageQueue.Instance.Warn(ceCode.ToString()); } else { MessageQueue.Instance.Insert("Camera load ok!"); int ret = HikCamera.Instance.SetReverseX("upCamera", EDir.Y, false); ret += HikCamera.Instance.SetReverseX("upCamera", EDir.X, false); if (ret != 0) { MessageQueue.Instance.Warn("Camera init error"); } ret = 0; ret = HikCamera.Instance.SetReverseX("downCamera", EDir.X, true); ret += HikCamera.Instance.SetReverseX("downCamera", EDir.Y, false); if (ret != 0) { MessageQueue.Instance.Warn("Camera init error"); } ret = HikCamera.Instance.StartGrab("upCamera"); if (ret != 0) { MessageQueue.Instance.Warn("Camera init error"); } ret = HikCamera.Instance.StartGrab("locationCamera"); if (ret != 0) { MessageQueue.Instance.Warn("Camera init error"); } ret = HikCamera.Instance.StartGrab("scanCamera"); if (ret != 0) { MessageQueue.Instance.Warn("Camera init error"); } } #endregion //使能所有轴卡 AxisControl.AllEnable(); SafeControl.Instance.Init(); NozzleManager.Init(); TestCenter.Instance.Init(); TrayPointManager.LoadPoint(); AxisControl.AllStop(); if (errNum==0) { MessageQueue.Instance.Insert("Init finished"); } else { MessageQueue.Instance.Insert("Init fail"); } Ops.On("上下气缸电磁阀原位"); Ops.Off("上下气缸电磁阀动位"); Ops.Off("下左相机光源触发"); Ops.Off("下右相机光源触发"); Ops.Off("上相机光源触发"); StockManager.Instance.Start(); MonitorSystemButton.Instance.Start(); }); } 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; } 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) { return IoManager.Instance.ReadIn(ioName) == 1; } public static bool IsOff(string ioName) { 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() { 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.NozzleZ5.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleZ6.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleZ7.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleZ8.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleZ9.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; if (!IsStop(AxisControl.NozzleZ5)) return false; if (!IsStop(AxisControl.NozzleZ6)) return false; if (!IsStop(AxisControl.NozzleZ7)) return false; if (!IsStop(AxisControl.NozzleZ8)) return false; if (!IsStop(AxisControl.NozzleZ9)) return false; return true; } public static bool AllRStoped() { if (!IsStop(AxisControl.NozzleR1)) return false; if (!IsStop(AxisControl.NozzleR2)) return false; if (!IsStop(AxisControl.NozzleR3)) return false; if (!IsStop(AxisControl.NozzleR4)) return false; if (!IsStop(AxisControl.NozzleR5)) return false; if (!IsStop(AxisControl.NozzleR6)) return false; if (!IsStop(AxisControl.NozzleR7)) return false; if (!IsStop(AxisControl.NozzleR8)) return false; if (!IsStop(AxisControl.NozzleR9)) return false; return true; } public static bool AllRHomed() { if (AxisControl.NozzleR1.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR2.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR3.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR4.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR5.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR6.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR7.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR8.HomeStatus != EHomeStatus.Finished) return false; if (AxisControl.NozzleR9.HomeStatus != EHomeStatus.Finished) return false; return true; } /// /// 检查有没有轴报警 /// /// public static bool CheckHasAlarm() { return false; } public static double GetCurPosition(string axisName) { double pos = 0.0; IAxis axis=AxisControl.GetAxis(axisName); 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($"{axisName}StartPos"), GlobalVar.WholeSpeed); while (!Ops.IsStop(axisName) && timeout.ElapsedMilliseconds < 5000) { Thread.Sleep(10); } } timeout.Stop(); }); } /// /// 是否已回原并在起始位 /// /// public static bool IsHomedAndNearStartPos(string axisName) { IAxis axis = AxisControl.GetAxis(axisName); if(axis.HomeStatus==EHomeStatus.Finished) { double curPos = GetCurPosition(axisName); double startPos = SysConfigParam.GetValue($"{axisName}StartPos"); if (Math.Abs(curPos - startPos) <= 0.02) { return true; } } return false; } } }