Skip to content
Snippets Groups Projects
Commit 1a277e94 authored by al.schwinn's avatar al.schwinn
Browse files

Enable modbus support

- squash modbus library into silecs library, so that no extra-linking
will be required
parent c65dbae2
No related branches found
No related tags found
No related merge requests found
...@@ -13,10 +13,9 @@ DEPENDENT_COMPILER_OPTIONS += -I$(SILECS_COMM_HOME)/include ...@@ -13,10 +13,9 @@ DEPENDENT_COMPILER_OPTIONS += -I$(SILECS_COMM_HOME)/include
DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH) DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH)
DEPENDENT_COMPILER_OPTIONS += -I$(BOOST_HOME)/include 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$(SNAP7_BASE) -lsnap7
DEPENDENT_LINKER_OPTIONS += -L/usr/lib64 -lxml2 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 DEPENDENT_LINKER_OPTIONS += -lstdc++ -lxml2 -lboost_system -lboost_filesystem -lcurl
# Set default library search path # Set default library search path
......
...@@ -38,11 +38,19 @@ COMPILER_FLAGS = -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH) ...@@ -38,11 +38,19 @@ COMPILER_FLAGS = -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH)
#Enable C++11 Support #Enable C++11 Support
COMPILER_FLAGS += -std=c++11 COMPILER_FLAGS += -std=c++11
# Comment IN/Out to enable NI-Support ifdef NI_SUPPORT_ENABLED
#COMPILER_FLAGS += -DNI_SUPPORT_ENABLED=TRUE COMPILER_FLAGS += -DNI_SUPPORT_ENABLED=TRUE
$(info --- Build with NI support: enabled)
# Comment IN/Out to enable Modbus-Support else
#COMPILER_FLAGS += -DMODBUS_SUPPORT_ENABLED=TRUE $(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 the generic make file
include $(COMMON_MAKE_PATH)/Make.generic include $(COMMON_MAKE_PATH)/Make.generic
\ No newline at end of file
...@@ -5,16 +5,11 @@ SNAP7_BASE ?= ../snap7/snap7-full ...@@ -5,16 +5,11 @@ SNAP7_BASE ?= ../snap7/snap7-full
BOOST_HOME ?= /opt/gsi/3rdparty/boost/$(BOOST_VERSION) BOOST_HOME ?= /opt/gsi/3rdparty/boost/$(BOOST_VERSION)
ifdef MODBUS_SUPPORT_ENABLED ifdef MODBUS_SUPPORT_ENABLED
MODBUS_VERSION = 3.0.6 MODBUS_VERSION = 3.1.7
MODBUS_ROOT=$(RELEASE_LOCATION)/$(CPU)/3rdparty/libmodbus-$(MODBUS_VERSION) MODBUS_BASE=/common/usr/cscofe/silecs/modbus/$(MODBUS_VERSION)
MODBUS_SRC=$(MODBUS_ROOT)/src DEPENDENT_COMPILER_OPTIONS += -I$(MODBUS_BASE)/include
MODBUS_LIB=$(MODBUS_SRC)/.libs
MODBUS_RPATH=$(RELEASE_LOCATION)/$(CPU)/3rdparty/libmodbus-$(MODBUS_VERSION)/src/.libs
endif endif
ifdef MODBUS_SUPPORT_ENABLED
DEPENDENT_COMPILER_OPTIONS += -I$(MODBUS_SRC)
endif
DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH) DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH)
DEPENDENT_COMPILER_OPTIONS += -I$(SNAP7_BASE)/release/Wrappers/c-cpp DEPENDENT_COMPILER_OPTIONS += -I$(SNAP7_BASE)/release/Wrappers/c-cpp
DEPENDENT_COMPILER_OPTIONS += -I$(BOOST_HOME)/include DEPENDENT_COMPILER_OPTIONS += -I$(BOOST_HOME)/include
\ No newline at end of file
...@@ -7,6 +7,8 @@ SILECS_VERSION=$2 ...@@ -7,6 +7,8 @@ SILECS_VERSION=$2
SCRIPT=$(readlink -f "$0") SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT") # path where this script is located in SCRIPTPATH=$(dirname "$SCRIPT") # path where this script is located in
CPU=x86_64
RELEASE_DIR=${RELEASE_DIR_BASE}/${SILECS_VERSION}/silecs-communication-cpp RELEASE_DIR=${RELEASE_DIR_BASE}/${SILECS_VERSION}/silecs-communication-cpp
if [ -d ${RELEASE_DIR} ]; then if [ -d ${RELEASE_DIR} ]; then
echo "Error: ${RELEASE_DIR} already exists ...skipping" echo "Error: ${RELEASE_DIR} already exists ...skipping"
...@@ -18,7 +20,15 @@ MINOR=`echo $SILECS_VERSION | cut -d. -f2` ...@@ -18,7 +20,15 @@ MINOR=`echo $SILECS_VERSION | cut -d. -f2`
PATCH=`echo $SILECS_VERSION | cut -d. -f3` PATCH=`echo $SILECS_VERSION | cut -d. -f3`
make -C ${SCRIPTPATH} clean 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} mkdir -p ${RELEASE_DIR}
cp -r ${SCRIPTPATH}/build/include ${RELEASE_DIR} cp -r ${SCRIPTPATH}/build/include ${RELEASE_DIR}
......
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
...@@ -257,7 +257,8 @@ int MBConnection::readRegisters(PLC *thePLC, long address, unsigned long offset, ...@@ -257,7 +257,8 @@ int MBConnection::readRegisters(PLC *thePLC, long address, unsigned long offset,
if (doOpen(thePLC)) if (doOpen(thePLC))
{ {
// connection is established then acquire data // connection is established then acquire data
readLock(); Lock lock(readMux_);
// Schneider uses 16bit alignment memory. Block address is expressed in // Schneider uses 16bit alignment memory. Block address is expressed in
// bytes (==> /2) // bytes (==> /2)
long addr = (address + offset) / 2; long addr = (address + offset) / 2;
...@@ -269,7 +270,6 @@ int MBConnection::readRegisters(PLC *thePLC, long address, unsigned long offset, ...@@ -269,7 +270,6 @@ int MBConnection::readRegisters(PLC *thePLC, long address, unsigned long offset,
err = readFrames(readCtx_, addr, (unsigned short)size, pBuffer, isIO); err = readFrames(readCtx_, addr, (unsigned short)size, pBuffer, isIO);
checkError(thePLC, err, false); // close the connection, will try again checkError(thePLC, err, false); // close the connection, will try again
// at the next access // at the next access
readUnlock();
} }
return err; return err;
} }
...@@ -298,7 +298,8 @@ int MBConnection::writeRegisters(PLC *thePLC, long address, unsigned long offset ...@@ -298,7 +298,8 @@ int MBConnection::writeRegisters(PLC *thePLC, long address, unsigned long offset
if (doOpen(thePLC)) if (doOpen(thePLC))
{ {
// connection is established then send data // connection is established then send data
writeLock(); Lock lock(writeMux_);
// Schneider uses 16bit alignment memory. Block address is expressed in // Schneider uses 16bit alignment memory. Block address is expressed in
// bytes (==> /2) // bytes (==> /2)
long addr = (address + offset) / 2; long addr = (address + offset) / 2;
...@@ -310,7 +311,6 @@ int MBConnection::writeRegisters(PLC *thePLC, long address, unsigned long offset ...@@ -310,7 +311,6 @@ int MBConnection::writeRegisters(PLC *thePLC, long address, unsigned long offset
err = writeFrames(writeCtx_, (unsigned short)addr, (unsigned short)size, pBuffer); err = writeFrames(writeCtx_, (unsigned short)addr, (unsigned short)size, pBuffer);
checkError(thePLC, err, false); // close the connection, will try again checkError(thePLC, err, false); // close the connection, will try again
// at the next access // at the next access
writeUnlock();
} }
return err; return err;
} }
...@@ -334,7 +334,7 @@ int MBConnection::readBits(PLC *thePLC, long address, unsigned long offset, unsi ...@@ -334,7 +334,7 @@ int MBConnection::readBits(PLC *thePLC, long address, unsigned long offset, unsi
if (doOpen(thePLC)) if (doOpen(thePLC))
{ {
// connection is established then acquire data // 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 // 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 // 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 ...@@ -351,7 +351,6 @@ int MBConnection::readBits(PLC *thePLC, long address, unsigned long offset, unsi
err = readCoils(readCtx_, addr, (unsigned short)size, pBuffer); err = readCoils(readCtx_, addr, (unsigned short)size, pBuffer);
checkError(thePLC, err, false); // close the connection, will try again checkError(thePLC, err, false); // close the connection, will try again
// at the next access // at the next access
readUnlock();
} }
return err; return err;
} }
...@@ -375,7 +374,7 @@ int MBConnection::writeBits(PLC *thePLC, long address, unsigned long offset, uns ...@@ -375,7 +374,7 @@ int MBConnection::writeBits(PLC *thePLC, long address, unsigned long offset, uns
if (doOpen(thePLC)) if (doOpen(thePLC))
{ {
// connection is established then send data // 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 // 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 // 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 ...@@ -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); err = writeCoils(writeCtx_, (unsigned short)addr, (unsigned short)size, pBuffer);
checkError(thePLC, err, false); // close the connection, will try again checkError(thePLC, err, false); // close the connection, will try again
// at the next access // at the next access
writeUnlock();
} }
return err; return err;
} }
......
...@@ -15,7 +15,7 @@ Contributors: ...@@ -15,7 +15,7 @@ Contributors:
#define _MB_CONNECTION_H_ #define _MB_CONNECTION_H_
#include <silecs-communication/interface/communication/SilecsConnection.h> #include <silecs-communication/interface/communication/SilecsConnection.h>
#include <modbus.h> #include <modbus/modbus.h>
namespace Silecs namespace Silecs
{ {
......
...@@ -15,7 +15,7 @@ Contributors: ...@@ -15,7 +15,7 @@ Contributors:
#define _MBHARDWARE_H_ #define _MBHARDWARE_H_
#include <silecs-communication/interface/communication/ietype.h> #include <silecs-communication/interface/communication/ietype.h>
#include <modbus.h> #include <modbus/modbus.h>
/*----------------------------------------------------------*/ /*----------------------------------------------------------*/
/* Time funtion /* Time funtion
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment