Posting non-error messages to the PME

Discusses CAPE-OPEN specific middleware and corresponding development kit

Moderator: jasper

Post Reply
User avatar
desyk
Posts: 7
Joined: 12 March 2025, 09:43
Location: U.K. / Greece

Posting non-error messages to the PME

Post by desyk »

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.
User avatar
jasper
Posts: 1146
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Posting non-error messages to the PME

Post by jasper »

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:

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);
		}
	}
User avatar
desyk
Posts: 7
Joined: 12 March 2025, 09:43
Location: U.K. / Greece

Re: Posting non-error messages to the PME

Post by desyk »

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.

Code: Select all

void putSimulationContext(/*in*/ CAPEOPEN_1_2::CapeSimulationContext context)
{
	diagnostic=static_cast<CAPEOPEN_1_2::CapeDiagnostic>(context); //may not be implemented
}
User avatar
jasper
Posts: 1146
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Posting non-error messages to the PME

Post by jasper »

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?
User avatar
desyk
Posts: 7
Joined: 12 March 2025, 09:43
Location: U.K. / Greece

Re: Posting non-error messages to the PME

Post by desyk »

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:

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)
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.
User avatar
jasper
Posts: 1146
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Posting non-error messages to the PME

Post by jasper »

I thought this was fixed a while ago - which version of the COBIA-SDK are you using?
User avatar
desyk
Posts: 7
Joined: 12 March 2025, 09:43
Location: U.K. / Greece

Re: Posting non-error messages to the PME

Post by desyk »

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 :D .
User avatar
jasper
Posts: 1146
Joined: 24 October 2012, 15:33
Location: Spain
Contact:

Re: Posting non-error messages to the PME

Post by jasper »

Excellent - good to hear.
Post Reply

Return to “CAPE-OPEN Binary Interop Architecture”