[TRNSYS-users] c++ type: call utility subroutine “Messages()”

Sergio.Pintaldi at csiro.au Sergio.Pintaldi at csiro.au
Wed Feb 18 14:44:26 PST 2015


Hi,

You have to define it in TRNSYS.h like this (I renamed the function in my case, otherwise you can use the default name in capitals letters):

extern "C" __declspec(dllimport) void	_cdecl MESSAGES(int* errorCode,char* message, char* severity, int* unitNo, int* typeNo, int n, int m);
#define Messages						MESSAGES

Then you have to declare in your code:

int errCode = 0;
char Severity0[10],Message0[800];
strcpy_s(Message0,"Hot water temperature out of boundaries!");
strcpy_s(Severity0,"NOTICE");

when you want your error code to pop up in the simulation list:

if(condition)
{
		errCode = 1;
		Messages(&errCode,Message0,Severity0,&iunit,&itype,strlen(Message0),strlen(Severity0));
}

Of course you call message with the severity ERROR (see manual) the simulation will stop!

Regards,

Sergio Pintaldi

-----Original Message-----
From: gernot.steindl at gmx.at [mailto:gernot.steindl at gmx.at] 
Sent: Tuesday, 17 February 2015 1:46 AM
To: trnsys-users at lists.onebuilding.org
Subject: [TRNSYS-users] c++ type: call utility subroutine “Messages()”

Hello,
I have some trouble using the utility subroutine Messages() in a type programmed in C++.
I edited the TRNSYS.h and added a declaration as it is done for TYPECK():

extern "C" __declspec(dllimport) void _cdecl MESSAGES(int *errorCode,char *message, char *serverity, int *unitNo, int *typeNo);


If the messages function is called in the code I get a stack overflow error. I think the reason for this is passing of the char array.
Here is the code how the message function is called:

				int error=1, unitNo=222, typeNo=222;
				char mes[800]="message";
				char serverity[800]="Fatal";
				MESSAGES(&error, *mes, serverity, &unitNo, &typeNo);

My first attempt was to define the char arrays like ‘char *mes="message"’ but I got the same error and I read that the default maxMessageLength is set to 800, so I tired this too.
Has anyone used the function in C++ and can show me an example.
Thank you very much!



More information about the TRNSYS-users mailing list