0
votes

I want to make a system call out of a Matlab Simulink model running on external hardware. In my case I want to switch the original Raspberry Pi Touch Display (7") off and an.

I tried using a Matlab function with a Matlab "system" command but it just doesn't have any affect on the display (the system calls itself works with the terminal).

function display_backlight(old_status)
coder.extrinsic('system')

if old_status == 1
    system('echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power')
else 
    system('echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power')
end    
end

Any ideas how to make this work or do I need to use another block like mentioned here System call from Simulink possible? (Link in the answer doesn't work)

Or do I even have to write this in C and integrate this to Simulink?

2

2 Answers

1
votes

This is my solution as it won't work directly from a matlab simulink block:

  1. Add a "Matlab System" Block
  2. Add an .m source file which runs .c/.h code.
  3. Add a .c/.h file which runs the system command from c.
#include <display_backlight_on.h>

char command[50];        

void display_backlight_on_command(boolean_T turn_on)
{  
    if (turn_on == 1)
    {
        strcpy( command, "echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power" );
        system(command);
    }
}
0
votes

The MATLAB system function is not codegen capable. So if you use system within a MATLAB function block, it will not generate code and so there won't be any effect.

You should create a new block if you want something as mentioned in the question.