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

keilholz, werner werner.keilholz at cstb.fr
Thu Oct 7 08:19:18 PDT 2010


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 <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 at siemens.com] 
Envoyé : mardi 5 octobre 2010 23:56
À : trnsys-users at 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20101007/8e2dbcb4/attachment-0005.htm>


More information about the TRNSYS-users mailing list