CModbusException Class
class CModbusException : public CException
A CModbusException object represents an exception condition related to a communication operation whith modbus slave device. These exceptions include communications exceptions and modbus functions exceptions, for instance , if you try to preset a register and the address is invalid, the modbus slave return a message indicating this invalid operation.
You do not need to create objects of this class, this creation is intended to be made inside CModbus Class.
Constructor
CModbusException(CString& sMessage,int nError);
parameters
sMessage - String with error Description.
nError - Error number.
example
extern CModbus* pModbus; // this pointer is created by a derived class.
pModbus->ThrowException(TRUE);
try {
//It's not needed to verify each call for errors
pModbus->ForceSingleCoil(17,172,TRUE) ; //force coil 173 ON in slave device 17
pModbus->PresetSingleRegister(17,1,3) ; //preset register 40002 to 03 in slave device 17
}
catch(CModbusException* pException) {
TCHAR szCause[255];
CString strFormatted;
pException->GetErrorMessage(szCause, 255);
strFormatted = _T("Modbus Function Error-");strFormatted += szCause; AfxMessageBox(strFormatted);
AfxMessageBox(strFormatted);
pException->Delete();
}
See also: CException in MCF library help files.