Exemplo n.º 1
0
        public static bool StartMotor(Electromotor Motor, AbstractComm Comm)
        {
            var result = Motor.IsStarted || Comm.SetCoilOn(Motor.StartCoil.Addr);

            Motor.IsStarted = result;
            return(result);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 启动连续地址电机,如加样器Y轴,距离地址连续,启动地址连续,反馈信号地址连续
        /// </summary>
        /// <param name="motors"></param>
        /// <param name="Distances">为负值时,不会应用校正因子</param>
        /// <param name="gap"></param>
        /// <param name="Comm"></param>
        /// <returns></returns>
        public static bool MoveMotors(Electromotor[] motors, decimal[] Distances, decimal[] gap, AbstractComm Comm, bool OnlyStart, bool PauseScan = true, bool IsInjectorY = false, bool IsInitInjectorY = false)
        {
            Constants.PauseResetEvent.WaitOne();
            if (Constants.UserAbort)
            {
                return(false);
            }
            var len = motors.Length;

            byte[] dis = new byte[len * 4];
            for (byte b = 0; b < len; b++)
            {
                var realdis = motors[b].GetRealDistance(Distances[b], gap == null?0m:gap[b]);
                if (motors[b].CurrentDistance == realdis)
                {
                    return(true);
                }
                else
                {
                    motors[b].CurrentDistance = realdis < 0?0: realdis;
                    Distances[b] = realdis;
                    var val  = Convert.ToInt32(realdis < 0? realdis:(realdis * Convert.ToDecimal(motors[b].Factor.SetValue)));
                    var bval = ByteUtil.Int4ToBytes(val);
                    Array.Copy(bval, 0, dis, 4 * b, 4);
                }
            }
            var result = true;

            if (PauseScan)
            {
                Comm.ScanRestEvent.Reset();
            }
            //关闭完成信号
            result = result && Comm.SetBatchCoil(motors[0].DoneCoil.Addr, (short)len, 0x00);

            result = result && Comm.SetBatchRegister(Comm.ConvertFatekAddrToModbusAddr(motors[0].Distance.Addr.Substring(1)), (short)(len * 2), dis);
            if (IsInjectorY)
            {
                result = result && Comm.SetCoilOn("M99");
                if (IsInitInjectorY)
                {
                    for (byte b = 0; b < Distances.Length; b++)
                    {
                        if (Distances[b] == 0)
                        {
                            Comm.SetCoilOn(motors[b].DoneCoil.Addr);//开启反馈信号
                        }
                    }
                }
            }
            else
            {
                result = result && StartMotor(motors, Comm, true, false);
            }
            if (PauseScan)
            {
                Comm.ScanRestEvent.Set();
            }
            if (!OnlyStart)
            {
                result = result && Comm.Doned(30000, true, motors.Select(item => item.DoneCoil.Addr).ToArray());
            }
            return(result);
        }