Hi,
I wanted to know if I can use DDE to exchange data from a java application. I have a small application which I built in java which implements few algorithms. I want vensim model to run the java application and get those values while the simulation is running.
e.g
I start the simulation, for some variable I need vensim so call this java module which would fetch some values from excel and some values form database run some calculation and send it back to vensim.
I tried looking at the DDE manual but its not clear what kind of application can use DDE and how to implement it.
Using external calls we can build c++ functions but to call java methods from c++ is quite tricky to implement with vensim included.
Akshay D.
DDE
-
- Super Administrator
- Posts: 4838
- Joined: Wed Mar 05, 2003 3:10 am
DDE might not be the most appropriate to exchange info, but you can use it.
I found this on the web
http://www.nevaobject.com/_docs/_javadde/JavaDde.htm
You would need to modify your Java application and add a DDE server. Then write some Vensim external functions to initiate a conversation with your application and request some data.
If you look in the DSS reference supplement of the Vensim help file, chapter 9 contains details on vdde_initiate, vdde_poke, vdde_request and vdde_terminate. These are what you would need to link in with your C/C++ functions.
Hope this helps.
I found this on the web
http://www.nevaobject.com/_docs/_javadde/JavaDde.htm
You would need to modify your Java application and add a DDE server. Then write some Vensim external functions to initiate a conversation with your application and request some data.
If you look in the DSS reference supplement of the Vensim help file, chapter 9 contains details on vdde_initiate, vdde_poke, vdde_request and vdde_terminate. These are what you would need to link in with your C/C++ functions.
Hope this helps.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
You might also take a look at
http://journals.ecs.soton.ac.uk/java/tu ... ethod.html
(and probably others that was the first one google returned). Using JNI to call the Java methods is likely to be more effective - the only tricky thing is the lifetime of the objects - if you can declare them with simulation_setup and then delete them with simulation_shutdown that would be the most effective but I am not sure how that will work.
http://journals.ecs.soton.ac.uk/java/tu ... ethod.html
(and probably others that was the first one google returned). Using JNI to call the Java methods is likely to be more effective - the only tricky thing is the lifetime of the objects - if you can declare them with simulation_setup and then delete them with simulation_shutdown that would be the most effective but I am not sure how that will work.
Thank you for your quick response.
My confusion with regard to using JNI is that the call needs to be initiated by a java module. In my case it is being called from vensim external function which would be c++ ( through the DLL) then I would need to have observers which would notify the java program to initiate a call. trying to achieve this through vensim using DLL seems to be the tricky part. Also for observer to be able to function through out the simulation would be troublesome as the life time of java object is not predictable and might be deleted by the garbage collector.
However I would try the DDE if it can work for me.
My confusion with regard to using JNI is that the call needs to be initiated by a java module. In my case it is being called from vensim external function which would be c++ ( through the DLL) then I would need to have observers which would notify the java program to initiate a call. trying to achieve this through vensim using DLL seems to be the tricky part. Also for observer to be able to function through out the simulation would be troublesome as the life time of java object is not predictable and might be deleted by the garbage collector.
However I would try the DDE if it can work for me.
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
I am not sure how to get the Java runtime engine running - seems like it should be doable but who knows.
It occurs to me that an alternative to DDE which might be easier to implement would be to use system calls or files to pipe information to Java and then files to read information back from Java. I don't think going through files will cost that much in speed relative to DDE which is itself pretty slow.
It occurs to me that an alternative to DDE which might be easier to implement would be to use system calls or files to pipe information to Java and then files to read information back from Java. I don't think going through files will cost that much in speed relative to DDE which is itself pretty slow.