This example shows you how to run remote Linux command on your PandaBoard™ hardware.
|On this page…|
PandaBoard™ hardware runs an Ubuntu® Linux® distribution as the operating system. Using utilities shipped in the Simulink Support Package for PandaBoard Hardware, you can remotely execute Linux commands on the PandaBoard hardware directly from the MATLAB® command line. For example, you can run and stop a Simulink® model, list the contents of a directory, look up the CPU load of a process running on the PandaBoard hardware, etc. You can also launch an interactive PuTTY SSH session directly from within MATLAB.
Simulink Support Package for PandaBoard Hardware uses an SSH connection over TCP/IP to remotely execute Linux commands while building and running Simulink models on the PandaBoard hardware. You can use the infrastructure developed for this purpose to communicate with the PandaBoard hardware.
1. Create a panda object by executing the following on the MATLAB command line:
h = panda
The panda function returns a connection object, h, for PandaBoard hardware that has been set up using the targetupdater function. The IP address, user name, and password used to construct the panda object are the default MATLAB session values for these parameters. Simulink Support Package for PandaBoard Hardware saves one set of communication parameters, i.e. IP address, user name and password, for the PandaBoard hardware as default MATLAB session values. Note, the default MATLAB session values for the communication parameters are first determined during the firmware update process. The communication parameters may subsequently be changed using the Tools > Run on Target Hardware > Options and are sticky, meaning that once you change the communication parameter values they are saved as default MATLAB session values, and are used for all Simulink models.
You may explicitly specify the host name or IP address, user name, password when you create the panda object:
h = panda('<IP address>', '<user name>', '<password>');
The command above shows how to specify host name, user name, and password. You may want to use this form if you have multiple PandaBoard hardware in your network that you need to distinguish individually.
2. Test connection to your PandaBoard hardware by executing the following command on the MATLAB command line:
message = h.connect
If successful, the connect method returns 'Connection successful' in the output argument message. The connect method executes the "echo Connection successful" Linux command over SSH. In case of a connection failure, a diagnostics error message is reported on the MATLAB command line. If the connection has failed, the most likely cause is incorrect IP address. To diagnose connection problems refer to the Troubleshooting Connection Problems section below.
You can use the execute method of the panda object to execute various Linux commands on the PandaBoard hardware from MATLAB.
1. Execute the following on the MATLAB command line:
[status, message] = h.execute(['ls -al ~'])
If successful, the command above returns a status of 0 and a message representing the output returned by the executed command. The returned message is a directory listing of the home directory.
2. Execute the following on the MATLAB command line:
h.execute(['ls -al ~'], true)
This command executes the same Linux command as in Step 1 of this task but directly outputs the result on the MATLAB command line rather than returning it in a variable.
The execute method of the panda object runs a Linux® command on the PandaBoard hardware using SSH protocol. Alternatively, you can open a PuTTY SSH terminal by executing the following command:
The PuTTY SSH terminal enables you to run interactive Linux commands on PandaBoard hardware. You may, for example, execute the same Linux commands introduced in the previous section to get a listing of the home directory.
Simulink Support Package for PandaBoard Hardware generates a Linux executable for each Simulink model you run on the PandaBoard hardware. The generated executable has the same name as the Simulink model and is stored in a directory under the Build directory you selected. To run/stop a Simulink model, you can use the run and stop methods of the panda communication object.
1. To run a Simulink model you previously run on the PandaBoard hardware, execute the following command on the MATLAB command line:
where the string '<model name>' is the name of the Simulink model you want to run on the PandaBoard hardware. The run method launches the Linux process corresponding to the Simulink model you specified.
2. To stop a Simulink model running on the PandaBoard hardware, execute the following command on the MATLAB command line:
This command kills the Linux process with the name '<model name>' on the PandaBoard hardware. Alternatively, you may execute the following commands to accomplish the same:
[~, pid] = h.execute('pidof <model name>'); [st, msg] = h.execute(['echo ', h.Password, ' |sudo -S kill -9 ', pid])
1. How do I verify my Ethernet connection?
Verify that the yellow LED on the Ethernet connector on your PandaBoard hardware is on and that the green LED is blinking. If not, then the other end of the Ethernet connection may not be live or the Ethernet cable might be bad.
2. What are the different Ethernet connection options for the PandaBoard hardware?
Your PandaBoard hardware must be connected to:
a) a LAN/WAN network with an Ethernet cable b) the host computer directly with an Ethernet cable
If your PandaBoard hardware has a direct connection to the host computer, you must set a static IP address for your PandaBoard hardware. You must also ensure that the Ethernet card in your host computer has been assigned a static IP addressassigned a static IP address.
3. How do I find the IP address of the PandaBoard hardware?
You may obtain the IP address of the PandaBoard hardware by pressing and releasing the USER button. The PandaBoard hardware will then speak its IP address. Note that you must have speakers or headphones connected to the AUDIO OUT connector of the PandaBoard hardware for you to hear. If you don't hear PandaBoard hardware speak an IP address, the PandaBoard hardware did not get an IP address from a DHCP server in your network. If you connected the PandaBoard hardware directly to your host computer, there is no DHCP server that can provide and IP address. Therefore, you must assign a static IP address to the your Ethernet card on your host computer as described in step 1 above. If you connected your PandaBoard hardware to a LAN/WAN Ethernet network and you are sure that there is a DHCP server in your network, check if the DHCP server is using MAC address filtering. If so, you can add the MAC address of the PandaBoard hardware to the list of allowed MAC addresses in your DHCP server or router configuration. To find the MAC address of the PandaBoard hardware, you need to open a serial PuTTY session (follow instructions in 6 below) and execute the following on the Linux shell:
sudo cat /etc/network/interfaces| grep hwaddress
You can also find the IP address of the PandaBoard hardware using a serial terminal as described below.
4. How do I test the SSH connection to PandaBoard hardware?
To test the SSH connection to your PandaBoard hardware, create a panda communication object and execute the following command on the MATLAB command line:
message = h.connect
If successful, the connect method returns 'Connection successful' in the output argument message. In case of a connection failure, a diagnostics error message is reported on the MATLAB command line. If the connection has failed, the most likely cause is the wrong IP address. Follow 2 above to find the IP address. If you found the IP address and still cannot connect to the PandaBoard hardware, refer to 5.
5. I know the IP address of the PandaBoard hardware but SSH connection still fails.
There are a couple of likely scenarios. If your PandaBoard hardware is connected directly to the host computer using an Ethernet cable, you must make sure that the Ethernet card on your host computer to which the PandaBoard hardware is connected has a static IP address. For instructions on how to assign a static IP address to your Ethernet card under Windows refer to the following guideguide. You must also ensure that the PandaBoard hardware and your computer is on the same subnet. For example, if you assigned a static IP address of 192.168.1.1 to your Ethernet card on the host computer, and the subnet mask is set to 255.255.255.0, you must assign an IP address in the range 192.168.1.2 to 192.168.1.254 to the PandaBoard hardware and a subnet mask that matches that of your host computer (usually 255.255.255.0).
If you are on a LAN/WAN network and cannot establish an SSH connection to the PandaBoard hardware, check that you do not have a firewall or anti-virus program that blocks TCP/IP port 22 used by the PuTTY SSH client. If you do, add this port to the list of TCP/IP ports that are not blocked or disable your firewall or anti-virus program. If SSH connection still fails, check that the SSH daemon is running on the PandaBoard hardware. To do this, execute the following on a PuTTY serial terminal:
initctl list | grep ssh
This command returns the status of the ssh server. You should see an output similar to the following if the ssh server is running:
ssh start/running, process 882
If ssh server is not running for some reason, try restarting the server by executing the following command on the serial terminal:
sudo /etc/init.d/networking restart
6. How do I open a serial terminal to communicate with the PandaBoard hardware?
To open a serial terminal, use the PuTTY application shipped with MATLAB. To open a PuTTY interactive terminal, execute the following command on the MATLAB command line:
h = panda h.openShell('serial')
This command opens up the PuTTY terminal client. Set the parameters of the serial connection as shown below, making sure to set the 'Serial line' parameter to the COM port number on your computer that is connected to your PandaBoard hardware:
The serial communication parameters are:
Speed (Baud rate): 115200 Data bits : 8 Stop bits : 1 Parity : None Flow control : None
Click Open to open the serial terminal.
On the serial terminal, enter the username and the password of your PandaBoard hardware. If you are using the PandaBoard Ubuntu firmware image from MathWorks, execute the following on the MATLAB command line to find the user name and the password of the board:
h = panda
7. How do I find the IP address of the PandaBoard hardware using the serial connection?
Open a serial terminal using PuTTY as described above. Execute the following command on the PuTTY serial terminal to find the IP address:
This command lists the Ethernet parameters for each Ethernet network interface on your PandaBoard hardware. Find the 'inet addr' for network interface 'eth0'. This is the IP address of your PandaBoard hardware. Alternatively, you can execute the following Linux command to find the IP address: