ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 01-30-2009
Lolke Koopmans's Avatar
Lolke Koopmans Lolke Koopmans is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Posts: 42
Downloads: 21
Uploads: 0
Thanks: 24
Thanked 14 Times in 10 Posts
Rep Power: 163
Lolke Koopmans is on a distinguished road
Default Multiple files open

Hello,

For a large model I would like to have multiple text files open to write my results during the simulation run. Preferable by using a dll.
I know how to open/close files in a dll. Also multiple files is possible, but only within 1 function. I would like to have some kind of reference to the files, so that I do not have to open and close the files each time.
Is this possible and does anyone know how?

Thanks,
Lolke
  #2  
Old 01-30-2009
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

You can use the C library's fopen command, which returns a FILE * type. Then you just need to globally define your FILE* variables.
Code:
FILE* myglobalfile1;
FILE* myglobalfile2;
double myfileopenfunc()
{
   myglobalfile1 = fopen("C:\\log1.txt", "w");
   myglobalfile2 = fopen("C:\\log2.txt", "w");
}
...
After that you use the c library's file i/o commands, i.e. fwrite, fprintf, fclose. A good reference site is www.cplusplus.com.
The Following 3 Users Say Thank You to Anthony Johnson For This Useful Post:
RalfGruber (01-30-2009)
  #3  
Old 01-31-2009
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Anthony,

I was under the impression that you couldn't have global variables in a DLL?


Steven
  #4  
Old 02-03-2009
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Steven,
I think you're confusing Flexsim's "Global Variables" feature with a standard C++ global variable. A dll can have as many C++ global variables as you want to have, which is what was being used in the example code above. In 4.32 it wasn't possible to connect a dll to a Flexsim Global Variable, although it is possible now in 4.5 with a little extra connecting code. This isn't documented, so get back to me if you need to connect to Flexsim's Global Variables.
The Following User Says Thank You to Anthony Johnson For This Useful Post:
Lolke Koopmans (02-04-2009)
  #5  
Old 02-04-2009
Lolke Koopmans's Avatar
Lolke Koopmans Lolke Koopmans is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Posts: 42
Downloads: 21
Uploads: 0
Thanks: 24
Thanked 14 Times in 10 Posts
Rep Power: 163
Lolke Koopmans is on a distinguished road
Default

It seems that there are missing some replies in the forum.
Lars-Olof posted a very usefull piece of example code in this thread...
  #6  
Old 02-04-2009
Lars-Olof Leven Lars-Olof Leven is offline
Flexsim Distributor
 
Join Date: Aug 2007
Location: Sweden, Borlnge
Posts: 312
Downloads: 278
Uploads: 2
Thanks: 300
Thanked 256 Times in 139 Posts
Rep Power: 330
Lars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to beholdLars-Olof Leven is a splendid one to behold
Default

Everytime I try to post the code again I get an error.
I attach the code in a file until the problem is solved.

L-O
Attached Files
File Type: zip main.zip (1.6 KB, 226 views)
The Following 2 Users Say Thank You to Lars-Olof Leven For This Useful Post:
Lolke Koopmans (02-04-2009)
  #7  
Old 02-08-2010
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Anthony,

I tried searching the forum but I couldn't find anything. Could you explain a bit more how to use Global Variabels from Flexsim in the DLL?

I have looked at the file userfuncs.h and there it states how to define them but I expect that userfuncs has to be called somewhere. Is that in the DLLmain.cpp on the same location where also the Flexsimfuncs.h is called? We tried this but weren't succesfull.

Steven

Last edited by Steven Hamoen; 02-08-2010 at 09:02 AM.


Thread Thread Starter Forum Replies Last Post
how to open another GUI qin tian Q&A 13 01-04-2010 06:52 AM
Flowitem Bin and Media Files Martijn van Oostenbrugge Q&A 10 09-04-2008 09:13 AM
State files and global variables Markus Bans Q&A 3 07-08-2008 12:22 PM
Creating fsm-Files Ralfi Q&A 4 10-16-2007 06:07 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.