<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<title>Calling external program from a new C++ Component</title>
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=WordSection1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>Thank
you for your quick reply Werner,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>You
said:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'> “</span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>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).</span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>” </span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>That’s
a good idea, I tried to do that but can I have more explanation of how do you
do that :<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>“</span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>adding the TRNSYS
TYPE function which should then just call the main()</span><span
style='font-size:11.0pt;font-family:"Calibri","sans-serif"'> ”<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>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:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>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<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>As
you said, TRNSYS is only able to load dll that contain a type (that is
explained in that message)<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>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"<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>So
the question is, how do you add the TRNSYS type function which will call the
main function of my program ?<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>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 </span><span
style='font-family:"Calibri","sans-serif"'>//*** Call N ('normal' call) ?<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif"'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-family:"Calibri","sans-serif"'>Thx again<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> keilholz, werner
[mailto:werner.keilholz@cstb.fr] <br>
<b>Sent:</b> Thursday, October 07, 2010 11:19 AM<br>
<b>To:</b> Bezzarga, Amine (SCR US EXT); trnsys-users@cae.wisc.edu<br>
<b>Subject:</b> RE: [TRNSYS-users] Calling external program from a new C++
Component<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hi Amine, <o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>‘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.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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: </span><span lang=FR><a
href="http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx"><span
lang=EN-US>http://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx</span></a></span><o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>One challenge is to make sure the exe has finished before you
try to recover any results it may have put somewhere.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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).<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hope this helps,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Werner<o:p></o:p></span></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span
lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Bezzarga,
Amine (SCR US EXT) [mailto:amine.bezzarga.ext@siemens.com] <br>
<b>Envoyé :</b> mardi 5 octobre 2010 23:56<br>
<b>À :</b> trnsys-users@cae.wisc.edu<br>
<b>Objet :</b> [TRNSYS-users] Calling external program from a new C++
Component<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><span lang=FR><o:p> </o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>Hi everybody,</span><span
lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>I’m stuck with
TRNSYS  v 16.1</span> <span style='font-family:"Calibri","sans-serif"'>,
the part of the API that normally allow to call an external program (an exe
written in c++)</span> <span style='font-family:"Calibri","sans-serif"'>seems
to not be supported by the C++ plugin (I can just create my</span> <span
style='font-family:"Calibri","sans-serif"'> own component that will basically
calculate the output from the input)</span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>I mean the linker
can’t find the</span> <span style='font-family:"Calibri","sans-serif"'>“call”</span> <span
style='font-family:"Calibri","sans-serif"'> subroutine just like described in
the programmer’s guide of the manual (part 8):</span><span lang=FR><o:p></o:p></span></p>

<p><b><i><span style='font-size:13.5pt;font-family:"Arial","sans-serif"'>8.4.4.1.
Calling External Programs</span></i></b><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>I know</span> <span
style='font-family:"Calibri","sans-serif"'>the example shown is</span> <span
style='font-family:"Calibri","sans-serif"'>for fortran but, in the file 
..\Trnsys16_1\SourceCode\Templates\CppType.cpp we have this at the line 133:</span><span
lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>  //*** Call N
('normal' call)</span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>That seems to be the
function that allow me to call an external program, however there is no
reference of that function in the</span> <span style='font-family:"Calibri","sans-serif"'>“TRNSYS.h”,
So I’m being stuck with a linker problem.</span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>What I want to do</span> <span
style='font-family:"Calibri","sans-serif"'>is to</span> <span style='font-family:
"Calibri","sans-serif"'>start a simulation in TRNSYS, then when it reach a
certain component, TRNSYS will call a external program with data (in</span> <span
style='font-family:"Calibri","sans-serif"'>argument if possible)</span> <span
style='font-family:"Calibri","sans-serif"'> and wait for it to finish,</span> <span
style='font-family:"Calibri","sans-serif"'>and then get back value from my
program?</span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>Unfortunately, TRNSYS
doesn’t seem to support Socket connection to</span> <span
style='font-family:"Calibri","sans-serif"'>exchange data. I see that type66 do
it  (This routine calls a program called Engineering Equation Solver
(EES)) with the data exchange</span> <span style='font-family:"Calibri","sans-serif"'>protocol
via the windows’ clipboard. </span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>To resume:</span><span
lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>So do I have to start over
with the fortran plugin to be</span> <span style='font-family:"Calibri","sans-serif"'>able
to call external program?</span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>Or do you</span> <span
style='font-family:"Calibri","sans-serif"'>know a other way to do</span> <span
style='font-family:"Calibri","sans-serif"'>what I want ?</span><span lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>And</span> <span
style='font-family:"Calibri","sans-serif"'>do you think I need to communicate
through a file ?</span><span lang=FR><o:p></o:p></span></p>

<p class=MsoNormal><span lang=FR><o:p> </o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>Thanks a lot for your help.</span><span
lang=FR><o:p></o:p></span></p>

<p><span style='font-family:"Calibri","sans-serif"'>Amine</span><span lang=FR><o:p></o:p></span></p>

</div>

</body>

</html>