The Enable button: enable an axis
The Enable button functions as an Enable or Disable button, depending on whether the axis is enabled or disabled. When an axis is disabled, click Enable to enable it. If an axis is already enabled, click Disable to disable it.
The method of this button is btnENABLE_Click. You need to enable an axis before you start any motion. We declare the variable Mindex
to receive the index of an axis.
Next, we check the state of the axis. In the StatusWord object, the third bit (bit 2) is "operation enabled." If this bit is true, the axis has been enabled. In this case, when Mindex
is equal to or greater than zero, and the third bit is true, it means there is at least one axis is in the list and the axis has been enabled, so the button is Disable. If the third bit is false, the button is Enable. PowerAxis is used to enable and disable the axis. If the Mindex
is less than zero, it means there is no axis in the list, the text of the Connect button is changed to "Connect."
To know whether the third bit is true, we use the bitwise AND operator. The condition "((KSMServo(Mindex).Value And &H4) >> 2 = &H1) = True
" is described below:
- Perform a logical AND operation for the value of the selected axis and the hex value
&H4
. - Take the result from the AND operation and shift the bits of the value two positions to the right.
- After shifting the bits, check whether it is equal to the hex value
&H1
. If it is true, run the following code.
Private Sub btnENABLE_Click(sender As Object, e As EventArgs) Handles btnENABLE.Click
Dim Mindex As Integer = lbMList.SelectedIndex
If (((KSMServo(Mindex).Value And &H4) >> 2 = &H1) = True) Then
'Enables or disables the operation of an axis.
Command = KS_API.WaitForCommand(1, False, motion.PowerAxis(Mindex, False, True, True))
If Not Command.Done Then
lbErrorStatus.Text = "Failed to enable the axis: " + Command.ErrorId.ToString("X")
Return
End If
Else
'Enables or disables the operation of an axis.
Command = KS_API.WaitForCommand(1, False, motion.PowerAxis(Mindex, True, True, True))
If Not Command.Done Then
lbErrorStatus.Text = "Failed to enable the axis: " + Command.ErrorId.ToString("X")
Return
End If
End If
End Sub
Private Sub t_Staus_Tick(sender As Object, e As EventArgs) Handles t_Staus.Tick
...........
If Mindex >= 0 Then
If (((KSMServo(Mindex).Value And &H4) >> 2 = &H1) = True) Then
btnENABLE.Text = "Disable"
Else
btnENABLE.Text = "Enable"
End If
Else
btnConnect.Text = "Connect"
End If
...........
End Sub