Hello all,
Is it possible to post non-error messages to the PME using COBIA (e.g. warnings/info)? If so, are there any examples on how to do so available? I am aware of the Simulation Context Interface, which includes the LogMessage and PopUpMessage functions, and I have also checked out the ThermoClientPMETest example from the COBIA source code, but I have not figured out how to properly use it yet. Any advice would be appreciated.
Posting non-error messages to the PME
Moderator: jasper
Re: Posting non-error messages to the PME
Any PME that supports this (mostly all) will set the simulation context.
There, you can query for the ICapeDiagnostics interface. Make that a class member.
Then, use LogMessage from the ICapeDiagnostics.
Example:
There, you can query for the ICapeDiagnostics interface. Make that a class member.
Then, use LogMessage from the ICapeDiagnostics.
Example:
Code: Select all
CAPEOPEN_1_2::CapeDiagnostic diagnostic;
void putSimulationContext(/*in*/ CAPEOPEN_1_2::CapeSimulationContext context) {
diagnostic=context; //may not be implemented
}
void LogMessage(CapeStringImpl &messsage) {
if (diagnostic) {
diagnostic.LogMessage(messsage);
}
}
Re: Posting non-error messages to the PME
Thank you!
For reference, I needed to make a very minor modification for the code to compile. When setting the context, the MSVC compiler needed to be explicitly told to cast the CapeSimulationContext object to the CapeDiagnostic class.
For reference, I needed to make a very minor modification for the code to compile. When setting the context, the MSVC compiler needed to be explicitly told to cast the CapeSimulationContext object to the CapeDiagnostic class.
Code: Select all
void putSimulationContext(/*in*/ CAPEOPEN_1_2::CapeSimulationContext context)
{
diagnostic=static_cast<CAPEOPEN_1_2::CapeDiagnostic>(context); //may not be implemented
}
Re: Posting non-error messages to the PME
For me it works without the cast.
Note that the assignment operator does a queryInterface and the result may be null.
What is the compilation error message without the cast?
Note that the assignment operator does a queryInterface and the result may be null.
What is the compilation error message without the cast?
Re: Posting non-error messages to the PME
I had assumed the latter to be the case from the code samples you provided. I also confirmed it the hard way when I forgot to check for the pointer's existence before clearing it in the Terminate() function and got an access violation exception in combase!CoGetContextToken. That was fun to debug...
As for the error when no cast is used:
I should mention that I was using an older version of COBIA (probably 1.2.1.0). I only realised that just now and updated to the latest, 1.2.1.2. The error disappeared after updating. For reference, I am using MSVC v143 with ISO C++20 and ISO C17. If you'd like further information, please let me know.
As for the error when no cast is used:
Code: Select all
Code Description
E0349 no operator "=" matches these operands
C2679 binary '=': no operator found which takes a right-hand operand of type 'CAPEOPEN_1_2::CapeSimulationContext' (or there is no acceptable conversion)
Re: Posting non-error messages to the PME
I thought this was fixed a while ago - which version of the COBIA-SDK are you using?
Re: Posting non-error messages to the PME
I installed the COBIA SDK on my PC in January 2025, so it must have been 1.2.1.0, which released in February 2024. I cannot be sure, though, since I updated to 1.2.1.2 shortly before I posted my previous reply in this thread (that's when it occurred to me that this might be the cause). I can confirm that updating did fix the error
.

Re: Posting non-error messages to the PME
Excellent - good to hear.