RS232 Blockset |
Links for RS232Blockset download: (version 1.2.5 of 24.Jul.2004)Matlab 5.3+: RS232v5.3 1.2.2.zip (328Kb) (27.Feb.2004)*Matlab 6.0: RS232v6.0 1.2.2.zip (332Kb) (27.Feb.2004)*Matlab 6.5: RS232v6.5 1.2.5.zip (120Kb) (27.Feb.2004)*The 5.3 and 6.0 versions are updated only upon request. Just simply e-mail me... The User ManualThe User Manual reports the full content of this web page, with added more details and example on the use of the blockset. PDF Manual: RS232Blockset.pdf (437 Kb)PAGE INDEXIntroduction
|
--> Click on the block to go to the relative help instructions |
In the table that follows, the current available blocks are described.
Initialization |
RS232_Setup: Initialize and close the
serial communication. The settings of the serial communication are
selectable using the block panel. The parameters are:
If needed, a port number greater then 4 can be used simply modifying the block's mask. The block has two output ports:
Remarks: Even if this block is executed at each step, this block is active only in correspondence to the first and the last step of the simulation, step in which the block, respectively, open and close the communication. During the simulations, when the communication is open, the handle (out1) and the flag (out2) are constant, unless a major communications error occurs: in that case, out1 and out2 becomes 0. |
Unbuffered Formatted Communication |
RS232_Read_Format: This block reads from
the serial port a formatted string (function analogue to the standard-C sscanf
function).
The block panel allows the selection of the following parameters:
The block has 2 inputs and 3 outputs:
Remarks: The block starts its read operations when received a '1' flag from the input 2. The read operation remains active until the completion of the data read (that may request more than one simulation step). Once completed the read of the string, it modify the output 3 with new data and put the output 2 flag to '1' for only one simulation step. Each block instance use an internal buffer to accumulate pieces of data read from the serial port but that compose (for example) the next message. The buffer is used in the next step to complete the read of the incoming message. The buffer is separated for each instantiated block and resizes dynamically to manage eventual data quantity peak or, more generally, the multitasking of the OS. When the head of the message (all the part of the format message that precedes the first '%' character) is detected into the buffer, all the buffer that precedes the head is simply discarded and removed from the buffer. If both the head and the end of the message are detected in the buffer, the message is interpreted and, after, all the chars that precede (and contain) the end of the message are discarded from the buffer. See the example in the RS232 Read Format Behavior page. While the block is not active (the comm. handle is not valid (0) or the input flag (iput 2) is not active) and no read operation is pending, the block doesn't performs any operation. Cautions: Putting two Read_Format block in cascade to read two different formatted messages may work but with unpredictable result. Each block, when activated to read its kind of message, may read from serial port part of the message addressed to another block. In this case, the other block, when activated in the next step, may skip a message destined to it, waiting until this message back in the input port in a successive simulation time. Go to the RS232 Read Format Behavior page to see a typical behavior of two Read_Format block configured in cascade. |
|||||||||||||||||||||||||
RS232_Write_Format: This block writes to
the serial port a formatted string (function analogue to the standard-C sprintf
function).
The block panel allows the selection of the following parameters:
The block has 3 inputs and 2 outputs:
Remarks: While the block is not active (the comm. handle is not valid (0) or the input flag (input 2) is not active) the block doesn't performs any operation. |
|||||||||||||||||||||||||
RS232_Write_String: This block writes to
the serial port the string indicated as block parameter.
The block panel allows the selection of the following parameters:
The block has 2 inputs and 3 outputs:
Remarks: While the block is not active (the comm. handle is not valid (0) or the input flag (input 2) is not active) the block doesn't performs any operation. |
|||||||||||||||||||||||||
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 (thanks to Nelson Rojas Mendelewski
for his suggestions and requests about the topics.).
The block panel allows the selection of the following parameters:
The block has 2 inputs and 2 outputs:
Details:
Examples: To read a string like this one: "#DATA:123.19,1010.1,23.1*" you have to use a format string as follows: "#DATA:%6d4%,%6d8%,%4d8%*" In this example format string:
The decimal point inside the field should be taken into account in the evaluation of the field length. In your case, the string to read is something like this: "_00594-003+000357000000_" The format string is the following: "_%5i4%%4i4%%4i4%%3i4%%3i4%%3i4%_" |
Buffered Formatted Communication |
RS232_Create_Buffer: Initialize and
allocate an input communication buffer.
The block panel allows the selection of the following parameters:
The block has one output port:
Remarks: Even if this block is executed at each step, this block is active only in correspondence to the first and the last step of the simulation, step in which the block, respectively, create and destroy the buffer. During the simulations, the handle (out1) is constant. The output of this block should be propagated to all Read_Buffer blocks that use the same serial port. Create another buffer to manage another serial port. In the case that the read of the actual message need more space, the Read_Buffer block may allocate more memory space itself. |
|||||||||||||||||||||
RS232_Read_Buffer: This block 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).
The block panel allows the selection of the following parameters:
The block has 3 inputs and 3 outputs:
Remarks: The block starts its read operations when received a '1' flag from the input 2. The read operation remains active until the completion of the data read (that may request more than one simulation step). Once completed the read of the string, it modify the output 3 with new data and put the output 2 flag to '1' for only one simulation step. Each block instance use the buffer indicated by the handle (received as input 3) to accumulate pieces of data read from the serial port. The buffer is used in the next step from the same block or from another block to complete the read of the incoming message. The buffer is common for each instantiated block that receive the same handle and resizes dynamically to manage eventual data quantity peak or, more generally, the multitasking of the OS. When the head of the message (all the part of the format message that precedes the first '%' character) is detected into the buffer, all the buffer that precedes the head is simply discarded and removed from the buffer. If both the head and the end of the message are detected in the buffer, the message is interpreted and, after, all the chars that precede (and contain) the end of the message are discarded from the buffer. See the example in the RS232 Read Buffer Behavior page. While the block is not active (the comm. handle is not valid (0) or the input flag (iput 2) is not active) and no read operation is pending, the block doesn't performs any operation. |
|||||||||||||||||||||
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.
The block panel allows the selection of the following parameters:
The block has 3 inputs and 2 outputs:
Remarks: The block starts its check operations when received a '1' flag from the input 2. The check operation (that consists in the storing of the incoming bytes into the buffer until a message header is detected) remains active until the completion (that may request more than one simulation step). Once completed the read of the string, it modifies the output 2 with a flag '1' for only one simulation step into the component of the vector relative to the message header detected. All the flags output of this block must be managed by at least one block, or the read from serial port may block the read sequence. Each block instance use the buffer indicated by the handle (received as input 3) to accumulate pieces of data read from the serial port. The buffer is used in the next step from the same block or from another block to complete the read of the incoming message. The buffer is common for each instantiated block that receive the same handle and resizes dynamically to manage eventual data quantity peak or, more generally, the multitasking of the OS. See the example in the RS232 Read Buffer Behavior page. While the block is not active (the comm. handle is not valid (0) or the input flag (iput 2) is not active) and no read operation is pending, the block doesn't performs any operation. The output 2 of this block should be propagated to all Read_Buffer blocks that needs a coordination in the read operation from the buffer. |
|||||||||||||||||||||
RS232_Buffer_Size:
This block reads the status of the buffer in terms of buffer utilized
space, buffer allocated space and input byte progressive count.
The block panel allows the selection of the following parameter:
The block has 1 input and 1:
Remarks: This
block is always operative when a valid buffer handle is in the block input
port. In the output vector, the following information are available: |
RS232_Write_Binary: Write a binary
formatted data to the serial output
The block panel allows the selection of the following parameters:
The block has 3 inputs (minimum) and 2 outputs:
Remarks: While the block is not active (the comm. handle is not valid (0) or the input flag (input 2) is not active) the block doesn't performs any operation. |
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.
The block panel allows the selection of the following parameters:
The block has 3 inputs and at least 3 outputs:
Remarks: The block starts its read operations when received a '1' flag from the input 2. The read operation remains active until the completion of the data read (that may request more than one simulation step). Once completed the read of the data, it modify the output 3 with new data and put the output 2 flag to '1' for only one simulation step. Each block instance use the buffer indicated by the handle (received as input 3) to accumulate pieces of data read from the serial port. The buffer is used in the next step from the same block or from another block to complete the read of the incoming message. The buffer is common for each instantiated block that receive the same handle and resizes dynamically to manage eventual data quantity peak or, more generally, the multitasking of the OS. When the input flag is "1", the buffer is read when and only when the buffer size is greater than the total size of the data to read. The total size is automatically calculated by the block. See the example in the RS232 Read Binary Buffer Behavior page. After the read is complete, the read portion of data is removed from the buffer. While the block is not active (the comm. handle is not valid (0) or the input flag (iput 2) is not active) and no read operation is pending, the block doesn't performs any 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 block panel allows the selection of the following parameters:
The block has 3 inputs and 2 outputs:
Remarks: The block starts its check operations when received a '1' flag from the input 2. The check operation (that consists in the storing of the incoming bytes into the buffer until a new data header is detected) remains active until the completion (that may request more than one simulation step). Once found the data header, it modifies the output 2 with a flag '1' for only one simulation step. Once the data header is found, all the bytes before the data header are simply removed. Each block instance use the buffer indicated by the handle (received as input 3) to accumulate pieces of data read from the serial port. The buffer is used in the next step from the same block or from another block to complete the read of the incoming message. The buffer is common for each instantiated block that receive the same handle and resizes dynamically to manage eventual data quantity peak or, more generally, the multitasking of the OS. See the example in the RS232 Read Binary Buffer Behavior page. While the block is not active (the comm. handle is not valid (0) or the input flag (iput 2) is not active) and no read operation is pending, the block doesn't performs any operation. The output 2 of this block should be propagated to the Read_Binary_Buffer block that needs a coordination in the read operation from the buffer. |
RS232 blockset Application Example
An application example is the one reported in the figure and contained in the installation pack of the blockset (RS232ex3.mdl).
To setup your computer for this example model, connect an inverting serial cable between the COM1 and COM2 ports.
In this example, two asynchronous messages are sent from the Write Format block with different rates (the rate is generated by two pulse generator with different pulse period) . A Wait Buffer Synch block is used to detect which message is first in the input queue.
Scope:
Scope4: |
---|
Information and Warranty for the End User
I must remember to all the users of this blockset that this is a product not covered by any warranty abut its working performances and characteristics, because it's completely free. All the material and the manual has been realized by myself independently from any contractual constraint with any University or company, then the intellectual property is exclusive of the author (me).
The present library is actually under development and more blocks will be added. The notice from the users of any problem will be appreciated and recorded and any collaboration will be mentioned in the final version of the blockset.
Installation of the RS232 blockset
At the start of this page, a link to the file RS232.zip allows the download of the RS232 blockset library. The zip file has been memorized without any reference to an installation directory, then the directory will be selected from the end user at the installation time.
After the start of the Winzip (or equivalent) program, press the button "Extract" to extract all files in the desired directory. Preferably, select a folder (or create a new folder) insied the <MatlabDir>\work directory.
Installation Directory selection window
After the completion of the setup, add the path of the selected directory utilizing the menu item File-->Set Path...
Now the installation is complete. To open the RS232 Blockset library is sufficient to type in the matlab command window the command "RS232". A window containing all the available blocks will be displayed.
Many
thanks for their suggestions and requests:
Nelson
Rojas Mendelewski, from Chile, for his suggestions and requests about many
topics. | |
Juan
Francisco Blanes Noguera, from Valencia (Espana), for his requests about
upgrade of the RS232_Read_Format block. | |
Pramlia
Rani, from Vanderbilt University (Nashville, Tennessee - USA) that suggested
me the creation of the binary blocks. | |
Francesco
Nebula and Domenico Liguori from CIRA (Italy) for their update request. |
Many
thanks for their debugging activity:
Hugo
Montenegro, from Argentina, for his debugging activity on the
RS232_Wait_Buffer_Synch block. | |
Jens
Haecker, from Institute for Statics and Dynamics of Aerospace
Structures (ISD), University of Stuttgart
(Germany), for his requests about the RS232_Format_Read for his debugging on
the formatted write and read. | |
Lutz
Evert, from FH-Bielefeld, Germany,
for his debugging activity. |
Many
thanks for their encouragement and contributes:
Jeff
Renaud and Charles Bienvenue from l’Université du Québec, Montreal,
Canada | |
Ciamak
Abkai, from Germany | |
Cord
Elias, from Mathworks Gmbh, Germany | |
Victor
Polidoro, from MIT, Boston, USA | |
Gordon
Strickert, from Germany | |
Stefan
Thomas, from Wien, Austria | |
Juan
Francisco Blanes Noguera, from Escuela Universitaria de Informática,
Valencia, Spain | |
Peter
How, from MIT, Boston, USA | |
Tarif
Erf, from Turkey | |
Phaisit
Chewputtanagul, from I don’t know where | |
Thorsten
Knappenberger, from Germany | |
Sithabiso
Madlala, from Zaire | |
Shu-An
Lee, from Taiwan | |
Wesley
Yu, from Republic of China | |
Jacy
Montenegro Magalhaes Neto, from Instituto Militar de Engenharia, Rio de
Janeiro, Brasil | |
Costanzo
Salvatore and Gullì Daniel, from Genova (Italy) |
This page has been updated on day 04/12/04.
Leonardo
Daga's Warehouseâ,
http://leonardodaga.insyde.it |