Sending Data
In addition to receiving data over a TCP/IP stream, data can be sent back to your model to control parameters that manipulate the hardware. This is done by using the probe tag, which sends the specified inputs back over the stream. Data can be input to the probe directly from a qdex element (button, slider, etc) using a signal tag, or the value of a Lua variable can be sent using a system tag.
Signalling from an App Control Element
The values of a button, toggle or slider can be sent directly over the stream by using the signal and probe tags. In this case, the signal tag is used to listen to the slider/button value, while the probe tag is used to send the data back. Sliders send their current value (a number between 0-100 in the example below), while buttons/toggles send either a 0 (not pressed) or a 1 (pressed).
<client name="myStream" uri="tcpip://172.16.0.62:18000" /> <slider name="sliderName" min="0" max="100" value="50" /> <simulation name="sim" period="0.01"> <solver name="solver2"> <series> <signal ref="mySection.sliderName"/> <probe ref="mySection.myStream" /> </series> </solver> </simulation>
Sending Lua Values
A custom system can be used to send Lua variables over the stream back to your model. A single point of data can be sent, or multiple values can be combined into a vector.
Single Data Point
If sending a single point of data, it can be directly referenced by name in the onOutputs method of the custom system. In the example below, the variable myVariable is manipulated elsewhere in the code (not shown) before being sent over the stream. .
<client name="myStream" uri="tcpip://172.16.0.62:18000" /> <simulation name="sim" period="0.01"> <solver name="solver2"> <series> <system name="mySystem"> <output name="myOutput" width="1" /> <onOutputs> return myVariable </onOutputs> </system> <probe ref="mySection.myStream" /> </series> </solver> </simulation>
Vector of Data
The system block can be used to send a Lua vector over the stream. The vector can contain different types of data, including the value of other Lua variables, or the value of an app control element like a toggle or slider.
In the below example, the value of the toggle switch is assigned to the first index of a vector, and the value of a slider is mapped to the second index. Both values are sent over the stream using the custom system.
<client name="myStream" uri="tcpip://172.16.0.62:18000" /> <script> local valueVector = vector(2); </script> <toggle name="toggleName"> <onValueChanged> valueVector[1] = toggleName.Value; </onValueChanged> </toggle> <slider name="mySlider" min="0" max="15" value="0"> <onValueChanged> valueVector[2] = value; </onValueChanged> </slider> <simulation name="sim" period="0.01"> <solver name="solver2"> <series> <system name="mySystem"> <output name="myOutput" width="2" /> <onOutputs> return valueVector </onOutputs> </system> <probe ref="mySection.myStream" /> </series> </solver> </simulation>