示例#1
0
        //给单片机发送非电机轴的指令,仅指令,无参数
        public void SendCommandToArm(Board board, ArmCommandCode Code)
        {
            if (!IsBoardConnected(board))
            {
                return;
            }

            Message.MakeSendArrayByCode((byte)Code, ref m_SendMeas);
            m_MyTcpClientArm[(int)board].ClientWrite(m_SendMeas);
        }
示例#2
0
        public static void ProcessArmControlerMessage(Board board, TcpMeas meassage)
        {
            if (meassage != null)
            {
                ArmCommandCode Code = (ArmCommandCode)meassage.MeasCode;
                switch (Code)
                {
                case ArmCommandCode.GetOutput:       //读取输出口缓冲区数据
                {
                } break;

                case ArmCommandCode.GetInput:        //读取输入口的IO
                {
                    int  DataIndex = Message.MessageCommandIndex + 1;
                    uint dataInput = (uint)meassage.Param[DataIndex + 3] * 0x1000000
                                     + (uint)meassage.Param[DataIndex + 2] * 0x10000
                                     + (uint)meassage.Param[DataIndex + 1] * 0x100
                                     + (uint)meassage.Param[DataIndex + 0];

                    m_ArmControler.SetInputPoint(board, dataInput);
                    ProcessArmControlerInputPoint(board);
                } break;

                case ArmCommandCode.GetAxisStepsAbs:
                {
                    int  DataIndex = Message.MessageCommandIndex + 2;
                    uint steps     = (uint)meassage.Param[DataIndex + 3] * 0x1000000
                                     + (uint)meassage.Param[DataIndex + 2] * 0x10000
                                     + (uint)meassage.Param[DataIndex + 1] * 0x100
                                     + (uint)meassage.Param[DataIndex + 0];

                    Axis axis = (Axis)meassage.Param[Message.MessageCommandIndex + 1];
                    m_ArmControler.SetAxisPostion(axis, steps);
                    ProcessArmControlerAxisPosition(board);
                }
                break;

                case ArmCommandCode.GetAxisState:
                {
                    Axis AxisNum = (Axis)meassage.Param[Message.MessageCommandIndex + 1];
                    byte State   = meassage.Param[Message.MessageCommandIndex + 2];
                    m_ArmControler.SetAxisState(AxisNum, State);
                }
                break;

                default:
                    break;
                }
            }
        }
示例#3
0
        //给单片机发送电机轴相关的指令,axis 轴号, code命令
        public bool SendCommandToArmWithAxis(Axis axis, ArmCommandCode Code)
        {
            int indexBoard = (int)axis / MAX_AXIS_CHANNEL; //板卡索引
            int indexAxis  = (int)axis % MAX_AXIS_CHANNEL; //板卡内轴号索引

            if (!IsBoardConnected((Board)indexBoard))
            {
                return(false);
            }

            Message.MakeSendArrayByCode((byte)Code, ref m_SendMeas);
            m_SendMeas[Message.MessageCommandIndex + 1] = (byte)indexAxis;
            m_SendMeas[Message.MessageSumCheck]         = MyMath.CalculateSum(m_SendMeas, Message.MessageLength);

            m_MyTcpClientArm[indexBoard].ClientWrite(m_SendMeas);

            return(true);
        }
示例#4
0
        /// <summary>
        /// 设置电机轴速度参数
        /// </summary>
        /// <param name="axis">轴号</param>
        /// <param name="velLow">初速度</param>
        /// <param name="velHigh">运行速度</param>
        /// <param name="acc">加速度</param>
        /// <param name="dec">减速度</param>
        /// <param name="Default">是否为默认值</param>
        public bool SetSpeedParam(Axis axis, int velLow, int velHigh, int acc, int dec, bool Default)
        {
            int indexBoard = (int)axis / MAX_AXIS_CHANNEL; //板卡索引
            int indexAxis  = (int)axis % MAX_AXIS_CHANNEL; //板卡内轴号索引

            if (!IsBoardConnected((Board)indexBoard))
            {
                return(false);
            }

            ArmCommandCode Code = Default ? ArmCommandCode.SetAxisParametersDefault : ArmCommandCode.SetAxisParameters;

            Message.MakeSendArrayByCode((byte)Code, ref m_SendMeas);

            int DataIndex = Message.MessageCommandIndex + 1;

            m_SendMeas[DataIndex] = (byte)indexAxis;

            m_SendMeas[DataIndex + 1]  = (byte)(velLow & 0xffU);
            m_SendMeas[DataIndex + 2]  = (byte)((velLow >> 8) & 0xffU);
            m_SendMeas[DataIndex + 3]  = (byte)((velLow >> 16) & 0xffU);
            m_SendMeas[DataIndex + 4]  = (byte)((velLow >> 24) & 0xffU);
            m_SendMeas[DataIndex + 5]  = (byte)(velHigh & 0xffU);
            m_SendMeas[DataIndex + 6]  = (byte)((velHigh >> 8) & 0xffU);
            m_SendMeas[DataIndex + 7]  = (byte)((velHigh >> 16) & 0xffU);
            m_SendMeas[DataIndex + 8]  = (byte)((velHigh >> 24) & 0xffU);
            m_SendMeas[DataIndex + 9]  = (byte)(acc & 0xffU);
            m_SendMeas[DataIndex + 10] = (byte)((acc >> 8) & 0xffU);
            m_SendMeas[DataIndex + 11] = (byte)((acc >> 16) & 0xffU);
            m_SendMeas[DataIndex + 12] = (byte)((acc >> 24) & 0xffU);
            m_SendMeas[DataIndex + 13] = (byte)(dec & 0xffU);
            m_SendMeas[DataIndex + 14] = (byte)((dec >> 8) & 0xffU);
            m_SendMeas[DataIndex + 15] = (byte)((dec >> 16) & 0xffU);
            m_SendMeas[DataIndex + 16] = (byte)((dec >> 24) & 0xffU);

            m_SendMeas[Message.MessageSumCheck] = MyMath.CalculateSum(m_SendMeas, Message.MessageLength);

            m_MyTcpClientArm[indexBoard].ClientWrite(m_SendMeas);

            return(true);
        }