From 5555b3679f78303f7fc53ab7a663187b8e9227fa Mon Sep 17 00:00:00 2001 From: Alexander Oster Date: Fri, 9 Jan 2026 23:32:37 +0000 Subject: [PATCH] CifX Driver fix --- .../libmcdriver_cifx_channel.cpp | 35 ++++++++++++++++--- .../libmcdriver_cifx_channel.hpp | 3 +- .../libmcdriver_cifx_parameter.cpp | 9 ++++- .../libmcdriver_cifx_parameter.hpp | 2 ++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Drivers/CifX/Implementation/libmcdriver_cifx_channel.cpp b/Drivers/CifX/Implementation/libmcdriver_cifx_channel.cpp index 8da635417..596f8715c 100644 --- a/Drivers/CifX/Implementation/libmcdriver_cifx_channel.cpp +++ b/Drivers/CifX/Implementation/libmcdriver_cifx_channel.cpp @@ -42,6 +42,8 @@ Abstract: This is a stub class definition of CChannelInformation #define CIFX_DEFAULT_HOSTSTATETIMEOUT 5000 #define CIFX_DEFAULT_BUSSTATETIMEOUT 2000 #define CIFX_DEFAULT_SYNCDELAY 10 +#define CIFX_DEFAULT_READTIMEOUT 1000 +#define CIFX_DEFAULT_WRITETIMEOUT 1000 using namespace LibMCDriver_CifX::Impl; @@ -325,7 +327,7 @@ std::vector& CDriver_CifXChannelBuffer::getBuffer() CDriver_CifXChannelThreadState::CDriver_CifXChannelThreadState(PCifXSDK pCifXSDK, uint32_t nInputSize, uint32_t nOutputSize, cifxHandle hChannel) - : m_pCifXSDK(pCifXSDK), m_hChannel(hChannel), m_bDebugMode(true), m_InputBuffer(nInputSize), m_OutputBuffer(nOutputSize), m_bThreadIsRunning (false) + : m_pCifXSDK(pCifXSDK), m_hChannel(hChannel), m_bCancelFlag(false), m_bThreadIsRunning(false), m_bDebugMode(true), m_InputBuffer(nInputSize), m_OutputBuffer(nOutputSize) { if (pCifXSDK.get() == nullptr) throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM); @@ -576,7 +578,8 @@ void CDriver_CifXChannelThreadState::writeOutputParameter(CDriver_CifXParameter* CDriver_CifXChannel::CDriver_CifXChannel(pugi::xml_node& channelNode) - : m_nChannelIndex(0), m_nInputSize(0), m_nOutputSize(0), m_nHostStateTimeOut(CIFX_DEFAULT_HOSTSTATETIMEOUT), m_nBusStateTimeOut(CIFX_DEFAULT_BUSSTATETIMEOUT), m_SyncDelay (CIFX_DEFAULT_SYNCDELAY) + : m_nChannelIndex(0), m_nInputSize(0), m_nOutputSize(0), m_nHostStateTimeOut(CIFX_DEFAULT_HOSTSTATETIMEOUT), m_nBusStateTimeOut(CIFX_DEFAULT_BUSSTATETIMEOUT), m_SyncDelay(CIFX_DEFAULT_SYNCDELAY), + m_nReadTimeout(CIFX_DEFAULT_READTIMEOUT), m_nWriteTimeout(CIFX_DEFAULT_WRITETIMEOUT) { auto boardAttrib = channelNode.attribute("board"); @@ -626,6 +629,30 @@ CDriver_CifXChannel::CDriver_CifXChannel(pugi::xml_node& channelNode) m_nBusStateTimeOut = nBusStateTimeout; } + auto syncDelayAttrib = channelNode.attribute("syncdelay"); + if (!syncDelayAttrib.empty()) { + int nSyncDelay = syncDelayAttrib.as_int(0); + if (nSyncDelay <= 0) + throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM, "invalid syncdelay attribute"); + m_SyncDelay = nSyncDelay; + } + + auto readTimeoutAttrib = channelNode.attribute("readtimeout"); + if (!readTimeoutAttrib.empty()) { + int nReadTimeout = readTimeoutAttrib.as_int(0); + if (nReadTimeout <= 0) + throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM, "invalid readtimeout attribute"); + m_nReadTimeout = nReadTimeout; + } + + auto writeTimeoutAttrib = channelNode.attribute("writetimeout"); + if (!writeTimeoutAttrib.empty()) { + int nWriteTimeout = writeTimeoutAttrib.as_int(0); + if (nWriteTimeout <= 0) + throw ELibMCDriver_CifXInterfaceException(LIBMCDRIVER_CIFX_ERROR_INVALIDPARAM, "invalid writetimeout attribute"); + m_nWriteTimeout = nWriteTimeout; + } + auto inputIONode = channelNode.child("input_io"); if (!inputIONode.empty()) { @@ -804,8 +831,8 @@ void CDriver_CifXChannel::startSyncThread(PCifXSDK pCifXSDK, cifxHandle hDriverH uint32_t nBusState = 0; pCifXSDK->checkError(pCifXSDK->xChannelBusState(hChannel, CIFX_BUS_STATE_ON, &nBusState, m_nBusStateTimeOut)); - uint32_t nReadTimeout = 1000; - uint32_t nWriteTimeout = 1000; + uint32_t nReadTimeout = m_nReadTimeout; + uint32_t nWriteTimeout = m_nWriteTimeout; uint32_t nSyncDelay = m_SyncDelay; auto pInputs = m_Inputs; diff --git a/Drivers/CifX/Implementation/libmcdriver_cifx_channel.hpp b/Drivers/CifX/Implementation/libmcdriver_cifx_channel.hpp index fa77b8f64..99ab1d259 100644 --- a/Drivers/CifX/Implementation/libmcdriver_cifx_channel.hpp +++ b/Drivers/CifX/Implementation/libmcdriver_cifx_channel.hpp @@ -139,6 +139,8 @@ namespace Impl { uint32_t m_nHostStateTimeOut; uint32_t m_nBusStateTimeOut; uint32_t m_SyncDelay; + uint32_t m_nReadTimeout; + uint32_t m_nWriteTimeout; std::shared_ptr m_pThreadState; @@ -183,4 +185,3 @@ namespace Impl { #endif // __LIBMCDRIVER_CIFX_CHANNEL - diff --git a/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.cpp b/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.cpp index 623acabbc..dec7d45d7 100644 --- a/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.cpp +++ b/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.cpp @@ -246,21 +246,25 @@ CDriver_CifXParameter_Integer::~CDriver_CifXParameter_Integer() int64_t CDriver_CifXParameter_Integer::GetActualIntegerValue() { + std::lock_guard lockGuard(m_ValueMutex); return m_nActualValue; } void CDriver_CifXParameter_Integer::SetActualIntegerValue(int64_t nValue) { + std::lock_guard lockGuard(m_ValueMutex); m_nActualValue = nValue; } int64_t CDriver_CifXParameter_Integer::GetTargetIntegerValue() { + std::lock_guard lockGuard(m_ValueMutex); return m_nTargetValue; } void CDriver_CifXParameter_Integer::SetTargetIntegerValue(int64_t nValue) { + std::lock_guard lockGuard(m_ValueMutex); m_nTargetValue = nValue; } @@ -277,21 +281,25 @@ CDriver_CifXParameter_Double::~CDriver_CifXParameter_Double() double CDriver_CifXParameter_Double::GetActualDoubleValue() { + std::lock_guard lockGuard(m_ValueMutex); return m_dActualValue; } void CDriver_CifXParameter_Double::SetActualDoubleValue(double dValue) { + std::lock_guard lockGuard(m_ValueMutex); m_dActualValue = dValue; } double CDriver_CifXParameter_Double::GetTargetDoubleValue() { + std::lock_guard lockGuard(m_ValueMutex); return m_dTargetValue; } void CDriver_CifXParameter_Double::SetTargetDoubleValue(double dValue) { + std::lock_guard lockGuard(m_ValueMutex); m_dTargetValue = dValue; } @@ -311,4 +319,3 @@ uint32_t CDriver_CifXParameter_Bool::getBit() { return m_nBit; } - diff --git a/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.hpp b/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.hpp index 3f38f395f..af834be75 100644 --- a/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.hpp +++ b/Drivers/CifX/Implementation/libmcdriver_cifx_parameter.hpp @@ -109,6 +109,7 @@ namespace Impl { class CDriver_CifXParameter_Integer : public CDriver_CifXParameter { private: + mutable std::mutex m_ValueMutex; int64_t m_nActualValue; int64_t m_nTargetValue; @@ -129,6 +130,7 @@ namespace Impl { class CDriver_CifXParameter_Double : public CDriver_CifXParameter { private: + mutable std::mutex m_ValueMutex; double m_dActualValue; double m_dTargetValue;