variable size signal of Serial Send block in Simulink

7 ビュー (過去 30 日間)
Koki Ishimoto
Koki Ishimoto 2020 年 11 月 2 日
回答済み: Kiran Felix Robert 2020 年 11 月 4 日
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.

採用された回答

Kiran Felix Robert
Kiran Felix Robert 2020 年 11 月 4 日
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 件)

カテゴリ

Help Center および File ExchangeEmbedded Coder についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by