CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2014
    Posts
    4

    Button Command issue

    I am pressing a button which has a command built in to turn a servo on an arduino 90 degrees. It works no problem but after it moves on the console it still trys to send the command again and again and uses up its number of retries.
    Code:
     private void btnTurnServo0_Click_1(object sender, EventArgs e)
            {
                
               
                Cancel = false;
    
                if (DiscoverDevice(false) == false)
                {
                    MessageBox.Show("Error, device is not responding");
                    return;
                }
                string servo = "";
                MyModemSerialInterfaceLayer.WriteTextAndWaitForResponse("TL,S," + txtToolID.Text + ",30", "\r\n", 4, ref servo, 500);
                string Settings = "";
    
                MyModemSerialInterfaceLayer.WriteTextAndWaitForResponse("TL,T," + txtToolID.Text + "\r\n", "\r\n", 4, ref Settings, 500);
    
                ReleaseDevice();//release the config tool after config is completed
            }
    Code:
     while (true)
                {            
                    //looking for the RX Response from the UUT, indicating that the message was successfully received    
                    System.Threading.Thread.Sleep(1);
    
                  
                    if (Timer-- <= 0)//timed out, see if we can retry of simply fail
                    {
                        Parent.UpdateConsole("Retry Command\r\n");
    
                        if (NumberRetries-- > 0)
                        {
                            ReturnString = "";
                            TesterComPort.WriteLine(Command);//write command to UUT
                            Timer = TimeToWait;//reset counter
                        }
                        else
                        {
                            Parent.UpdateConsole("Used up Retries\r\n");
                            return false;//timed out
                        }
                    }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Button Command issue

    Where is the while(true) called? What causes the while loop to exit during a success?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured