1. SG精度检保存检测结果(保存到文件)
2. SG精度检字符串需要UTF-8(BOM)
| | |
| | | #include "pch.h" |
| | | #include "pch.h" |
| | | #include "CCLinkIEControl.h" |
| | | |
| | | CCCLinkIEControl::CCCLinkIEControl() : CPerformanceMelsec(BoardType::CC_LINK_IE_CONTROL) {} |
| | |
| | | #ifndef CCLINKIECONTROL_H |
| | | #ifndef CCLINKIECONTROL_H |
| | | #define CCLINKIECONTROL_H |
| | | |
| | | #include "PerformanceMelsec.h" |
| | |
| | | // PerformanceMelsec.cpp: implementation of the CPerformanceMelsec class. |
| | | // PerformanceMelsec.cpp: implementation of the CPerformanceMelsec class. |
| | | // |
| | | ////////////////////////////////////////////////////////////////////// |
| | | #include "pch.h" |
| | |
| | | #ifndef PERFORMANCE_MELSEC_H |
| | | #ifndef PERFORMANCE_MELSEC_H |
| | | #define PERFORMANCE_MELSEC_H |
| | | |
| | | #include "Mdfunc.h" |
| | |
| | | #include "pch.h" |
| | | #include "pch.h" |
| | | #include "Logger.h" |
| | | |
| | | CLogger& CLogger::Instance() |
| | |
| | | #pragma once |
| | | #pragma once |
| | | #include <afx.h> |
| | | |
| | | class CLogger |
| | |
| | | #include "pch.h" |
| | | #include "pch.h" |
| | | #include "PLCSignalListener.h" |
| | | |
| | | // === æ¥å¿æå°ç±»å === |
| | |
| | | // ä¸å沿触å |
| | | switch (i) { |
| | | case 0: |
| | | // Start å½ä»¤ |
| | | if (m_cbStart) { |
| | | m_cbStart(); |
| | | WriteOutValues(OutValuesArray{ 0.0, 0.0, 0.0, 0.0 }); |
| | | if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) { |
| | | m_vecAckSent[i] = true; |
| | | m_vecAckCounter[i] = 0; |
| | | } |
| | | |
| | | std::string strProductID; |
| | | if (ReadProductID(strProductID)) { |
| | |
| | | LOG_MSG(msg, LOG_TYPE_SUCCESS); |
| | | } |
| | | } |
| | | |
| | | // åéåºçä¿¡å· |
| | | if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) { |
| | | m_vecAckSent[i] = true; |
| | | m_vecAckCounter[i] = 0; |
| | | } |
| | | break; |
| | | |
| | | case 1: |
| | | // Stop å½ä»¤ |
| | | if (m_cbStop) { |
| | | m_cbStop(); |
| | | if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) { |
| | | m_vecAckSent[i] = true; |
| | | m_vecAckCounter[i] = 0; |
| | | } |
| | | } |
| | | |
| | | // Analyze å½ä»¤ |
| | | if (m_cbAnalyze) { |
| | | auto results = m_cbAnalyze(); |
| | | WriteOutValues(results); |
| | | } |
| | | |
| | | // åéåºçä¿¡å· |
| | | if (m_pPlc->SetBitDeviceEx(m_station, PLC_BIT_DEVICE_TYPE, PLC_ACK_BASE_BIT + i) == 0) { |
| | | m_vecAckSent[i] = true; |
| | | m_vecAckCounter[i] = 0; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | |
| | | #pragma once |
| | | #pragma once |
| | | |
| | | #include "CCLinkIEControl.h" |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #include "pch.h" |
| | | #include "ProductResultStorage.h" |
| | | |
| | | CProductResultStorage::CProductResultStorage() |
| | | { |
| | | TCHAR szPath[MAX_PATH] = { 0 }; |
| | | GetModuleFileName(NULL, szPath, MAX_PATH); |
| | | CString strExePath(szPath); |
| | | int pos = strExePath.ReverseFind(_T('\\')); |
| | | if (pos != -1) { |
| | | m_strBaseResultDir = strExePath.Left(pos) + _T("\\Data"); |
| | | } |
| | | else { |
| | | m_strBaseResultDir = _T(".\\Data"); |
| | | } |
| | | } |
| | | |
| | | void CProductResultStorage::SaveAnalyzeResult(const CString& strProductID, const std::array<double, 4>& result) |
| | | { |
| | | CString strFilePath = MakeResultCsvPath(_T("MeasurementResults")); |
| | | CString strHeader = _T("Timestamp,ProductID,OUT1,OUT2,OUT3,OUT4\r\n"); |
| | | |
| | | // æ¶é´æ³ |
| | | CTime now = CTime::GetCurrentTime(); |
| | | CString strTimestamp; |
| | | strTimestamp.Format(_T("%02d:%02d:%02d"), now.GetHour(), now.GetMinute(), now.GetSecond()); |
| | | |
| | | // ç»æè¡ |
| | | CString strBody; |
| | | strBody.Format(_T("%s,%s,%.3f,%.3f,%.3f,%.3f\r\n"), strTimestamp, strProductID, result[0], result[1], result[2], result[3]); |
| | | AppendCsvWithHeader(strFilePath, strHeader, strBody); |
| | | } |
| | | |
| | | CString CProductResultStorage::MakeResultCsvPath(const CString& strFileName) |
| | | { |
| | | SYSTEMTIME st; |
| | | GetLocalTime(&st); |
| | | |
| | | CString strDate; |
| | | strDate.Format(_T("%04d%02d%02d"), st.wYear, st.wMonth, st.wDay); |
| | | |
| | | if (GetFileAttributes(m_strBaseResultDir) == INVALID_FILE_ATTRIBUTES) { |
| | | CreateDirectory(m_strBaseResultDir, NULL); |
| | | } |
| | | |
| | | CString strFilePath; |
| | | strFilePath.Format(_T("%s\\%s_%s.csv"), m_strBaseResultDir, strFileName, strDate); |
| | | |
| | | return strFilePath; |
| | | } |
| | | |
| | | BOOL CProductResultStorage::AppendCsvWithHeader(const CString& strFilePath, const CString& strHeader, const CString& strBody) |
| | | { |
| | | if (strBody.IsEmpty()) { |
| | | return FALSE; |
| | | } |
| | | |
| | | CFile f; |
| | | CFileException ex; |
| | | if (!f.Open(strFilePath, CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate | CFile::shareDenyWrite | CFile::shareDenyRead, &ex)) { |
| | | return FALSE; |
| | | } |
| | | |
| | | if (f.SeekToEnd() == 0L) { |
| | | f.Write(strHeader, strHeader.GetLength() * sizeof(TCHAR)); |
| | | } |
| | | f.Write(strBody, strBody.GetLength() * sizeof(TCHAR)); |
| | | f.Close(); |
| | | return TRUE; |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | #pragma once |
| | | #include <array> |
| | | |
| | | class CProductResultStorage |
| | | { |
| | | public: |
| | | CProductResultStorage(); |
| | | ~CProductResultStorage() = default; |
| | | |
| | | void SaveAnalyzeResult(const CString& strProductID, const std::array<double, 4>& result); |
| | | |
| | | private: |
| | | CString MakeResultCsvPath(const CString& strFileName); |
| | | BOOL AppendCsvWithHeader(const CString& strFilePath, const CString& strHeader, const CString& strBody); |
| | | |
| | | CString m_strBaseResultDir; |
| | | }; |
| | | |
| | |
| | | |
| | |  |
| | | // SGMeasurement.cpp: å®ä¹åºç¨ç¨åºçç±»è¡ä¸ºã |
| | | // |
| | | |
| | |
| | | |
| | |  |
| | | // SGMeasurement.h: PROJECT_NAME åºç¨ç¨åºç主头æä»¶ |
| | | // |
| | | |
| | |
| | | <ClInclude Include="Logger.h" /> |
| | | <ClInclude Include="pch.h" /> |
| | | <ClInclude Include="PLCSignalListener.h" /> |
| | | <ClInclude Include="ProductResultStorage.h" /> |
| | | <ClInclude Include="Resource.h" /> |
| | | <ClInclude Include="SGMeasurement.h" /> |
| | | <ClInclude Include="SGMeasurementDlg.h" /> |
| | |
| | | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> |
| | | </ClCompile> |
| | | <ClCompile Include="PLCSignalListener.cpp" /> |
| | | <ClCompile Include="ProductResultStorage.cpp" /> |
| | | <ClCompile Include="SGMeasurement.cpp" /> |
| | | <ClCompile Include="SGMeasurementDlg.cpp" /> |
| | | </ItemGroup> |
| | |
| | | <ClInclude Include="PLCSignalListener.h"> |
| | | <Filter>头æä»¶</Filter> |
| | | </ClInclude> |
| | | <ClInclude Include="ProductResultStorage.h"> |
| | | <Filter>头æä»¶</Filter> |
| | | </ClInclude> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ClCompile Include="SGMeasurement.cpp"> |
| | |
| | | <ClCompile Include="PLCSignalListener.cpp"> |
| | | <Filter>æºæä»¶</Filter> |
| | | </ClCompile> |
| | | <ClCompile Include="ProductResultStorage.cpp"> |
| | | <Filter>æºæä»¶</Filter> |
| | | </ClCompile> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ResourceCompile Include="SGMeasurement.rc"> |
| | |
| | | |
| | |  |
| | | // SGMeasurementDlg.cpp: å®ç°æä»¶ |
| | | // |
| | | |
| | |
| | | result[i] = AnalyzeStoredData(i + 1); // OUT1 ~ OUT4 |
| | | } |
| | | |
| | | std::string strProductID; |
| | | m_plcListener.ReadProductID(strProductID); |
| | | m_resultStorage.SaveAnalyzeResult(CString(strProductID.c_str()), result); |
| | | |
| | | CString strLog; |
| | | strLog.Format(_T("åæç»æï¼OUT1: %.3f, OUT2: %.3f, OUT3: %.3f, OUT4: %.3f"), result[0], result[1], result[2], result[3]); |
| | | return result; |
| | |
| | | |
| | |  |
| | | // SGMeasurementDlg.h: 头æä»¶ |
| | | // |
| | | |
| | | #pragma once |
| | | |
| | | #include "PLCSignalListener.h" |
| | | #include "ProductResultStorage.h" |
| | | |
| | | #include <map> |
| | | #include <vector> |
| | |
| | | * @brief PLC ä¿¡å·çå¬å¨å®ä¾ï¼ç¨äºå¤ç PLC ä¿¡å·äºä»¶ |
| | | */ |
| | | CPLCSignalListener m_plcListener; |
| | | |
| | | // === 产åç»æåå¨ === |
| | | |
| | | /** |
| | | * @brief 产åç»æåå¨å®ä¾ï¼ç¨äºä¿ååç®¡çæµéç»æ |
| | | */ |
| | | CProductResultStorage m_resultStorage; |
| | | }; |
| | |
| | | #pragma once |
| | | #pragma once |
| | | |
| | | #ifndef VC_EXTRALEAN |
| | | #define VC_EXTRALEAN // ä» Windows 头䏿餿å°ä½¿ç¨çèµæ |
| | |
| | | // pch.cpp: ä¸é¢ç¼è¯æ 头对åºçæºæä»¶ |
| | | // pch.cpp: ä¸é¢ç¼è¯æ 头对åºçæºæä»¶ |
| | | |
| | | #include "pch.h" |
| | | |
| | |
| | | // pch.h: è¿æ¯é¢ç¼è¯æ 头æä»¶ã |
| | | // pch.h: è¿æ¯é¢ç¼è¯æ 头æä»¶ã |
| | | // 䏿¹ååºçæä»¶ä»
ç¼è¯ä¸æ¬¡ï¼æé«äºå°æ¥çæççææ§è½ã |
| | | // è¿è¿å°å½±å IntelliSense æ§è½ï¼å
æ¬ä»£ç 宿å许å¤ä»£ç æµè§åè½ã |
| | | // 使¯ï¼å¦ææ¤å¤ååºçæä»¶ä¸çä»»ä½ä¸ä¸ªå¨çæä¹é´ææ´æ°ï¼å®ä»¬å
¨é¨é½å°è¢«éæ°ç¼è¯ã |
| | |
| | | //{{NO_DEPENDENCIES}} |
| | | //{{NO_DEPENDENCIES}} |
| | | // Microsoft Visual C++ çæçå
嫿件ã |
| | | // ä¾ SGMeasurement.rc ä½¿ç¨ |
| | | // |
| | |
| | | #pragma once |
| | | #pragma once |
| | | |
| | | // å
æ¬ SDKDDKVer.h å°å®ä¹å¯ç¨çæé«çæ¬ç Windows å¹³å°ã |
| | | |