From 31371b8633493dc5d0301f173b6ae352c7b8e4c0 Mon Sep 17 00:00:00 2001 From: zhouhuang Date: Thu, 26 Dec 2024 19:59:34 +0800 Subject: [PATCH] test --- das-dn/hostadsbf/hostadsbf.cpp | 82 ++++++++++++++++++++++++++++++++-- das-dn/hostadsbf/hostadsbf.h | 47 ++++++++++++++++++- 2 files changed, 124 insertions(+), 5 deletions(-) diff --git a/das-dn/hostadsbf/hostadsbf.cpp b/das-dn/hostadsbf/hostadsbf.cpp index 18003cd0..5722cae3 100644 --- a/das-dn/hostadsbf/hostadsbf.cpp +++ b/das-dn/hostadsbf/hostadsbf.cpp @@ -1032,6 +1032,7 @@ BOOLEAN CHostADSBFProcess::readFileID() if (uid < 0 || uid >= UNIT_NUM) return TRUE; vLog(LOG_DEBUG, "%s here read file info\n", m_pidName.c_str()); +#if 0 AdsVariable wPathInfoInvalid {*m_turbine, ".gwPathInfoInvalid"}; //vLog(LOG_DEBUG, "Read back with first value %d\n", (WORD)wPathInfoInvalid); AdsVariable wCurrentFolderNo {*m_turbine, ".gwCurrentFolderNo"}; @@ -1046,7 +1047,77 @@ BOOLEAN CHostADSBFProcess::readFileID() //vLog(LOG_DEBUG, "Read back with first value %d\n", (DWORD)wFirstFolderNoRecoverable); AdsVariable wFirstFileNoRecoverable {*m_turbine, ".gwFirstFileNoRecoverable"}; //vLog(LOG_DEBUG, "Read back with first value %d\n", (DWORD)wFirstFileNoRecoverable); - +#else + WORD wPathInfoInvalid; + myAdsVariable myPathInfoInvalid {*m_turbine, ".gwPathInfoInvalid"}; + if (!myPathInfoInvalid.Read(2, &wPathInfoInvalid)) + { + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wCurrentFolderNo; + myAdsVariable myCurrentFolderNo {*m_turbine, ".gwCurrentFolderNo"}; + if (!myCurrentFolderNo.Read(4, &wCurrentFolderNo)) + { + vLog(LOG_ERROR, "Read .gwCurrentFolderNo error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wCurrentFileNo; + myAdsVariable myCurrentFileNo {*m_turbine, ".gwCurrentFileNo"}; + if (!myCurrentFileNo.Read(4, &wCurrentFileNo)) + { + vLog(LOG_ERROR, "Read .gwCurrentFileNo error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFirstFileNoInFolder; + myAdsVariable myFirstFileNoInFolder {*m_turbine, ".gwFirstFileNoInFolder"}; + if (!myFirstFileNoInFolder.Read(4, &wFirstFileNoInFolder)) + { + vLog(LOG_ERROR, "Read .gwFirstFileNoInFolder error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFileCountInFolder; + myAdsVariable myFileCountInFolder {*m_turbine, ".gwFileCountInFolder"}; + if (!myFileCountInFolder.Read(4, &wFileCountInFolder)) + { + vLog(LOG_ERROR, "Read .gwFileCountInFolder error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFirstFolderNoRecoverable; + myAdsVariable myFirstFolderNoRecoverable {*m_turbine, ".gwFirstFolderNoRecoverable"}; + if (!myFirstFolderNoRecoverable.Read(4, &wFirstFolderNoRecoverable)) + { + vLog(LOG_ERROR, "Read .gwFirstFolderNoRecoverable error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } + + DWORD wFirstFileNoRecoverable; + myAdsVariable myse {*m_turbine, ".gwFirstFileNoRecoverable"}; + if (!myFirstFolderNoRecoverable.Read(4, &wFirstFileNoRecoverable)) + { + vLog(LOG_ERROR, "Read .gwFirstFileNoRecoverable error.\n"); + delete m_turbine; + m_turbine = NULL; + return TRUE; + } +#endif + m_iv = (WORD)wPathInfoInvalid; if (m_iv) { vLog(LOG_DEBUG, "路径信息无效\n"); @@ -1099,11 +1170,14 @@ BOOLEAN CHostADSBFProcess::readRealData() BYTE params[MAX_UNIT_POINT_PARAM_SIZE]; BYTE* pParam = params; - AdsVariable> turbineData {*m_turbine, ADSIGRP_IOIMAGE_RWOB, m_adsOverviewDataMemAddr}; - pData = ((std::array)turbineData).data(); - if (!m_turbine->IsConnected()) +// AdsVariable> turbineData {*m_turbine, ADSIGRP_IOIMAGE_RWOB, m_adsOverviewDataMemAddr}; +// pData = ((std::array)turbineData).data(); + myAdsVariable turbineData {*m_turbine, ADSIGRP_IOIMAGE_RWOB, m_adsOverviewDataMemAddr}; + if (!turbineData.Read(1024, buffer)) { vLog(LOG_ERROR, "%s Read data error\n", m_pidName.c_str()); + delete m_turbine; + m_turbine = NULL; return TRUE; } diff --git a/das-dn/hostadsbf/hostadsbf.h b/das-dn/hostadsbf/hostadsbf.h index b3c033ed..2b4c5d09 100644 --- a/das-dn/hostadsbf/hostadsbf.h +++ b/das-dn/hostadsbf/hostadsbf.h @@ -9,7 +9,52 @@ #include "AdsVariable.h" #include "RouterAccess.h" using namespace Beckhoff::Ads; -//using namespace bhf::ads; + +#include "AdsDevice.h" + +namespace Beckhoff +{ +namespace Ads +{ +struct myAdsVariable { + myAdsVariable(const AdsDevice& route, const std::string& symbolName) + : m_Route(route), + m_IndexGroup(ADSIGRP_SYM_VALBYHND), + m_Handle(route.GetHandle(symbolName)) + {} + + myAdsVariable(const AdsDevice& route, const uint32_t group, const uint32_t offset) + : m_Route(route), + m_IndexGroup(group), + m_Handle(route.GetHandle(offset)) + {} + + BOOLEAN Read(const size_t size, void* data) const + { + if (!m_Route.IsConnected()) return FALSE; + uint32_t bytesRead = 0; + auto error = m_Route.ReadReqEx2(m_IndexGroup, + *m_Handle, + size, + data, + &bytesRead); + + if (error || (size != bytesRead)) { + vLog(LOG_ERROR, "AdsVariable read failed: %d,%s\n", error, strerror(errno)); + return FALSE; + } + + return TRUE; + } + +private: + const AdsDevice& m_Route; + const uint32_t m_IndexGroup; + const AdsHandle m_Handle; +}; +} +} + typedef std::unordered_map register2typemap;