Example #1
0
        /// <summary>
        /// 微笑,这个函数存在的原因是网上魔改的buttonEnabled函数无法在线程中使用,只能在定时器定时刷新
        /// </summary>
        /// <param name="button"></param>
        /// <param name="button_state"></param>
        private void button_Enabled_Text_Set(System.Windows.Forms.Button button, ROBOT_State button_state)
        {
            switch (button_state)
            {
            case ROBOT_State.Off_line:
            {
                SetControlEnabled(button, false);
                button.Text = button.Text.Split('\n')[0] + "\noff-line";
                break;
            }

            case ROBOT_State.On_line_alive:
            {
                SetControlEnabled(button, true);
                button.Text = button.Text.Split('\n')[0] + "\nalive";
                break;
            }

            case ROBOT_State.On_line_controlled:
            {
                SetControlEnabled(button, true);
                button.Text = button.Text.Split('\n')[0] + "\ncontroled";
                break;
            }

            default:
            {
                break;
            }
            }
        }
Example #2
0
        private void timer_MsgSend_Tick(object sender, EventArgs e)
        {
            if (IsKeyDown(Keys.W))//前
            {
                commonVx = MOTION_SPEED + 1000;
            }
            else if (IsKeyDown(Keys.S))
            {
                commonVx = -MOTION_SPEED + 1000;
            }
            else
            {
                //commonVx = 1000;//回中放在UP事件中
            }

            if (IsKeyDown(Keys.D))//右
            {
                commonVy = MOTION_SPEED + 1000;
            }
            else if (IsKeyDown(Keys.A))
            {
                commonVy = -MOTION_SPEED + 1000;
            }

            if (IsKeyDown(Keys.NumPad6) || IsKeyDown(Keys.E))//顺  //D6是一排数字键,NumPad6是小键盘区6
            {
                commonVw = MOTION_SPEED + 1000;
            }
            else if (IsKeyDown(Keys.NumPad4) || IsKeyDown(Keys.Q))
            {
                commonVw = -MOTION_SPEED + 1000;
            }

            if (RobotInfo[(int)msgSendRovotIndex].On_line_state == ROBOT_State.On_line_controlled)
            {
                sendMsgArray[0] = 0x5A;
                sendMsgArray[1] = 0x00;
                sendMsgArray[2] = (byte)(msgSendRovotIndex + 1);
                sendMsgArray[3] = (Byte)(commonVx >> 8);
                sendMsgArray[4] = (Byte)(commonVx);
                sendMsgArray[5] = (Byte)(commonVy >> 8);
                sendMsgArray[6] = (Byte)(commonVy);
                sendMsgArray[7] = (Byte)(commonVw >> 8);
                sendMsgArray[8] = (Byte)(commonVw);
                serial.Write(sendMsgArray, 0, 9);
            }


            msgSendRovotIndex++;
            if ((int)msgSendRovotIndex > 3)   //只检索ID 0-3
            {
                msgSendRovotIndex = 0;
            }
        }
Example #3
0
        private void button_color_set(System.Windows.Forms.Button button, ROBOT_State button_state)
        {
            //button.Name.Length//可以通过长度、字符串识别来识别传入的按钮属于什么684835
            switch (button_state)
            {
            case ROBOT_State.Off_line:
            {
                button.BackColor = Color.FromArgb(65, 65, 65);         //灰色 disconnect
                button.ForeColor = Color.FromArgb(140, 140, 140);      //160 160 160
                //button.Enabled = false;
                //SetControlEnabled(button, false);
                //button.Text = button.Text.Split('\n')[0]+ "\noff-line";//f**k this!线程中连按钮文本都不能改变????服  了
                break;
            }

            case ROBOT_State.On_line_alive:
            {
                button.BackColor = Color.FromArgb(2, 80, 120);         //浅色alive 20 140 210
                button.ForeColor = Color.FromArgb(160, 160, 160);      //160 160 160 字体颜色//200 200 200
                // button.Enabled = false;
                //SetControlEnabled(button, false);//转移到定时器里了

                //button.Text = button.Text.Split('\n')[0] + "\nhas_occupied";//f**k this!线程中连按钮文本都不能改变????服  了

                break;
            }

            case ROBOT_State.On_line_controlled:
            {
                button.BackColor = Color.FromArgb(2, 131, 201);
                button.ForeColor = Color.FromArgb(243, 249, 252);        //46 58 132
                // button.Enabled = false;
                //SetControlEnabled(button, false); //转移到定时器里去了

                //button.Text = button.Text.Split('\n')[0] + "\nconnect_OK";//f**k this!线程中连按钮文本都不能改变????服  了
                /////////////////////////button.Text = button.Text.Replace("click_connect", "off-line");
                break;
            }

            default:
            {
                break;
            }
            }
        }
Example #4
0
 private void test_button_Click(object sender, EventArgs e)
 {
     test_button_state++;
     if (test_button_state == ROBOT_State.ROBOT_State_num)
     {
         test_button_state = 0;
     }
     test_button.Text = test_button_state.ToString();
     button_color_set(btnRobot1State, test_button_state);
     button_color_set(btnRobot2State, test_button_state);
     button_color_set(btnRobot3State, test_button_state);
     button_color_set(btnRobot4State, test_button_state);
     button_color_set(btnRobot5State, test_button_state);
     button_color_set(btnRobot6State, test_button_state);
     button_color_set(btnRobot7State, test_button_state);
     button_color_set(btnRobot8State, test_button_state);
     button_Enabled_Text_Set(btnRobot1State, test_button_state);
     button_Enabled_Text_Set(btnRobot2State, test_button_state);
 }