From dc1197a7a6b24f4cb268a332acdfa23fd66c91cf Mon Sep 17 00:00:00 2001 From: kochalas <konstantinos.chalas@cern.ch> Date: Fri, 8 Sep 2017 11:04:49 +0200 Subject: [PATCH] [SIL-317] Change address type from unsigned long to signed long and take care of negative address value inside read/write operations --- .../interface/communication/CNVConnection.cpp | 8 ++++---- .../interface/communication/CNVConnection.h | 12 ++++++------ .../interface/communication/MBConnection.cpp | 12 ++++++------ .../interface/communication/MBConnection.h | 12 ++++++------ .../interface/communication/SNAP7Connection.cpp | 8 ++++---- .../interface/communication/SNAP7Connection.h | 12 ++++++------ .../interface/communication/SilecsConnection.h | 8 ++++---- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp index 0623f57..e5c2f5a 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.cpp @@ -97,22 +97,22 @@ namespace Silecs return errorCode; } - int CNVConnection::readMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int CNVConnection::readMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { return readData(thePLC, address, offset, size, pBuffer); } - int CNVConnection::writeMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int CNVConnection::writeMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { return writeData(thePLC, address, offset, size, pBuffer); } - int CNVConnection::readIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int CNVConnection::readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { LOG(ERROR) << "Read IO not supported for CNV"; return 0; } - int CNVConnection::writeIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int CNVConnection::writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { LOG(ERROR) << "Write IO not supported for CNV"; return 0; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.h index 98a30c4..4e99e0b 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/CNVConnection.h @@ -67,21 +67,21 @@ namespace Silecs // not implemented. here because of virtual in super class // TODO: review in order to get read of it - int readData(PLC* thePLC, unsigned long address, + int readData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* buffer){ return -1;}; // not implemented. here because of virtual in super class // TODO: review in order to get read of it - int writeData(PLC* thePLC, unsigned long address, + int writeData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* buffer){return -1;}; - int readMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int readIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); private: // Subscriber 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 4c17eff..830200a 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.cpp @@ -141,7 +141,7 @@ namespace Silecs } - int MBConnection::readData(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int MBConnection::readData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { int rc = 0; int error = 0; @@ -178,7 +178,7 @@ namespace Silecs } - int MBConnection::writeData(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int MBConnection::writeData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { int rc = 0; int error = 0; @@ -214,25 +214,25 @@ namespace Silecs } - int MBConnection::readMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int MBConnection::readMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { return readData(thePLC, address, offset, size, pBuffer); } - int MBConnection::writeMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int MBConnection::writeMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { return writeData(thePLC, address, offset, size, pBuffer); } - int MBConnection::readIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int MBConnection::readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { return readData(thePLC, address, offset, size, pBuffer); } - int MBConnection::writeIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) + int MBConnection::writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { return writeData(thePLC, address, offset, size, pBuffer); } 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 a9263d4..98ef27e 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/MBConnection.h @@ -35,18 +35,18 @@ namespace Silecs MBConnection(PLC* thePLC); virtual ~MBConnection(); - int readMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeMemory(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int readIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeMemory(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); private: modbus_t* readCtx_; modbus_t* writeCtx_; bool open(PLC* thePLC); bool close(PLC* thePLC); - int readData(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeData(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); int mbWriteFrames(modbus_t* ctx, uint16_t dataAddr, uint16_t dataSize, uint8_t* dataBuffer); int mbReadFrames(modbus_t* ctx, uint16_t dataAddr, uint16_t dataSize, uint8_t* dataBuffer); bool checkError(PLC* thePLC, int err, bool retry); diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp index 2de7fd4..b31c9fa 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp @@ -199,7 +199,7 @@ bool SNAP7Connection::isRunning(PLC* thePLC) throw SilecsException(__FILE__, __LINE__, UNKNOWN_ERROR, std::string("PLC Status is: UNKNOWN")); } } -int SNAP7Connection::readMemory(PLC* thePLC, unsigned long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer) +int SNAP7Connection::readMemory(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer) { int err = 0; //(re)connect the PLC if needed and (re)synchronize the retentive registers @@ -215,7 +215,7 @@ int SNAP7Connection::readMemory(PLC* thePLC, unsigned long DBn, unsigned long of } return err; } -int SNAP7Connection::writeMemory(PLC* thePLC, unsigned long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer) +int SNAP7Connection::writeMemory(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer) { int err = 0; //(re)connect the PLC if needed and (re)synchronize the retentive registers @@ -232,7 +232,7 @@ int SNAP7Connection::writeMemory(PLC* thePLC, unsigned long DBn, unsigned long o return err; } -int SNAP7Connection::readIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) +int SNAP7Connection::readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { int err = 0; //(re)connect the PLC if needed and (re)synchronize the retentive registers @@ -250,7 +250,7 @@ int SNAP7Connection::readIO(PLC* thePLC, unsigned long address, unsigned long of return err; } -int SNAP7Connection::writeIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) +int SNAP7Connection::writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer) { int err = 0; //(re)connect the PLC if needed and (re)synchronize the retentive registers diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.h index 030a25f..aab6a06 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.h @@ -41,12 +41,12 @@ namespace Silecs bool isRunning(PLC* thePLC); - int readData(PLC* thePLC, unsigned long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeData(PLC* thePLC, unsigned long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int readMemory(PLC* thePLC, unsigned long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeMemory(PLC* thePLC, unsigned long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int readIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); - int writeIO(PLC* thePLC, unsigned long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readData(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeData(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readMemory(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeMemory(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); + int writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer); //Extension Silecs methods int coldRestart(PLC* thePLC); diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h index 4c5b9a7..784c1a8 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h @@ -43,25 +43,25 @@ namespace Silecs virtual ~Connection(); virtual int readMemory(PLC* thePLC, - unsigned long address, + long address, unsigned long offset, unsigned long size, unsigned char* buffer) = 0; virtual int writeMemory(PLC* thePLC, - unsigned long address, + long address, unsigned long offset, unsigned long size, unsigned char* buffer) = 0; virtual int readIO(PLC* thePLC, - unsigned long address, + long address, unsigned long offset, unsigned long size, unsigned char* buffer) = 0; virtual int writeIO(PLC* thePLC, - unsigned long address, + long address, unsigned long offset, unsigned long size, unsigned char* buffer) = 0; -- GitLab