From f48732b2178bbaf64f39099391832a6f271fed4d Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期六, 13 九月 2025 16:15:09 +0800
Subject: [PATCH] 1. SG精度检保存界面上的参数到配置文件 2. SG精度检允许设置开机自启动 3. 修改日志保存路径
---
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 153 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index ecdface..6ee6018 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -94,6 +94,7 @@
, m_nTrayIconID(0)
, m_bTrayIconCreated(FALSE)
, m_bExitingFromTray(FALSE)
+ , m_nAutoStart(TRUE)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
@@ -131,6 +132,9 @@
}
m_plcListener.Stop();
+
+ // 淇濆瓨閰嶇疆鏂囦欢
+ SaveConfig(GetConfigPath());
DestroyWindow();
CDialogEx::OnClose();
@@ -301,6 +305,134 @@
strLine.Empty();
}
}
+}
+
+CString CSGMeasurementDlg::GetAppDirectory()
+{
+ TCHAR szPath[MAX_PATH] = { 0 };
+ GetModuleFileName(NULL, szPath, MAX_PATH);
+
+ CString strPath = szPath;
+ int pos = strPath.ReverseFind('\\');
+ if (pos != -1) {
+ strPath = strPath.Left(pos + 1);
+ }
+
+ return strPath;
+}
+
+CString CSGMeasurementDlg::GetConfigPath()
+{
+ return GetAppDirectory() + _T("SGConfig.ini");
+}
+
+bool CSGMeasurementDlg::LoadConfig(const CString& strFile)
+{
+ CString strSection = _T("StorageConfig");
+ TCHAR buf[256];
+
+ GetPrivateProfileString(strSection, _T("UseTrigger"), _T("0"), buf, 256, strFile);
+ m_nUseTrigger = _ttoi(buf);
+
+ GetPrivateProfileString(strSection, _T("SavePointCount"), _T("100000"), buf, 256, strFile);
+ m_nSavePointCount = _ttoi(buf);
+
+ // 杈撳嚭绔彛
+ GetPrivateProfileString(strSection, _T("OutputPort"), _T("OUT1"), buf, 256, strFile);
+ {
+ int idx = m_comboOutputPort.FindStringExact(-1, buf);
+ if (idx != CB_ERR) {
+ m_comboOutputPort.SetCurSel(idx);
+ }
+ else {
+ m_comboOutputPort.SetCurSel(0);
+ }
+ }
+
+ // 璺冲彉妫�娴嬪弬鏁�
+ GetPrivateProfileString(strSection, _T("JumpThreshold"), _T("0.2"), buf, 256, strFile);
+ m_fJumpThreshold = static_cast<float>(_tstof(buf));
+
+ GetPrivateProfileString(strSection, _T("JumpWindow"), _T("3"), buf, 256, strFile);
+ m_nJumpWindow = _ttoi(buf);
+
+ GetPrivateProfileString(strSection, _T("ValleyMargin"), _T("0"), buf, 256, strFile);
+ m_nValleyMargin = _ttoi(buf);
+
+ GetPrivateProfileString(strSection, _T("MinGlass1Count"), _T("10"), buf, 256, strFile);
+ m_nMinGlass1Count = _ttoi(buf);
+
+ // 绋冲畾鍖哄煙鍙傛暟
+ GetPrivateProfileString(strSection, _T("FixedCount"), _T("5"), buf, 256, strFile);
+ m_nFixedCount = _ttoi(buf);
+
+ GetPrivateProfileString(strSection, _T("MaxDelta"), _T("0.05"), buf, 256, strFile);
+ m_fMaxDelta = static_cast<float>(_tstof(buf));
+
+ // 鑷惎鍔�
+ GetPrivateProfileString(strSection, _T("AutoStart"), _T("1"), buf, 256, strFile);
+ m_nAutoStart = _ttoi(buf);
+
+ return true;
+}
+
+bool CSGMeasurementDlg::SaveConfig(const CString& strFile)
+{
+ CString strSection = _T("StorageConfig");
+
+ WritePrivateProfileString(strSection, _T("UseTrigger"), std::to_wstring(m_nUseTrigger).c_str(), strFile);
+ WritePrivateProfileString(strSection, _T("SavePointCount"), std::to_wstring(m_nSavePointCount).c_str(), strFile);
+
+ // 杈撳嚭绔彛涓嬫媺妗�
+ CString strPort;
+ m_comboOutputPort.GetWindowText(strPort);
+ WritePrivateProfileString(strSection, _T("OutputPort"), strPort, strFile);
+
+ // 璺冲彉妫�娴�
+ WritePrivateProfileString(strSection, _T("JumpThreshold"), std::to_wstring(m_fJumpThreshold).c_str(), strFile);
+ WritePrivateProfileString(strSection, _T("JumpWindow"), std::to_wstring(m_nJumpWindow).c_str(), strFile);
+ WritePrivateProfileString(strSection, _T("ValleyMargin"), std::to_wstring(m_nValleyMargin).c_str(), strFile);
+ WritePrivateProfileString(strSection, _T("MinGlass1Count"), std::to_wstring(m_nMinGlass1Count).c_str(), strFile);
+
+ // 绋冲畾鍖�
+ WritePrivateProfileString(strSection, _T("FixedCount"), std::to_wstring(m_nFixedCount).c_str(), strFile);
+ WritePrivateProfileString(strSection, _T("MaxDelta"), std::to_wstring(m_fMaxDelta).c_str(), strFile);
+
+ // 鑷惎鍔�
+ WritePrivateProfileString(strSection, _T("AutoStart"), std::to_wstring(m_nAutoStart).c_str(), strFile);
+
+ return true;
+}
+
+bool CSGMeasurementDlg::SetAutoStart(bool bEnable)
+{
+ // 鑾峰彇褰撳墠绋嬪簭璺緞
+ TCHAR szPath[MAX_PATH] = { 0 };
+ GetModuleFileName(NULL, szPath, MAX_PATH);
+ CString strAppPath = szPath;
+
+ // 鑾峰彇搴旂敤绋嬪簭鍚嶇О
+ CString strAppName = ::PathFindFileName(strAppPath);
+ strAppName = strAppName.Left(strAppName.ReverseFind('.'));
+
+ HKEY hKey;
+ LONG lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_WRITE, &hKey);
+
+ if (lRet != ERROR_SUCCESS) {
+ return false;
+ }
+
+ if (bEnable) {
+ // 璁剧疆鑷惎
+ lRet = RegSetValueEx(hKey, strAppName, 0, REG_SZ, (BYTE*)(LPCTSTR)strAppPath, (strAppPath.GetLength() + 1) * sizeof(TCHAR));
+ }
+ else {
+ // 鍙栨秷鑷惎
+ lRet = RegDeleteValue(hKey, strAppName);
+ }
+
+ RegCloseKey(hKey);
+ return (lRet == ERROR_SUCCESS);
}
bool CSGMeasurementDlg::ConnectToDevice()
@@ -942,6 +1074,27 @@
});
m_plcListener.Start();
+ // 鍔犺浇閰嶇疆鏂囦欢
+ if (LoadConfig(GetConfigPath())) {
+ AppendLogLineRichStyled(_T("閰嶇疆宸蹭粠 SGConfig.ini 鍔犺浇鎴愬姛"), LOG_COLOR_SUCCESS);
+ }
+ else {
+ AppendLogLineRichStyled(_T("閰嶇疆鍔犺浇澶辫触锛屼娇鐢ㄩ粯璁ゅ弬鏁�"), LOG_COLOR_WARNING);
+ }
+
+ // 璁剧疆鑷姩鍚姩
+ if (SetAutoStart(m_nAutoStart)) {
+ if (m_nAutoStart) {
+ AppendLogLineRichStyled(_T("宸插惎鐢ㄥ紑鏈鸿嚜鍚姩"), LOG_COLOR_SUCCESS);
+ }
+ else {
+ AppendLogLineRichStyled(_T("宸插彇娑堝紑鏈鸿嚜鍚姩"), LOG_COLOR_WARNING);
+ }
+ }
+ else {
+ AppendLogLineRichStyled(_T("璁剧疆寮�鏈鸿嚜鍚姩澶辫触锛岃妫�鏌ユ潈闄�"), LOG_COLOR_ERROR);
+ }
+
// 鍒濆鍖栨棩蹇楁
AppendLogLineRichStyled(_T("鍑嗗灏辩华..."), LOG_COLOR_SUCCESS);
--
Gitblit v1.9.3