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 7276087145f64dd1071ff685e566673af86cdb5a..ea562aacb40311a201aa25a30f4013635cea89d0 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.cpp @@ -198,4 +198,37 @@ namespace Silecs return 0; } +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// + //Puts the CPU in RUN mode performing a COLD START. + int SNAP7Connection::coldRestart(PLC* thePLC) + { + if(doOpen(thePLC)) + { + Lock lock(writeMux_); + int error = Cli_PlcColdStart(sendClient_); + if(error) + throw SilecsException(__FILE__, __LINE__, UNEXPECTED_ERROR," SNAP7 Error: " + getSNAP7ErrorMessage(error)); + + } + return 0; + } + + //Puts the CPU in STOP mode. + int SNAP7Connection::plcStop(PLC* thePLC) + { + if(doOpen(thePLC)) + { + Lock lock(writeMux_); + int error = Cli_PlcStop(sendClient_); + if(error) + throw SilecsException(__FILE__, __LINE__, UNEXPECTED_ERROR," SNAP7 Error: " + getSNAP7ErrorMessage(error)); + + } + return 0; + } +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + } // namespace 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 5d14818f47bade0cf3378e471f6139005dbc8e6a..740dc9bd4cde83420920c53c20383dd6d5093dff 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SNAP7Connection.h @@ -43,6 +43,10 @@ namespace Silecs 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); + //Extension Silecs methods + int coldRestart(PLC* thePLC); + int plcStop(PLC* thePLC); + private: S7Object recvClient_; S7Object sendClient_; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp index 7e3e053acc32f34b20544d05215b0d2bacf0f17d..d89db59b1108b9658020d1699905dbca78af283a 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp @@ -263,6 +263,20 @@ namespace Silecs return -1; } + //PERFORM COLD RESTART + int Connection::coldRestart(PLC* thePLC) + { + throw SilecsException(__FILE__, __LINE__, DIAG_PLC_REPORT_NOT_SUPPORTED, thePLC->getName()); + return -1; + } + + //PERFORM COLD RESTART + int Connection::plcStop(PLC* thePLC) + { + throw SilecsException(__FILE__, __LINE__, DIAG_PLC_REPORT_NOT_SUPPORTED, thePLC->getName()); + return -1; + } + //------------------------------------------------------------------------------------------------------------------- bool Connection::checkError(PLC* thePLC, int err, bool retry) 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 ca2319a0fcf80d0ce325c9f395eda5062c6ee683..ed9d0177af471602dd917d46873d8f04142ea5ba 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.h @@ -89,6 +89,9 @@ namespace Silecs virtual int readUnitStatus(PLC* thePLC, UnitStatusType& dataStruct); virtual int readCPUInfo(PLC* thePLC, CPUInfoType& dataStruct); virtual int readCPInfo(PLC* thePLC, CPInfoType& dataStruct); + //SET PLC COLD RESTART + virtual int coldRestart(PLC* thePLC); + virtual int plcStop(PLC* thePLC); protected: friend class Cluster; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp index 4db7910b03ee37d53c9196ecf383f540a8ce0de0..4f92638884add44201c6ec8ebf9de0c95b4f41c9 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp @@ -240,7 +240,7 @@ namespace Silecs { if( pDeviceIter->second->hasBlock((*blockIter)->getName())) { - LOG(COMM) << "Updating block '" << (*blockIter)->getName() << "' for device '" << pDeviceIter->second->getLabel()<< "'"; + LOG(COMM) << "Updating block '" << (*blockIter)->getName() << "' for device '" << pDeviceIter->second->getLabel()<< "'"; pDeviceIter->second->recv((*blockIter)->getName()); } } @@ -270,8 +270,22 @@ namespace Silecs { return getConnection()->readCPInfo(this, dataStruct); } +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// + //Puts the CPU in RUN mode performing a COLD START. + int PLC::sendColdRestart() + { + return getConnection()->coldRestart(this); + //return getConnection()->coldRestart(); + } - + int PLC::sendPlcStop() + { + return getConnection()->plcStop(this); + //return getConnection()->coldRestart(); + } +// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int PLC::recv(std::string blockName) { //Synchronous data receive diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h index 9f0b73d6f6555c285e024f1feb97a847b4901957..43f513e06a638b703046a8b4baad57620aa8e6b5 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h @@ -270,6 +270,9 @@ namespace Silecs int recvCPUInfo(CPUInfoType& dataStruct); int recvCPInfo(CPInfoType& dataStruct); + //Cold RESTART + int sendColdRestart(); + int sendPlcStop(); /*! * \brief Acquires one particular registers block of all devices of that PLC. * The method tries to (re)connect the PLC if the connection is not established yet or unexpectedly interrupted (network failure, PLC down, etc.).