public static bool SwitchSpeed(AbstractComm Comm, DoubleSpeedMotor Motor, bool IsSencond) { var result = true; result = result && Comm.SetRegister(Motor.Speed.Addr, (IsSencond ? Motor.SecondSpeed : Motor.Speed).SetValue); 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); }
public static void Set2PLC <T>(PLCParameter <T> pLCParameter, Type targetType, float factor, AbstractComm Comm) { if (String.IsNullOrEmpty(pLCParameter.Addr)) { return; } String TypeName = targetType == null ? typeof(T).Name : targetType.Name; switch (TypeName) { case "Boolean": { Comm.SetCoil((bool)(Object)pLCParameter.SetValue, Comm.ConvertFatekAddrToModbusAddr(pLCParameter.Addr)); break; } case "Single": { Comm.SetRegister(pLCParameter.Addr, (float)(Object)pLCParameter.SetValue * factor); break; } case "Int32": { Comm.SetRegister(pLCParameter.Addr, Convert.ToInt32(Convert.ToSingle((Object)pLCParameter.SetValue) * factor)); break; } case "Int16": { var val = Convert.ToInt16(Convert.ToSingle((Object)pLCParameter.SetValue) * factor); //Console.WriteLine("val=" + val); Comm.SetRegister(pLCParameter.Addr, val); break; } default: { break; } } }
/// <summary> /// 移到指定位置,移动前关闭反馈完成信号 /// </summary> /// <param name="Motor"></param> /// <param name="Comm"></param> /// <returns></returns> public static bool MoveMotor(Electromotor Motor, AbstractComm Comm, decimal?Distance, bool OnlyStart = false, bool Start = true, decimal gap = 0m) { Constants.PauseResetEvent.WaitOne(); if (Constants.UserAbort) { return(false); } if (!Distance.HasValue) { return(false); } if (Distance.Value < 0) { Distance = 0; } var realdis = Motor.GetRealDistance(Distance.Value, gap); if (Motor.CurrentDistance == realdis) { return(true); } else { //关闭完成信号 Comm.SetCoil(false, Motor.DoneCoil.Addr); } Motor.CurrentDistance = realdis; int distance = Convert.ToInt32(realdis * Convert.ToDecimal(Motor.Factor.SetValue)); var result = Comm.SetRegister(Motor.Distance.Addr, distance); if (Start) { StartMotor(Motor, Comm); } if (!OnlyStart) { result = Comm.Doned(30000, true, Motor.DoneCoil); } return(result); }
public bool ChangeSpeed(Electromotor motor, int speed, AbstractComm Comm) { var res = Comm.SetRegister(motor.Speed.Addr, speed); return(res); }