[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TRNSYS-users] Calling external program from a new C++ Component



Title: Calling external program from a new C++ Component

Thank you for your quick reply Werner,

 

You said:

 “If you have the source code of the exe, another option would be to recompile it as a DLL, adding the TRNSYS TYPE function which should then just call the main() function of your application (you can then easily pass parameters and recover results).

 

That’s a good idea, I tried to do that but can I have more explanation of how do you do that :

adding the TRNSYS TYPE function which should then just call the main()

 

Because I tried to recompile my exe into a dll, then link my lib to the new component project, it compile without problem but when I run the simulation in TRNSYS, I get this error:

TRNSYS Message    105 : A TYPE was called in the TRNSYS input file but was either not linked into trndll.dll or was not found in an external dll. A dummy subroutine was called in its place. Please link the TYPE or remove it from the input file  Reported information  : Reported by LINKCK

 

As you said, TRNSYS is only able to load dll that contain a type (that is explained in that message)

TRNSYS Message    199 : TRNSYS found at least one user DLL in the UserLib directory. (Note: Only DLL's including Types that are used in the simulation are loaded)  Reported information  : 1 user DLL was loaded after searching in "C:\Program Files\Trnsys16_1\UserLib\ReleaseDLLs"

 

So the question is, how do you add the TRNSYS type function which will call the main function of my program ?

 

Should I create a new type with the studio, then add a function wich will do the same as my exe, and call that function where there is that comment //*** Call N ('normal' call) ?

 

Thx again

 

From: keilholz, werner [mailto:werner.keilholz@cstb.fr]
Sent: Thursday, October 07, 2010 11:19 AM
To: Bezzarga, Amine (SCR US EXT); trnsys-users@cae.wisc.edu
Subject: RE: [TRNSYS-users] Calling external program from a new C++ Component

 

Hi Amine,

 

‘Call’ is not the name of a TRNSYS API function, but just a comment to say that at this point in the example, the C routine is called for the Nth time.

 

To call an external program in C, you should use the Windows API. There are many ways to do this, one is to use CreateProcess() function, as described here: http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx

 

One challenge is to make sure the exe has finished before you try to recover any results it may have put somewhere.

 

If you have the source code of the exe, another option would be to recompile it as a DLL, adding the TRNSYS TYPE function which should then just call the main() function of your application (you can then easily pass parameters and recover results).

 

Hope this helps,

 

Werner

 

 

 

De : Bezzarga, Amine (SCR US EXT) [mailto:amine.bezzarga.ext@siemens.com]
Envoyé : mardi 5 octobre 2010 23:56
À : trnsys-users@cae.wisc.edu
Objet : [TRNSYS-users] Calling external program from a new C++ Component

 

Hi everybody,

I’m stuck with TRNSYS  v 16.1 , the part of the API that normally allow to call an external program (an exe written in c++) seems to not be supported by the C++ plugin (I can just create my  own component that will basically calculate the output from the input)

I mean the linker can’t find the “call”  subroutine just like described in the programmer’s guide of the manual (part 8):

8.4.4.1. Calling External Programs

I know the example shown is for fortran but, in the file  ..\Trnsys16_1\SourceCode\Templates\CppType.cpp we have this at the line 133:

  //*** Call N ('normal' call)

That seems to be the function that allow me to call an external program, however there is no reference of that function in the “TRNSYS.h”, So I’m being stuck with a linker problem.

What I want to do is to start a simulation in TRNSYS, then when it reach a certain component, TRNSYS will call a external program with data (in argument if possible)  and wait for it to finish, and then get back value from my program?

Unfortunately, TRNSYS doesn’t seem to support Socket connection to exchange data. I see that type66 do it  (This routine calls a program called Engineering Equation Solver (EES)) with the data exchange protocol via the windows’ clipboard.

To resume:

So do I have to start over with the fortran plugin to be able to call external program?

Or do you know a other way to do what I want ?

And do you think I need to communicate through a file ?

 

Thanks a lot for your help.

Amine