Is there is a way to convert Signal from Signal Builder Block to Test Sequence code?

조회 수: 16 (최근 30일)
The MATLAB automatically generate test harness using the signal builder block. i need to convert the all the signals from signal builder block to test sequence code , Please Help

채택된 답변

Pat Canny
Pat Canny 2022년 6월 2일
Assuming you need to use a Signal Builder instead of a Signal Editor (Signal Editor is the recommended approach; look here for a utility to convert from Signal Builder to Signal Editor), you can author a Test Sequence block programmatically.
To do this, try using the following functions:
  1. Select the Signal Builder block in the model and use the signalbuilder function to retrieve the signal data for each group in the Signal Builder. Example code:
[time,data,signames,groupnames] = signalbuilder(gcb);
new_system('example_model')
blockName = 'example_model/Test Sequence';
sltest.testsequence.newBlock(blockName);
3. You can then start creating Test Sequence steps (starting with sltest.testsequence.addStep). The number of steps could be based on the number of elements in the Signal Builder data. Here is just some starter code for one of the signals:
numSteps = numel(data{1})-1; %assumes all signal data vectors are of equal length
numsignals = numel(signames);
for i=1:numsignals
sltest.testsequence.addSymbol(blockName,...
signames{i},'Data','Output');
end
actionDesc1 = [signames(1) + " = " + string(data{1}(1)) + ";"]; %just defines Action for first signal
stepNames = "Step" + string(1:numSteps);
sltest.testsequence.addStep(blockName,stepNames(1),'Action',actionDesc1)
% You could then use string concatenation to define Action for all signals in
% Step1
for k=2:numSteps-1
actionDesc = [signames(1) + " = " + string(data{1}(k)) + ";"]; %just defines Action for first signal
sltest.testsequence.addStepAfter(blockName,stepNames(k),stepNames(k-1),'Action',actionDesc);
transitionDuration = time{1}(k) - time{1}(k-1);
transitionCondition = "after(" + string(transitionDuration)+")";
sltest.testsequence.addTransition(blockName,stepNames(k-1),transitionCondition,stepNames(k))
end
  댓글 수: 1
Pat Canny
Pat Canny 2022년 6월 2일
Just a quick follow-up on my answer: the "Action Description" is just a string. My "starter code" would need to be updated to include data type casting and other considerations. The code above simply sets each signal to a double. My goal was to demonstrate the general workflow and show which functions to consider.

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

추가 답변 (1개)

Anwin Kushal M
Anwin Kushal M 2022년 6월 3일
Yes, I am referring automatically generated tests from Simulink Design Verifier
-Thank you.
  댓글 수: 3
Pat Canny
Pat Canny 2022년 6월 6일
편집: Pat Canny 2022년 6월 6일
Thanks @Anwin Kushal M! Could you please send me an email at patcanny@mathworks.com ?

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

카테고리

Help CenterFile Exchange에서 Inputs에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by