From 0239509af412b74083b33a6924ffd79007dfda5f Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 18 十一月 2024 10:41:13 +0800
Subject: [PATCH] 1.轴对话框,当前参数读取和显示;
---
SourceCode/Bond/BondEq/AxisSettingsDlg.cpp | 47 +++++++++++++++++++++++
SourceCode/Bond/BondEq/CBonder.cpp | 5 ++
SourceCode/Bond/BondEq/AxisSettingsDlg.h | 10 +++++
SourceCode/Bond/BondEq/CPLC.cpp | 2
SourceCode/Bond/BondEq/ToolUnits.h | 3 +
SourceCode/Bond/BondEq/CBonder.h | 1
SourceCode/Bond/BondEq/ToolUnits.cpp | 17 ++++++++
SourceCode/Bond/BondEq/BondEqDlg.cpp | 5 +-
8 files changed, 87 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp
index e92cb8c..08b3107 100644
--- a/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/AxisSettingsDlg.cpp
@@ -5,7 +5,11 @@
#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 +20,7 @@
{
m_nInitialWidth = 0;
m_nInitialHeight = 0;
+ m_pPLC = nullptr;
}
CAxisSettingsDlg::~CAxisSettingsDlg()
@@ -48,11 +53,17 @@
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()
{
@@ -70,6 +81,9 @@
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
@@ -243,3 +257,36 @@
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);
+}
diff --git a/SourceCode/Bond/BondEq/AxisSettingsDlg.h b/SourceCode/Bond/BondEq/AxisSettingsDlg.h
index 793b693..1cc4b38 100644
--- a/SourceCode/Bond/BondEq/AxisSettingsDlg.h
+++ b/SourceCode/Bond/BondEq/AxisSettingsDlg.h
@@ -1,5 +1,6 @@
锘�#pragma once
#include "afxdialogex.h"
+#include "CPLC.h"
// CAxisSettingsDlg 瀵硅瘽妗�
@@ -11,6 +12,10 @@
public:
CAxisSettingsDlg(CWnd* pParent = nullptr); // 鏍囧噯鏋勯�犲嚱鏁�
virtual ~CAxisSettingsDlg();
+
+public:
+ void SetPLC(CPLC* pPLC);
+
// 瀵硅瘽妗嗘暟鎹�
#ifdef AFX_DESIGN_TIME
@@ -48,4 +53,9 @@
private:
int m_nInitialWidth;
int m_nInitialHeight;
+
+private:
+ CPLC* m_pPLC;
+public:
+ afx_msg void OnTimer(UINT_PTR nIDEvent);
};
diff --git a/SourceCode/Bond/BondEq/BondEqDlg.cpp b/SourceCode/Bond/BondEq/BondEqDlg.cpp
index 21935a5..70fa037 100644
--- a/SourceCode/Bond/BondEq/BondEqDlg.cpp
+++ b/SourceCode/Bond/BondEq/BondEqDlg.cpp
@@ -542,8 +542,9 @@
m_pTopToolbar->SetOperatorBtnText(_T("未登录"));
}
- CAxisSettingsDlg loginDlg;
- loginDlg.DoModal();
+ CAxisSettingsDlg axisDlg;
+ axisDlg.SetPLC(theApp.m_model.getBonder().getPLC("PLC(1)"));
+ axisDlg.DoModal();
}
}
diff --git a/SourceCode/Bond/BondEq/CBonder.cpp b/SourceCode/Bond/BondEq/CBonder.cpp
index 6a8cc5b..104a6fe 100644
--- a/SourceCode/Bond/BondEq/CBonder.cpp
+++ b/SourceCode/Bond/BondEq/CBonder.cpp
@@ -69,6 +69,11 @@
return m_components;
}
+CPLC* CBonder::getPLC(const char* pszName)
+{
+ return (CPLC*)GetComponent("PLC(1)");
+}
+
int CBonder::save()
{
CFile file;
diff --git a/SourceCode/Bond/BondEq/CBonder.h b/SourceCode/Bond/BondEq/CBonder.h
index 3a3d58a..c932b47 100644
--- a/SourceCode/Bond/BondEq/CBonder.h
+++ b/SourceCode/Bond/BondEq/CBonder.h
@@ -42,6 +42,7 @@
void setListener(BondListener& listener);
void setWorkDir(const char* pszWorkDir);
const std::vector<CComponent*>& getComponents();
+ CPLC* getPLC(const char* pszName);
int init();
int term();
void sendBroadcast(CComponent* pSender, CIntent* pIntent);
diff --git a/SourceCode/Bond/BondEq/CPLC.cpp b/SourceCode/Bond/BondEq/CPLC.cpp
index 9b1584c..7a7afcf 100644
--- a/SourceCode/Bond/BondEq/CPLC.cpp
+++ b/SourceCode/Bond/BondEq/CPLC.cpp
@@ -308,7 +308,7 @@
static int iii = 0;
iii++;
if (iii % 5 == 3) {
- if (!m_pChannel->isConnected())
+ if (m_pChannel != nullptr && !m_pChannel->isConnected())
m_pChannel->connect();
}
}
\ No newline at end of file
diff --git a/SourceCode/Bond/BondEq/ToolUnits.cpp b/SourceCode/Bond/BondEq/ToolUnits.cpp
index fecc6c1..3c65c30 100644
--- a/SourceCode/Bond/BondEq/ToolUnits.cpp
+++ b/SourceCode/Bond/BondEq/ToolUnits.cpp
@@ -145,3 +145,20 @@
DWORD attributes = GetFileAttributes(path.c_str());
return (attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY));
}
+
+double CToolUnits::toInt32(const char* pBuffer)
+{
+ return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8 | (pBuffer[2] & 0xff) << 16 | (pBuffer[3] & 0xff) << 24;
+}
+
+double CToolUnits::toInt16(const char* pBuffer)
+{
+ return (pBuffer[0] & 0xff) | (pBuffer[1] & 0xff) << 8;
+}
+
+void CToolUnits::setDlgItemDouble(CWnd* pWnd, int nCtrlId, double value)
+{
+ CString strText;
+ strText.Format(_T("%.03f"), value);
+ pWnd->SetDlgItemText(nCtrlId, strText);
+}
diff --git a/SourceCode/Bond/BondEq/ToolUnits.h b/SourceCode/Bond/BondEq/ToolUnits.h
index 3dfc929..167cf0e 100644
--- a/SourceCode/Bond/BondEq/ToolUnits.h
+++ b/SourceCode/Bond/BondEq/ToolUnits.h
@@ -20,5 +20,8 @@
static std::string getCurrentExePath();
static bool isFile(const std::string& path);
static bool isDirectory(const std::string& path);
+ static double toInt32(const char* pBuffer);
+ static double toInt16(const char* pBuffer);
+ static void setDlgItemDouble(CWnd* pWnd, int nCtrlId, double value);
};
--
Gitblit v1.9.3