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

Re: [TRNSYS-users] C++ API not working



Michael,

I assume you are using TRNSYS16 coding style in your component. I'm not sure that the getMaxLabelLength() function works with the coding style.However, the function works fine in my TRNSYS'17' coding style component.

The getDeckFileName() seems to me that the function does not care about C/C++ strings. I have got exactly same error.
Unless, you modified the function to cope with C/C++ style, I think that you can not avoid the access violation error.
For example, I have added the following new function in the TrnsysFunction.f90 to avoid the error.

-TrnsysFunction.f90

Function getDeckFileNameEx() bind(c,name="getDeckFileNameEx")
 !dec$ attributes dllexport :: getDeckFileNameEx
 Use TrnsysData
 Use, intrinsic :: iso_c_binding
 type(C_ptr) :: getDeckFileNameEx
 Character(len=maxPathLength) ret 
 ret = trim(deckn1)//CHAR(0)
 getDeckFileNameEx = C_LOC(ret)
End Function getDeckFileNameEx

- C/C++ Component sourcecode
extern "C" __declspec(dllimport) char*    _cdecl getDeckFileNameEx(void);

      char *dckfilename;
      dckfilename = getDeckFileNameEx();

I do not like this idea because an expensive Fortran compiler is needed to build.
Does anyone know that how to call FORTRAN function returns characters?

Best regards,

Yuichi Yasuda
quattro corporate design co.,ltd
T2000 Bld. 4F, 1-11-29 Mita, Meguro-ku, Tokyo, 153-0062, Japan
Tel:+81 (0)3 5768 6744 Fax:+81 (0)3 5768 6745
Email: yasuda@qcd.co.jp
http://www.qcd.co.jp/



 


On 2016/05/21 0:22, Michael Holzhauser via TRNSYS-users wrote:
Hello all,

I managed to build a customized TRNSYS Type in C++ by extending the Type202 example that is delivered with TRNSYS 17. I can access the input values and return the corresponding output values without any problems. However, the communication with the TRNSYS Core functions somehow don’t work. Whenever I invoke some function that returns an integer value (like getMaxLabelLength()), the result is NaN. Whenever I try to invoke some function that returns characters (like getDeckFileName()), TRNSYS crashes with something like „Access violation at address XXXXX in module ‚TRNDLL.DLL‘. Write of address XXXXX.“ or with „forttrl: severe (408): fort: (18): Dummy character variable ‚GETLABEL@0‘ has length 300 which is greater than actual variable length 1“ (in case of getLabel).

As I read in other topics like this one, there seemed to be several issues in the TRNSYS.h header file and the library files long ago: 

However, 11 years later, is there a workaround for this problem?

Thanks in advance.

--

M.Sc. Michael Holzhauser
AG Optimization
University of Kaiserslautern

Paul-Ehrlich-Str. 14 - 451
67663 Kaiserslautern, Germany

Phone:  +49 (631) 205-2511
E-mail: holzhauser@mathematik.uni-kl.de




_______________________________________________
TRNSYS-users mailing list
TRNSYS-users@lists.onebuilding.org
http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org