Can JaamSim servers read and write files?

398 views
Skip to first unread message

Thom DeCarlo

unread,
May 23, 2017, 2:31:20 PM5/23/17
to Jaamsim Users Discussion Group
I need to create a simulation that reads from files in one directory, performs a transformation of the information that was read, and writes the transformed data to a different location. I need to be able to vary the read frequency and transformation speed either randomly (with a known distribution) or manually when triggered by the user. 

I know that I can do the time-varying operations in JaamSim, but I'm not sure that there is any mechanism to read and write files during simulation execution. Is there a solution to that aspect of my problem?

Thanks!
Thom

Harry King

unread,
May 23, 2017, 2:50:18 PM5/23/17
to Jaamsim Users Discussion Group
Hi Thom,

We haven't built anything into JaamSim to read/write data files dynamically during a simulation run. You might be able to structure your input file as a TimeSeries and use the EntityLogger object to write entries to an output file.

Would that work for you?

Harry

Thom DeCarlo

unread,
May 23, 2017, 3:06:58 PM5/23/17
to Jaamsim Users Discussion Group
Hi Harry,
Unfortunately, this simulation in JaamSim would be fed data from other processes and would be, in turn, feeding its results to other processes. So, I don't think I would be able to know all that is required for input at start time. I might be able to use the logging feature to mimic the file output, but that only produces a single file which I'd need to parse in realtime into separate output files for the consumer of JaamSim's output.

-Thom

Harry King

unread,
May 23, 2017, 3:14:57 PM5/23/17
to Jaamsim Users Discussion Group
Thom,

It wouldn't be difficult for you to write some custom objects for your application. All the necessary infrastructure for file handling is already available in JaamSim, and you can easily make them drag-and-drop-able.

We would be happy to support you on this.

Harry

Thom DeCarlo

unread,
May 23, 2017, 3:22:38 PM5/23/17
to Jaamsim Users Discussion Group
Thanks Harry! I have cloned the repo from github and I'm digging into the code and examples now. I'm sure that I'll be back with more questions soon.

-Thom

Harry King

unread,
May 23, 2017, 4:31:57 PM5/23/17
to Jaamsim Users Discussion Group
Thom,

The DemoEntity class in the package "com.jaamsim.Examples" will give you an example of how to program a new object for JaamSim. By default, the Examples palette and DemoEntity are not shown in the Model Builder, however, they can be activated by editing the file "resources/inputs/examples.inc" and deleting the following line of input:

DemoEntity  DragAndDrop { FALSE }

Let me know if you have any questions.

Harry

Harry King

unread,
Jun 2, 2017, 4:13:29 PM6/2/17
to Jaamsim Users Discussion Group
Thom,

I am working on a new object that will read an external file and set its output "Value" to a 1D or 2D array of numbers in the data file. In the present version, the file is read and the output populated when the configuration file is loaded.

I gather that you want to change the contents of the data file and re-read it while the simulation is running. I suppose that this action could be triggered by the object receiving an entity. The ability to allow the user to trigger the action could be provided by creating a new object that generated an entity when clicked by the user when the simulation is running. Both of these features would be easy to accomplish.

Would the above give you the functionality you need?

Harry

Thom DeCarlo

unread,
Jun 2, 2017, 7:08:57 PM6/2/17
to Harry King, Jaamsim Users Discussion Group
Harry,
Yes! That sounds very close to exactly what I was asking for. Of course, my client has since moved the goalposts. I'm not sure if it's now harder or easier, though.

I think reading from a file, either at start-up or during execution, is still good. But, instead of writing to a disk file, he wants to use an http GET/POST to send the message to a remote server. I may be able to do that by running a separate service that just monitors the output directory and creates the http traffic when new data appears.

I will definitely be digging into this next week. Thanks again for your help!

-Thom

Sent from my iPad and at the mercy of Autocorrect



--
You received this message because you are subscribed to a topic in the Google Groups "Jaamsim Users Discussion Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jaamsim-users/KGzayx75X10/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jaamsim-user...@googlegroups.com.
Visit this group at https://groups.google.com/group/jaamsim-users.
To view this discussion on the web, visit https://groups.google.com/d/msgid/jaamsim-users/a0d1bba2-3c9b-44cf-a314-c28e7dbc4252%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harry King

unread,
Jun 7, 2017, 12:07:59 PM6/7/17
to Jaamsim Users Discussion Group, d.harr...@gmail.com
Thom,

I've created two new objects FileToVector and FileToMatrix that read a data file and populate an output named "Value" with the numerical values. For FileToVector, the output Value is a 1-dimensional array, while for FileToMatrix, it is a 2-dimensional array. For the latter case, there is a separate entry for each record in the file. These outputs can used in expressions in the normal fashion. Each object reads the data file when it is first specified as an input and (optionally) whenever the object receives an entity.

You can try them out by downloading the HarryWIP branch from the github repository. They will appear officially in the next release (2017-06).

Harry

Harry King

unread,
Jun 14, 2017, 8:22:27 PM6/14/17
to Jaamsim Users Discussion Group, d.harr...@gmail.com
Thom,

Release 2017-06 with FileToVector and FileToMatrix is now available.

Harry
Reply all
Reply to author
Forward
0 new messages