List Box:裝置清單
List Box 用以顯示裝置清單,m_MotorList 變數控制 List Box,我們使用此變數在計時器 60(60 為計時器的 ID)被呼叫時擷取裝置清單,並使用變數 Mindex 來接收結果。
if (nIDEvent == 60)
{
int Mindex = m_MotorList.GetCurSel();
.........
}
連接狀態變更為 Op 後,我們使用 Mindex 來檢查已連結硬體的索引,若至少有一個裝置存在,則我們使用 ReadAxisStatusWord 讀取 Statusword 變數,並用 ReadAxisActualPosition 與 ReadAxisActualVelocity 獲得實際位置和實際速度,我們宣告 CString 變數 ReadStr 以儲存位置和速度值,接著將此二值傳送至 IDC_ACT_POS 和 IDC_ACT_VEL 編輯控制 (Edit Control)。
if (Mindex >= 0)
{
//Reads the status word from an axis.
::ReadAxisStatusWord(Mindex, &KSMServo[Mindex]);
//Reads the current position from an axis using the primary encoder.
::ReadAxisActualPosition(Mindex, &PositionValue[Mindex]);
//Reads the actual velocity from an axis.
::ReadAxisActualVelocity(Mindex, &VelocityValue[Mindex]);
CString ReadStr;
ReadStr.Format(_T("%d"), PositionValue[Mindex]);
GetDlgItem(IDC_ACT_POS)->SetWindowText(ReadStr);
ReadStr.Format(_T("%d"), VelocityValue[Mindex]);
GetDlgItem(IDC_ACT_VEL)->SetWindowText(ReadStr);
}