xPC Target | ![]() ![]() |
Example Using RS232 Binary Mode I/O
To understand the flexibility provided by the RS232 Binary Receive block, we present an example of how this block can be used. The model that implements this setup is provided with xPC Target. To access this model, type
at the command prompt. This will open the model, which is essentially self-documenting. Open each subsystem in the model to see what that part is supposed to accomplish.
Here, we describe an example of a messaging protocol that the model has to conform to.
The protocol consists of a one-byte header, followed by a variable length body. The header can have only two legal values, 12 and 17. If the header is 12, the body is 6 bytes long, and consists of a uint16
followed by an int32
(in terms of MATLAB data types). If the header is 17, the body is 4 bytes long, and consists of a uint16
followed by an int16
.
The model receives one header byte at a time, rejecting any invalid ones. As soon as a valid header byte is received, the execution switches to the body block, where the proper number of bytes is received. The data is then appropriately decoded and displayed on an xPC Target Scope of type target. The model should serve as an example of how this is done.
The basic algorithm is to receive a header byte and then compare it to the list of known headers (12 and 17). The body length is set appropriately depending on the header, and the "Done" function-call output of the header block is used to trigger functioning of the body block (via the "distributor" function call subsystem).
![]() | RS232 Binary Unpack Block | GPIB I/O Support | ![]() |