| | |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "AxisSettingsDlg.h" |
| | | #include "ToolUnits.h" |
| | | |
| | | |
| | | #define TIMER_INIT 1 |
| | | #define TIMER_READ_PLC_DATA 2 |
| | | |
| | | // CAxisSettingsDlg 对话框 |
| | | |
| | |
| | | { |
| | | m_nInitialWidth = 0; |
| | | m_nInitialHeight = 0; |
| | | m_pPLC = nullptr; |
| | | } |
| | | |
| | | CAxisSettingsDlg::~CAxisSettingsDlg() |
| | |
| | | ON_WM_SIZE() |
| | | ON_WM_CTLCOLOR() |
| | | ON_WM_SIZING() |
| | | ON_WM_TIMER() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | | // CAxisSettingsDlg 消息处理程序 |
| | | |
| | | void CAxisSettingsDlg::SetPLC(CPLC* pPLC) |
| | | { |
| | | ASSERT(pPLC); |
| | | m_pPLC = pPLC; |
| | | } |
| | | |
| | | BOOL CAxisSettingsDlg::OnInitDialog() |
| | | { |
| | |
| | | rect.bottom *= 1.5; |
| | | // 调整对话框大小 |
| | | MoveWindow(rect); |
| | | |
| | | SetTimer(TIMER_READ_PLC_DATA, 500, nullptr); |
| | | |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |
| | |
| | | pWnd->SetFont(&newFont); |
| | | pWnd->Invalidate(); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent) |
| | | { |
| | | if (TIMER_READ_PLC_DATA == nIDEvent) { |
| | | ASSERT(m_pPLC); |
| | | |
| | | int addr1, addr2, readSize; |
| | | addr1 = 5120; |
| | | addr2 = 5425; |
| | | readSize = (addr2 - addr1 + 1) * 2; |
| | | auto funOnReadData = [&, addr1, readSize](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void { |
| | | if (nDataSize == readSize && flag == 0) { |
| | | double fCurPos = CToolUnits::toInt32(pData) * 0.001; |
| | | double fManualSpeed = CToolUnits::toInt32(&pData[(5422- addr1)*2]) * 0.001; |
| | | double fAutoSpeed = CToolUnits::toInt32(&pData[(5424 - addr1) * 2]) * 0.001; |
| | | double fPrm = CToolUnits::toInt32(&pData[(5150 - addr1) * 2]) * 0.1; |
| | | int nLoad = CToolUnits::toInt16(&pData[(5154 - addr1) * 2]); |
| | | int nErrCode = CToolUnits::toInt16(&pData[(5126 - addr1) * 2]); |
| | | int nAlarmCode = CToolUnits::toInt16(&pData[(5127 - addr1) * 2]); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_POS, fCurPos); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_MANUAL_SPEED, fManualSpeed); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_AUTO_SPEED, fAutoSpeed); |
| | | CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_ROTA_SPEED, fPrm); |
| | | SetDlgItemInt(IDC_EDIT_AXIS_CURR_LOAD, nLoad); |
| | | SetDlgItemInt(IDC_EDIT_AXIS_CURR_ERROR_NUMBER, nErrCode); |
| | | SetDlgItemInt(IDC_EDIT_AXIS_CURR_ALARM_NUMBER, nAlarmCode); |
| | | } |
| | | }; |
| | | m_pPLC->readData(MC::SOFT_COMPONENT::D, addr1, readSize, funOnReadData); |
| | | } |
| | | |
| | | CDialogEx::OnTimer(nIDEvent); |
| | | } |