Hey cody,
To achieve the desired workflow given by you where you do not want to execute from command window or click Button in Simulink tooltip, you can use a combination of MATLAB Function blocks and callbacks. Specifically, you can create a custom block (such as a Push Button) that triggers a MATLAB function to execute the desired command.
Below are the steps to achieve this
- Create a MATLAB Function Block
1. Open your Simulink model.
2. Drag a "MATLAB Function" block from the Simulink library into your model.
- Define the MATLAB Function
1. Double-click the MATLAB Function block to open the editor.
2. Define a function that executes the desired command (`set_param(gcs,'SimulationCommand','connect')` in this case).
function connectToHardware()
coder.extrinsic('set_param');
set_param(gcs,'SimulationCommand','connect');
- Create a Push Button Block
1. Drag a "Push Button" block from the Simulink library (found under Simulink > Dashboard) into your model.
2. Name the Push Button block (e.g., `Connect`).
- Configure the Push Button Block
1. Right-click the Push Button block and select "Properties".
2. In the Properties dialog, set the `Tag` property to a unique identifier (e.g., `ConnectTag`).
- Add a Callback to the Push Button
1. In the Simulink model, go to the "Model Properties" (right-click on the model background and select "Model Properties").
2. In the "Callbacks" tab, add a callback for the "StartFcn" or "InitFcn" (whichever suits your needs).
add_exec_event_listener('ConnectTag', 'PostSet', @connectToHardwareCallback);
function connectToHardwareCallback(~, ~)
NOTE:
Make sure the `Tag` property of the Push Button block matches the tag used in the `add_exec_event_listener` function.