public static bool StopMotor(Electromotor Motor, AbstractComm Comm, bool ForceStope = false) { var result = true; if (ForceStope) { result = result && Comm.SetCoilOff(Motor.StartCoil.Addr); } else { result = result && (!Motor.IsStarted || Comm.SetCoilOff(Motor.StartCoil.Addr)); } Motor.IsStarted = false; return(result); }
/// <summary> /// 初始化电机,先归零,再初始化 /// </summary> /// <param name="Motor"></param> /// <param name="Comm"></param> /// <returns></returns> public static bool InitMotor(Electromotor Motor, AbstractComm Comm, bool OnlyStart = false, decimal gap = 0m) { Constants.UserAbort = false; //var result=MoveMotor(Motor, Comm, 0); var result = StopMotor(Motor, Comm, true); result = result && Comm.SetRegister(Motor.Distance.Addr, 0); result = result && Comm.SetCoilOff(Motor.InitCoil.Addr); result = result && Comm.SetCoilOn(Motor.InitCoil.Addr); Motor.CurrentDistance = 0m; Motor.IsBack = true; Motor.IsStarted = false; if (!OnlyStart) { result = result && Comm.Doned(30000, false, Motor.InitCoil); if (Motor.ProgramZero > 0) { result = result && MoveMotor(Motor, Comm, 0, false, true, gap); } } else { if (Motor.ProgramZero > 0) { Task.Run(() => { MoveMotor(Motor, Comm, 0, false, true, gap); }); } } return(result); }