Mirco Malagoli wrote:
I used this simple code for years on C++2009
<snip>
Now i have only recompiled on C++10S
What is "C++10S" supposed to be? C++Builder 10.x? Seattle, Berlin, or
Tokyo?
after some second i receive an "External exception EEFFACE".
EEFFACE means a C++ language exception was thrown and not caught in the
C++ code, it was caught by an exception handler inside the Delphi RTL,
which doesn't know how to handle C++ exceptions.
Is there anything to consider in working the indy components when
changing compiler version?
This is not a compiler issue. Your C++ code has a bug that threw an
uncaught exception. So catch it, and debug your code. Start with
using 'catch (const Exception &)' instead of 'catch (...)', the latter
doesn't always work correctly.
I would suggest simplifying your thread Execute() method:
void __fastcall TThIO::Execute()
{
while( !Terminated )
{
try
{
pSock->Connect();
try
{
while( !Terminated )
ProtocolloModbus();
}
__finally
{
pSock->Disconnect();
}
}
catch (const Exception &)
{
flInit = false;
Sleep(200);
}
}
}
Also, Modbus TCP has structure to it, but your ProtocolloModbus()
method is not really reading that structure very well. Try something
more like this:
void __fastcall TThIO::ProtocolloModbus()
{
TIdBytes header, data;
pSock->IOHandler->ReadBytes(header, 6);
int n = ((header[4] << 8) & 0xFF00) | header[5];
if( (header[0] == bufTx[0]) && (header[1] == bufTx[1]) )
{
pSock->IOHandler->ReadBytes(data, n);
// process data as needed...
}
else
pSock->IOHandler->Discard(n);
}
--
Remy Lebeau (TeamB)
Connect with Us