RS232 Blockset

This blockset allows Simulink to communicate with remote devices using RS232 interface.
20.2K Downloads
Updated 4 Jun 2004

No License

RS232 Blockset is a block library that allows to a simulation model to communicate directly and in real time (using, for example, the RT Blockset also published in MATLAB Central) with a remote device.

Actually, it's possible to use a simple communication protocol based on formatted string (in which simulation data is used to compose the message) using a ANSI C printf-like formatting standard.

12 blocks are actually available:

Initialization:
- RS232_Setup: Initialize and close the serial communication. The settings of the serial communication are selectable using the block panel
Unbuffered Formatted Communication:
- RS232_Read_Format: Reads from the serial port a formatted string (function analogue to the standard-C sscanf function).
- RS232_Write_Format: writes to the serial port a formatted string (function analogue to the standard-C sprintf function).
- RS232_Write_String: writes to the serial port the string indicated as block parameter.
- RS232_Read_Fix_Format: Read fix formatted string from a buffer. This block has been generated specifically to read Flight Simulator's formatted data string.
Buffered Formatted Communication:
- RS232_Create_Buffer: Initialize and allocate an input communication buffer.
- RS232_Read_Buffer: Reads bytes from the serial port, add them to the input buffer and looks into the buffer for a formatted string (function analogue to the standard-C sscanf function), leaving into the buffer all the bytes that doesn't correspond to the searched string (except the ones that are before the found string).
- RS232_Wait_Buffer_Synch: Looks for messages headers into the buffer and returns the "code" of first message in the buffer. Read data from the serial port and add it to the buffer, but doesn't remove any byte from it.
Bynary Formatted Communication:
- RS232_Write_Binary: Write a binary formatted data to the serial output.
Binary Buffered Formatted Communication:
- RS232_Read_Binary_Buffer: This block reads bytes from the serial port, add them to the input buffer and gets, starting at the start of the buffer, formatted data (the format is declared in the format string argument), leaving into the buffer all the bytes that exceeds the read operation.
- RS232_Peek_Binary_Buffer: This block peeks bytes from the serial port, add them to the input buffer and gets, starting at the start of the buffer, formatted data (the format is declared in the format string argument), leaving unmodified the buffer (no bytes are removed from the buffer, eventually some data are added in the case that new data is in the input port).
The interface of this function is the same respect to the RS232_Read_Binary_Buffer block, except that after the read is complete, the read portion of data is NOT removed from the buffer.
- RS232_Synch_Binary_Buffer: Looks for data header into the buffer and returns "1" at the output flag when the header is found.

The library blocks allow to write a simple string, to read and write a formatted string, to buffer strings and read multiple string types, to read and write a fix formatted string and to read and write a binary formatted strings. Some more blockset will be available in the new version, specialized for read and write to the RS232 port using the NMEA protocol or the TAIP (Trimble ASCII) protocol.
The RTW and xPC release of this blockset will be also available in the next future.

Cite As

Leonardo Daga (2024). RS232 Blockset (https://www.mathworks.com/matlabcentral/fileexchange/5060-rs232-blockset), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Block Libraries in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0