From 6d106eb1bb92dc235bcbda976ae232729bf52c7c Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期一, 25 十一月 2024 13:46:15 +0800
Subject: [PATCH] 合并代码
---
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 111 insertions(+), 4 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index d12c269..e83a616 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -5,7 +5,10 @@
#include "BondEq.h"
#include "afxdialogex.h"
#include "AxisSettingsDlg.h"
+#include "ToolUnits.h"
+#define TIMER_INIT 1
+#define TIMER_READ_PLC_DATA 2
// CAxisSettingsDlg 瀵硅瘽妗�
@@ -16,6 +19,7 @@
{
m_nInitialWidth = 0;
m_nInitialHeight = 0;
+ m_pPLC = nullptr;
}
CAxisSettingsDlg::~CAxisSettingsDlg()
@@ -29,9 +33,21 @@
m_mapFonts.clear();
}
+void CAxisSettingsDlg::SetPLC(CPLC* pPLC)
+{
+ ASSERT(pPLC);
+ m_pPLC = pPLC;
+}
+
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);
}
CFont* CAxisSettingsDlg::GetOrCreateFont(int nFontSize)
@@ -98,12 +114,45 @@
// 鏍规嵁鎺т欢楂樺害鍔ㄦ�佽皟鏁村瓧浣撳ぇ灏�
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::SetStatusColor(CBLLabel& label, BOOL bStatus)
+{
+ if (bStatus) {
+ label.SetBkColor(RGB(0, 255, 0)); // 缁胯壊
+ }
+ else {
+ label.SetBkColor(RGB(255, 0, 0)); // 绾㈣壊
+ }
+
+ label.Invalidate(); // 鏍囪鍖哄煙鏃犳晥
+ label.UpdateWindow(); // 绔嬪嵆鍒锋柊
}
@@ -127,6 +176,7 @@
ON_WM_SIZE()
ON_WM_CTLCOLOR()
ON_WM_SIZING()
+ ON_WM_TIMER()
END_MESSAGE_MAP()
@@ -138,6 +188,18 @@
CDialogEx::OnInitDialog();
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
+ SetWindowText(_T("Axis璁惧畾"));
+
+ // 璁剧疆娴嬭瘯鐘舵��
+ CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr };
+ for (auto pLabel : pLabels) {
+ SetStatusColor(*pLabel, FALSE);
+ pLabel->ModifyStyle(0, SS_NOTIFY);
+ pLabel->SetTextColor(RGB(255, 255, 255));
+ pLabel->SetAlignment(AlignCenter);
+ pLabel->SetDynamicFont(TRUE);
+ }
+
CRect screenRect, dlgRect, clientRect;
GetClientRect(&clientRect);
m_nInitialWidth = clientRect.Width();
@@ -178,6 +240,8 @@
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
@@ -188,11 +252,21 @@
CDialogEx::OnSize(nType, cx, cy);
// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
- CRect rect;
- GetClientRect(&rect);
+ 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(rect.Width(), rect.Height());
+ AdjustControls(dScaleX, dScaleY);
+
+ // 鍔ㄦ�佽皟鏁村悇涓� CBLLabel 鐨勫瓧浣撳ぇ灏�
+ CBLLabel* pLabels[] = { &m_staticFLS, &m_staticDOG, &m_staticRLS, &m_staticReady, &m_staticBusy, &m_staticErr };
+ for (auto pLabel : pLabels) {
+ AdjustLabelFont(*pLabel);
+ }
}
void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect)
@@ -297,4 +371,37 @@
void CAxisSettingsDlg::OnBnClickedButtonAxisTestStop()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
-}
\ No newline at end of file
+}
+
+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);
+}
--
Gitblit v1.9.3