Why do I receive the error "Invalid Signal" when using "getsignal" from Simulink Real-Time in R2020a and earlier?

18 views (last 30 days)
I'm trying to retrieve the value of a signal from my Simulink Real-Time (SLRT) model running on the target machine. However, "getsignal" claims that the signal does not exist - despite it being listed:
>> tg.load('rtapp');
>> tg.ShowSignals = 'on'
Target: TargetPC1
Connected = Yes
Application = rtapp
Mode = Real-Time Single-Tasking
Status = running
CPUOverload = none
<...>
Scopes = 1
NumSignals = 2
ShowSignals = on
Signals = INDEX VALUE Type BLOCK NAME LABEL
0 1.000000 DOUBLE Gain myGain
1 0.737111 DOUBLE Source block mySource
NumParameters = 2
ShowParameters = off
>> tg.getsignal('myGain')
Error using xpctarget.xpc/getsignal
Invalid Signal
What am I doing wrong?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Jul 2021
Edited: MathWorks Support Team on 29 Jul 2021
The SimulinkRealTime.target.getsignal function accepts either a signal ID or a SLRT signal name (block path) as the input. In this case, although "myGain" is the name of the Simulink signal, it is considered the label of the SLRT signal.
To access the signal by label, we must first access its signal ID, as follows:
>> sigID = tg.getsignalidsfromlabel('myGain');
>> tg.getsignal(sigID)
However, we recommend using "getsignal" with the block path instead of the signal label. For instance:
>> tg.getsignal('Gain')
This is a neater solution to access the signal compared to using the signal ID.
More information regarding accessing SLRT signals by name can be found in the documentation: https://www.mathworks.com/help/releases/R2020a/xpc/api/getsignal.html#d120e44386

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!