XPC M-file Communication
m (→Common commands:)
Latest revision as of 10:39, 24 May 2006
There are several ways to communicate with the target PC using the host PC. In the simulink window, you have the ability to start/stop the model and change various parameters on the fly using the external mode. The target PC can also be communicated with using the matlab command line. Since you can do that, you can also create an m-file that runs a sequence of commands. This section describes various commands and gives a few examples.
In order to execute commands from the matlab prompt or from an m-file, the model must be compiled and loaded to the target PC.
- +tg / -tg
- Starts/stops the model running on the target PC. Typing "+tg" will start the model. The model will finish running when its simulation time expires or when you type "-tg". Typing without a semicolon outputs the target PC settings before the model is started. If you type "+tg;", these settings are suppressed and the model is executed instantly.
- Returns the value of a parameter. The argument to getparam is the paramter's ID, which is obtained using tg.getparamid.
- Sets the value of a parameter, just as you would do by double-clicking on a block in simulink.
- Returns the integer ID of a parameter in the simulink model. In order to access a parameter, you will need to know the integer ID of that parameter. getparamid takes two arguments: 1) the name of the parameter (which is what is displayed just below the block in your simulink diagram - you can edit this too) and 2) the type of parameter. For example, to get the ID of a gain you set called "Kp" and save it as PARAM_KP, you would type:
- Toggles the display of parameters list in the matlab window after building/starting/stopping the model. You can use this command to find the names/IDs of your model parameters. The argument is either 'on' or 'off'.
- Returns the value of a signal. Use this for data-logging. You need to know the ID of the signal, which you can get from tg.getsignalid.
- Returns the integer ID of a signal in the simulink model. To get the ID of a signal, you need to know the name of the signal, which you can set yourself in the simulink diagram window. Check the name by setting tg.showsignals('on').
>> SIGNAL_SIN=tg.getparamid('Sine Wave');
- Toggles the display of signals list in the matlab window after building/starting/stopping the model. You can use this command to find the names/IDs of your model signals. The argument is either 'on' or 'off'.
- Returns an array of execution time, given in seconds. This is only used after execution has finished. Use it like this:
>> TIME = tg.TimeLog;
- Returns an array (column vectors actually) of output data after execution has finished. Outputs are created by connecting signals in the simulink model to "out" blocks. This can also return matrices if multiple signals are muxed into a single "out" block or multiple "out" blocks are present. Use it like this (make sure and use the semicolon, or you will get lots of numbers):
>> DATA = tg.OutputLog;
- Checks communication ability between host and target computers. Returns "success" if host and target can connunicate, and "failed" otherwise.