Skip to content
Snippets Groups Projects
Commit ce91609e authored by kochalas's avatar kochalas Committed by al.schwinn
Browse files

[SIL-317] Throw an exception when a negative address is used

parent dc1197a7
No related branches found
No related tags found
No related merge requests found
......@@ -143,8 +143,14 @@ namespace Silecs
int MBConnection::readData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer)
{
int rc = 0;
int error = 0;
int rc = 0;
int error = -1;
if (address < 0)
{
LOG(COMM) << "Invalid address: " << address;
throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(address));
}
//Schneider uses 16bit alignment memory. Block address is expressed in bytes, must be an even value!
if (address % 2) throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(address));
......@@ -180,8 +186,14 @@ namespace Silecs
int MBConnection::writeData(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer)
{
int rc = 0;
int error = 0;
int rc = 0;
int error = -1;
if (address < 0)
{
LOG(COMM) << "Invalid address: " << address;
throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(address));
}
//Schneider uses 16bit alignment memory. Block address is expressed in bytes, must be an even value!
if (address % 2) throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(address));
......
......@@ -201,7 +201,14 @@ bool SNAP7Connection::isRunning(PLC* thePLC)
}
int SNAP7Connection::readMemory(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer)
{
int err = 0;
int err = 1;
if (DBn < 0)
{
LOG(COMM) << "Invalid DB number: " << DBn;
throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(DBn));
}
//(re)connect the PLC if needed and (re)synchronize the retentive registers
if (doOpen(thePLC))
{
......@@ -217,7 +224,14 @@ int SNAP7Connection::readMemory(PLC* thePLC, long DBn, unsigned long offset, uns
}
int SNAP7Connection::writeMemory(PLC* thePLC, long DBn, unsigned long offset, unsigned long size, unsigned char* pBuffer)
{
int err = 0;
int err = 1;
if (DBn < 0)
{
LOG(COMM) << "Invalid DB number: " << DBn;
throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(DBn));
}
//(re)connect the PLC if needed and (re)synchronize the retentive registers
if (doOpen(thePLC))
{
......@@ -234,7 +248,13 @@ int SNAP7Connection::writeMemory(PLC* thePLC, long DBn, unsigned long offset, un
int SNAP7Connection::readIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer)
{
int err = 0;
int err = 1;
if (address < 0)
{
LOG(COMM) << "Invalid address: " << address;
throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(address));
}
//(re)connect the PLC if needed and (re)synchronize the retentive registers
if (doOpen(thePLC))
{
......@@ -252,7 +272,13 @@ int SNAP7Connection::readIO(PLC* thePLC, long address, unsigned long offset, uns
int SNAP7Connection::writeIO(PLC* thePLC, long address, unsigned long offset, unsigned long size, unsigned char* pBuffer)
{
int err = 0;
int err = 1;
if (address < 0)
{
LOG(COMM) << "Invalid address: " << address;
throw SilecsException(__FILE__, __LINE__, PARAM_INCORRECT_BLOCK_ADDRESS, StringUtilities::toString(address));
}
//(re)connect the PLC if needed and (re)synchronize the retentive registers
if (doOpen(thePLC))
{
......
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