From bb1ef33e064b1802729a352744f67a8916943117 Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 26 十二月 2024 10:02:01 +0800
Subject: [PATCH] 1.细部设定界面写入PLC
---
SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp | 138 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp
index f0907b8..d9e0aaf 100644
--- a/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisDetailSettingsDlg.cpp
@@ -204,6 +204,143 @@
GetDlgItem(IDC_EDIT_AXIS_MODITFY_DECE_TIME_MAX)->SetWindowText(formatDouble(axisDetails.decelerationTime.maxValue));
}
+bool CAxisDetailSettingsDlg::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 CAxisDetailSettingsDlg::writeAxisDataToPLC(int nAxisId)
+{
+ // 鑾峰彇杞存暟鎹�
+ RecipeManager& recipeManager = RecipeManager::getInstance();
+ AxisInfo axisData = recipeManager.getAxis(nAxisId);
+
+ MC::SOFT_COMPONENT enComponent;
+ int nStartAddress, nEndAddress, nSize;
+ if (!ParsePLCAddress(CString(axisData.startAddress.c_str()), enComponent, nStartAddress)) {
+ AfxMessageBox(_T("鏃犳晥鐨勮捣濮嬪湴鍧�锛�"));
+ }
+ nEndAddress = nStartAddress + 300;
+ nSize = (nEndAddress - nStartAddress + 1) * 2;
+
+ char szWrite[300] = { 0 };
+
+ auto writeIntToBuffer = [&](int value, int nWriteIndex) {
+ if (nWriteIndex + 4 <= sizeof(szWrite)) {
+ szWrite[nWriteIndex] = static_cast<char>(value & 0xFF); // 浣庡瓧鑺�
+ szWrite[nWriteIndex + 1] = static_cast<char>((value >> 8) & 0xFF); // 娆′綆瀛楄妭
+ szWrite[nWriteIndex + 2] = static_cast<char>((value >> 16) & 0xFF); // 娆¢珮瀛楄妭
+ szWrite[nWriteIndex + 3] = static_cast<char>((value >> 24) & 0xFF); // 楂樺瓧鑺�
+ }
+ };
+
+ // 鍐欏叆鎵嬪姩閫熷害
+ // writeIntToBuffer(static_cast<int>(axisData.manualSpeed.minValue * 1000), 0);
+ writeIntToBuffer(static_cast<int>(axisData.manualSpeed.currentValue * 1000), 82);
+ // writeIntToBuffer(static_cast<int>(axisData.manualSpeed.maxValue * 1000), 0);
+
+ // 鍐欏叆鑷姩閫熷害
+ // writeIntToBuffer(static_cast<int>(axisData.autoSpeed.minValue * 1000), 0);
+ writeIntToBuffer(static_cast<int>(axisData.autoSpeed.currentValue * 1000), 84);
+ // writeIntToBuffer(static_cast<int>(axisData.autoSpeed.maxValue * 1000), 0);
+
+ // 鍐欏叆鍔犻�熸椂闂�
+ // writeIntToBuffer(static_cast<int>(axisData.accelerationTime.minValue * 1000), 0);
+ writeIntToBuffer(static_cast<int>(axisData.accelerationTime.currentValue * 1000), 62);
+ // writeIntToBuffer(static_cast<int>(axisData.accelerationTime.maxValue * 1000), 0);
+
+ // 鍐欏叆鍑忛�熸椂闂�
+ // writeIntToBuffer(static_cast<int>(axisData.decelerationTime.minValue * 1000), 0);
+ writeIntToBuffer(static_cast<int>(axisData.decelerationTime.currentValue * 1000), 64);
+ // writeIntToBuffer(static_cast<int>(axisData.decelerationTime.maxValue * 1000), 0);
+
+ // 鍐欏叆寰姩閲�
+ // writeIntToBuffer(static_cast<int>(axisData.jogDistance.minValue * 1000), 0);
+ writeIntToBuffer(static_cast<int>(axisData.jogDistance.currentValue * 1000), 81);
+ // writeIntToBuffer(static_cast<int>(axisData.jogDistance.maxValue * 1000), 0);
+
+ // 瀹氫綅鐐规暟鎹�
+ int nIndex = 100;
+ for (int i = 0; i < axisData.positions.size(); ++i) {
+ const auto& position = axisData.positions[i];
+ // writeIntToBuffer(static_cast<int>(position.range.minValue * 1000), 0);
+ writeIntToBuffer(static_cast<int>(position.range.currentValue * 1000), nIndex + (i * 2));
+ // writeIntToBuffer(static_cast<int>(position.range.maxValue * 1000), 0);
+ }
+
+ // 鍚� PLC 鍐欏叆淇″彿
+ m_pPLC->writeData(enComponent, nStartAddress, szWrite, nSize, [nStartAddress, &szWrite](IMcChannel* pChannel, int nAddr, DWORD nValue, int nFlag) {
+ if (nFlag == 0) {
+ TRACE("鎿嶄綔鎴愬姛锛氬湴鍧�=%d锛屽��=%s\n", nStartAddress, szWrite);
+ }
+ else {
+ TRACE("鎿嶄綔澶辫触锛氬湴鍧�=%d锛岄敊璇爜=%d\n", nStartAddress, nFlag);
+ }
+ });
+}
+
void CAxisDetailSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
CBaseDlg::DoDataExchange(pDX);
@@ -385,6 +522,7 @@
// 淇濆瓨杞存暟鎹埌鏂囦欢
CString cstrMessage;
if (RecipeManager::getInstance().saveRecipe(std::string(CT2A(m_strRecipeName)))) {
+ writeAxisDataToPLC(m_nAxisNO);
cstrMessage.Format(_T("淇濆瓨杞� [%d] 缁嗛儴鍙傛暟鎴愬姛锛�"), m_nAxisNO);
SystemLogManager::getInstance().log(SystemLogManager::LogType::Operation, std::string(CT2A(cstrMessage)));
}
--
Gitblit v1.9.3