The StreamToSerialPort control allows any Virtuoso data stream to be routed to a COM Port on the host computer, so that the virtual target can use a physical serial port for development.
The data stream routing maintains the Virtuoso IStreamSource stream interface model. Any stream source can be used to source data to the serial port for transmission, and the StreamToSerialPort control provides a stream source for data received from the serial port, 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 StreamToSerialPort 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 StreamToSerialPort control, for direct routing of data to a serial port. 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 StreamToSerialPort 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 UARTRxDataReceived(unsigned char * pSrc, int Length)
// Process received UART data
Compile the project, then add the UART Rx stream as a down stream on the Target Model using the Target Model Builder, as shown.
Then add the UART 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 UART simulation driver to use.
Build the project and open MainWindow.xaml. Now add the StreamToSerialPort control to the host view by opening MainWindow.xaml in the Solution Explorer, and dragging and dropping the StreamToSerialPort 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. StreamToSerialPortViewModel – Specifies the name to be used for the serial port view model property that is created for this serial port.
2. Baud Rate – Specifies the baud rate for the serial port.
3. Target – Specifies which Target contains the Up and Down streams which will be connected to the serial port. 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 serial port consumes any stream source interface. The serial port 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 StreamToSerialPort view model initialization code.
4. Data Bits – Specifies the number of serial port data bits to use.
5. Select In Stream – Specifies a target Up Stream to use as the stream source for the serial port transmit data direction.
6. Parity Bit – Specifies the parity bit for the serial port to use.
7. Select Out Stream – Specifies a target Down Stream to use as the stream consumer for the serial port receive data direction.
8. Stop Bit – Specifies the stop bit for the serial port to use.
9. Port Name – Specifies the host COM Port to be used at runtime. This COM Port should be visible in the Device Manager and not be in use by other applications.
10. Handshake – Specifies the handshaking to be used by the serial port.
11. Display Name – Can be used to add a label below the serial port.
Click “Submit” to submit the serial port configuration once all items have been specified. When deleting a StreamToSerialPort control after it has been configured by the wizard, you should use the “Delete” icon below the “Wizard” icon. If a serial port control hasn’t been configured yet, you will need to just click on the serial port component in the view and press the delete button to remove it from the view.
When a StreamToSerialPort 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 serial port component wizard automates the configuration of the serial port view component as a normal MVVM view component, just like a TextBox or a Button. Using the wizard to configure the serial port as outlined above performs the following standard MVVM design tasks in the background:
1) A StreamToSerialPortViewModel component is added as a property of the specified Target ViewModel class, as shown below:
private StreamToSerialPortViewModel _StreamToSerialPortViewModel1;
public StreamToSerialPortViewModel StreamToSerialPortViewModel1
2) The serial port 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.
_StreamToSerialPortViewModel1 = new StreamToSerialPortViewModel(this, UARTTx, UARTRx, "Select", 0, Parity.None, 0, StopBits.None, Handshake.None, " ");
3) The DataContext property for the serial port is bound to the new StreamToSerialPortViewModel property exposed by the Target ViewModel, as shown below.