Setting up a Communication Stream
Communications in qdex use common communication protocols and associated parameters, often TCP/IP. In this way, all that is required to send and receive data is the IP address of the computer or device. Communications in qdex require two key blocks:
1) A client block to specify the communication protocol and reference address of the stream.
2) A simulation block to send and receive data over that stream. Inside the simulation, the signal and probe blocks are used to send/receive different types of data.
The client block is used to define the communication stream. It requires a name and a reference address to work. The URI must specify the protocol, the address, and the port number. You can also write scripts that are triggered when one of the following events occur:
- onConnected - occurs when connection to stream is made..
- onDisconnected - occurs when disconnection from stream is made.
- onReceive - occurs when data is received from stream.
Note that the client block maintains a persistent connection, which means that it automatically reconnects whenever the connection is lost. To stop this persistent connection the simulation that is referencing the client block must be stopped.
This example uses a client block, that when connected and disconnected, updates the text of a button and notifies you when data is received.
<client name="myClient" uri="tcpip://18.104.22.168:18000"> <!--Updating button text.--> <onConnected> myButton.Text = "Disconnect" </onConnected> <!--Updating button text.--> <onDisconnected> myButton.Text = "Connect" </onDisconnected> <!--Notifying user when data is recieved.--> <onReceive> notify(" Data Received") </onReceive> </client>
The simulation is used to send and receive data over a stream. A connection with the client will not be established until the simulation has been started and connection will be maitained until simulation stops.
<!--Simulation--> <simulation name="mySim" period="0.01"> <solver> <series> <!--Recieving data, outputting to plot--> <signal ref ="mySection.myClient"/> <probe ref="mySection.myPlot" /> </series> </solver> <!--Sending value from qdex slider--> <solver> <series> <signal ref ="mySection.mySlider"/> <probe ref ="mySection.myClient"/> </series> </solver> </simulation>