7.11. Data exchange between Ptolemy II and programs that are started by the Simulator actor

Simulation programs that are started by the Simulator actor exchange data with Ptolemy II through a BSD socket connection. Each simulation program has its own socket connection. The exchange data is parsed into a text string, and this text string is sent from the simulation program to the Simulator actor, and from the Simulator actor to the simulation program.

The text string has the following format:

a b c d e f g_1 g_2

where a is the version number that is defined by the constant MAINVERSION in lib/defines.h and b is a flag that is defined in Table 7.2, “Definition of flag of BSD Socket message”. What follows are the number of variables that are exchanged. In particular, c is the number of doubles, d is the number of integers and e is the number of booleans that will be exchanged. Currently, d and e need to be set to 0. Next, f is the current simulation time in seconds. The remaining entries g_1, g_2 up to g_c are the double values. The string is terminated by the character \n.

The flag b is defined as follows:

Table 7.2. Definition of flag of BSD Socket message

FlagDescription
+1Simulation reached end time.
0Normal operation.
-1Simulation terminated due to an unspecified error.
-10Simulation terminated due to an error during the initialization.
-20Simulation terminated due to an error during the time integration.


An example where 2 values are sent at time equals 60 looks like

2 0 2 0 0 6.000000000000000e+01 9.958333333333334e+00 9.979166666666666e+00

To stop a simulation program because the final time has been reached, send the following string:

2 1 0 0 0