diff --git a/silecs-cli-client/Makefile.dep b/silecs-cli-client/Makefile.dep index ef15141f10f7c2aeb991f503ef40af6a802689e5..a51ce186dab93f1d16811de0e7652225e37203bb 100644 --- a/silecs-cli-client/Makefile.dep +++ b/silecs-cli-client/Makefile.dep @@ -13,10 +13,9 @@ DEPENDENT_COMPILER_OPTIONS += -I$(SILECS_COMM_HOME)/include DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH) DEPENDENT_COMPILER_OPTIONS += -I$(BOOST_HOME)/include -DEPENDENT_LINKER_OPTIONS += -L$(SILECS_COMM_HOME)/lib/$(CPU) DEPENDENT_LINKER_OPTIONS += -L$(SNAP7_BASE) -lsnap7 DEPENDENT_LINKER_OPTIONS += -L/usr/lib64 -lxml2 -DEPENDENT_LINKER_OPTIONS += -lsilecs-comm +DEPENDENT_LINKER_OPTIONS += -L$(SILECS_COMM_HOME)/lib/$(CPU) -lsilecs-comm DEPENDENT_LINKER_OPTIONS += -lstdc++ -lxml2 -lboost_system -lboost_filesystem -lcurl # Set default library search path diff --git a/silecs-communication-cpp/Makefile b/silecs-communication-cpp/Makefile index 1a542d42493eb2fa631e2d610e9c70b523986167..df95e10961d67c06c2abc896d0ca53e176062e10 100644 --- a/silecs-communication-cpp/Makefile +++ b/silecs-communication-cpp/Makefile @@ -38,11 +38,19 @@ COMPILER_FLAGS = -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH) #Enable C++11 Support COMPILER_FLAGS += -std=c++11 -# Comment IN/Out to enable NI-Support -#COMPILER_FLAGS += -DNI_SUPPORT_ENABLED=TRUE - -# Comment IN/Out to enable Modbus-Support -#COMPILER_FLAGS += -DMODBUS_SUPPORT_ENABLED=TRUE +ifdef NI_SUPPORT_ENABLED +COMPILER_FLAGS += -DNI_SUPPORT_ENABLED=TRUE +$(info --- Build with NI support: enabled) +else +$(info --- Build with NI support: disabled) +endif + +ifdef MODBUS_SUPPORT_ENABLED +COMPILER_FLAGS += -DMODBUS_SUPPORT_ENABLED=TRUE +$(info --- Build with modbus support: enabled) +else +$(info --- Build with modbus support: disabled) +endif # Include the generic make file -include $(COMMON_MAKE_PATH)/Make.generic \ No newline at end of file +include $(COMMON_MAKE_PATH)/Make.generic diff --git a/silecs-communication-cpp/Makefile.dep b/silecs-communication-cpp/Makefile.dep index 580e172e750328698c70864072fff0d9652f2886..17163129e9ffae9aaf6b42f919f16ff4df373327 100644 --- a/silecs-communication-cpp/Makefile.dep +++ b/silecs-communication-cpp/Makefile.dep @@ -5,16 +5,11 @@ SNAP7_BASE ?= ../snap7/snap7-full BOOST_HOME ?= /opt/gsi/3rdparty/boost/$(BOOST_VERSION) ifdef MODBUS_SUPPORT_ENABLED - MODBUS_VERSION = 3.0.6 - MODBUS_ROOT=$(RELEASE_LOCATION)/$(CPU)/3rdparty/libmodbus-$(MODBUS_VERSION) - MODBUS_SRC=$(MODBUS_ROOT)/src - MODBUS_LIB=$(MODBUS_SRC)/.libs - MODBUS_RPATH=$(RELEASE_LOCATION)/$(CPU)/3rdparty/libmodbus-$(MODBUS_VERSION)/src/.libs + MODBUS_VERSION = 3.1.7 + MODBUS_BASE=/common/usr/cscofe/silecs/modbus/$(MODBUS_VERSION) + DEPENDENT_COMPILER_OPTIONS += -I$(MODBUS_BASE)/include endif -ifdef MODBUS_SUPPORT_ENABLED - DEPENDENT_COMPILER_OPTIONS += -I$(MODBUS_SRC) -endif DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH) DEPENDENT_COMPILER_OPTIONS += -I$(SNAP7_BASE)/release/Wrappers/c-cpp DEPENDENT_COMPILER_OPTIONS += -I$(BOOST_HOME)/include \ No newline at end of file diff --git a/silecs-communication-cpp/install.sh b/silecs-communication-cpp/install.sh index aa870caed6f502a2f4042154f555e8b214b3501f..0e31cea230431e74363bc8d617fa1c1574f7c3ec 100755 --- a/silecs-communication-cpp/install.sh +++ b/silecs-communication-cpp/install.sh @@ -7,6 +7,8 @@ SILECS_VERSION=$2 SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "$SCRIPT") # path where this script is located in +CPU=x86_64 + RELEASE_DIR=${RELEASE_DIR_BASE}/${SILECS_VERSION}/silecs-communication-cpp if [ -d ${RELEASE_DIR} ]; then echo "Error: ${RELEASE_DIR} already exists ...skipping" @@ -18,7 +20,15 @@ MINOR=`echo $SILECS_VERSION | cut -d. -f2` PATCH=`echo $SILECS_VERSION | cut -d. -f3` make -C ${SCRIPTPATH} clean -make -C ${SCRIPTPATH} CPU=x86_64 MAJOR=${MAJOR} MINOR=${MINOR} PATCH=${PATCH} -j4 +MODBUS_SUPPORT_ENABLED=true make -C ${SCRIPTPATH} CPU=${CPU} MAJOR=${MAJOR} MINOR=${MINOR} PATCH=${PATCH} -j4 + +# Squash the silecs library with the modbus library, so no extra-lining will be required +SILECS_LIB=${SCRIPTPATH}/build/lib/${CPU}/libsilecs-comm.a +SQUASHED_LIB=${SCRIPTPATH}/build/lib/${CPU}/libsquashed.a +cd ${SCRIPTPATH} +ar -M <squash_modbus_lib.mri +rm ${SILECS_LIB} +mv ${SQUASHED_LIB} ${SILECS_LIB} mkdir -p ${RELEASE_DIR} cp -r ${SCRIPTPATH}/build/include ${RELEASE_DIR} diff --git a/silecs-communication-cpp/squash_modbus_lib.mri b/silecs-communication-cpp/squash_modbus_lib.mri new file mode 100644 index 0000000000000000000000000000000000000000..145b3152f4805139b195f8a2699e12eb5ff1fb42 --- /dev/null +++ b/silecs-communication-cpp/squash_modbus_lib.mri @@ -0,0 +1,5 @@ +create build/lib/x86_64/libsquashed.a +addlib build/lib/x86_64/libsilecs-comm.a +addlib /common/usr/cscofe/silecs/modbus/3.1.7/lib/libmodbus.a +save +end diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp index 9cc7500eb96515018ca35e1e37363a9dfb9e6e3e..f4d5eb9799180d57cef2963fb5d2cfde4bd431ba 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp @@ -257,7 +257,8 @@ int MBConnection::readRegisters(PLC *thePLC, long address, unsigned long offset, if (doOpen(thePLC)) { // connection is established then acquire data - readLock(); + Lock lock(readMux_); + // Schneider uses 16bit alignment memory. Block address is expressed in // bytes (==> /2) long addr = (address + offset) / 2; @@ -269,7 +270,6 @@ int MBConnection::readRegisters(PLC *thePLC, long address, unsigned long offset, err = readFrames(readCtx_, addr, (unsigned short)size, pBuffer, isIO); checkError(thePLC, err, false); // close the connection, will try again // at the next access - readUnlock(); } return err; } @@ -298,7 +298,8 @@ int MBConnection::writeRegisters(PLC *thePLC, long address, unsigned long offset if (doOpen(thePLC)) { // connection is established then send data - writeLock(); + Lock lock(writeMux_); + // Schneider uses 16bit alignment memory. Block address is expressed in // bytes (==> /2) long addr = (address + offset) / 2; @@ -310,7 +311,6 @@ int MBConnection::writeRegisters(PLC *thePLC, long address, unsigned long offset err = writeFrames(writeCtx_, (unsigned short)addr, (unsigned short)size, pBuffer); checkError(thePLC, err, false); // close the connection, will try again // at the next access - writeUnlock(); } return err; } @@ -334,7 +334,7 @@ int MBConnection::readBits(PLC *thePLC, long address, unsigned long offset, unsi if (doOpen(thePLC)) { // connection is established then acquire data - readLock(); + Lock lock(readMux_); // addr is a byte address, therefore we don't need to convert to a word address // However, we need to calculate the coil address from the register address @@ -351,7 +351,6 @@ int MBConnection::readBits(PLC *thePLC, long address, unsigned long offset, unsi err = readCoils(readCtx_, addr, (unsigned short)size, pBuffer); checkError(thePLC, err, false); // close the connection, will try again // at the next access - readUnlock(); } return err; } @@ -375,7 +374,7 @@ int MBConnection::writeBits(PLC *thePLC, long address, unsigned long offset, uns if (doOpen(thePLC)) { // connection is established then send data - writeLock(); + Lock lock(writeMux_); // addr is a byte address, therefore we don't need to convert to a word address // However, we need to calculate the coil address from the register address @@ -391,7 +390,6 @@ int MBConnection::writeBits(PLC *thePLC, long address, unsigned long offset, uns err = writeCoils(writeCtx_, (unsigned short)addr, (unsigned short)size, pBuffer); checkError(thePLC, err, false); // close the connection, will try again // at the next access - writeUnlock(); } return err; } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.h index ec13ffa935ab5882a7666bf3fb6c1b85f6cac47c..3810a27d2efa2a1148580c1f3a38f91f9811cdc4 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.h @@ -15,7 +15,7 @@ Contributors: #define _MB_CONNECTION_H_ #include <silecs-communication/interface/communication/SilecsConnection.h> -#include <modbus.h> +#include <modbus/modbus.h> namespace Silecs { diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBHardware.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBHardware.h index 8b0d1d0456b4262ec2e914a678bd43be93894578..48650f5e3f8e534d9be7e4d5210dd47a133621d9 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBHardware.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBHardware.h @@ -15,7 +15,7 @@ Contributors: #define _MBHARDWARE_H_ #include <silecs-communication/interface/communication/ietype.h> -#include <modbus.h> +#include <modbus/modbus.h> /*----------------------------------------------------------*/ /* Time funtion