The Enable button: enable an axis

It functions as an Enable or Disable button. After you select an axis and click this button, the axis will be enabled. If an axis has already been enabled, click to disable it.

The button's name is btnEnable, which has the signal clicked connected to two slots: btnEnableClicked and actionEnable. In btnEnableClicked, when Enable is clicked, it is disabled, and updateAxisData updates the button's state.

In updateAxisData, if Enable is disabled, we check the button's text. If it is "Enable," we set the text to "Disable" and enable this button, which means after Enable is clicked, the button is changed to Disable, and Jog Forward and Jog Backward are enabled. On the other hand, if the text is "Disable," we set the text to "Enable" and enable this button, which means after Disable is clicked, the button is changed to Enable, and the Jog buttons are disabled.

If Enable is enabled, we use the power state of the axis to determine what the button's text is, and whether the Jog buttons are enabled.

The following code is in QtGui.cpp:

void QtGui::btnEnableClicked()
{
   ui->btnEnable->setEnabled(false);
}

The following code is in QtGui.cpp:

void QtGui::updateAxisData(axisData data)
{
   if (!ui->btnEnable->isEnabled())
   {
      if (ui->btnEnable->text() == "Enable" && data.powerStatus)
      {
         ui->btnEnable->setText("Disable");
         ui->btnEnable->setEnabled(true);
         ui->btnJogForward->setEnabled(true);
         ui->btnJogBackward->setEnabled(true);
      }
      else if (ui->btnEnable->text() == "Disable" && !data.powerStatus)
      {
         ui->btnEnable->setText("Enable");
         ui->btnEnable->setEnabled(true);
         ui->btnJogForward->setEnabled(false);
         ui->btnJogBackward->setEnabled(false);
      }
   }
   else
   {
      if (data.powerStatus)
      {
         ui->btnEnable->setText("Disable");
         ui->btnJogForward->setEnabled(true);
         ui->btnJogBackward->setEnabled(true);
      }
      else
      {
         ui->btnEnable->setText("Enable");
         ui->btnJogForward->setEnabled(false);
         ui->btnJogBackward->setEnabled(false);
      }
   }
   .........
}

In actionEnable, to enable an axis, first we use ResetAxis to reset the alarm of the axis in case it has any error. Next, we use PowerAxis to enable the axis, and set its power state to TRUE. If the axis has been enabled, we use PowerAxis to disable the axis, and set its power state to FALSE. In case it takes too long for PowerAxis to run, we use WaitForCommand to give it a period of 1 second to complete. If it doesn't, the next command will be run.

The following code is in ksworker.cpp:

void ksWorker::actionEnable()
{
   if (powerStatus[currentIndex] == FALSE)
   {
      ResetAxis(currentIndex);
      KsCommandStatus Command = { 0 };
      Command = WaitForCommand(1, FALSE, PowerAxis(currentIndex, TRUE, TRUE, TRUE));

      if(Command.Done) 
         powerStatus[currentIndex] = TRUE;
   }
   else
   {
      KsCommandStatus Command = { 0 };
      Command = WaitForCommand(1, FALSE, PowerAxis(currentIndex, FALSE, FALSE, FALSE));

      if (Command.Done) 
         powerStatus[currentIndex] = FALSE;
   }
}