Transferring Strings Between Vortex and Simulink


In this document we'll show how to transfer strings between Vortex and Simulink. While there is a "string" type in Simulink, it is not available in the public API and so cannot be incorporated directly with Vortex. To circumvent this limitation, we opt to treat strings in the Vortex block as vectors of unsigned 8 bit integers (uint8) and use the string blocks available in the Simulink library to transform, pad and display the strings appropriately. 

Sending Strings from Vortex to Simulink

To achieve this, all we need to do is convert the uint8 vector coming from Vortex to a Simulink string and display it. We do this using Simulink's "ASCII to String" and "Display" blocks, as illustrated in the model below:

To test this model, we create a mechanism in Vortex with a Simulink Block Extension and VHL interface that hardcodes a string (e.g. "hello from Vortex") and sends it to the input of the Simulink block extension via a connection container.

If everything is connected correctly, running the Simulink simulation should result in the string being displayed in the "Display" block:

Sending Strings from Simulink to Vortex

This case is a little bit more complicated. We use the "String Constant" and "String to ASCII" blocks to produce the uint8 vector that will be sent to the Vortex block. However, the output port of the "String to ASCII" block drives a signal of variable size, whereas the ports in our Simulink block only accept signals of fixed size. To work around this, we will use a custom Matlab function block to truncate or pad the output of the "String to ASCII" block as needed to deliver a signal of fixed size (256) to the Vortex block.  

In the Matlab function block, all we do is pad the signal with 0s or truncate it so that its size is 256.

Within Vortex, all we need to do is add an output field to our Simulink block extension, an input field to our VHL, and connect them in the connections container.

If everything is connected correctly, running the Simulink simulation should result in the string from Simulink being displayed in the Vortex Simulink extension output field.

The full Simulink model is illustrated below:

Limitations

String size is currently limited to 256 characters.

References

https://www.mathworks.com/help/simulink/ug/simulink-strings.html