Serial communication using Stream Input/Output blocks receives delayed data

9 visualizaciones (últimos 30 días)
As part of a project I am using Simulink to send and receive serial data. The shown setup only concerns the necessary parts for this question. I send the (string) output of a ramp signal with slope 1 every 5 seconds to COM9. This data is instantly forwarded to COM10. I am using the Virtual Serial Port Driver by Electronic Team to emulate the serial ports and forward the received data. Simulink then reads out the data at COM10 with a sample time = 0.05. I use Simulation Pacing in Simulink to ensure simulation time corresponds to wall clock time. I have attached my Simulink script.
The problem:
There are two scenarios.
1) The first one uses the setup as described above and as shown below.
Some time after T = 5 s, I expect Serial Port [10] to read "5". Instead, it reads "0", and will continue to lag behind 5 seconds, i.e., at T = 10 s, it will read "5", etc.
2) In the second setup, I do not read COM10 in Simulink, but use PuTTY to open a terminal at baud = 115200.
What happens is that right after pressing Run, COM10 receives a "0", and it will correctly receive "5" at T = 5 s, "10" at T = 10 s, etc. This is the desired behaviour for the simulation in scenario 1.
Question:
How can I get rid of the "delay" in scenario 1?

Respuesta aceptada

Jan Houska
Jan Houska el 2 de Dic. de 2022
Hi Ama,
the Stream Output block, when run in Connected IO mode like you are running it, has one sample period delay between its input signal and the value sent to its output device. If you don't want this behavior, you can use e.g. a triggered subsystem and inherited sample time for the Stream Output block, as shown in the attached example.
Good Luck, Jan

Más respuestas (2)

Jan Houska
Jan Houska el 10 de Nov. de 2022
Hi Ama,
you should not use Simulink Pacing together with Simulink Desktop Real-Time. Simulink Desktop Real-Time I/O blocks synchronize to real time by themselves. Please turn off Simulink Pacing because it may interfere with the synchronization performed by the Stream Output block. Please get back here if this does not help.
And, another unrelated tip - you don't need to convert your data to string before sending it via Stream Output block. Instead, to send a number, you can use the %d format specifier in the Stream Output block that converts the number to a string internally, which is more efficient.
Good Luck, Jan
  2 comentarios
Ama Nesciri
Ama Nesciri el 10 de Nov. de 2022
Editada: Ama Nesciri el 10 de Nov. de 2022
Hi Jan,
Thank you for the advice and tip. Unfortunately, the problem persists.
Ama Nesciri
Ama Nesciri el 18 de Nov. de 2022
Update: I have logged the 'missed ticks' port and noticed that in the faulty case, that output is consistently 1. The scenario without delayed has zero missed ticks. Is there a way to resolve that?

Iniciar sesión para comentar.


Jan Houska
Jan Houska el 24 de Nov. de 2022
Hi Ama,
in your model, please select DEBUG, Information Overlays, Execution Order. This will tell you in which order your blocks execute. It is quite probable that the input block executes before the output block, because there is no logical connection between them.
Please change the block priorities so that the execution order reverses - right-click on the block, go to Properties, Priority, and set priority for both the blocks in such a way that Output has lower value (say 10) and Input has higher value (say 20) here. Lower number means higher priority, so this should do the trick. Please get back here if this does not help, I'll try to watch the thread more carefully this time ;-).
Good Luck, Jan
  1 comentario
Ama Nesciri
Ama Nesciri el 28 de Nov. de 2022
Hi Jan, I have tried to alter the priorities (Stream Output to 10 and Stream Input to 20) but this does not alter execution behaviour.

Iniciar sesión para comentar.

Categorías

Más información sobre General Applications en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by