示例#1
0
        public static bool StopMotor(Electromotor[] Motors, AbstractComm Comm, bool IsContinuity, bool ForceStop)
        {
            if (!ForceStop && Motors.All(m => !m.IsStarted))
            {
                return(true);
            }
            var result = true;

            if (IsContinuity)
            {
                byte val = 0x00;
                for (int i = Motors.Length - 1; i >= 0; i--)
                {
                    Motors[i].IsStarted = false;
                }
                result = Comm.SetBatchCoil(Motors[0].StartCoil.Addr, (short)Motors.Length, val);
            }
            else
            {
                foreach (var Motor in Motors)
                {
                    result = result && StopMotor(Motor, Comm);
                }
            }
            return(result);
        }
示例#2
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);
        }