From ce3793790d007a89ccfa483fdb802bf5f778a4c1 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期二, 10 十二月 2024 11:29:03 +0800
Subject: [PATCH] 1.配方管理类中定位点添加标识符 2.axis设定读取不可写的定位点数据,并且刷新 3. 完善axis细部设定界面资源
---
/dev/null | 130 ---------------------
SourceCode/Bond/BondEq/Resource.h | 0
SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp | 64 ++++++++++
SourceCode/Bond/BondEq/BondEq.rc | 0
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 79 ++++++++----
SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.h | 7 +
SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp | 23 ++-
SourceCode/Bond/BondEq/FileManager/RecipeManager.h | 8 +
8 files changed, 144 insertions(+), 167 deletions(-)
diff --git a/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp
deleted file mode 100644
index 36e7b07..0000000
--- a/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp
+++ /dev/null
@@ -1,1116 +0,0 @@
-锘�// AxisSettingsDlg.cpp: 瀹炵幇鏂囦欢
-//
-
-#include "stdafx.h"
-#include "BondEq.h"
-#include "afxdialogex.h"
-#include "AxisSettingsDlg.h"
-#include "ToolUnits.h"
-#include <cctype>
-#include <algorithm>
-
-#define TIMER_INIT 1
-#define TIMER_READ_PLC_DATA 2
-#define TIMER_JOG_ADD 3
-#define TIMER_JOG_SUB 4
-
-// OnUpdateDataToUI
-#define ID_MSG_UPDATA_DATA_TO_UI WM_USER + 101
-
-// CAxisSettingsDlg 瀵硅瘽妗�
-
-IMPLEMENT_DYNAMIC(CAxisSettingsDlg, CDialogEx)
-
-CAxisSettingsDlg::CAxisSettingsDlg(CWnd* pParent /*=nullptr*/)
- : CDialogEx(IDD_DIALOG_AXIS_SETTINGS, pParent)
-{
- m_nInitialWidth = 0;
- m_nInitialHeight = 0;
- m_pPLC = nullptr;
-
- m_bSEV = FALSE;
- m_fCurPos = 0.0;
- m_fManualSpeed = 0.0;
- m_fAutoSpeed = 0.0;
- m_fPrm = 0.0;
- m_nLoad = 0;
- m_nErrCode = 0;
- m_nAlarmCode = 0;
- m_bFLS = FALSE;
- m_bDOG = FALSE;
- m_bRLS = FALSE;
- m_bReady = FALSE;
- m_bBusy = FALSE;
- m_bErr = FALSE;
-}
-
-CAxisSettingsDlg::~CAxisSettingsDlg()
-{
- for (auto& pair : m_mapFonts) {
- if (pair.second) {
- pair.second->DeleteObject();
- delete pair.second;
- }
- }
- m_mapFonts.clear();
-}
-
-void CAxisSettingsDlg::SetPLC(CPLC* pPLC)
-{
- ASSERT(pPLC);
- m_pPLC = pPLC;
-}
-
-void CAxisSettingsDlg::SetRecipeName(const CString& strRecipeName)
-{
- m_strRecipeName = strRecipeName;
-}
-
-void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX)
-{
- CDialogEx::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_STATIC_AXIS_TEST_FLS, m_staticFLS);
- DDX_Control(pDX, IDC_STATIC_AXIS_TEST_DOG, m_staticDOG);
- DDX_Control(pDX, IDC_STATIC_AXIS_TEST_RLS, m_staticRLS);
- DDX_Control(pDX, IDC_STATIC_AXIS_TEST_READY, m_staticReady);
- DDX_Control(pDX, IDC_STATIC_AXIS_TEST_BUSY, m_staticBusy);
- DDX_Control(pDX, IDC_STATIC_AXIS_TEST_ERR, m_staticErr);
- DDX_Control(pDX, IDC_COMBO_AXIS_NAME, m_comboAxisNO);
- DDX_Control(pDX, IDC_STATIC_AXIS_NUMBER, m_staticAxisNO);
- DDX_Control(pDX, IDC_STATIC_AXIS_DESCRIP, m_staticAxisDescription);
- DDX_Control(pDX, IDC_STATIC_START_ADDRESS, m_staticStartAddress);
- DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_POS, m_editManualSpeed);
- DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_AUTO_SPEED, m_editAutoSpeed);
- DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_ACCE_TIME, m_editAccelerationTime);
- DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_DECE_TIME, m_editDecelerationTime);
- DDX_Control(pDX, IDC_EDIT_AXIS_MODITFY_MICROMENTUM, m_editJogDistance);
- DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, m_pageButtons[0]);
- DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP2, m_pageButtons[1]);
- DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP3, m_pageButtons[2]);
- DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP4, m_pageButtons[3]);
- DDX_Control(pDX, IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP5, m_pageButtons[4]);
-}
-
-UINT CAxisSettingsDlg::FindIDByName(const CString& strControlID)
-{
- // 灏嗚祫婧愭枃浠朵腑瀹氫箟鐨勬帶浠跺悕绉板拰 ID 鍔犺浇鍒颁竴涓槧灏勪腑
- static const std::map<CString, UINT> controlIdMap = {
- {"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP1", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP1},
- {"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP2", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP2},
- {"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP3", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP3},
- {"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP4", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP4},
- {"IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP5", IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP5},
- {"IDC_EDIT_AXIS_ANCHOR_POINT1", IDC_EDIT_AXIS_ANCHOR_POINT1},
- {"IDC_EDIT_AXIS_ANCHOR_POINT2", IDC_EDIT_AXIS_ANCHOR_POINT2},
- {"IDC_EDIT_AXIS_ANCHOR_POINT3", IDC_EDIT_AXIS_ANCHOR_POINT3},
- {"IDC_EDIT_AXIS_ANCHOR_POINT4", IDC_EDIT_AXIS_ANCHOR_POINT4},
- {"IDC_EDIT_AXIS_ANCHOR_POINT5", IDC_EDIT_AXIS_ANCHOR_POINT5}
- // 鍙互缁х画娣诲姞鍏朵粬鎺т欢鍚嶇О鍜� ID
- };
-
- // 鏌ユ壘鎺т欢鍚嶇О鏄惁鍦ㄦ槧灏勪腑
- auto it = controlIdMap.find(strControlID);
- if (it != controlIdMap.end()) {
- return it->second;
- }
-
- return 0;
-}
-
-CFont* CAxisSettingsDlg::GetOrCreateFont(int nFontSize)
-{
- auto it = m_mapFonts.find(nFontSize);
- if (it != m_mapFonts.end()) {
- return it->second;
- }
-
- CFont* font = new CFont();
- LOGFONT logFont = { 0 };
- _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
- logFont.lfHeight = -nFontSize;
- logFont.lfQuality = CLEARTYPE_QUALITY;
- font->CreateFontIndirect(&logFont);
- m_mapFonts[nFontSize] = font;
-
- return font;
-}
-
-void CAxisSettingsDlg::SetDefaultFont()
-{
- CFont* defaultFont = GetOrCreateFont(12);
-
- // 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
- CWnd* pWnd = GetWindow(GW_CHILD);
- while (pWnd) {
- pWnd->SetFont(defaultFont, TRUE);
- pWnd = pWnd->GetNextWindow();
- }
-}
-
-void CAxisSettingsDlg::AdjustControls(float dScaleX, float dScaleY)
-{
- CWnd* pWnd = GetWindow(GW_CHILD);
- while (pWnd) {
- int nCtrlID = pWnd->GetDlgCtrlID();
- if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end())
- {
- CRect originalRect = m_mapCtrlLayouts[nCtrlID];
- CRect newRect(
- static_cast<int>(originalRect.left * dScaleX),
- static_cast<int>(originalRect.top * dScaleY),
- static_cast<int>(originalRect.right * dScaleX),
- static_cast<int>(originalRect.bottom * dScaleY));
-
- TCHAR szClassName[256];
- GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
-
- if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
- CComboBox* pComboBox = (CComboBox*)pWnd;
- pComboBox->SetItemHeight(-1, newRect.Height()); // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
- }
-
- pWnd->MoveWindow(&newRect);
- AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
- }
- pWnd = pWnd->GetNextWindow();
- }
-}
-
-void CAxisSettingsDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight)
-{
- // 鏍规嵁鎺т欢楂樺害鍔ㄦ�佽皟鏁村瓧浣撳ぇ灏�
- int fontSize = nHeight / 2;
- if (fontSize < 8) fontSize = 8;
- if (fontSize > 24) fontSize = 24; // 鏈�澶у瓧浣撳ぇ灏�
-
- // 鑾峰彇鎴栧垱寤哄瓧浣�
- CFont* pFont = GetOrCreateFont(fontSize);
-
- pWnd->SetFont(pFont);
- pWnd->Invalidate(); // 鍒锋柊鎺т欢鏄剧ず
-}
-
-void CAxisSettingsDlg::AdjustLabelFont(CBLLabel& label)
-{
- // 鑾峰彇鎺т欢鐨勭煩褰㈠尯鍩�
- CRect rect;
- label.GetClientRect(&rect);
-
- // 鍔ㄦ�佽绠楀瓧浣撳ぇ灏忥紝鍩轰簬鎺т欢鐨勯珮搴�
- int fontSize = rect.Height() / 2; // 鎺т欢楂樺害鐨勪竴鍗婁綔涓哄瓧浣撳ぇ灏�
- if (fontSize < 8) fontSize = 8; // 鏈�灏忓瓧浣撳ぇ灏�
- if (fontSize > 30) fontSize = 30; // 鏈�澶у瓧浣撳ぇ灏�
-
- // 璁剧疆瀛椾綋澶у皬
- label.SetFontSize(fontSize);
-
- // 鍒锋柊鎺т欢鏄剧ず
- label.Invalidate();
- label.UpdateWindow();
-}
-
-void CAxisSettingsDlg::SetLabelColor(CBLLabel& label, COLORREF color)
-{
- label.SetBkColor(color);
- label.Invalidate(); // 鏍囪鍖哄煙鏃犳晥
- label.UpdateWindow(); // 绔嬪嵆鍒锋柊
-}
-
-void CAxisSettingsDlg::updatePageButtonStates()
-{
- for (int i = 0; i < 5; ++i) {
- if (i + 1 == m_currentPage) {
- m_pageButtons[i].SetFaceColor(RGB(0, 122, 204)); // 閫変腑鑳屾櫙鑹诧紙钃濊壊锛�
- }
- else {
- m_pageButtons[i].SetFaceColor(RGB(240, 240, 240)); // 榛樿鑳屾櫙鑹�
- }
-
- m_pageButtons[i].Invalidate();
- }
-}
-
-int CAxisSettingsDlg::getCurrentSelectedAxisID()
-{
- int currentIndex = m_comboAxisNO.GetCurSel();
- if (currentIndex == CB_ERR) {
- return -1;
- }
-
- CString strAxisIDStr;
- m_comboAxisNO.GetLBText(currentIndex, strAxisIDStr);
- return _ttoi(strAxisIDStr);
-}
-
-void CAxisSettingsDlg::initializeAxisIDCombo()
-{
- // 妫�鏌ラ厤鏂规槸鍚﹀姞杞芥垚鍔�
- RecipeManager& recipeManager = RecipeManager::getInstance();
- if (m_strRecipeName.IsEmpty() || !recipeManager.loadRecipe(std::string(CT2A(m_strRecipeName)))) {
- AfxMessageBox(_T("鍔犺浇閰嶆柟澶辫触锛�"));
- return;
- }
-
- // 鑾峰彇鎵�鏈夎酱鐨勭紪鍙�
- auto axisNumbers = recipeManager.getAllAxisID();
-
- // 娓呯┖涓嬫媺妗�
- m_comboAxisNO.ResetContent();
-
- // 濉厖鏁版嵁鍒颁笅鎷夋
- for (const auto& axisID : axisNumbers) {
- CString axisCString;
- axisCString.Format(_T("%d"), axisID);
- m_comboAxisNO.AddString(axisCString);
- }
-
- // 榛樿閫夋嫨绗竴椤�
- if (m_comboAxisNO.GetCount() > 0) {
- m_comboAxisNO.SetCurSel(0);
- }
-}
-
-void CAxisSettingsDlg::refreshAxisDetails(int nAxisId)
-{
- // 鑾峰彇杞存暟鎹�
- RecipeManager& recipeManager = RecipeManager::getInstance();
- auto axisDetails = recipeManager.getAxis(nAxisId);
-
- auto formatDouble = [](double value) -> CString {
- CString str;
- str.Format(_T("%.3f"), value);
- return str;
- };
-
- // 鏇存柊鎺т欢鏄剧ず
- m_staticAxisNO.SetWindowText(CString(axisDetails.number.c_str())); // 杞寸紪鍙�
- m_staticAxisDescription.SetWindowText(CString(axisDetails.description.c_str())); // 杞存弿杩�
- m_staticStartAddress.SetWindowText(CString(axisDetails.startAddress.c_str())); // 璧峰鍦板潃
- m_editJogDistance.SetWindowText(formatDouble(axisDetails.jogDistance)); // 寰姩閲�
- m_editManualSpeed.SetWindowText(formatDouble(axisDetails.manualSpeed)); // 鎵嬪姩閫熷害
- m_editAutoSpeed.SetWindowText(formatDouble(axisDetails.autoSpeed)); // 鑷姩閫熷害
- m_editAccelerationTime.SetWindowText(formatDouble(axisDetails.accelerationTime)); // 鍔犻�熸椂闂�
- m_editDecelerationTime.SetWindowText(formatDouble(axisDetails.decelerationTime)); // 鍑忛�熸椂闂�
-}
-
-void CAxisSettingsDlg::refreshPositionDetails(int nAxisId, int pageNumber)
-{
- RecipeManager& recipeManager = RecipeManager::getInstance();
- // 姣忛〉鏄剧ず鐨勫畾浣嶇偣鏁伴噺
- const int pageSize = 5;
-
- // 鑾峰彇瀹氫綅鐐规暟鎹�
- auto positions = recipeManager.getPositions(nAxisId, pageNumber, pageSize);
-
- // 鍒锋柊 UI
- for (int i = 0; i < pageSize; ++i) {
- CString descriptionCtrlName, positionCtrlName;
- descriptionCtrlName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP%d"), i + 1);
- positionCtrlName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
-
- UINT descriptionCtrlId = FindIDByName(descriptionCtrlName);
- UINT positionCtrlId = FindIDByName(positionCtrlName);
-
- CWnd* pDescriptionCtrl = GetDlgItem(descriptionCtrlId);
- CWnd* pPositionCtrl = GetDlgItem(positionCtrlId);
-
- if (i < positions.size()) {
- CString description = CString(positions[i].first.c_str());
- CString value;
- value.Format(_T("%.3f"), positions[i].second);
-
- if (pDescriptionCtrl) pDescriptionCtrl->SetWindowText(description);
- if (pPositionCtrl) pPositionCtrl->SetWindowText(value);
- }
- else {
- if (pDescriptionCtrl) pDescriptionCtrl->SetWindowText(_T(""));
- if (pPositionCtrl) pPositionCtrl->SetWindowText(_T(""));
- }
- }
-}
-
-void CAxisSettingsDlg::updateAxisSelection(int offset)
-{
- int currentIndex = m_comboAxisNO.GetCurSel();
- if (currentIndex == CB_ERR) {
- AfxMessageBox(_T("璇烽�夋嫨涓�涓湁鏁堢殑杞寸紪鍙凤紒"));
- return;
- }
-
- int newIndex = currentIndex + offset;
- if (newIndex < 0 || newIndex >= m_comboAxisNO.GetCount()) {
- CString error;
- error.Format(_T("宸茬粡鍒拌揪%s涓�涓酱锛�"), offset < 0 ? _T("涓�") : _T("涓�"));
- AfxMessageBox(error);
- return;
- }
-
- m_comboAxisNO.SetCurSel(newIndex);
- refreshAxisDetails(newIndex + 1);
- refreshPositionDetails(newIndex + 1, m_currentPage);
- updatePageButtonStates();
-}
-
-void CAxisSettingsDlg::updateDataFromUI(int nAxisId)
-{
- const int pageSize = 5; // 姣忛〉鏄剧ず 5 涓畾浣嶇偣
-
- RecipeManager& recipeManager = RecipeManager::getInstance();
- auto axisData = recipeManager.getAxis(nAxisId);
-
- // 鑾峰彇鐣岄潰涓婄殑淇敼鍙傛暟
- CString text;
- m_editManualSpeed.GetWindowText(text);
- axisData.manualSpeed = _ttof(text);
-
- m_editAutoSpeed.GetWindowText(text);
- axisData.autoSpeed = _ttof(text);
-
- m_editAccelerationTime.GetWindowText(text);
- axisData.accelerationTime = _ttof(text);
-
- m_editDecelerationTime.GetWindowText(text);
- axisData.decelerationTime = _ttof(text);
-
- m_editJogDistance.GetWindowText(text);
- axisData.jogDistance = _ttof(text);
-
- // 鏇存柊瀹氫綅鐐规暟鎹�
- for (int i = 0; i < pageSize; ++i) {
- int index = (m_currentPage - 1) * pageSize + i;
-
- if (index < axisData.positions.size()) {
- CString descriptionName, positionName;
- descriptionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP%d"), i + 1);
- positionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
-
- CEdit* pDescriptionEdit = (CEdit*)GetDlgItem(FindIDByName(descriptionName));
- CEdit* pPositionEdit = (CEdit*)GetDlgItem(FindIDByName(positionName));
-
- if (pDescriptionEdit && pPositionEdit) {
- CString description, positionValue;
- pDescriptionEdit->GetWindowText(description);
- pPositionEdit->GetWindowText(positionValue);
-
- // 鏇存柊 RecipeManager 涓殑鏁版嵁
- axisData.positions[index].first = CT2A(description);
- axisData.positions[index].second = _ttof(positionValue);
- }
- }
- }
-
- // 淇濆瓨鍥� RecipeManager
- recipeManager.updateAxis(axisData);
-}
-
-void CAxisSettingsDlg::switchToPage(int targetPage)
-{
- try {
- // 濡傛灉褰撳墠椤甸潰宸茬粡鏄洰鏍囬〉闈紝鐩存帴杩斿洖
- if (m_currentPage == targetPage) {
- return;
- }
-
- // 鑾峰彇褰撳墠閫変腑鐨勮酱 ID
- int axisId = getCurrentSelectedAxisID();
- if (axisId == -1) {
- AfxMessageBox(_T("璇烽�夋嫨涓�涓湁鏁堢殑杞寸紪鍙凤紒"));
- return;
- }
-
- // 鏇存柊 UI 鏁版嵁鍒板唴瀛�
- updateDataFromUI(axisId);
-
- // 鍒囨崲椤甸潰
- m_currentPage = targetPage;
- refreshPositionDetails(axisId, targetPage);
- updatePageButtonStates();
- }
- catch (const std::exception& ex) {
- CString errorMsg;
- errorMsg.Format(_T("鍒锋柊瀹氫綅缁�%d澶辫触锛�%s"), targetPage, CString(ex.what()));
- AfxMessageBox(errorMsg, MB_ICONERROR);
- }
-}
-
-bool CAxisSettingsDlg::ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr)
-{
- if (address.GetLength() < 2) {
- return false;
- }
-
- // 鎻愬彇缁勪欢绫诲瀷锛堢涓�涓瓧绗︼級
- TCHAR componentChar = address[0];
- if (address.Left(2) == _T("ZR")) {
- component = MC::SOFT_COMPONENT::ZR;
- // 鎻愬彇鏁板瓧閮ㄥ垎锛堝幓闄R鍓嶇紑锛�
- CString numericAddress = address.Mid(2);
- addr = _ttoi(numericAddress);
- return addr != 0 || numericAddress.CompareNoCase(_T("0")) == 0; // 濡傛灉鏄� "0"锛屼篃璁や负鏈夋晥
- }
-
- // 瀵逛簬鍏朵粬缁勪欢锛屾寜鐓у父瑙勮鍒欏鐞�
- CString hexAddress = address.Mid(1);
- switch (componentChar) {
- case 'D':
- component = MC::SOFT_COMPONENT::D;
- addr = _ttoi(hexAddress);
- break;
- case 'M':
- component = MC::SOFT_COMPONENT::M;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'X':
- component = MC::SOFT_COMPONENT::X;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'Y':
- component = MC::SOFT_COMPONENT::Y;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'W':
- component = MC::SOFT_COMPONENT::W;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'L':
- component = MC::SOFT_COMPONENT::L;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'S':
- component = MC::SOFT_COMPONENT::S;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'B':
- component = MC::SOFT_COMPONENT::B;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- case 'F':
- component = MC::SOFT_COMPONENT::F;
- addr = _tcstoul(hexAddress, nullptr, 16);
- break;
- default:
- return false;
- }
-
- // 妫�鏌ュ湴鍧�鏄惁鏈夋晥
- if (addr == 0 && hexAddress.CompareNoCase(_T("0")) != 0) {
- return false;
- }
-
- return true;
-}
-
-void CAxisSettingsDlg::writeAxisDataToPLC(int nAxisId)
-{
- // 浠� RecipeManager 鑾峰彇杞存暟鎹�
- RecipeManager& recipeManager = RecipeManager::getInstance();
- auto axisData = recipeManager.getAxis(nAxisId);
-
- int startAddress;
- MC::SOFT_COMPONENT component;
- if (!ParsePLCAddress(CString(axisData.startAddress.c_str()), component, startAddress)) {
- AfxMessageBox(_T("鏃犳晥鐨勮捣濮嬪湴鍧�锛�"));
- }
-
- // 鍐欏叆鎵嬪姩閫熷害
- m_pPLC->writeDWord(component, startAddress + 82, (int)axisData.manualSpeed * 1000, [](IMcChannel* pChannel, int addr, DWORD value, int flag) {
- if (flag == 0) {
- TRACE("\n鍐欏叆鎴愬姛: 鎵嬪姩閫熷害, 鍦板潃: %d, 鍊�: %lu\n", addr, value);
- }
- else {
- TRACE("\n鍐欏叆澶辫触: 鎵嬪姩閫熷害, 鍦板潃: %d, 閿欒鐮�: %d\n", addr, flag);
- }
- });
-
- // 鍐欏叆鑷姩閫熷害
- m_pPLC->writeDWord(component, startAddress + 84, (int)(axisData.autoSpeed * 1000.0), [](IMcChannel* pChannel, int addr, DWORD value, int flag) {
- if (flag == 0) {
- TRACE("\n鍐欏叆鎴愬姛: 鑷姩閫熷害, 鍦板潃: %d, 鍊�: %lu\n", addr, value);
- }
- else {
- TRACE("\n鍐欏叆澶辫触: 鑷姩閫熷害, 鍦板潃: %d, 閿欒鐮�: %d\n", addr, flag);
- }
- });
-
- // 鍐欏叆鍔犻�熸椂闂�, 杞崲涓烘绉�
- m_pPLC->writeDWord(component, startAddress + 62, (int)(axisData.accelerationTime * 1000.0), [](IMcChannel* pChannel, int addr, DWORD value, int flag) {
- if (flag == 0) {
- TRACE("\n鍐欏叆鎴愬姛: 鍔犻�熸椂闂�, 鍦板潃: %d, 鍊�: %lu\n", addr, value);
- }
- else {
- TRACE("\n鍐欏叆澶辫触: 鍔犻�熸椂闂�, 鍦板潃: %d, 閿欒鐮�: %d\n", addr, flag);
- }
- });
-
- // 鍐欏叆鍑忛�熸椂闂�, 杞崲涓烘绉�
- m_pPLC->writeDWord(component, startAddress + 64, (int)(axisData.decelerationTime * 1000.0), [](IMcChannel* pChannel, int addr, DWORD value, int flag) {
- if (flag == 0) {
- TRACE("\n鍐欏叆鎴愬姛: 鍑忛�熸椂闂�, 鍦板潃: %d, 鍊�: %lu\n", addr, value);
- }
- else {
- TRACE("\n鍐欏叆澶辫触: 鍑忛�熸椂闂�, 鍦板潃: %d, 閿欒鐮�: %d\n", addr, flag);
- }
- });
-
- // 鍐欏叆寰姩閲�
- m_pPLC->writeWord(component, startAddress + 81, (int)(axisData.jogDistance * 1000.0), [](IMcChannel* pChannel, int addr, DWORD value, int flag) {
- if (flag == 0) {
- TRACE("\n鍐欏叆鎴愬姛: 寰姩閲�, 鍦板潃: %d, 鍊�: %lu\n", addr, value);
- }
- else {
- TRACE("\n鍐欏叆澶辫触: 寰姩閲�, 鍦板潃: %d, 閿欒鐮�: %d\n", addr, flag);
- }
- });
-
- // 鍐欏叆瀹氫綅鐐规暟鎹�
- int positionStartAddress = startAddress + 100;
- for (size_t i = 0; i < axisData.positions.size(); ++i) {
- const auto& position = axisData.positions[i];
- unsigned int positionAddress = positionStartAddress + (i * 2);
-
- m_pPLC->writeDWord(component, positionAddress, (int)(position.second * 1000), [i, positionAddress](IMcChannel* pChannel, int addr, DWORD value, int flag) {
- if (flag == 0) {
- TRACE("\n鍐欏叆鎴愬姛: 瀹氫綅鐐� %d, 鍦板潃: %d, 鍊�: %lu\n", i + 1, positionAddress, value);
- }
- else {
- TRACE("\n鍐欏叆澶辫触: 瀹氫綅鐐� %d, 鍦板潃: %d, 閿欒鐮�: %d\n", i + 1, positionAddress, flag);
- }
- });
- }
-
-}
-
-void CAxisSettingsDlg::handleAxisOperation(AxisOperationType eOpType, bool bPressed)
-{
- int nAxisId = getCurrentSelectedAxisID();
- if (nAxisId == -1) {
- AfxMessageBox(_T("鏈�夋嫨鏈夋晥鐨勮酱缂栧彿锛�"));
- return;
- }
-
- // 鑾峰彇杞存暟鎹�
- RecipeManager& recipeManager = RecipeManager::getInstance();
- auto axisData = recipeManager.getAxis(nAxisId);
-
- int startAddress;
- MC::SOFT_COMPONENT component;
- if (!ParsePLCAddress(CString(axisData.startAddress.c_str()), component, startAddress)) {
- AfxMessageBox(_T("鏃犳晥鐨勮捣濮嬪湴鍧�锛�"));
- }
-
- // 鏍规嵁鎿嶄綔绫诲瀷璁$畻鐩爣鍦板潃
- int bitIndex = 0;
- char szWrite[4] = { 0x0, 0x0, 0x0, 0x0 };
- switch (eOpType) {
- case AxisOperationType::OPR:
- startAddress += 0; // OPR 淇″彿鍦板潃 0,闂姩淇℃伅06.0
- szWrite[0] = bPressed ? 0x1 : 0;
- break;
- case AxisOperationType::JOG_ADD:
- startAddress += 01; // JOG+ 淇″彿鍦板潃 c
- szWrite[1] = bPressed ? 0x10 : 0;
- break;
- case AxisOperationType::JOG_SUB:
- startAddress += 01; // JOG- 淇″彿鍦板潃 d
- szWrite[1] = bPressed ? 0x20 : 0;
- break;
- case AxisOperationType::STOP:
- startAddress += 05; // STOP 淇″彿鍦板潃 5.e
- szWrite[1] = bPressed ? 0x40 : 0;
- break;
- case AxisOperationType::SEV_ON:
- startAddress += 01; // SEV_ON 淇″彿鍦板潃 1.a
- szWrite[1] = bPressed ? 0x04 : 0;
- break;
- case AxisOperationType::POSITION_1:
- case AxisOperationType::POSITION_2:
- case AxisOperationType::POSITION_3:
- case AxisOperationType::POSITION_4:
- case AxisOperationType::POSITION_5:
- startAddress += ((m_currentPage - 1) * 5 + ((int)eOpType - (int)AxisOperationType::POSITION_1 + 1)) / 16;
- bitIndex = ((m_currentPage-1) * 5 + ((int)eOpType - (int)AxisOperationType::POSITION_1 + 1)) % 16;
- if(bPressed) CToolUnits::setBit(szWrite, bitIndex);
- break;
- default:
- AfxMessageBox(_T("鏈煡鎿嶄綔绫诲瀷锛�"));
- return;
- }
-
- // 鍚� PLC 鍐欏叆淇″彿
- m_pPLC->writeData(component, startAddress, szWrite, 2, [eOpType, startAddress, bPressed](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) {
- if (nFlag == 0) {
- TRACE("鎿嶄綔鎴愬姛锛氱被鍨�=%d锛屽湴鍧�=%d锛屽��=%d\n", static_cast<int>(eOpType), nAddr, bPressed);
- }
- else {
- TRACE("鎿嶄綔澶辫触锛氱被鍨�=%d锛屽湴鍧�=%d锛岄敊璇爜=%d\n", static_cast<int>(eOpType), nAddr, nFlag);
- }
- });
-}
-
-void CAxisSettingsDlg::readPLCDataToUI(int nAxisId)
-{
- // 浠� RecipeManager 鑾峰彇杞存暟鎹�
- RecipeManager& recipeManager = RecipeManager::getInstance();
- auto axisData = recipeManager.getAxis(nAxisId);
-
- MC::SOFT_COMPONENT component;
- int startAddress, endAddress, readSize;
- if (!ParsePLCAddress(CString(axisData.startAddress.c_str()), component, startAddress)) {
- AfxMessageBox(_T("鏃犳晥鐨勮捣濮嬪湴鍧�锛�"));
- }
- endAddress = startAddress + 300;
- readSize = (endAddress - startAddress + 1) * 2;
-
- auto funOnReadData = [&, startAddress, readSize](IMcChannel* pChannel, int addr, char* pData, unsigned int nDataSize, int flag) -> void {
- if (nDataSize == readSize && flag == 0 && ::IsWindow(m_hWnd)) {
- m_fCurPos = CToolUnits::toInt32(&pData[20 * 2]) * 0.001;
- m_fManualSpeed = CToolUnits::toInt32(&pData[82 * 2]) * 0.001;
- m_fAutoSpeed = CToolUnits::toInt32(&pData[84 * 2]) * 0.001;
- m_fPrm = CToolUnits::toInt32(&pData[50 * 2]) * 0.1;
- m_nLoad = CToolUnits::toInt16(&pData[54 * 2]);
- m_nErrCode = CToolUnits::toInt16(&pData[26 * 2]);
- m_nAlarmCode = CToolUnits::toInt16(&pData[27 * 2]);
-
- m_bSEV = CToolUnits::getBit(pData[1 * 2 + 1], 0xa - 8);
- m_bFLS = CToolUnits::getBit(pData[10 * 2], 1);
- m_bDOG = CToolUnits::getBit(pData[10 * 2], 6);
- m_bRLS = CToolUnits::getBit(pData[10 * 2], 0);
- m_bReady = CToolUnits::getBit(pData[10 * 2 + 1], 0xA - 8);
- m_bBusy = CToolUnits::getBit(pData[10 * 2 + 1], 0xB - 8);
- m_bErr = CToolUnits::getBit(pData[10 * 2 + 1], 0xF - 8);
-
- PostMessage(ID_MSG_UPDATA_DATA_TO_UI);
- }
- };
- m_pPLC->readData(component, startAddress, readSize, funOnReadData);
-}
-
-
-BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CDialogEx)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_LAST, &CAxisSettingsDlg::OnBnClickedButtonAxisLast)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_NEXT, &CAxisSettingsDlg::OnBnClickedButtonAxisNext)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP2, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup2)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP3, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup3)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP4, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup4)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP5, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup5)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT1, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint1)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT2, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint2)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT3, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint3)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT4, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint4)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT5, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint5)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_OPR, &CAxisSettingsDlg::OnBnClickedButtonAxisTestOpr)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_TEST_STOP, &CAxisSettingsDlg::OnBnClickedButtonAxisTestStop)
- ON_CBN_SELCHANGE(IDC_COMBO_AXIS_NAME, &CAxisSettingsDlg::OnSelchangeComboAxisName)
- ON_BN_CLICKED(IDC_BUTTON_AXIS_SAVE, &CAxisSettingsDlg::OnBnClickedButtonAxisSave)
- ON_MESSAGE(ID_MSG_UPDATA_DATA_TO_UI, &CAxisSettingsDlg::OnUpdateDataToUI)
- ON_WM_SIZE()
- ON_WM_CTLCOLOR()
- ON_WM_SIZING()
- ON_WM_TIMER()
- ON_WM_CLOSE()
- ON_BN_CLICKED(IDC_BUTTON_AXIS_SEV, &CAxisSettingsDlg::OnBnClickedButtonAxisSev)
-END_MESSAGE_MAP()
-
-
-// CAxisSettingsDlg 娑堟伅澶勭悊绋嬪簭
-
-
-BOOL CAxisSettingsDlg::OnInitDialog()
-{
- CDialogEx::OnInitDialog();
-
- // TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
- CString strTitle;
- strTitle.Format(_T("Axis璁惧畾(閰嶆柟: %s)"), m_strRecipeName);
- SetWindowText(strTitle);
-
- // 璁剧疆娴嬭瘯鐘舵��
- CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr };
- for (auto pLabel : pLabels) {
- pLabel->SetBkColor(RGB(0, 180, 0));
- pLabel->ModifyStyle(0, SS_NOTIFY);
- pLabel->SetTextColor(RGB(255, 255, 255));
- pLabel->SetAlignment(AlignCenter);
- pLabel->SetDynamicFont(TRUE);
- }
-
- // 鍒濆鍖栧綋鍓嶉〉闈负绗竴椤�
- m_currentPage = 1;
- updatePageButtonStates();
-
- initializeAxisIDCombo();
- refreshAxisDetails(1);
- refreshPositionDetails(1, m_currentPage);
-
- CRect screenRect, dlgRect, clientRect;
- GetClientRect(&clientRect);
- m_nInitialWidth = clientRect.Width();
- m_nInitialHeight = clientRect.Height();
-
- // 鍒濆鍖栭粯璁ゅ瓧浣�
- CFont* pDefaultFont = GetOrCreateFont(12);
-
- // 閬嶅巻鎵�鏈夊瓙鎺т欢锛岃褰曞垵濮嬩綅缃苟璁剧疆榛樿瀛椾綋
- CWnd* pWnd = GetWindow(GW_CHILD);
- while (pWnd) {
- int nCtrlID = pWnd->GetDlgCtrlID();
- if (nCtrlID != -1) {
- // 璁板綍鎺т欢鍒濆甯冨眬
- CRect ctrlRect;
- pWnd->GetWindowRect(&ctrlRect);
- ScreenToClient(&ctrlRect);
- m_mapCtrlLayouts[nCtrlID] = ctrlRect;
-
- // 璁剧疆榛樿瀛椾綋
- pWnd->SetFont(pDefaultFont);
- }
- pWnd = pWnd->GetNextWindow();
- }
-
- GetWindowRect(&dlgRect);
- int dlgWidth = dlgRect.Width() * 2;
- int dlgHeight = dlgRect.Height() * 2;
-
- SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0);
- if (dlgWidth > screenRect.Width()) {
- dlgWidth = screenRect.Width();
- }
- if (dlgHeight > screenRect.Height()) {
- dlgHeight = screenRect.Height();
- }
-
- int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2;
- int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2;
- MoveWindow(centerX, centerY, dlgWidth, dlgHeight);
-
- SetTimer(TIMER_READ_PLC_DATA, 500, nullptr);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
-}
-
-BOOL CAxisSettingsDlg::PreTranslateMessage(MSG* pMsg)
-{
- // TODO: 鍦ㄦ娣诲姞涓撶敤浠g爜鍜�/鎴栬皟鐢ㄥ熀绫�
-
- if (pMsg->message == WM_LBUTTONDOWN) {
- if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD)->m_hWnd) {
- TRACE("JOG+ 鎸夐挳鎸変笅\n");
- handleAxisOperation(AxisOperationType::JOG_ADD, true);
- }
- else if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB)->m_hWnd) {
- TRACE("JOG- 鎸夐挳鎸変笅\n");
- // 鍚姩瀹氭椂鍣ㄨ繛缁彂閫佷俊鍙�
- handleAxisOperation(AxisOperationType::JOG_SUB, true);
- }
- }
- else if (pMsg->message == WM_LBUTTONUP) {
- if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_ADD)->m_hWnd) {
- TRACE("JOG+ 鎸夐挳鏉惧紑\n");
- handleAxisOperation(AxisOperationType::JOG_ADD, false);
- }
- else if (pMsg->hwnd == GetDlgItem(IDC_BUTTON_AXIS_TEST_JOG_SUB)->m_hWnd) {
- TRACE("JOG- 鎸夐挳鏉惧紑\n");
- handleAxisOperation(AxisOperationType::JOG_SUB, false);
- }
- }
-
- return CDialogEx::PreTranslateMessage(pMsg);
-}
-
-void CAxisSettingsDlg::OnSize(UINT nType, int cx, int cy)
-{
- CDialogEx::OnSize(nType, cx, cy);
-
- // TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
- if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) {
- return;
- }
-
- float dScaleX = static_cast<float>(cx) / m_nInitialWidth;
- float dScaleY = static_cast<float>(cy) / m_nInitialHeight;
-
- // 閬嶅巻瀵硅瘽妗嗕腑鐨勬墍鏈夋帶浠�
- AdjustControls(dScaleX, dScaleY);
-
- // 鍔ㄦ�佽皟鏁村悇涓� CBLLabel 鐨勫瓧浣撳ぇ灏�
- CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr };
- for (auto pLabel : pLabels) {
- AdjustLabelFont(*pLabel);
- }
-
- // 璋冩暣涓嬫媺妗嗛珮搴�
- CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_AXIS_NAME);
- CButton* pButtonLeft = (CButton*)GetDlgItem(IDC_BUTTON_AXIS_LAST);
- CButton* pButtonRight = (CButton*)GetDlgItem(IDC_BUTTON_AXIS_NEXT);
-
- if (pComboBox && pButtonLeft && pButtonRight) {
- CRect rectButton;
- pButtonLeft->GetWindowRect(&rectButton); // 鑾峰彇鎸夐挳灏哄
- ScreenToClient(&rectButton); // 杞崲涓哄鎴风鍧愭爣
-
- CRect rectComboBox;
- pComboBox->GetWindowRect(&rectComboBox);
- ScreenToClient(&rectComboBox);
-
- // 璋冩暣涓嬫媺妗嗛珮搴�
- int heightAdjustment = 2;
- rectComboBox.top = rectButton.top;
- rectComboBox.bottom = rectButton.bottom + heightAdjustment;
- pComboBox->MoveWindow(&rectComboBox);
- pComboBox->SetItemHeight(-1, rectButton.Height() - 6);
- }
-}
-
-void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect)
-{
- if (fwSide == WMSZ_BOTTOMRIGHT) {
- if (pRect->right - pRect->left < 200) {
- pRect->right = pRect->left + 200;
- }
- if (pRect->bottom - pRect->top < 150) {
- pRect->bottom = pRect->top + 150;
- }
- }
-
- CDialogEx::OnSizing(fwSide, pRect);
-}
-
-HBRUSH CAxisSettingsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
-{
- HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
-
- // TODO: 鍦ㄦ鏇存敼 DC 鐨勪换浣曠壒鎬�
-
- // TODO: 濡傛灉榛樿鐨勪笉鏄墍闇�鐢荤瑪锛屽垯杩斿洖鍙︿竴涓敾绗�
- return hbr;
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisLast()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- updateAxisSelection(-1);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisNext()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- updateAxisSelection(1);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- switchToPage(1);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup2()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- switchToPage(2);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup3()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- switchToPage(3);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup4()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- switchToPage(4);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup5()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- switchToPage(5);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint1()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::POSITION_1, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::POSITION_1, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint2()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::POSITION_2, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::POSITION_2, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint3()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::POSITION_3, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::POSITION_3, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint4()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::POSITION_4, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::POSITION_4, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPoint5()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::POSITION_5, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::POSITION_5, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisTestOpr()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::OPR, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::OPR, false);
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisTestStop()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::STOP, true);
- Sleep(200);
- handleAxisOperation(AxisOperationType::STOP, false);
-}
-
-void CAxisSettingsDlg::OnSelchangeComboAxisName()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- int axisId = getCurrentSelectedAxisID();
- if (axisId == -1) {
- AfxMessageBox(_T("璇烽�夋嫨涓�涓湁鏁堢殑杞寸紪鍙凤紒"));
- return;
- }
-
- refreshAxisDetails(axisId);
- refreshPositionDetails(axisId, m_currentPage);
- updatePageButtonStates();
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisSave()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- int axisId = getCurrentSelectedAxisID();
- if (axisId == -1) {
- AfxMessageBox(_T("璇烽�夋嫨涓�涓湁鏁堢殑杞寸紪鍙凤紒"));
- return;
- }
-
- CString cstrMessage;
- cstrMessage.Format(_T("鏄惁淇濆瓨杞� [%d] 鍙傛暟锛�"), axisId);
- int ret = AfxMessageBox(_T(cstrMessage), MB_OKCANCEL | MB_ICONEXCLAMATION);
- if (ret != IDOK) {
- return;
- }
-
- updateDataFromUI(axisId);
- if (RecipeManager::getInstance().saveRecipe(std::string(CT2A(m_strRecipeName)))) {
- writeAxisDataToPLC(axisId);
- cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟鎴愬姛锛�"), axisId);
- SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, std::string(CT2A(cstrMessage)));
- }
- else {
- cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟澶辫触锛�"), axisId);
- SystemLogManager::getInstance().log(SystemLogManager::LogType::Error, std::string(CT2A(cstrMessage)));
- }
-
- AfxMessageBox(cstrMessage);
-}
-
-LRESULT CAxisSettingsDlg::OnUpdateDataToUI(WPARAM wParam, LPARAM lParam)
-{
- CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_POS, m_fCurPos);
- CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_MANUAL_SPEED, m_fManualSpeed);
- CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_AUTO_SPEED, m_fAutoSpeed);
- CToolUnits::setDlgItemDouble(this, IDC_EDIT_AXIS_CURR_ROTA_SPEED, m_fPrm);
- SetDlgItemInt(IDC_EDIT_AXIS_CURR_LOAD, m_nLoad);
- SetDlgItemInt(IDC_EDIT_AXIS_CURR_ERROR_NUMBER, m_nErrCode);
- SetDlgItemInt(IDC_EDIT_AXIS_CURR_ALARM_NUMBER, m_nAlarmCode);
-
- //OPR 淇″彿
- if (m_bFLS) {
- SetLabelColor(m_staticFLS, RGB(0, 255, 0));
- }
- else {
- SetLabelColor(m_staticFLS, RGB(0, 180, 0));
- }
-
- if (m_bDOG) {
- SetLabelColor(m_staticDOG, RGB(0, 255, 0));
- }
- else {
- SetLabelColor(m_staticDOG, RGB(0, 180, 0));
- }
-
- if (m_bRLS) {
- SetLabelColor(m_staticRLS, RGB(0, 255, 0));
- }
- else {
- SetLabelColor(m_staticRLS, RGB(0, 180, 0));
- }
-
- if (m_bReady) {
- SetLabelColor(m_staticReady, RGB(0, 255, 0));
- }
- else {
- SetLabelColor(m_staticReady, RGB(0, 180, 0));
- }
-
- if (m_bBusy) {
- SetLabelColor(m_staticBusy, RGB(0, 255, 0));
- }
- else {
- SetLabelColor(m_staticBusy, RGB(0, 180, 0));
- }
-
- if (m_bErr) {
- SetLabelColor(m_staticErr, RGB(255, 0, 0));
- }
- else {
- SetLabelColor(m_staticErr, RGB(0, 180, 0));
- }
-
- return 0;
-}
-
-void CAxisSettingsDlg::OnTimer(UINT_PTR nIDEvent)
-{
- if (TIMER_READ_PLC_DATA == nIDEvent) {
- ASSERT(m_pPLC);
-
- int nAxisId = getCurrentSelectedAxisID();
- if (nAxisId == -1) {
- return;
- }
-
- readPLCDataToUI(nAxisId);
- }
-
- CDialogEx::OnTimer(nIDEvent);
-}
-
-void CAxisSettingsDlg::OnClose()
-{
- // TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
- KillTimer(TIMER_READ_PLC_DATA);
-
- CDialogEx::OnClose();
-}
-
-void CAxisSettingsDlg::OnBnClickedButtonAxisSev()
-{
- // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
- handleAxisOperation(AxisOperationType::SEV_ON, !m_bSEV);
-}
diff --git a/SourceCode/Bond/BondEq/AxisSettingsDlg.h b/SourceCode/Bond/BondEq/AxisSettingsDlg.h
deleted file mode 100644
index 688f61b..0000000
--- a/SourceCode/Bond/BondEq/AxisSettingsDlg.h
+++ /dev/null
@@ -1,130 +0,0 @@
-锘�#pragma once
-#include "afxdialogex.h"
-#include "BlButton.h"
-#include "BLLabel.h"
-#include "CPLC.h"
-
-// CAxisSettingsDlg 瀵硅瘽妗�
-
-enum class AxisOperationType {
- OPR = 0, // 鍥炲師鐐�
- JOG_ADD, // 姝e悜鐐瑰姩
- JOG_SUB, // 鍙嶅悜鐐瑰姩
- STOP, // 鍋滄鎿嶄綔
- SEV_ON, // 浣胯兘
- POSITION_1, // 瀹氫綅鐐�1
- POSITION_2, // 瀹氫綅鐐�2
- POSITION_3, // 瀹氫綅鐐�3
- POSITION_4, // 瀹氫綅鐐�4
- POSITION_5 // 瀹氫綅鐐�5
-};
-
-class CAxisSettingsDlg : public CDialogEx
-{
- DECLARE_DYNAMIC(CAxisSettingsDlg)
-
-public:
- CAxisSettingsDlg(CWnd* pParent = nullptr); // 鏍囧噯鏋勯�犲嚱鏁�
- virtual ~CAxisSettingsDlg();
-
-public:
- void SetPLC(CPLC* pPLC);
- void SetRecipeName(const CString& strRecipeName);
-
-// 瀵硅瘽妗嗘暟鎹�
-#ifdef AFX_DESIGN_TIME
- enum { IDD = IDD_DIALOG_AXIS_SETTINGS };
-#endif
-
-private:
- UINT FindIDByName(const CString& strControlID);
- CFont* GetOrCreateFont(int nFontSize);
- void SetDefaultFont();
- void AdjustControls(float dScaleX, float dScaleY);
- void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight);
- void AdjustLabelFont(CBLLabel& label);
- void SetLabelColor(CBLLabel& label, COLORREF color);
- void updatePageButtonStates();
- int getCurrentSelectedAxisID();
- void initializeAxisIDCombo();
- void refreshAxisDetails(int nAxisId);
- void refreshPositionDetails(int nAxisId, int pageNumber);
- void updateAxisSelection(int offset);
- void updateDataFromUI(int nAxisId);
- void switchToPage(int targetPage);
- bool ParsePLCAddress(const CString& address, MC::SOFT_COMPONENT& component, int& addr);
- void writeAxisDataToPLC(int nAxisId);
- void handleAxisOperation(AxisOperationType eOpType, bool bPressed);
- void readPLCDataToUI(int nAxisId);
-
-private:
- CPLC* m_pPLC;
- int m_nInitialWidth;
- int m_nInitialHeight;
-
- // 褰撳墠閫変腑鐨勫畾浣嶉〉闈㈢储寮�
- int m_currentPage;
-
- // 閰嶆柟鍚嶇О
- CString m_strRecipeName;
-
- // 鎸変笅鏍囪瘑
- BOOL m_bJogAddPressed;
- BOOL m_bJogSubPressed;
-
- // 鎺т欢
- CBLLabel m_staticFLS, m_staticDOG, m_staticRLS, m_staticReady, m_staticBusy, m_staticErr;
- CComboBox m_comboAxisNO;
- CStatic m_staticAxisNO, m_staticAxisDescription, m_staticStartAddress;
- CEdit m_editManualSpeed, m_editAutoSpeed, m_editAccelerationTime, m_editDecelerationTime, m_editJogDistance;
- CBlButton m_pageButtons[5];
-
- std::map<int, CRect> m_mapCtrlLayouts;
- std::map<int, CFont*> m_mapFonts;
-
- // 璇诲埌鐨勬暟鎹�
- BOOL m_bSEV;
- double m_fCurPos;
- double m_fManualSpeed;
- double m_fAutoSpeed;
- double m_fPrm;
- int m_nLoad;
- int m_nErrCode;
- int m_nAlarmCode;
- BOOL m_bFLS;
- BOOL m_bDOG;
- BOOL m_bRLS;
- BOOL m_bReady;
- BOOL m_bBusy;
- BOOL m_bErr;
-
-protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 鏀寔
- virtual BOOL OnInitDialog();
- virtual BOOL PreTranslateMessage(MSG* pMsg);
- afx_msg void OnSize(UINT nType, int cx, int cy);
- afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
- afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
- afx_msg void OnBnClickedButtonAxisLast();
- afx_msg void OnBnClickedButtonAxisNext();
- afx_msg void OnBnClickedButtonAxisAnchorPointGroup1();
- afx_msg void OnBnClickedButtonAxisAnchorPointGroup2();
- afx_msg void OnBnClickedButtonAxisAnchorPointGroup3();
- afx_msg void OnBnClickedButtonAxisAnchorPointGroup4();
- afx_msg void OnBnClickedButtonAxisAnchorPointGroup5();
- afx_msg void OnBnClickedButtonAxisAnchorPoint1();
- afx_msg void OnBnClickedButtonAxisAnchorPoint2();
- afx_msg void OnBnClickedButtonAxisAnchorPoint3();
- afx_msg void OnBnClickedButtonAxisAnchorPoint4();
- afx_msg void OnBnClickedButtonAxisAnchorPoint5();
- afx_msg void OnBnClickedButtonAxisTestOpr();
- afx_msg void OnBnClickedButtonAxisTestStop();
- afx_msg void OnSelchangeComboAxisName();
- afx_msg void OnBnClickedButtonAxisSave();
- afx_msg LRESULT OnUpdateDataToUI(WPARAM wParam, LPARAM lParam);
- afx_msg void OnTimer(UINT_PTR nIDEvent);
- afx_msg void OnClose();
- DECLARE_MESSAGE_MAP()
-public:
- afx_msg void OnBnClickedButtonAxisSev();
-};
diff --git a/SourceCode/Bond/BondEq/BondEq.rc b/SourceCode/Bond/BondEq/BondEq.rc
index faee66e..4a24646 100644
--- a/SourceCode/Bond/BondEq/BondEq.rc
+++ b/SourceCode/Bond/BondEq/BondEq.rc
Binary files differ
diff --git a/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp b/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp
index 004463c..dcd0554 100644
--- a/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp
+++ b/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp
@@ -37,6 +37,8 @@
axisInfo.number = axisNode.attribute("number").value();
axisInfo.description = axisNode.attribute("description").value();
axisInfo.startAddress = axisNode.attribute("start_address").value();
+ axisInfo.maxPositioningSpeed = axisNode.attribute("maxPositioningSpeed").as_double();
+ axisInfo.maxManualSpeed = axisNode.attribute("maxManualSpeed").as_double();
// 加载 ValueRange 值
axisInfo.jogDistance = ValueRange(
@@ -66,7 +68,9 @@
);
// 加载 PositionRange 值
+ axisInfo.positioningPointCount = axisNode.child("Positions").attribute("positioningPointCount").as_int();
for (auto positionNode : axisNode.child("Positions").children("Position")) {
+ bool isEnable = positionNode.attribute("isEnable").as_bool();
std::string description = positionNode.attribute("description").value();
ValueRange positionRange(
positionNode.attribute("min").as_double(),
@@ -74,7 +78,7 @@
positionNode.attribute("current").as_double()
);
- axisInfo.positions.emplace_back(PositionRange(description, positionRange));
+ axisInfo.positions.emplace_back(PositionRange(isEnable, description, positionRange));
}
m_axes[axisInfo.id] = axisInfo;
@@ -111,6 +115,8 @@
axisNode.append_attribute("number") = axisInfo.number.c_str();
axisNode.append_attribute("description") = axisInfo.description.c_str();
axisNode.append_attribute("start_address") = axisInfo.startAddress.c_str();
+ axisNode.append_attribute("maxPositioningSpeed") = axisInfo.maxPositioningSpeed;
+ axisNode.append_attribute("maxManualSpeed") = axisInfo.maxManualSpeed;
// 保存 ValueRange 值
auto jog_distance = axisNode.append_child("jog_distance");
@@ -140,8 +146,10 @@
// 保存 PositionRange 值
auto positionsNode = axisNode.append_child("Positions");
+ positionsNode.append_attribute("positioningPointCount") = axisInfo.positioningPointCount;
for (const auto& position : axisInfo.positions) {
auto positionNode = positionsNode.append_child("Position");
+ positionNode.append_attribute("isEnable") = position.isEnable;
positionNode.append_attribute("description") = position.description.c_str();
positionNode.append_attribute("min") = position.range.minValue;
positionNode.append_attribute("max") = position.range.maxValue;
@@ -160,6 +168,9 @@
for (int axisId = 1; axisId <= 12; ++axisId) {
AxisInfo axisInfo;
axisInfo.id = axisId;
+ axisInfo.positioningPointCount = 25;
+ axisInfo.maxPositioningSpeed = 100.0;
+ axisInfo.maxManualSpeed = 100.0;
axisInfo.number = "M100-M" + std::to_string(axisId);
axisInfo.description = "Default_Axis" + std::to_string(axisId);
axisInfo.startAddress = "ZR" + std::to_string(10000 + (axisId - 1) * 300);
@@ -172,10 +183,10 @@
axisInfo.decelerationTime = ValueRange(1.0, 10.0, 1.0);
// 添加定位点并设置默认的最小值和最大值
- for (int posId = 1; posId <= 25; ++posId) {
- double minPos = posId * 5.0;
- double maxPos = posId * 20.0;
- axisInfo.positions.emplace_back(PositionRange("Position " + std::to_string(posId), ValueRange(minPos, maxPos, posId * 10.0)));
+ for (int posId = 0; posId < axisInfo.positioningPointCount; ++posId) {
+ double minPos = (posId + 1) * 5.0;
+ double maxPos = (posId + 1) * 20.0;
+ axisInfo.positions.emplace_back(PositionRange(TRUE, "Position " + std::to_string(posId + 1), ValueRange(minPos, maxPos, (posId + 1) * 10.0)));
}
m_axes[axisId] = axisInfo;
@@ -195,7 +206,7 @@
}
// 如果没有找到该轴,返回一个默认的无效 AxisInfo
- return AxisInfo{ -1, "", "", "", ValueRange(), ValueRange(), ValueRange(), ValueRange(), ValueRange(), {} };
+ return AxisInfo{ -1, 0, 0.0, 0.0, "", "", "", ValueRange(), ValueRange(), ValueRange(), ValueRange(), ValueRange(), {} };
}
// 更新轴信息
diff --git a/SourceCode/Bond/BondEq/FileManager/RecipeManager.h b/SourceCode/Bond/BondEq/FileManager/RecipeManager.h
index aabc1b5..547c378 100644
--- a/SourceCode/Bond/BondEq/FileManager/RecipeManager.h
+++ b/SourceCode/Bond/BondEq/FileManager/RecipeManager.h
@@ -17,17 +17,21 @@
};
struct PositionRange {
+ BOOL isEnable; // 是否启用
std::string description; // 定位点描述
ValueRange range; // 位置的最小值、最大值和当前值
// 构造函数初始化
- PositionRange(const std::string& desc = "", const ValueRange& r = ValueRange())
- : description(desc), range(r) {}
+ PositionRange(BOOL b = TRUE, const std::string& desc = "", const ValueRange& r = ValueRange())
+ :isEnable(b), description(desc), range(r) {}
};
// 轴信息结构体
struct AxisInfo {
int id; // 轴ID
+ int positioningPointCount; // 定位点数
+ double maxPositioningSpeed; // 定位速度上限
+ double maxManualSpeed; // 手动速度上限
std::string number; // 轴编号
std::string description; // 轴描述
std::string startAddress; // 起始地址
diff --git a/SourceCode/Bond/BondEq/Resource.h b/SourceCode/Bond/BondEq/Resource.h
index 0be8425..915361d 100644
--- a/SourceCode/Bond/BondEq/Resource.h
+++ b/SourceCode/Bond/BondEq/Resource.h
Binary files differ
diff --git a/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp
index 29d1963..893d77b 100644
--- a/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp
@@ -32,16 +32,70 @@
m_pPLC = pPLC;
}
+void CAxisDetailSettingsDlg::UpdateAxisDetailSettings()
+{
+ // 鑾峰彇杞存暟鎹�
+ RecipeManager& recipeManager = RecipeManager::getInstance();
+ auto axisDetails = recipeManager.getAxis(m_nAxisNO);
+
+ auto formatDouble = [](double value) -> CString {
+ CString str;
+ str.Format(_T("%.3f"), value);
+ return str;
+ };
+
+ auto formatInt = [](int value) -> CString {
+ CString str;
+ str.Format(_T("%d"), value);
+ return str;
+ };
+
+ m_staticAxisNO.SetWindowText(CString(axisDetails.number.c_str())); // 杞寸紪鍙�
+ m_staticAxisDescription.SetWindowText(CString(axisDetails.description.c_str())); // 杞存弿杩�
+ m_staticStartAddress.SetWindowText(CString(axisDetails.startAddress.c_str())); // 璧峰鍦板潃
+
+ GetDlgItem(IDC_EDIT_AXIS_POSITIONING_SPEED_LIMIT)->SetWindowText(formatDouble(axisDetails.maxPositioningSpeed)); // 瀹氫綅閫熷害涓婇檺
+ GetDlgItem(IDC_EDIT_AXIS_JOG_SPEED_LIMIT)->SetWindowText(formatDouble(axisDetails.maxManualSpeed)); // 鎵嬪姩閫熷害涓婇檺
+ GetDlgItem(IDC_EDIT_AXIS_POSITIONING_POINTS)->SetWindowText(formatInt(axisDetails.positioningPointCount)); // 瀹氫綅鐐规暟
+
+ // 寰姩閲�
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_MICROMENTUM_MIN)->SetWindowText(formatDouble(axisDetails.jogDistance.minValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_MICROMENTUM)->SetWindowText(formatDouble(axisDetails.jogDistance.currentValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_MICROMENTUM_MAX)->SetWindowText(formatDouble(axisDetails.jogDistance.maxValue));
+
+ // 鎵嬪姩閫熷害
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_POS_MIN)->SetWindowText(formatDouble(axisDetails.manualSpeed.minValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_POS)->SetWindowText(formatDouble(axisDetails.manualSpeed.currentValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_POS_MAX)->SetWindowText(formatDouble(axisDetails.manualSpeed.maxValue));
+
+ // 鑷姩閫熷害
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_AUTO_SPEED_MIN)->SetWindowText(formatDouble(axisDetails.autoSpeed.minValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_AUTO_SPEED)->SetWindowText(formatDouble(axisDetails.autoSpeed.currentValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_AUTO_SPEED_MAX)->SetWindowText(formatDouble(axisDetails.autoSpeed.maxValue));
+
+ // 鍔犻�熸椂闂�
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_ACCE_TIME_MIN)->SetWindowText(formatDouble(axisDetails.accelerationTime.minValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_ACCE_TIME)->SetWindowText(formatDouble(axisDetails.accelerationTime.currentValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_ACCE_TIME_MAX)->SetWindowText(formatDouble(axisDetails.accelerationTime.maxValue));
+
+ // 鍑忛�熸椂闂�
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_DECE_TIME_MIN)->SetWindowText(formatDouble(axisDetails.decelerationTime.minValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_DECE_TIME)->SetWindowText(formatDouble(axisDetails.decelerationTime.currentValue));
+ GetDlgItem(IDC_EDIT_AXIS_MODITFY_DECE_TIME_MAX)->SetWindowText(formatDouble(axisDetails.decelerationTime.maxValue));
+}
+
void CAxisDetailSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC_AXIS_NUMBER, m_staticAxisNO);
DDX_Control(pDX, IDC_STATIC_AXIS_DESCRIP, m_staticAxisDescription);
DDX_Control(pDX, IDC_STATIC_START_ADDRESS, m_staticStartAddress);
+ DDX_Control(pDX, IDC_CUSTOM_AXIS_ANCHOR_POINT, m_gridAxisDetailSettings);
}
BEGIN_MESSAGE_MAP(CAxisDetailSettingsDlg, CDialogEx)
+ ON_BN_CLICKED(IDC_BUTTON_AXIS_DETAIL_SETTINGS_SAVE, &CAxisDetailSettingsDlg::OnBnClickedButtonAxisDetailSettingsSave)
END_MESSAGE_MAP()
@@ -67,10 +121,14 @@
return FALSE;
}
- m_staticAxisNO.SetWindowText(CString(axisDetails.number.c_str())); // 杞寸紪鍙�
- m_staticAxisDescription.SetWindowText(CString(axisDetails.description.c_str())); // 杞存弿杩�
- m_staticStartAddress.SetWindowText(CString(axisDetails.startAddress.c_str())); // 璧峰鍦板潃
+ UpdateAxisDetailSettings();
return TRUE; // return TRUE unless you set the focus to a control
// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
}
+
+void CAxisDetailSettingsDlg::OnBnClickedButtonAxisDetailSettingsSave()
+{
+ // TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+ EndDialog(IDOK);
+}
diff --git a/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.h b/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.h
index d375f88..ab3c04b 100644
--- a/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.h
+++ b/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.h
@@ -1,5 +1,6 @@
锘�#pragma once
#include "afxdialogex.h"
+#include "GridCtrl.h"
// CAxisDetailSettingsDlg 瀵硅瘽妗�
@@ -21,6 +22,10 @@
#endif
private:
+ void UpdateAxisDetailSettings();
+
+
+private:
CPLC* m_pPLC;
int m_nInitialWidth;
int m_nInitialHeight;
@@ -31,9 +36,11 @@
// 鎺т欢
CStatic m_staticAxisNO, m_staticAxisDescription, m_staticStartAddress;
+ CGridCtrl m_gridAxisDetailSettings;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 鏀寔
virtual BOOL OnInitDialog();
+ afx_msg void OnBnClickedButtonAxisDetailSettingsSave();
DECLARE_MESSAGE_MAP()
};
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index 0a60bd2..28d37c1 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -277,6 +277,7 @@
RecipeManager& recipeManager = RecipeManager::getInstance();
if (m_strRecipeName.IsEmpty() || !recipeManager.loadRecipe(std::string(CT2A(m_strRecipeName)))) {
AfxMessageBox(_T("鍔犺浇閰嶆柟澶辫触锛�"));
+ recipeManager.saveRecipe(std::string(CT2A(m_strRecipeName)));
return;
}
@@ -353,12 +354,22 @@
// 鏄剧ず瀹氫綅鐐圭殑褰撳墠浣嶇疆
CString value;
value.Format(_T("%.3f"), position.range.currentValue);
- if (pPositionCtrl) pPositionCtrl->SetWindowText(value);
+ if (pPositionCtrl) {
+ pPositionCtrl->SetWindowText(value);
+ pPositionCtrl->EnableWindow(position.isEnable);
+ }
}
else {
// 娓呯┖鎺т欢鍐呭
- if (pDescriptionCtrl) pDescriptionCtrl->SetWindowText(_T(""));
- if (pPositionCtrl) pPositionCtrl->SetWindowText(_T(""));
+ if (pDescriptionCtrl) {
+ pDescriptionCtrl->SetWindowText(_T(""));
+ pDescriptionCtrl->EnableWindow(FALSE);
+ }
+
+ if (pPositionCtrl) {
+ pPositionCtrl->SetWindowText(_T(""));
+ pPositionCtrl->EnableWindow(FALSE);
+ }
}
}
}
@@ -455,7 +466,7 @@
if (index < axisData.positions.size()) {
// 鏋勫缓鎺т欢鍚嶇О
- CString descriptionName, positionName, minValueName, maxValueName;
+ CString descriptionName, positionName;
descriptionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT_DESCRIP%d"), i + 1);
positionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
@@ -464,7 +475,7 @@
CEdit* pPositionEdit = (CEdit*)GetDlgItem(FindIDByName(positionName));
if (pDescriptionEdit && pPositionEdit) {
- CString description, positionValue, minValue, maxValue;
+ CString description, positionValue;
// 鑾峰彇鎺т欢涓殑鏂囨湰
pDescriptionEdit->GetWindowText(description);
@@ -770,19 +781,17 @@
m_nBtnsFlashState8 = ((BYTE)pData[b + 4] | (BYTE)pData[b + 5] << 8);
m_nBtnsFlashState8 |= ((BYTE)pData[b + 6] << 16 | (BYTE)pData[b + 7] << 24);
- //AxisInfo axisInfo = RecipeManager::getInstance().getAxis(nAxisId);
- //axisInfo.autoSpeed.currentValue = m_fAutoSpeed; // 鑷姩閫熷害
- //axisInfo.manualSpeed.currentValue = m_fManualSpeed; // 鎵嬪姩閫熷害
- //axisInfo.jogDistance.currentValue = CToolUnits::toInt32(&pData[81 * 2]) * 0.001; // 寰姩閲�
- //axisInfo.accelerationTime.currentValue = CToolUnits::toInt32(&pData[62 * 2]) * 0.001; // 鍔犻�熸椂闂�
- //axisInfo.decelerationTime.currentValue = CToolUnits::toInt32(&pData[64 * 2]) * 0.001; // 鍑忛�熸椂闂�
-
// 璇诲彇瀹氫綅鐐规暟鎹�
- //for (int i = 0; i < axisInfo.positions.size(); ++i) {
- // unsigned int positionAddress = 100 + (i * 2);
- // axisInfo.positions[i].range.currentValue = CToolUnits::toInt32(&pData[positionAddress * 2]) * 0.001;
- //}
- //RecipeManager::getInstance().updateAxis(axisInfo);
+ AxisInfo axisInfo = RecipeManager::getInstance().getAxis(nAxisId);
+ for (int i = 0; i < axisInfo.positions.size(); ++i) {
+ if (axisInfo.positions[i].isEnable == FALSE) {
+ unsigned int positionAddress = 100 + (i * 2);
+ //axisInfo.positions[i].range.minValue = CToolUnits::toInt32(&pData[positionAddress * 2]) * 0.001;
+ axisInfo.positions[i].range.currentValue = CToolUnits::toInt32(&pData[positionAddress * 2]) * 0.001;
+ //axisInfo.positions[i].range.maxValue = CToolUnits::toInt32(&pData[positionAddress * 2]) * 0.001;
+ }
+ }
+ RecipeManager::getInstance().updateAxis(axisInfo);
PostMessage(ID_MSG_UPDATA_DATA_TO_UI);
}
@@ -1290,20 +1299,16 @@
if (ret != IDOK) {
return;
}
- writeAxisDataToPLC(axisId);
- //Sleep(2000);
-
- //refreshAxisDetails(axisId);
- //refreshPositionDetails(axisId, m_currentPage);
+ updateDataFromUI(axisId);
if (RecipeManager::getInstance().saveRecipe(std::string(CT2A(m_strRecipeName)))) {
- cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟鍒版枃浠舵垚鍔燂紒"), axisId);
- SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, std::string(CT2A(cstrMessage)));
+ writeAxisDataToPLC(axisId);
- updateDataFromUI(axisId);
+ cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟鎴愬姛锛�"), axisId);
+ SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, std::string(CT2A(cstrMessage)));
}
else {
- cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟鍒版枃浠跺け璐ワ紒"), axisId);
+ cstrMessage.Format(_T("淇濆瓨杞� [%d] 鍙傛暟澶辫触锛�"), axisId);
SystemLogManager::getInstance().log(SystemLogManager::LogType::Error, std::string(CT2A(cstrMessage)));
}
@@ -1335,6 +1340,9 @@
CAxisDetailSettingsDlg dlg(m_strRecipeName, nAxisId, this);
dlg.SetPLC(m_pPLC);
dlg.DoModal();
+
+ refreshAxisDetails(nAxisId);
+ refreshPositionDetails(nAxisId, m_currentPage);
}
LRESULT CAxisSettingsDlg::OnUpdateDataToUI(WPARAM wParam, LPARAM lParam)
@@ -1349,6 +1357,25 @@
// 鏇存柊Labels鐘舵��
UpdateLabels();
+
+ // 鏇存柊涓嶅彲鍐欑殑瀹氫綅鐐规暟鎹�
+ RecipeManager& recipeManager = RecipeManager::getInstance();
+ for (int i = 0; i < AXIS_PAGE_SIZE; ++i) {
+ PositionRange position = recipeManager.getPositionByIndex(getCurrentSelectedAxisID(), m_currentPage, AXIS_PAGE_SIZE, 0);
+ if (position.isEnable) {
+ continue;
+ }
+
+ CString positionName;
+ positionName.Format(_T("IDC_EDIT_AXIS_ANCHOR_POINT%d"), i + 1);
+
+ CEdit* pPositionEdit = (CEdit*)GetDlgItem(FindIDByName(positionName));
+ if (pPositionEdit) {
+ CString positionValue;
+ positionValue.Format(_T("%.3f"), position.range.currentValue);
+ pPositionEdit->GetWindowText(positionValue);
+ }
+ }
// OPR鎸夐挳鏄惁瑕侀棯鐑佹垨鍋滄闂儊
// 06.0鍜�08.0
--
Gitblit v1.9.3