Пример #1
0
 public bool MotorMove(TExecuteMode ExecuteMode, TMoveMode MoveMode, short Distance)
 {
     return(MotorMove(ExecuteMode, MoveMode, TMovePowerGrp.MOVE_POWER_DEF, Distance, 0, 0));
 }
Пример #2
0
        //Distance: -32768~32767
        public bool MotorMove(TExecuteMode ExecuteMode, TMoveMode MoveMode, TMovePowerGrp MovePower,
                              short Distance, UInt16 Speed, UInt16 Ramp)
        {
            //当前马达所在的坐标与需要移动到的位置的误差在误差范围内则认为是马达不需要移动
            if (Globals.g_CheckRange)
            {
                //如果是相对移动
                if (MoveMode == TMoveMode.MOVE_ABS)
                {
                    //判断距离值是否在误差允许范围内
                    if (Math.Abs(_Pos1 - Distance) <= Globals.ALLOW_DEV)
                    {
                        return(true);
                    }
                }
            }

            byte[] Cmd = new byte[8];

            //0为执行状态,0x80为预备状态
            byte Byte1 = (ExecuteMode == TExecuteMode.emExecute) ? (byte)0 :(byte)0x80;

            switch (MoveMode)
            {
            case TMoveMode.MOVE_REL:
                Byte1 += 0x01;    //0x81
                break;

            case TMoveMode.MOVE_SCAN:
                Byte1 += 0x02;    //0x82
                break;

            case TMoveMode.MOVE_AS_HOME:
                Byte1 += 0x03;    //0x83
                break;

            case TMoveMode.MOVE_SCAN_REL:
                Byte1 += 0x04;    //0x84
                break;
            }

            switch (MovePower)
            {
            case TMovePowerGrp.MOVE_POWER1:
                Byte1 += 0x10;
                break;

            case TMovePowerGrp.MOVE_POWER2:
                Byte1 += 0x20;
                break;

            case TMovePowerGrp.MOVE_POWER3:
                Byte1 += 0x40;
                break;
            }



            int Dis = Globals.ConvertDistance(Distance);

            Cmd[0] = (byte)TMotorCommand.CMD_MOTOR_MOVE;
            //移动的情况
            Cmd[1] = (byte)Byte1;
            Cmd[2] = (byte)(Dis & 0x00FF);  //低字节
            Cmd[3] = (byte)(Dis >> 8);      //高字节
            Cmd[4] = (byte)(Speed & 0xFF);
            Cmd[5] = (byte)(Speed >> 8);
            Cmd[6] = (byte)(Ramp & 0xFF);
            Cmd[7] = (byte)(Ramp >> 8);


            SendMsg(Cmd);

            return(true);
            //发送运动指令后需要等待运动完成,在调用线程中等待运动结束
        }