Serial communication using Stream Input/Output blocks receives delayed data

조회 수: 16 (최근 30일)
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?

채택된 답변

Jan Houska
Jan Houska 2022년 12월 2일
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

추가 답변 (2개)

Jan Houska
Jan Houska 2022년 11월 10일
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
Ama Nesciri
Ama Nesciri 2022년 11월 10일
편집: Ama Nesciri 2022년 11월 10일
Hi Jan,
Thank you for the advice and tip. Unfortunately, the problem persists.
Ama Nesciri
Ama Nesciri 2022년 11월 18일
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?

댓글을 달려면 로그인하십시오.


Jan Houska
Jan Houska 2022년 11월 24일
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
Ama Nesciri
Ama Nesciri 2022년 11월 28일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by