MATLAB Answers

variable size signal of Serial Send block in Simulink

6 views (last 30 days)
Hi, I'm working on simulink for sending motor signal to servo motors through Serial Send block. I need to send some kinds of commands and the lengths differs in each states, but Serial Send block doesn't support variable size signal. How can I send different size commenads through serial communication?
Thank you.

  0 Comments

Sign in to comment.

Accepted Answer

Kiran Felix Robert
Kiran Felix Robert on 4 Nov 2020
Hi Koki,
It is my understanding that you are trying to send Variable size data signals over the serial send block, Unfortunately, the Serial Send block does not currently support inputs with variable size . The input data size is set upon compilation time, and will not change during execution. Though there are a few few workarounds, you can follow either of the following.
  1. Set all of the command sizes to the max command size and pad the shorter commands with some sort of null character that the hardware will ignore, this solution depends on the hardware.
  2. Avoid the Simulink Serial blocks and instead open a serial object through Stateflow with the MATLAB functions, and then write the data as necessary using "fwrite" (This method requires additional MATLAB programming skills, and is prone to error if "fclose" is not correctly called).
  3. Alternatively, you can use the Simulink Serial blocks. You can encapsulate the Serial Send block in a Function Call block with one input. Then, in the Stateflow chart, create two parallel states: one for the controller, and one for a serial interface. The controller adds data into a buffer, and the serial interface reads the buffer and sends data out one at a time along with an output event to activate the Serial Send block.
Kiran Felix Robert

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!