MATLAB Answers

How to connect to SLRT Target in App Designer with "slrt" command?

8 views (last 30 days)
Calling the "slrt" command from within App Designer does not seem to work.
I have an App created in App Designer to interface with SLRT machines. One of the buttons initiates the connection with the target by calling:
>> app.tg = slrt();
Then I check the connection with
>> app.tg.connected
However this always returns false. It seems like when the "slrt" command is called from within an App Designer callback, the connection does not seem to be made. However when I call the same command in the base workspace, it does create the connection with the target and everything works.
For an example to reproduce the issue, refer to the attached app "connectApp.mlapp".
1. Open "connectApp"
2. Click the "Connect" button
3. The connection status should be green if connected, red if not. You can also check in "slrtexplr".
4. Note that you can only change connection status by running "slrt" in the Command Window but not in the app callback.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Feb 2020
The issue seems to be that "slrt" is not evaluated when it is returned into a structure. However, you can evaluate it whenever you call the "tg" object with no semicolon. For example, consider the following sequence:
>> a.t = slrt
a =
struct with fields:
t: [1×1 SimulinkRealTime.target]
>> a.t.connected
ans =
'No'
>> a.t
Target: skyNet
Connected = Yes
Application = loader
>> a.t.connected
ans =
'Yes'
So essentially in order to fix the app, you can add a simple "app.tg" call inside the app callback with no semicolon, like seen below. This will make sure that it gets evaluated and connected.
>> app.tg = slrt;
>> app.tg %add this line
Note: "Connected" here mainly refers to a "communication status" between development and target computers and there is no real physical connection. So you can always go ahead and ping / load a model and it should work even if the connected command is not accurately set.

More Answers (2)

James Brown
James Brown on 21 Oct 2020
I've noticed that I often must use slrtPingTarget to 'wake up' the channel between the host and target. I often get failures with the something like
tg = slrt;
I usually use a try/catch scheme with a ping command before attempting the connection.

Pablo Romero
Pablo Romero on 16 Jul 2021
Simulink Real-Time had a major update in R2020b as described at R2020b Simulink Real-Time Major Update - MATLAB & Simulink (mathworks.com) that fixes many of these issues along with many other improvements and useful features.
You may consider upgrading to R2020b or later for a future-proof and more reliable instrumentation with AppDesigner.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!