![]() ![]() BRAHMS
User Guide » Developing Processes » Quick Start » 1199 » Generating Output
This documentation is offline - click here to go online
Index | Search: Go online to use Search
| ||
OverviewThe empty Process you've created doesn't generate any output. We can see this if we modify the test script to view the outputs it generates. M Source Code (against 995)
Running this script as it stands, you'll get the following. Matlab Console
>> test
sml_log object: 1-by-1
That is, an empty log object is generated, because no Process in the System generated any outputs to fill this structure. Notes
Adding an output portThe Process can create as many outputs as it likes whilst it is servicing EVENT_INIT_CONNECT. This event is fired multiple times, and you should create output ports as early as possible (on the first of these calls that you can). The only reason to not create an output on the very first call is if you need to see some of your inputs before you know what sort of output to create. We don't, so we're just going to create an output port on our first call. We'll create the port during EVENT_INIT_CONNECT, and store it for later use, so we'll have to also add a state variable to store it. We're going to add an output of data type C++ Source Code (against 1199)
// include the binding
brahms -1199.h"
// alias data namespace to something briefer namespace numeric C++ Source Code (against 1199)
/*
Private member data of the process goes here.
You can use this to store your parameters
and process state between calls to event().
*/
// an (numeric) output port numeric C++ Source Code (against 1199)
// on first call
if
F_FIRST_CALL // create one output output Viewing the output logIf you run the test script as it stands, you'll get output like this. Matlab Console
>> test
process: [sml_log]
The Process has now created an output, so the output structure gets a field named after the process. Currently, and unimaginatively, our Process is called "process". Let's make a couple of changes to the test script. First, let's call our process something more meaningful. We're going to make a model of a very simple neuron, so let's call it "neuron". Second, let's get a look at what outputs it actually created, by looking deeper into that output structure. M Source Code (against 995)
M Source Code (against 995)
% show output
disp
disp Matlab Console
>> test
neuron: [sml_log]
out0001: [0x10 double]
OK - seems we've generated an output, and it's named "out0001". Bit of a crap name, that. Naming the output portNaming an output port is straightforward. Modify your source file as follows. C++ Source Code (against 1199)
output outputMatlab Console
>> test
neuron: [sml_log]
out: [0x10 double]
OK - that's a much better name. Pretty generic, I suppose, but it'll certainly do for now. It's a numeric output because we created it as Setting the output structureExamining the test script, we have added the To give the output object the size we want, we can't ask the Framework, because the Framework doesn't know anything about the internals of Components. Instead, we call a function on the interface offered by the data object itself. Since the vast majority of data handling will involve Make the modifications below to set the output data structure to be double, real (not complex), and a two-element vector. Don't worry too much about the syntax of this call at this stage. C++ Source Code (against 1199)
// create one output
output
// structure it Matlab Console
>> test
neuron: [sml_log]
out: [2x10 double]
OK - Now we've got 10 samples of a two-element vector, which is what we intended. Viewing output dataNow let's have a look at the actual values in the output log. Modify your test script as follows, to view the actual content of the output log. M Source Code (against 995)
% show output
disp disp disp Matlab Console
>> test
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
Unsurprisingly, the output is filled with zeroes. If you want to know why, see Writing output dataWe haven't got anything much to put in the output yet, but let's write something in there just to see how it's done. We write data to our outputs when we receive EVENT_RUN_SERVICE. C++ Source Code (against 1199)
case EVENT_RUN_SERVICE
// get a pointer to the port's contents (actual numeric data) // it's got two elements, so let's write them both p p
// ok
return C_OK Matlab Console
>> test
42 42 42 42 42 42 42 42 42 42
0 1 2 3 4 5 6 7 8 9
OK - now we're writing data to our output object. On each successive call to EVENT_RUN_SERVICE (we receive 10 such calls) we write two items of data (42 and the current Base Clock time). If you want to know exactly why you see the numbers 0 to 9, read Clocks then Servicing. The Framework is logging these two-element vectors as they are generated, and it collates them into the log that is returned to us when BRAHMS exits, seen above. Where do I go from here?If you need more control over the Numeric Type of the output, see the documentation for In addition, you can create output Sets, if required, but this is not something you should adopt unless there is a real need - most processes don't need Sets. See Using Sets under Advanced Topics. To find out more about how you can interact with your outputs, review the documentation for SystemMLInterface. |
||
This is a documentation page for the BRAHMS Modular Execution (Simulation) Framework. For details of licensing and distribution, please click here. To advise of an error or omission, please click here. |