|
RS232+LAN+STR Blockset |
|
Links for COMM+STR+LAN download: (version 2.0 of 05.Sep.2004)Matlab 5.3+: Available free upon request*Matlab 6.0: Available free upon request*Matlab 6.5: COMMSTRv6.5 2.0.5.zip (348 Kb) (last updated 05.Dec.2004)Matlab 7.0: COMMSTRv7.0 2.0.5.zip (351 Kb) (last updated 05.Dec.2004, compiled 24.02/2006)*The 5.3 and 6.0 versions
should only be recompiled, but I have no much time... Just simply e-mail me... The User ManualDownload here the PDF version of the COMMSTR blockset (946 Kb).
PAGE INDEXIntroduction
|
Version
2.0.5 (5/12/04): Version 2.0.4 (17/9/04): Version 2.0.2 (10/9/04): Documentation of RS232 blocks, LAN blocks and some STR blocks has been added. STRtoFile function has been updated: two arguments (separator and terminator chars) have been added. Version 2.0.0 (5/9/04): First release. No documentation still available. |
The RS232+LAN+STR Blockset for Simulink
Each component of the blockset has been realized using a S-function written in C++ language (the relative DLLs are contained in the installation directory). The development of more blocks is foreseen in the case that one or more user of the blockset will signal a macro block needs.
|
Blockset Overview
|
![]() |
|
Block
Type |
Block
name |
Short
Description |
|
Serial
Port Communication |
Initialize
and close the serial communication. |
|
|
This
block reads from the serial port all the bytes in input and send it to the
block port as a string object. |
||
|
This
block writes to the serial port the string of the input port. |
||
|
LAN
Port Communication |
Initialize
and close the TCP/IP communication. |
|
|
This
block reads from the TCP/IP port all the bytes in input and send it to the
block port as a string object. |
||
|
This
block writes to the serial port the string of the input port. |
||
|
String
transformation blocks |
This
block divides a string in tokens, using the delimitation characters
declared as block panel argument. |
|
|
Converts
a vector of number into a vector of formatted strings |
||
|
Converts
a vector of numbers into a vector of binary strings |
||
|
Converts
a vector of binary strings into a vector of numbers |
||
| STRtoCStr | Converts
a string object in a C string |
|
| STRfromCStr | Converts a C string in a string object | |
|
String
utility blocks |
Generate
a constant string (object) |
|
|
Compute
the length of a string |
||
|
It’s
the string equivalent of the discrete memory block. It stores the input
for the next simulation step. |
||
|
Compute
the 8-bit or 16-bit checksum of the input string |
||
|
String formatting blocks |
STRwriteBin |
Create a string binary formatting the input number into string |
| STRreadBin |
Scan a binary string interpreting the content as described in the argument Format String |
|
| STRreadFixFmt | Translate a fix formatted string into a vector of numbers. | |
| STRwriteFmt | This function creates a formatted string | |
| STRreadFmt | This function translates a formatted string | |
| String manipulation blocks | STRleft | Extracts a left portion of the string, for the indicated length. |
| STRright | Extracts a right portion of the string, for the indicated length. | |
| STRmid | Extracts a mid portion of the string, starting from a given point, for the indicated length. | |
| STRadd | Sum the content of two or more strings, adding, if requested, a string separator or terminator. |
| String output
blocks |
STRprintf |
Print
the input string in the Matlab Command Window |
| STRtoFile |
Send
the input string to a file |
|
| String
search blocks |
STRfind |
Search
a substring in a string |
| STRextFind |
Search
an input substring in a string |
|
| String
customizable blocks |
STRcustomIN |
A
customization sample that use the output of the STRtoCStr
block. |
| STRcustomXBOW |
A
customization sample that generates a C-string pointer (and string
length) that (approximately) simulates the output of the Crossbow IMU
sensor. |
|
Purpose |
Initialize
and close the serial communication. The settings of the serial
communication are selectable using the block panel |
|
Parameters |
·
Port:
COM1/2/3/4 (If needed, a port number greater then 4 can be used simply
modifying the block's mask). ·
Baudrate:
115200,...,9600,...,110 baud ·
Number
of Databits:
8 / 7 / 6 / 5 bits ·
Number
of Stopbits:
1 / 2 ·
Parity:
None / Odd / Even |
|
Input |
None |
|
Output |
·
hnd:
the first is used to transmit an handle for the opened communication.
Therefore, it should be connected to all the blocks that use the port
opened by this block. More then one RS232 Setup block can be present at
the same time in the same simulation model, allowing the management of
many serial port at the same time. ·
flag:
The second port is used to communicate the state of the port (0: not open,
1: open). This output is used to conditioning the others RS232 blocks to
the actual status of the port. |
|
Description
|
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 (hnd)
and the flag (flag) are constant, unless a major communications
error occurs: in that case, hnd and flag becomes 0. |
|
Purpose |
This
block reads from the serial port all the bytes in input and send it to the
block port as a string object. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
hnd:
the handle to an open communication link generated from a RS232 Setup
block. ·
flag: flag
that enable the execution of the read operations (0: not enabled, 1:
enabled). It is sufficient that the input flag becomes 1 once, to let the
block executes its read operation. |
|
Output |
·
hnd:
A replication of the Input 1 handle ·
flag: A
flag that indicated the completion (successful or not) of the read
operation (0: no byte in input or port not open, 1: read complete). ·
str: a
string object containing the bytes read from the serial port. |
|
Description
|
Remarks: The
block starts its read operations when received a '1' flag from the input
2. Once completed the read it modify the output 3 with new data and put
the output 2 flag to '1' for only one simulation step. The string is
presented to output port for only the simulation step in which the string
has been read. 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. |
|
Purpose |
This
block writes to the serial port the string of the input port. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
hnd:
the handle to an open communication link generated from a RS232 Setup
block. ·
flag: flag
that enable the execution of the write operations (0: not enabled, 1:
enabled). It is sufficient that the input flag becomes 1 once, to let the
block executes its read operation. The block writes to the serial output
each time the flag becomes 1. ·
str: the
string to be written to the serial port. |
|
Output |
·
hnd:
A replication of the Input 1 handle ·
flag: A
flag that indicated the completion (successful or not) of the write
operation (0: not completed or not enabled, 1: write complete). |
|
Description
|
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. |
|
Purpose |
Initialize
and close the TCP/IP communication. The settings of the serial
communication are selectable using the block panel |
|
Parameters |
·
Port:
Number of client/server port to open. Use big numbers (greater then 200)
to avoid the use of an already busy port. ·
Address:
The address of the client/server. For a client block, this is the address
of the host that runs the server. For a server block, this is the address
(filter) of the client allowed to connect to the server. ·
Type: Type
of the port. May be client or server. |
|
Input |
None |
|
Output |
·
hnd:
the first is used to transmit an handle for the opened communication.
Therefore, it should be connected to all the blocks that use the port
opened by this block. More then one LAN Setup block can be present at the
same time in the same simulation model, allowing the management of many
serial port at the same time. ·
flag:
The second port is used to communicate the state of the port (0: not open,
1: open). This output is used to conditioning the others blocks to the
actual status of the port. |
|
Description
|
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 (hnd)
and the flag (flag) are constant, unless a major communications
error occurs: in that case, hnd and flag becomes 0. |
|
Purpose |
This
block reads from the TCP/IP port all the bytes in input and send it to the
block port as a string object. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
hnd:
the handle to an open communication link generated from a LAN Setup block. ·
flag: flag
that enable the execution of the read operations (0: not enabled, 1:
enabled). It is sufficient that the input flag becomes 1 once, to let the
block executes its read operation. |
|
Output |
·
hnd:
A replication of the Input 1 handle ·
flag: A
flag that indicated the completion (successful or not) of the read
operation (0: no byte in input or port not open, 1: read complete). ·
str: a
string object containing the bytes read from the serial port. |
|
Description
|
Remarks: The
block starts its read operations when received a '1' flag from the input
2. Once completed the read it modify the output 3 with new data and put
the output 2 flag to '1' for only one simulation step. The string is
presented to output port for only the simulation step in which the string
has been read. 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. |
|
Purpose |
This
block writes to the serial port the string of the input port. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
hnd:
the handle to an open communication link generated from a LAN Setup block. ·
flag: flag
that enable the execution of the write operations (0: not enabled, 1:
enabled). It is sufficient that the input flag becomes 1 once, to let the
block executes its read operation. The block writes to the serial output
each time the flag becomes 1. ·
str: the
string to be written to the serial port. |
|
Output |
·
hnd:
A replication of the Input 1 handle ·
flag: A
flag that indicated the completion (successful or not) of the write
operation (0: not completed or not enabled, 1: write complete). |
|
Description
|
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. |
|
Purpose |
This
block divides a string in tokens, using the delimitation characters
declared as block panel argument. |
|
Parameters |
·
Tokens
separators string: the
list of all characters that will be considered as string separators ·
Number
of output tokens: Indicates
the maximum number of tokens in output. If the number of token in the
string is smaller than the size of the output port, the remaining ports
channels output null strings. If the number of token in the string is
greater, the last port channel contains all the remaining non-tokenized
strings. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string to be subdivided in tokens; |
|
Output |
·
str:
A vector of token strings; |
|
Description
|
Remarks: Take
care in what you connect to the input port. If the input is not a string,
a major Simulink error may occurs. Example: Tokens
separators string:
@. Number
of output tokens: 3 Input
string: leonardo.daga@libero.it Output
vector: [leonardo, daga, libero.it] |
|
Purpose |
Converts
a vector of number into a vector of formatted strings |
|
Parameters |
·
format
string: a
formatting string, that specifies the final numeric format of the numeric
string. The format specification follows the same rules as the C-standard printf
function, as described in the string
format page. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
n: The
input number vector; |
|
Output |
·
str:
A vector of formatted strings. The width of the output is the same of the
input width. |
|
Description
|
Example: format
string:
%5.3f Input
number vector: [1,
5, 223.33, 4.4] Output
vector: [1.000,
5.000, 223.3, 4.400] |
|
Purpose |
Converts
a vector of numbers into a vector of binary strings |
|
Parameters |
·
Data
Type: The
binary structure of the string to create. Possible types are: DOUBLE,
SINGLE, INT8, UINT8, INT16, UINT16, INT32, UINT32; ·
Invert
byte order: Inverts
the order of the bytes in the created string. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
n: The
input number vector; |
|
Output |
·
str:
A vector of binary formatted strings. The width of the output is the same
of the input width. |
|
Description
|
Example: Data
Type: SINGLE Invert byte order: No Input
number vector: [1.0,
223.33, 4.4] Output
vector: [00
00 80 3f, 7b 54 5f 43, cd cc 8c 40] |
|
Purpose |
Converts
a vector of binary strings into a vector of numbers |
|
Parameters |
·
Data
Type: The
binary structure of the string to translate. Possible types are: DOUBLE,
SINGLE, INT8, UINT8, INT16, UINT16, INT32, UINT32; ·
Invert
byte order: Inverts
the order of the bytes in the created string. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str:
A vector of binary formatted strings. |
|
Output |
·
n: The
output number vector; The width of the output is the same of the input
width. |
|
Description
|
Example: Data
Type: SINGLE Invert byte order: Yes Input
string vector: [3f
80 00 00, 43 5f 54 7b, 40 8c cc cd] Output
numeric vector: [1.0,
223.33, 4.4] |
|
Purpose |
Generate
a constant string (object) |
|
Parameters |
·
Const
String: A
single-quoted text that represent the constant output string. More
single-quoted text separated by a comma, generate an output string vector; ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
none.
|
|
Output |
·
str: The
output string vector; The width of the output is given by the number of
comma-separated single-quoted text in the string parameter. |
|
Description
|
Example: Const
String:
‘const’, ‘abba’, ‘0010’ Output
string vector: [const,
abba, 0010] |
|
Purpose |
Compute
the length of a string |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
input string vector; |
|
Output |
·
len
(int32): The
output length vector; The number of elements of the output vector is the
same number of elements of the input vector. |
|
Description
|
Example: Input
numeric vector:
‘const’, ‘abba’, ‘0010’ Output
numeric vector: [5,
4, 4] |
|
Purpose |
It’s
the string equivalent of the discrete memory block. It stores the input
for the next simulation step. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
input string vector; |
|
Output |
·
str: The
output string vector, relative to the last simulation step. In the first
simulation step the output of the block is a null string. |
|
Description
|
Note:
Actually
there’s no way to set the output of the block in the first simulation
step. |
|
Purpose |
It’s
the string equivalent of the discrete memory block. It stores the input
for the next simulation step. |
|
Parameters |
·
Check
Type: (8 bit Sum/16 bit Sum): Selection of the checksum type to be computed ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
input string vector; |
|
Output |
·
chk: A
vector of uint8 (8-bit checksum) or uint16 (16-bit checksum) corresponding
to each input string. |
|
Description
|
The
checksum is the sum (8-bit) of the binary values corresponding to each
byte of the string, or the sum (16-bit) of the binary values corresponding
to each word (2 bytes) of the string. In the second case, the string must
contain a pair number of bytes. Example:
|
|
Purpose |
Create
a string binary formatting the input number into string |
|
Parameters |
·
Format
String: The
binary format of the data into the string ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
n
(1..n): the
nth input port contains the data to write to the n-th format element of
the output data. |
|
Output |
·
str: The
binary formatted string. |
|
Description
|
The
width and the type of the input port is dependant of the format string
argument, as reported in the
Binary Format Page. Example:
Format
String:
2i1,2u4,3d8,1i1 (i.e.: 2 1-byte integer, 2 4-byte unsigned integer, 3
8-byte double, 1 1-byte integer) Cautions: Sometimes,
Simulink avoid the saving of modifications of the Format String or the
number of input port. To override this problem, disable the link of the
block to the library (right-click on the block and then select the popup
menu item: Link Options®Disable. |
|
Purpose |
Scan
a binary string interpreting the content as described in the argument
Format String |
|
Parameters |
·
Format
String: The
binary format of the data into the string ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
binary formatted string. |
|
Output |
·
flag: A
flag that indicated the completion (successful or not) of the read
operation (0: not completed or not enabled, 1: read complete). ·
n
(1..n): the
output port that contains the data read from the input data. The nth
output port contains the read data relative to the n-th format element. |
|
Description
|
The
width and the type of the input port is dependant of the format string
argument, as reported in the Binary Format Page. Example:
Format
String:
2i1,2u4,3d8,1i1 (i.e.: 2 1-byte integer, 2 4-byte unsigned integer, 3
8-byte double, 1 1-byte integer)
Cautions: Sometimes,
Simulink avoid the saving of modifications of the Format String or the
number of input port. To override this problem, disable the link of the
block to the library (right-click on the block and then select the popup
menu item: Link Options®Disable. |
|
Purpose |
Translate
a fix formatted string into a vector of numbers. This block has been
generated specifically to read Flight Simulator's formatted data string,
but it can be adapted to many fix formatted string interpretation
problems. |
||||||||||||||||||||||
|
Parameters |
·
Format
String: The
format string is structured as follows: o
each
field is contained into a couple of '%' chars. o
each
field is structured as follows: - the number of characters that is
assigned to this field in the input string; o
the type
of the input data; o
the size
of the input data; o
each
field not contained in the '%' delimitators is considered as a simple
string, that should be found in each input string; ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
||||||||||||||||||||||
|
Input |
·
str: The
fix formatted string to translate. |
||||||||||||||||||||||
|
Output |
·
flag: A
flag that indicated the completion (successful or not) of the read
operation (0: not completed or not enabled, 1: read complete). ·
n
(1..n): the
output port that contains the data read from the input data. The nth
output port contains the read data relative to the n-th format element. |
||||||||||||||||||||||
|
Description
|
Details: The format interpretation string uses the following coding: %[nOfChr][Type]% where:
Remarks: The parsing of the input strings is based on the detection of the detection of the start and the end of the string to parse. No translation is possible if a string terminator or header is not present. For example, to parse the first three numeric fields of the string: '$GPRMC,231225.336,V,04408.1213,S,01211.121,E,321.2,113.2,251204,111.9,W,A,*23' you should add a format parsing string like: $GPRMC,%10d8%,%1c%,%10d8%,%1c%,%9d8%,%1c%,* The last '*' character is needed to correctly detect the start and the end of the string. Fields in the string to parse before and after the '*' not foreseen in the format string are simply skipped. Examples: About
the format string, for example, to read a string like this: "#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%_" Example:
Cautions: Sometimes,
Simulink forgets to saving the modifications of the Format String
or the number of input or output port. To override this problem, disable
the link of the block to the library (right-click on the block and then
select the popup menu item: Link Options®Disable). |
|
Purpose |
This
function creates a formatted string (function analogue to the standard-C sprintf
function). |
|
Parameters |
·
Format
String: A
format control string that defines how data is organized in the output
string. The format specification follows the same rules as the C-standard
sprintf function, as described in the string
format page. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
in
(1..n): The
input element to be formatted into the string. In this block, even strings
are accepted as input values. The number of ports is in the same number of
the type of argument. See description for more details. |
|
Output |
·
str: The
formatted output string. |
|
Description
|
The
type sequence of input port is predetermined, following the order fixed by
the following list:
Then,
if you have in you format string an integer, a string and two double (it
doesn’t matter the effective sequence of format tokens), the sequence of
input port will be: 1) double type port with width = 1, 2) integer type
port with width = 1, 3) string type port with width = 1. Example:
VERY IMPORTANT NOTE: In the example, even if STRwriteFmt 2nd and 3rd input are both int32
type, the 2nd input is an hexadecimal while the 3rd input is a string
type. Inverting types may cause a major memory protection error. Cautions: Sometimes,
Simulink forgets to saving the modifications of the Format String
or the number of input or output port. To override this problem, disable
the link of the block to the library (right-click on the block and then
select the popup menu item: Link Options®Disable). |
|
Purpose |
This
function translates a formatted string (function analogue to the
standard-C sprintf function). |
|
Parameters |
·
Format
String: A
format control string that defines how data is organized in the incoming
string. The format specification follows the same rules as the C-standard
sprintf function, as described in the string
format page. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string to be translated. |
|
Output |
·
flag:
A flag that indicated the completion (successful or not) of the read
operation (0: not completed or not enabled, 1: read complete). ·
out
(1..n): The
output element read from the string. In this block, even strings may be
presented as output values. The number of output ports is in the same
number of the type of argument. |
|
Description
|
The
type sequence of output port is predetermined, following the order fixed
by the following list:
Then,
if you have in you format string an integer, a string and two double (it
doesn’t matter the effective sequence of format tokens), the sequence of
output port will be: 1) double type port with width = 1, 2) integer type
port with width = 1, 3) string type port with width = 1. Remarks: While
the C-language fscan function is not able to discriminate a sequence of
input string, ReadFmt look first for the token end (in the example that
follows, a ‘;’, and then translates the token, being so able to
distinguish two or more successive strings or a string from successive
numbers. Example:
The output port sequence is: a single, the hex and two strings. Cautions: Sometimes,
Simulink forgets to saving the modifications of the Format String
or the number of input or output port. To override this problem, disable
the link of the block to the library (right-click on the block and then
select the popup menu item: Link Options®Disable). |
|
Purpose |
Convert
a string object in a C string |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: Whatever
string object. |
|
Output |
·
chr*: A
pointer to a permanent memory zone where the string is stored. Use this
area with care. The string could be not null-terminated, so do not apply
C-string function without taking into account the real length of the
string. ·
sz:
The size of memory reserved to the string (the length of the string). |
|
Description
|
Example:
The two outputs are the address of the memory containing the two strings. These address may be used by another block to process a string output and, for example, translate the content of the string. The second output is the length of the two strings and the length of the allocated memory. The address and the length of the string is permanent only for the actual simulation step, and it may change from one simulation step to the next one. |
|
Purpose |
Convert
a C string in a string object |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
chr*: A
pointer to a permanent memory zone where the string is stored. The string
could be not null-terminated, because the real end of the string is given
by the size port of the block. ·
sz:
The size of memory reserved to the string (the length of the string). |
|
Output |
·
str:
A string object containing the input string. |
|
Description
|
Example:
The two input channels of the first port are the address of the memory containing the two strings. These address may be generated by a custom block (see customizable block section). The second input port is the length of the two strings and the length of the allocated memory. The address and the length of the string must be permanent only for the actual simulation step, and it could change from one simulation step to the next one. |
|
Purpose |
This
block extracts a left portion of the string, for the indicated length.
|
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string from which the characters are extracted ·
nLeft:
The number of characters to extract from the left of the string. |
|
Output |
·
str:
A string containing a copy of the specified range of characters. Note that
the returned string may be empty; |
|
Description
|
Remarks: This
block works also for string vector arguments. The nLeft input is
applied cyclically on the input strings. Example: Input
string: [sample, oracle, virtuality] Input
nLeft: [3, 5] Output
vector: [sam, oracl, vir] |
|
Purpose |
This
block extracts a right portion of the string, for the indicated length.
|
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string from which the characters are extracted ·
nRight:
The number of characters to extract from the right of the string. |
|
Output |
·
str:
A string containing a copy of the specified range of characters. Note that
the returned string may be empty; |
|
Description
|
Remarks: This
block works also for string vector arguments. The nRight input is
applied cyclically on the input strings. Example: Input
string: [sample, oracle, virtuality] Input
nRight: [3, 5] Output
vector: [ple, racle, ity] |
|
Purpose |
This
block extracts a mid portion of the string, starting from a given point,
for the indicated length. |
|
Parameters |
·
Mode: application
mode. Select an option from the following list: o
apply
one per string:
apply the n-th element of the nLeft and nNum input vector to the n-th
element of the string input vector; o
apply
all on each string:
apply all the element of the nLeft and nNum input vector to each element
of the string input vector; ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string from which the characters are extracted ·
nLeft:
The position from which to extract the string. ·
nNum:
The number of characters to extract from the nLeft character of the
string. |
|
Output |
·
str:
A string containing a copy of the specified range of characters. Note that
the returned string may be empty; |
|
Description
|
Example: Mode:
Apply one per string Input
string: [sample, oracle, virtuality] Input
nLeft: [2, 3] Input
nNum: [2, 4] Output
vector: [mp,cle] Example: Mode:
Apply all on each string Input
string: [sample, oracle, virtuality] Input
nLeft: [2, 3] Input
nNum: [2, 4] Output
vector: [mp,ple,ac,cle,rt,tual] |
|
Purpose |
This
block sum the content of two or more strings, adding, if requested, a
string separator or terminator. |
|
Parameters |
·
Number
of string vector to sum: Number of block input port ·
Separator
character:
The character, if any, to be used as separator between strings. Special
characters are (still) not allowed. Max one character allowed. ·
Terminator
string: The
character, if any, to be used as terminator of the output string. Special
characters are (still) not allowed. One or more character allowed. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str
(1..n): The
string to sum |
|
Output |
·
str:
The resulting string |
|
Description
|
Remarks: This
block works also for string vector input. The separators and terminators
are applied even for each element of input vectors. Example: Number
of input vectors: 2 Separator
character: - Terminator
string: ** Input
string 1: [sample, oracle, virtuality] Input
string 2: [testing, simulink] Output
vector: [sample-oracle-virtuality-testing-simulink**] Cautions: Sometimes,
Simulink forgets to saving the modifications of the Format String
or the number of input or output port. To override this problem, disable
the link of the block to the library (right-click on the block and then
select the popup menu item: Link Options®Disable). |
|
Purpose |
Print
the input string in the Matlab Command Window |
|
Parameters |
··
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
··
str: The
string vector to print |
|
Output |
··
none |
|
Description
|
Each
sample time, the input string is printed in a row, separating each element
of the vector by a comma. Non printable chars are not translated to
printable chars before being sent to the Matlab Command Window. |
|
Purpose |
Send
the input string to a file |
|
Parameters |
·
Filename:
Name of the file (in the Matlab current directory) where to save the
strings ·
Separator
character:
The character, if any, to be used as separator between strings. Special
characters are (still) not allowed. Max one character allowed. ·
Terminator
string: The
character, if any, to be used as terminator of the output string. Special
characters are (still) not allowed. One or more character allowed. ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string vector to save on the file |
|
Output |
·
none |
|
Description
|
Remarks: This
block works also for string vector input. The separators and terminators
are applied even for each element of input vectors. Example: Number
of input vectors: 2 Separator
character: - Terminator
string: ** Input
string 1: [sample, oracle, virtuality] Input
string 2: [testing, simulink] String
saved on the file: [sample-oracle-virtuality-testing-simulink**] Cautions: Sometimes,
Simulink forgets to saving the modifications of the strings or the
number of input or output port. To override this problem, disable the link
of the block to the library (right-click on the block and then select the
popup menu item: Link Options®Disable). |
|
Purpose |
Search
a substring in a string |
|
Parameters |
·
String
to find: The
substring to search ·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string vector where substring should be searched |
|
Output |
·
pos: The
(0-based) position vector of the substring in each element of the input
string vector. If string is not found, the resulting output is –1; |
|
Description
|
Remarks: This
block works also for string vector input. Resulting vector reports the
position of the found string for each input vector element. Example: String to find: ‘IO’
Cautions: Sometimes,
Simulink forgets to saving the modifications of the Format String
or the number of input or output port. To override this problem, disable
the link of the block to the library (right-click on the block and then
select the popup menu item: Link Options®Disable). |
|
Purpose |
Search
an input substring in a string |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
str: The
string vector where substring should be searched ·
find:
The substring to search. Only 1-element (non vector) string allowed. Even
binary string accepted. |
|
Output |
·
pos: The
(0-based) position vector of the substring in each element of the input
string vector. If string is not found, the resulting output is –1; |
|
Description
|
Remarks: This
block works also for string vector input. Resulting vector reports the
position of the found string for each input vector element. Example:
Cautions: Sometimes,
Simulink forgets to saving the modifications of the Format String
or the number of input or output port. To override this problem, disable
the link of the block to the library (right-click on the block and then
select the popup menu item: Link Options®Disable). |
|
Purpose |
A
customization sample that use the output of the STRtoCStr
block. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). |
|
Input |
·
chr*: A
pointer to a permanent memory zone where the string is stored. The string
could be not null-terminated, because the real end of the string is given
by the size port of the block. ·
sz:
The size of memory reserved to the string (the length of the string). |
|
Output |
·
none |
|
Description
|
This
is a simple block that read the input string. The relative C-language
S-function is contained in the installation directory and its name is “STR_CustomFun.c”.
In this S-function, the mdlUpdate function use the input pointer and
length of the string to allocate some memory and print it on the Matlab
Command Window. See the source code of the S-function for more details. |
|
Purpose |
A
customization sample that generates a C-string pointer (and string length)
that (approximately) simulates the output of the Crossbow IMU sensor. |
|
Parameters |
·
Sample
Time: Indicates
if the sample time should be inherited from the preceding blocks or should
be defined independently (but it should be a multiple of the base sample
time). ·
DMU
Mode: o
VG Mode:
In voltage (VG) mode, the analog sensors are sampled and converted to
digital data with 1 mV resolution. The digital data represents the direct
output of the sensors. The data is 12-bit, unsigned. The value for each
sensor is sent as 2 bytes in the data packet over the serial interface. A
single data packet can be requested using a serial poll command or the DMU
can be set to continuously output data packets to the host. o
Scaled
sensor mode: the analog sensors are sampled, converted to digital data,
temperature compensated, and scaled to engineering units. The digital data
represents the actual value of the quantities measured. A calibration
table for each sensor is stored in the DMU non-volatile memory. A single
data packet can be requested using a serial poll command or the DMU can be
set to continuously output data packets to the host. The data is sent as
signed 16-bit 2’s complement integers. In this mode, the DMU operates as
a six-axis measurement system. ·
G
Range:
defines the maximum absolute value of detectable g (acceleration measured
in g); 1g (put “1” in the control) is a standard g maximum value. ·
Angular
rate range:
defines the maximum absolute value of detectable angular rate range; 150°/sec
(put “150” in the control) is a standard value. |
|
Input |
·
data: o
VG mode:
A double value 10 element vector containing the actual value (in the
order: roll and pitch angle, roll, pith and yaw angle rate, the x-y-z
accelerations, the temperature and time); o
Scaled
sensor mode: A double value 8 element vector containing the actual value
(in the order: roll, pith and yaw angle rate, the x-y-z accelerations, the
temperature and time); |
|
Output |
·
chr*: A
pointer to a permanent memory zone where the string is stored. The string
could be not null-terminated, because the real end of the string is given
by the size port of the block. ·
sz:
The size of memory reserved to the string (the length of the string). |
|
Description
|
This
is a simple block that output a C-String. The relative C-language
S-function is contained in the installation directory and its name is “STR_CustomFunIO.c”.
In this S-function, the mdlUpdate function translates the physical values
into scaled values and then compose the output string. See the C-function
for more details. |
In this example (that is contained in the blockset, STRnLAN_Test.mdl) , we want to simulate the output of a Crossbow IMU (that normally works on a serial port) on a LAN port. The LAN Setup block is configured to open a server connection on port 8000, to accept connections only from the local PC (connection mask: 127.0.0.1). The Noise block generates 10 random double values, that are traslated from the Crossbow IMU Simulation block (whose source is available free in the blockset) as it was the physical values sensed by the IMU. A classic C-String is generated as the output of the IMU block and translated into a String obkect from the STRfromCStr block. A string object is a non-official type of Simulink, created for the purposes of this blockset, and is propagated from a block to another using its handle, that is an int32 value. This string is then sent to the LAN Write block, that simply write it in the TCP server port, if a client is connected. The RT block is to maintain the real-time operations, and it can be found on the related page.
![]() |
|---|
In this other example, the message sent by the previous example is read from the LAN port and interpreted. Here the LAN Setup block opens a client connection to the port 8000 opened by the previous block. Every string read is sent as output of the LAN read block. The STRadd block add the read string to the string remained from the last simulation step, stored by the STRmem block. The resulting string is then scanned to search the position of the header of the message, that is the binary char 0xff. The block that perform the search operation is a macro block and is detailed in a next figure. When found the header, the STRright block extract (cut the right pos bytes from the string) all the chars that follows the header and then, if the length of the string (extracted from the STRlen block) is greater than 22 (22 is the fixed length of an IMU message) an IF action subsystem (whose content is detailed next) extracts data (only the 16bit values, not translated) from the string and outputs to a scope. The remaining string is sent to the STRmem block to be used in the next simulation step.
![]() |
|---|
The header position search block is quite easy. The string input is sent to the first port of the STRextFind block that look for the position of the string that receives in the second port. The string to search is obtained converting the byte 0xff = 255 into a 1-char string. The position of the found string is then subtracted to the total length of the string to obtain the number of bytes, from the right of the string, that should be extract to cutoff all bytes before the header. This number is the output of the block and then sent to the STRright block of the main model.
![]() |
|---|
The IF action subsystem of the main block extracts data from the received string. The input string is sent first to the STRreadBin block, that decompose the message into a byte (the 0xff char), a vector (10) of short integers (the encoding of the double values made by the Crossbow block) and the final characted, the checksum. The input string is sent also to a STRright block to remove the left 22 chars from the string, so obtaining the remaining string to be stored for the next simulation step. The input string is sent finally also to a STRmid block, to extract the middle string from the 2nd (1 is because strings are 0-based referenced) to the 21st character (20 for 0-based), that is the string that in the Crossbow IMU is used to compute the checksum. Then, the checksum is calculated using the STRchkSum block, and the result is compared with the checksum byte extracted from the STRreadBin block. If the comparison is successful the output of the STRreadBin block is propagated to the subsystem output, using another IFactionSubsystem that simply propagates the input to the output if the activating condition is valid.
![]() |
|---|
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.
At the start of this page, a link to the file COMMSTR.zip allows the download of the COMMSTR 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 COMMSTR Blockset library is sufficient to type in the matlab command window the command "COMMSTR". A window containing all the available blocks will be displayed.
Acknowledgements (even for RS232 blockset)
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:
| Alessandro Oliva, from Italy, for his debugging of the STRreadFixFmt block and the requests that generated the GPRMC sample, contained in the blockset after the 2.0.5 release. | |
| 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 24/02/06.
|
Leonardo
Daga's Warehouseâ,
http://leonardodaga.insyde.it |