The Jog buttons: jog motion
Two jog buttons are used for jog motion: one for jog forward and another for jog backward. The behavior of the buttons can be customized. In this sample, the buttons are used this way:
- Jog: press and hold the left mouse button.
- Stop jogging: release the left mouse button.
Because we don't use the click behavior, the code is not written in the OnBnClicked function. Instead, we use PreTranslateMessage to receive the mouse event. When the left mouse button is pressed and held, JogAxis is used to jog the axis forward or backward. When the button is released, HaltAxis is used to stop jogging. The command velocity is received from m_CMD_VEL, which is converted to a double-precision floating-point number.
BOOL CMFC_GUIDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_LBUTTONDOWN)
{
if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_F)->m_hWnd)
{
int Mindex = m_MotorList.GetCurSel();
//Commands a never-ending controlled motion at a specified velocity.
::JogAxis(Mindex, double(m_CMD_VEL), 36000, 36000, 3600000, mcPositiveDirection);
}
if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_B)->m_hWnd)
{
int Mindex = m_MotorList.GetCurSel();
//Commands a never-ending controlled motion at a specified velocity.
::JogAxis(Mindex, double(m_CMD_VEL), 36000, 36000, 3600000, mcNegativeDirection);
}
}
if (pMsg->message == WM_LBUTTONUP)
{
if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_F)->m_hWnd)
{
int Mindex = m_MotorList.GetCurSel();
//Commands a controlled motion stop.
::HaltAxis(Mindex, 3600, 360000, mcAborting);
}
if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_B)->m_hWnd)
{
int Mindex = m_MotorList.GetCurSel();
//Commands a controlled motion stop.
::HaltAxis(Mindex, 3600, 360000, mcAborting);
}
}
return CDialog::PreTranslateMessage(pMsg);
}