Receiving Data

Once a connection has been established using a signal to the stream, there are two main ways that the received data can be used: it can be sent directly to a qdex element (e.g. plot) using the probe tag, or it can be sent to a Lua variable for calculation or manipulation using the system tag. If receiving many different signals that need to be manipulated in various ways, the demux tag can be used to separate the received data for processing.

Probing to a Plot

Probing received data to a timePlot is the simplest way to use the data, and can be set up using very little code. Take a look at the examples below.

One set of data

If receiving a single data set from the stream, it can be displayed by probing to the plot directly after using the signal tag to reference the stream.

<client name="streamName" uri="tcpip://192.168.0.101:18000" />

<timePlot name="myPlot" />

<simulation period="0.01" name="thisSim">
  <solver name="solver">    
    <series>    
      <signal ref="mySection.streamName" />
      <probe ref="mySection.myPlot" />
    </series>
  </solver>
</simulation>

If receiving two or more sets of data from the stream, they can all be displayed on a single plot by setting the series attribute in the timePlot declaration to the number of series being received. 

<timePlot name="myPlot" series="2" />

The width attribute of the signal must also be set to the number of series being received. 

<signal ref="mySection.streamName" width="2" />


Two sets of data, separate plots

If receiving two or more sets of data from the stream, they can be displayed on separate plots by demultiplexing the received signal and probing to two separate plots inside of a stack. 

<client name="streamName" uri="tcpip://192.168.0.101:18000" />

<timePlot name="myPlot" />
<timePlot name="myOtherPlot" />

<simulation period="0.01" name="thisSim">
  <solver name="solver">    
    <series>    
      <signal ref="mySection.streamName" width="2" />
       <demux outputs="2" />
       <stack>
         <probe ref="mySection.myPlot" />
         <probe ref="mySection.myOtherPlot" />
       </stack>
    </series>
  </solver>
</simulation>

Lua Variable

You can also use the received data to update a Lua variable. The Lua variable can then be manipulated with math, or used to update an animation. Assigning the received data to a Lua variable requires the use of a custom system. 

<client name="myStream" uri="tcpip://192.168.0.101:18000" width="2" />

<script>
  local thisVar, thatVar;
</script>

<simulation period="0.1" name="sim">
  <solver name="solver">
    <series>
      <signal ref="mySection.myStream" width="2" />
      <system name="myCustomSystem">
        <input name="myReceivedData" width="2" />
        <onOutputs>
          thisVar = myReceivedData[1]
          thatVar = myReceivedData[2]
        </onOutputs>
      </system>
    </series>
  </solver>
</simulation>

The data that is received from the stream is fed into the input of the custom system as a vector. The values of the vector are assigned to the lua variables thisVar and thatVar, and are updated each period of the simulation. The simulation onUpdate method could be used to call a function that manipulates the variables.

Receiving Multiple Data Sets

Demultiplexing can be used to separate a number of data sets and manipulate them differently. In the below example, the received signal has a width of 10, and the demux tag is used to separate the received data into three "channels" in a stack:

  • Data sets 1 and 2 are assigned to the first channel, which is a probe that outputs to a plot in a stack
  • Data sets 3-5 are assigned to the second channel, which is a probe that outputs to a different plot in that same stack
  • Data sets 6-9 are assigned to the third channel, and act as the first input to the custom system
  • Data set 10 is assigned to the third channel, and acts as the second input to the custom system
<simulation name="thisSimulation" period="0.01">
  <solver name="mySolver">
    <series>
      <signal ref="mySection.streamName" width="10" />
      <demux outputs="2 3 4 1" />
      <stack>
        <probe ref="mySection.stackName.firstPlot" />
        <probe ref="mySection.stackName.secondPlot" />
        <system>
          <input name="inputOne" width="4" />
          <input name="inputTwo" width="1" />
          <onOutputs>
            local myVector = inputOne
            local myVariable = inputTwo[1]
          </onOutputs>
        </system>
      </stack>
    </series>
  </solver>
</simulation>

This method of demultiplexing the received data allows for the sending/receiving of more complicated stream data, where many different parameters can all be sent to/from qdex using a single stream.