Go Back
Virtuoso standard control libraries StreamIOToConsole Terminal


The StreamToTCPSocket control allows any Virtuoso data stream to be routed to a TCP socket on the host computer, so that the virtual target can communicate directly with remote networked devices.


The data stream routing maintains the Virtuoso IStreamSource stream interface model. Any stream source can be used to source data to the TCP socket for transmission, and the StreamToTCPSocket control provides a stream source for data received from the TCP socket, which can be used by any Virtuoso stream consumer.

The design wizard supports automatic connection to streams exposed on the Target Model (i.e. “Up Streams” and “Down Streams”, which are with respect to the target). However, the StreamToTCPSocket control supports connection with any data stream, not just Up and Down data streams exposed on the Target Model.

The image below shows the basic concept. At the top, a Tx Up Stream and a Rx down stream are connected directly to the StreamToTCPSocket control, for direct routing of data to a TCP socket. At the bottom, the same data flow is used, except a console terminal is placed in series. Data flowing in either direction is displayed on the console, color-coded to indicate the source.


The first step in adding a StreamToTCPSocket control is to add the data streams to your project that you want to interface with. First, add an Rx event handler to the project, as shown below, in the SIM_HW.c file.

void TCPSocketRxDataReceived(unsigned char * pSrc, int Length)
    // Process received UART data

Compile the project, then add the TCP Socket Rx stream as a down stream on the Target Model using the Target Model Builder, as shown.


Then add the TCP Socket Tx up stream to the Target Model as well, again using the Target Model Builder. This will create a stream handle for the up stream in Virtuoso.h for the TCP socket simulation driver to use.

Build the project and open MainWindow.xaml. Now add the StreamToTCPSocket control to the host view by opening MainWindow.xaml in the Solution Explorer, and dragging and dropping the StreamToTCPSocket control from the Virtuoso Standard Control Library Toolbox.


The console terminal will be displayed as an unadorned black panel. To the right of the StreamIOToConsoleTerminal control, click the topmost icon to open the Design Wizard.

The wizard dialog will open as shown below.

The configuration setting fields are described as follows:

1. StreamToTCPSocketViewModel – Specifies the name to be used for the TCP socket view model property that is created for this TCP socket.

2. Target – Specifies which Target contains the Up and Down streams which will be connected to the TCP socket. Note again the naming convention, that ‘Up’ specifically references a target pushing data up to a host, and ‘Down’ specifically references a target receiving data down from a host. Whereas ‘In’ and ‘Out’ indicate data flow direction without respect to the relationship between a target and the host. The In Stream of the TCP socket consumes any stream source interface. The TCP socket provides an Out Stream stream source interface which can be used by any component. The design wizard helps you easily locate and hook up target Up Streams and Down Streams. Non-target streams can be connected by manually passing in streams in the StreamToTCPSocket view model initialization code.

3. Select In Stream – Specifies a target Up Stream to use as the stream source for the TCP socket transmit data direction.

4. Port Number – Specifies the port number to use for the TCP socket.

5. Display Name – Can be used to add a label below the TCP socket.

Click “Submit” to submit the TCP socket configuration once all items have been specified. When deleting a StreamToTCPSocket control after it has been configured by the wizard, you should use the “Delete” icon below the “Wizard” icon. If a TCP socket control hasn’t been configured yet, you will need to just click on the TCP socket component in the view and press the delete button to remove it from the view.

When a StreamToTCPSocket control is dragged from the Virtuoso Standard Control Library to a window, this results in the XAML declaration as shown below to be added to the view.

The TCP socket component wizard automates the configuration of the TCP socket view component as a normal MVVM view component, just like a TextBox or a Button. Using the wizard to configure the TCP socket as outlined above performs the following standard MVVM design tasks in the background:

1) A StreamToTCPSocketViewModel component is added as a property of the specified Target ViewModel class, as shown below:

private StreamToTCPSocketViewModel _StreamToTCPSocketViewModel1;
public StreamToTCPSocketViewModel StreamToTCPSocketViewModel1
        return this._StreamToTCPSocketViewModel1;

2) The TCP socket component is constructed in the TargetViewModel initialization function based on the desired configuration. This is added as construction code in the Target ViewModel’s InitializeComponents method, as shown below.

_StreamToTCPSocketViewModel1 = new StreamToTCPSocketViewModel(this, TCPSocketTx, TCPSocketRx, 8001, "TCP Port");

3) The DataContextproperty for the serial port is bound to the new StreamToTCPSocketViewModel property exposed by the Target ViewModel, as shown below.