public static bool SystemExit(bool shutDown, bool isOk = true) { try { Globals.AppCfg.Shutdown = isOk; Globals.AppCfg.SaveDefaultSysConfigFile();//保存当前应用配置 if (X_Axis != null && X_Axis.Enabled) { X_Axis.AxisAotoEscapeLimit(); } if (Y_Axis != null && Y_Axis.Enabled) { Y_Axis.AxisAotoEscapeLimit(); } if (T_Axis != null && T_Axis.Enabled) { T_Axis.AxisAotoEscapeLimit(); } if (Z_Axis != null && Z_Axis.Enabled) { Z_Axis.AxisAotoEscapeLimit(); Z_Axis.AxisGoHomeWork(true); //Z轴回位操作 ReportCmdKeyProgress(CmdKey.S0407); //Z轴回零成功 } if (SPD != null && SPD.IsInit) { SPD.StopSpd(); ReportCmdKeyProgress(CmdKey.S0607); } HwProvider.UnInitHardwareDriver(); //关闭所有硬件 ReportCmdKeyProgress(CmdKey.S0023); //判定是否需要延迟断电 backWorker.CancelAsync(); LogHelper.CloseLogerConnect(); } catch { } if (shutDown) { ProcessCmd.SetSystemShutdown(); } else { //ProcessCmd.ShowWindowDesk();//显示Window桌面 //ProcessCmd.ShowLogicalDriver();//显示硬盘 //ProcessCmd.UsedTaskMgrForm();//使用任务管理器 //ProcessCmd.SetSystytemLoadShell(true);//设置系统默认加载路径并注销系统 } Application.Exit(); return(true); }
private static bool SystemInitCheckStatus() { if (!Globals.Load) { ReportCmdKeyProgress(CmdKey.S0106); return(false); } if (!X_Axis.Enabled) { X_Axis.EnableAmpC(); } if (!Y_Axis.Enabled) { Y_Axis.EnableAmpC(); } if (!Z_Axis.Enabled) { Z_Axis.EnableAmpC(); } if (!T_Axis.Enabled) { T_Axis.EnableAmpC(); } if (!X_Axis.Enabled) { ReportCmdKeyProgress(CmdKey.S0209); return(false); } if (!Y_Axis.Enabled) { ReportCmdKeyProgress(CmdKey.S0309); return(false); } if (!Z_Axis.Enabled) { ReportCmdKeyProgress(CmdKey.S0409); return(false); } if (!T_Axis.Enabled) { ReportCmdKeyProgress(CmdKey.S0509); return(false); } return(true); }
public static bool EmergencyStop() { try { Globals.LedCmd.Cmd = Globals.DevData.EmgLedCmd.Cmd; ReportCmdKeyProgress(CmdKey.S0093); bool flag = X_Axis.JogStop(); flag &= Y_Axis.JogStop(); flag &= T_Axis.JogStop(); flag &= Z_Axis.JogStop(); flag &= Z_Axis.AxisJogAbsWork(Globals.MacData.ZStartPos); Globals.EMG = false; return(flag); } catch { Common.ReportCmdKeyProgress(CmdKey.S0091); return(false); } }
void HandleOnDragStart(GameObject obj) { if (obj == X_Axis) { axis = Axis.X_Axis; Y_Axis.SetActive(false); Z_Axis.SetActive(false); } else if (obj == Y_Axis) { axis = Axis.Y_Axis; Z_Axis.SetActive(false); X_Axis.SetActive(false); } else if (obj == Z_Axis) { axis = Axis.Z_Axis; Y_Axis.SetActive(false); X_Axis.SetActive(false); } }
public static bool SystemInit() { try { if (SystemInitCheckStatus()) { bool flag = true; ReportCmdKeyProgress(CmdKey.S0100); //开始系统初始化 if (!InitAxisSystemParam()) //重新进行系统初始化 { flag = false; ReportCmdKeyProgress(CmdKey.S0013); } else { ReportCmdKeyProgress(CmdKey.S0012); } Globals.LedCmd.Cmd = Globals.DevData.InitLedCmd.Cmd; X_Axis.AxisAotoEscapeLimit(); Y_Axis.AxisAotoEscapeLimit(); Z_Axis.AxisAotoEscapeLimit(); T_Axis.AxisAotoEscapeLimit(); if (Z_Axis.AxisGoHomeWork(true)) { ReportCmdKeyProgress(CmdKey.S0407); } else { ReportCmdKeyProgress(CmdKey.S0408); flag &= false; } flag &= X_Axis.AxisGoHomeWork(); flag &= Y_Axis.AxisGoHomeWork(); flag &= T_Axis.AxisGoHomeWork(); if (!WaitAxisMoveDone(500))//延迟20S判断 { ReportCmdKeyProgress(CmdKey.S0096); return(false); } ReportCmdKeyProgress(CmdKey.S0108); flag &= X_Axis.SetPrePosition(X_Axis.Param.StartPos); flag &= Y_Axis.SetPrePosition(Y_Axis.Param.StartPos); flag &= T_Axis.SetPrePosition(T_Axis.Param.StartPos); ReportCmdKeyProgress(CmdKey.S0109); flag &= X_Axis.SetLimitSwitch(true); flag &= Y_Axis.SetLimitSwitch(true); flag &= T_Axis.SetLimitSwitch(true); flag &= X_Axis.SetSoftPLimit(X_Axis.Param.SoftPlimit); flag &= X_Axis.SetSoftNLimit(X_Axis.Param.SoftNlimit); flag &= Y_Axis.SetSoftPLimit(Y_Axis.Param.SoftPlimit); flag &= Y_Axis.SetSoftNLimit(Y_Axis.Param.SoftNlimit); flag &= T_Axis.SetSoftPLimit(T_Axis.Param.SoftPlimit); flag &= T_Axis.SetSoftNLimit(T_Axis.Param.SoftNlimit); if (flag) { Globals.LedCmd.Cmd = Globals.DevData.IdleLedCmd.Cmd; ReportCmdKeyProgress(CmdKey.S0101); } else { ReportCmdKeyProgress(CmdKey.S0102); } return(flag); } else { return(false); } } catch { ReportCmdKeyProgress(CmdKey.S0098); return(false); } }
private static void RunSynProgram() { try { do { switch (Globals.AppFunState) { case SysFunState.Load: { Globals.Load = SystemLoad(); if (Globals.Load) { if (Globals.AutoInit) { Globals.AppFunState = SysFunState.SysInit; //判断是否直接进行系统初始化操作 } else { Globals.AppFunState = SysFunState.IDIE; //空闲操作 } } else { Globals.AppFunState = SysFunState.IDIE; //空闲操作 } } break; case SysFunState.SysInit: //系统初始化 { Globals.IsInit = SystemInit(); Globals.AppFunState = SysFunState.IDIE; //空闲操作 } break; case SysFunState.TouchTesting: //测高 { if (Globals.IsInit) { ReportWorkingProgress(ProcessCmd.CsTestingStartCmd); if (TouchTestingHeight()) { ReportWorkingProgress(ProcessCmd.CsTestingEndCmd); } else { ReportWorkingProgress(ProcessCmd.CsTestingErrCmd); } Globals.Testing = false; Z_Axis.AxisGoHomeWork(true); //恢复系统默认回零模式 X_Axis.AxisJogAbsWork(X_Axis.Param.StartPos); Y_Axis.AxisJogAbsWork(Y_Axis.Param.StartPos); WaitAxisMoveDone(); } else { ReportCmdKeyProgress(CmdKey.H0000); } Globals.AppFunState = SysFunState.IDIE; //空闲操作 Globals.LedCmd.Cmd = Globals.DevData.IdleLedCmd.Cmd; } break; case SysFunState.NoTouchTesting: //测高 { if (Globals.Paused) //如果当前在暂停中进行非接触式测高 { Globals.AppFunState = SysFunState.Cutting; Globals.Paused = false; } else { Globals.AppFunState = SysFunState.IDIE; //空闲操作 } } break; case SysFunState.Cutting: { if (Globals.Load && Globals.IsInit) { Globals.CutStop = false; if (Globals.Cutting) { ReportCmdKeyProgress(CmdKey.P0101); ReportWorkingProgress(ProcessCmd.CutContinuesCmd); } else { ReportCmdKeyProgress(CmdKey.P0100); ReportWorkingProgress(ProcessCmd.CutStartCmd); } Globals.Cutting = true; if (RunGroupCut(Globals.Group)) { Globals.AppFunState = SysFunState.CutStop; //空闲操作 } else { if (Globals.CutStop) //停止划切 { Globals.AppFunState = SysFunState.CutStop; break; } if (Globals.Line.Pause) //暂停 { Globals.Paused = true; Globals.AppFunState = SysFunState.CutPause; Globals.LedCmd.Cmd = Globals.DevData.PauseLedCmd.Cmd; if (Globals.DevData.CutPauseCloseWater) //关闭切割水 { Common.DO[DoDefine.CUT_WATER] = false; } break; } } } else { Common.ReportCmdKeyProgress(CmdKey.S0090); Globals.AppFunState = SysFunState.CutStop; //空闲操作 } } break; case SysFunState.Emergency: //紧急停止 { //if (Globals.Cutting) //{ // ReportWorkingProgress(ProcessCmd.CutSopCmd);//划切终止 //} if (EmergencyStop()) { Globals.AppFunState = SysFunState.IDIE; //空闲操作 } else { ReportCmdKeyProgress(CmdKey.S0097); Globals.AppFunState = SysFunState.IDIE; //空闲操作 } } break; case SysFunState.CutStop: { ReportWorkingProgress(ProcessCmd.CutSopCmd); Globals.Group.AddBladeCutedPieces(); //添加已划切片数 Globals.Group.ClearAllChannelInfo(); //清除对准信息 Globals.Cutting = false; Globals.Paused = false; Globals.CutStop = false; Globals.LedCmd.Cmd = Globals.DevData.StopLedCmd.Cmd; if (Globals.DevData.CutStopCloseWater) //关闭切割水 { Common.DO[DoDefine.CUT_WATER] = false; } if (Globals.DevData.CutStopUnloadVacuum) //打开真空开关 { Common.DO[DoDefine.WORK_AIR] = false; } if (Globals.DevData.BuzzerUsed) //打开蜂鸣器 { DO[DoDefine.BUZZER] = true; } if (Globals.Group.Complate) //正常切割完成 { Globals.BldData.SaveBladeDataFile(Globals.AppCfg.BladeFileFullName); //保存当前文档 ReportCmdKeyProgress(CmdKey.P0103); } else { ReportCmdKeyProgress(CmdKey.P0104); } Globals.AppFunState = SysFunState.IDIE; //空闲操作 } break; case SysFunState.AutoFocus: { if (Globals.Load && Globals.IsInit) { AutoFocus(Capture, 40, 32); } Globals.AppFunState = SysFunState.IDIE; //空闲操作 } break; case SysFunState.HomeAutoFocus: { if (Globals.Load && Globals.IsInit) { Z_Axis.AxisGoHomeWork(true); AutoFocus(Capture, 40, 32); } Globals.AppFunState = SysFunState.IDIE; //空闲操作 } break; case SysFunState.CutPause: { //崩边检测 //继续划切 //if() 退出划切 if (Globals.CutStop) { Globals.AppFunState = SysFunState.CutStop; //空闲操作 } else { if (!Globals.Paused) //暂停取消 { Globals.AppFunState = SysFunState.Cutting; //继续划切 } } } break; default: // SyStatus.IDIE: 其他操作 { //操作 } break; } if (Globals.EMG) //如果需要紧急停止 { Globals.AppFunState = SysFunState.Emergency; //空闲操作 } else { if (Globals.Load) { SystemCheckStatus(); } } Thread.Sleep(100); } while (!backWorker.CancellationPending); } catch (Exception ex) { LogHelper.WriteDebugException(ex); if (Globals.Load) { Globals.EMG = true; Globals.AppFunState = SysFunState.Emergency; backWorker.RunWorkerAsync(); } } }
public static bool RunLineCut(CutLine line, bool preCut = false) { do { switch (line.CutStep) { case CutStep.Ready: //等待各轴移动到位 { if (line.SinDir || !line.Dual || (line.Dual && Globals.DevData.DualZlife)) //如果为单项划切或者必须返回 { Z_Axis.AxisJogAbsWork(line.SelfPos); //划切一刀 必须Z轴上升到安全位 } if (WaitAxisMoveDone()) //判断各轴是否到位 { line.Cutting = true; //开始切割 line.FirstCut = true; if (line.Seg != null && !line.Abs) { line.Seg.RepairXPosAndLength(Y_Axis.RealPos + line.StartPos.Y, line); //修正起始位置和长度 } if (preCut) //根据是否预划切 修正划切速度 { float s = Globals.Group.PreCut.GetPreDataSpeed(); if (s > 0 && s < line.Speed) //预划切值有效且小于当前划切速度 { line.Speed = s; } else { Globals.PreCut = false; } } line.CutStep = CutStep.ST1; } else { return(false); } } break; case CutStep.ST1: //X 轴移动到划切位置 需要根据当前Y轴位置重新计算X轴起点和划切长度 { X_Axis.JogAbs(line.BackSpeed, Globals.MacData.XCutBackAcc, line.StartPos.X); //设置X返回加速度 if (line.Abs) { Y_Axis.AxisJogAbsWork(line.StartPos.Y); } else { //float v = Math.Abs(line.StartPos.Y / line.Length * line.BackSpeed); //Y_Axis.JogInc(v, 0.1f, line.StartPos.Y); Y_Axis.AxisJogIncWork(line.StartPos.Y); //相对位置 } WaitAxisMoveDone(Y_Axis); if (WaitAxisMoveDone(X_Axis)) { line.CutStep = CutStep.ST2; } else { return(false); } } break; case CutStep.ST2: //Z轴下落到划切位置1 { float pos = line.ReDepth + Globals.TestHeightValue - Globals.BldData.RealCompensatedValue; if (pos < Globals.TestHeightValue) //防止切割到工作台 { pos = Globals.TestHeightValue; } Z_Axis.JogAbs(Globals.MacData.ZCutSpeed, Globals.MacData.ZCutAcc, pos); //Z轴下落到位 必须等候Z到位 if (WaitAxisMoveDone(Z_Axis)) { line.CutStep = CutStep.ST3; } else { return(false); } } break; case CutStep.ST3: //X轴进行划切操作 { X_Axis.JogInc(line.Speed, Globals.MacData.XCutAcc, line.Dir ? -line.Length : line.Length); //X轴开始缓慢划切 判断划切方向 if (WaitAxisMoveDone(X_Axis)) { line.CutStep = CutStep.ST4; Globals.BldData.AddCutedLinesAndLength(1, line.Length / 1000); //已划切刀数 } else { return(false); } } break; case CutStep.ST4: //Z轴是否抬刀 { if (line.SinDir || !line.Dual || (line.Dual && Globals.DevData.DualZlife)) //如果为单项划切或者必须返回 { Z_Axis.AxisJogAbsWork(line.SelfPos); //划切一刀 必须Z轴上升到安全位 if (!WaitAxisMoveDone(Z_Axis)) { return(false); } } if (line.Dual) { line.CutStep = CutStep.ST5; } else { line.CutStep = CutStep.CutStop; } } break; case CutStep.ST5: //X轴返回到划切位置 { line.FirstCut = false; if (line.SinDir) //如果是单向划切X轴必须返回到划切位置 { X_Axis.JogAbs(line.BackSpeed, Globals.MacData.XCutBackAcc, line.StartPos.X); //需要重新设置X划切返回速度 if (!WaitAxisMoveDone(X_Axis)) { return(false); } } line.CutStep = CutStep.ST6; } break; case CutStep.ST6: //Z轴下落到划切位置 { if (preCut) //根据是否预划切 修正划切速度 { float s = Globals.Group.PreCut.GetPreDataSpeed(); if (s > 0 && s < line.Speed) //预划切值有效且小于当前划切速度 { line.Speed = s; } else { Globals.PreCut = false; } } float pos = line.ReDepth2 + Globals.TestHeightValue - Globals.BldData.RealCompensatedValue; if (pos < Globals.TestHeightValue) { pos = Globals.TestHeightValue; } Z_Axis.JogAbs(Globals.MacData.ZCutSpeed, Globals.MacData.ZCutAcc, pos); //Z轴下落到位置2 if (WaitAxisMoveDone(Z_Axis)) { line.CutStep = CutStep.ST7; } else { return(false); } } break; case CutStep.ST7: //X轴开始划切 { if (line.SinDir) { X_Axis.JogInc(line.Speed, Globals.MacData.XCutAcc, line.Dir ? -line.Length : line.Length); //需要设置返回加速度 } else { X_Axis.JogInc(line.Speed, Globals.MacData.XCutAcc, line.Dir ? line.Length : -line.Length); } if (WaitAxisMoveDone(X_Axis)) { line.CutStep = CutStep.ST8; Globals.BldData.AddCutedLinesAndLength(1, line.Length / 1000); //已划切刀数 } else { return(false); } } break; case CutStep.ST8: //Z轴进行抬刀操作 { if (line.SinDir || !line.Dual) //如果为单项划切或者必须返回 { Z_Axis.AxisJogAbsWork(line.SelfPos); //划切一刀 必须Z轴上升到安全位 } line.Cutting = false; line.CutStep = CutStep.CutStop; } break; case CutStep.CutStop: //划切结束 { if (line.Pause) { line.CutStep = CutStep.Pause; } else { line.CutStep = CutStep.STEnd; //当前先判断为切割完成 后续需要判断是否暂停 刀痕检测 和测高 } ReportWorkingProgress(ProcessCmd.CutLineCmd, line); } break; case CutStep.KniefCheck: //进行刀痕检测 { } break; case CutStep.TestHeigh: //进行非接触式测高 { } break; case CutStep.Pause: { ReportCmdKeyProgress(CmdKey.P0105); line.CutStep = CutStep.STEnd; //配置为划切完成 return(false); //中断当前划切操作 } case CutStep.STEnd: { line.Complate = true; } break; default: { } break; } if (Globals.CutStop) { return(false); } ReportWorkingProgress(ProcessCmd.CutLineCmd, line); CuttingCheckStatus(); Thread.Sleep(10); } while (!line.Complate);//没有完成就一直循环 return(true); }//划切线
public static bool AutoFocus(IVideoProvider provider, float maxPos, float minPos, float step = 0.2f) { try { if (provider == null) { return(false); } bool isCapture = provider.IsRunning; Dictionary <double, float> pos = new Dictionary <double, float>(); Z_Axis.AxisJogAbsWork(maxPos); if (!WaitAxisMoveDone()) { return(false); } if (!isCapture) { provider.StartCapture(); } int stepTick = (int)((maxPos - minPos) / step); double scalValue = 0; int tick = 0; for (int i = 0; i < stepTick; i++) { Z_Axis.AxisJogIncWork(-step, true); Thread.Sleep(20); Bitmap map = provider.GetCurrentFrame(); double qua = map.GetLinearQuality(); if (!pos.ContainsKey(qua)) { if (qua < scalValue) { if (tick++ > 3) { break; } } else { tick = 0; } scalValue = qua; pos.Add(qua, z_Axis.RealPos); } } double maxKey = pos.Max(r => r.Key); float desPos = pos[maxKey]; Z_Axis.AxisJogAbsWork(desPos); if (!isCapture) { provider.StopCapture(); } pos.Clear(); GC.Collect(); if (step / 20 < 0.005) { return(true); } else { return(AutoFocus(provider, desPos + step, desPos - step, step / 10)); } } catch { return(false); } }
public static bool TouchTestingHeight() { TabData data = Globals.TabData; int tick = 30; ReportCmdKeyProgress(CmdKey.H0001); Globals.TestCancel = false; Globals.Testing = true; Globals.TestedHeight = false; //清零系统标志位 RunSpd(Globals.TabData.SpdSpeed, Globals.DevData.TestTime); Globals.LedCmd.Cmd = Globals.DevData.TestingLedCmd.Cmd; Z_Axis.AxisJogAbsWork(Z_Axis.Param.StartPos, true); //Z轴先返回到最高点 if (data.UsedTable.RotateType) //圆盘测高 { data.UsedTable.CurTpos += Globals.MacData.TTestOffset; if (data.UsedTable.CurTpos > data.MaxTpos) { data.UsedTable.CurTpos = data.UsedTable.StartTpos; } } else//方盘测高 { data.UsedTable.CurYpos += Globals.MacData.YTestOffset; data.UsedTable.CurTpos = data.UsedTable.StartTpos; if (data.UsedTable.CurYpos - data.UsedTable.StartYpos > data.UsedTable.Length) { data.UsedTable.CurYpos = data.UsedTable.StartYpos; } } X_Axis.AxisJogAbsWork(data.UsedTable.CurXpos); //X值坐标位置 Y_Axis.AxisJogAbsWork(data.UsedTable.CurYpos); //Y值坐标位置 WaitAxisMoveDone(); //等待X Y T移动到位 Z_Axis.AxisJogAbsWork(data.UsedTable.ZLowPos); //Z轴移动到高速位置 ReportCmdKeyProgress(CmdKey.H0003); do { if (!TesttingCheckStatus()) { return(false); } Thread.Sleep(50); } while (!Z_Axis.IsInPosition); //等待Z轴到位 Z_Axis.SetLimitSwitch(false); float[] num = new float[data.TestTick]; float startPos = 30; float homeOffset = Globals.MacData.ZRiseValue;//Z轴上升高度 float counterPos = Z_Axis.PhyPos; for (int i = 0; i < data.TestTick; i++) { ReportCmdKeyProgress((CmdKey)((int)CmdKey.H0004 + i)); Z_Axis.GoHome(Limit.UserLimit, Globals.MacData.ZTestSpeed, Globals.MacData.ZTestAcc, homeOffset); //Z轴开始向下测高操作 ,每次操作限时60S tick = 600; do { if (!TesttingCheckStatus()) { return(false); } tick--; Thread.Sleep(100); } while (!Z_Axis.HomeIsSuccessful && tick > 0); //等待回零完成 startPos = (Z_Axis.PhyPos - counterPos) + data.UsedTable.ZLowPos; //计算当前实际位置 Z_Axis.SetPrePosition(startPos); //设置起始位置 num[i] = startPos - homeOffset; ReportWorkingProgress(ProcessCmd.CsTestingTickCmd, num[i]); } if (num.Max() - num.Min() > data.CsMaxErrValue)//测高误差过大 { ReportCmdKeyProgress(CmdKey.H0007); return(false); } else { data.CsTestValue = num.Average(); Globals.TestHeightValue = data.CsTestValue; Globals.TestedHeight = true;//系统测高标志位 ReportCmdKeyProgress(CmdKey.H0008); return(true); } }
}//划切分度 private static bool RunningChannelCut(CutChannel c) { bool flag = true; Globals.Channel = c; Z_Axis.AxisJogAbsWork(c.SelfPos); //Z轴移动到安全位置 WaitAxisMoveDone(Z_Axis); T_Axis.AxisJogAbsWork(c.AlignT + c.TPosAdj); //T轴移动到偏移位置 X_Axis.AxisJogAbsWork(c.PausePos.X); //X轴移动到暂停位置 Y_Axis.AxisJogAbsWork(c.PausePos.Y); //Y轴移动到暂停位置(第一次划切默认为起始位置) WaitAxisMoveDone(); //等待各轴运动成功 c.Cutting = true; if (!c.Rotated) { ReportWorkingProgress(ProcessCmd.CutChStartCmd, c); //开始划切当前通道 c.Rotated = true; } if (c.StandMode) { flag = RunSegmentCut(c);//标准模式划切 } else { foreach (var item in c.Segs) { if (!item.Complate) { ReportWorkingProgress(ProcessCmd.CutSegStartCmd, c); //进行通道划切完成 item.Complate = RunSegmentCut(item); if (item.Complate) { c.CuttingIndex += item.Count; } else { flag = false; break;//退出当前循环 } } flag &= item.Complate; } } if (flag) { c.Cutting = false; ReportCmdKeyProgress(CmdKey.P0109); ReportWorkingProgress(ProcessCmd.CutChEndCmd, c); //当前通道划切完成 } else { c.PausePos.Y = Y_Axis.RealPos; //设置Y暂停位置为当前的位置 c.PausePos.X = Globals.ViewCenter.X; //设置X暂停位置为显微镜中心位置 Z_Axis.AxisJogAbsWork(c.SelfPos); //Z轴移动到安全位置 WaitAxisMoveDone(Z_Axis); X_Axis.AxisJogAbsWork(Globals.ViewCenter.X); //移动到显微镜视野 Y_Axis.AxisJogIncWork(Globals.KniefAdj); //划切位置+刀痕偏移值 将线移动到显微镜下面 WaitAxisMoveDone(); //等待移动停止 if (!Globals.CutStop) //判断是因为暂停导致的返回 { ReportWorkingProgress(ProcessCmd.CutPauseCmd, c); } } c.Complate = flag; return(c.Complate); }