Packing and Unpacking Messages

The CAN Pack/Unpack blocks provide a mechanism to specify the structure of a message using the signals table containining the field name, start bit, length etc for each value sent.
Are there similar blocks that provide the same mechanism for specifiying the message format but that aren't specifically for sending CAN messages?
I have a model to update which currently does all of the bit packing/shifting/concatenation in a very manual and time consuming way.

2 Comments

Hi Scott,
Which message type are you trying to generate / what protocol do you intend to use? There are similar helper blocks for different purposes, but each of them is quite specific in its design...
Best,
Dimitri
@Dimitri MANKOV Thanks for replying. I'm looking to generate messages for an RS485 based protocol and will be using a Speedgoat Real-time PC with one of their RS485 cards.

Sign in to comment.

Answers (1)

Dimitri MANKOV
Dimitri MANKOV on 20 Jul 2022
Hi Scott,
There are different formats used by serial devices to send and receive data. The Simulink model thus must be able to produce (send) and understand (receive) data in the required format. Simulink is designed to handle numerical data, while the actual serial data may be strings or bytes of data in a particular format. This means that some encoding/decoding using blocks included with Simulink Real-Time is necessary. Configuration of the lower-level serial protocol may also be needed, depending on the external device requirements.
Typically, serial devices communicate using either:
  • Binary format: data is packed into bytes, in a format specified by the device. You cannot interpret the data just by looking at the stream of bytes and must have knowledge about the format to encode/decode it properly.
  • ASCII format: device sends strings back and forth, which are usually user-readable.
There are several Simulink Real-Time examples showing how this encoding can be done here. In addition, Speedgoat recently released a series of product examples with their latest I/O Blockset version (v9.4.1), including an example showing a typical RS485 configuration. You can check them out here.
I hope this is helpful!
Dimitri

3 Comments

Hi @Dimitri MANKOV, thanks for your response. I'm fairly familiar with the processes required to encode/decode serial data.
I'm looking to do a binary format encoding of the data and I have the ICD document that specifies which bytes contains which values as well as the format of the message header and footers.
This ICD is based on one that I implemented before for CAN data and successfully used the CAN Pack the data to the correct binary format.
The purpose of my question, is whether there is a block similar to the CAN Pack block that allows me to pack data in to the binary format that isn't tied to the CAN or CAN FD protocols?
The CAN Pack/Unpack blocks allow me to format the entire message with a single block by entering the byte position and length in a tabular format.
Hi Scott,
I'm not aware of any similar block specifically designed for RS232/RS485-based protocols, but I guess it would be possible to misuse the CAN Pack block as follows:
Would that approach fulfill your requirements? Note that using a Mux block to create a vector of uint8 values before passing it to the driver blocks would work just as well.
@Dimitri MANKOV Misusing the CAN pack block was my backup option.
I'm hesitant to use mux/concatenate block to create the message given the size of the messages and the complexity of changing the model if a new parameter is added. It can be quite slow to build up these messages byte-by-byte dragging and dropping mux blocks around.

Sign in to comment.

Products

Release

R2020a

Tags

Asked:

on 18 Jul 2022

Commented:

on 20 Jul 2022

Community Treasure Hunt

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

Start Hunting!