| Contents | Index |
xPC Target Library for Misc.
The xPC Target From File block reads data from a file on the target computer hard disk and distributes that data in chunks every sample time. As the xPC Target kernel on the target computer reads the file data, it writes that data into a software buffer whose size is user-defined. The From File block then reads the data from this buffer in real time. One example where you might want to use the From File block is if you want to use externally-acquired data (data from a file) to drive a model.
The From File block distributes the data as a sequence of bytes. To use these data bytes as input to a model, convert the data into one or more signals. To do so, use the Byte Unpacking block. This block outputs data in various Simulink data types. For example, assume data in your file represents a single precision scalar and a double precision vector of width 3. To convert data of this type, set up the block to output every sample time:
28 bytes (1 * sizeof('single') + 3 * sizeof('double))This can then be converted into the appropriate signals by the Byte Unpacking block.
See the following topics:
File Format — Describes the target computer source file format
Block Parameters — Describes the block parameters for the From File block
Before you use a target computer file as the source for the From File block, format the data in the file properly. The file format is a concatenation of the different data elements for one time step, followed by the next time step, and so on.
For example, assume that the data in your file is the same as that in the preceding example. Assign a variable to each component, for example,
a — single precision value
b — double precision vector of 3
Assume, also, that there are N time steps worth of data. The array dimension for a and b are then
size(a) — [1, N]
size(b) — [3, N]
In sequence, write out the data like the following to create the file.
a(1, 1) 4 bytes b(:, 1) 24 bytes a(1, 2) 4 bytes b(:, 2) 24 bytes ... ... a(1, N) 4 bytes b(:, N) 24 bytes
If you already have the data as MATLAB variables, use the xpcbytes2file function to create the file on the host computer before transferring it to the target computer. This function has the following syntax:
xpcbytes2file(filename, var1, ... varn)
where
filename — Specify the name of the data file from which the From File block distributes data
var1, ... varn — Specify the column of data to be output to the model.
Enter the name of the target computer file that contains the data.
Enter the size, in bytes, of the data to be distributed each sample time.
Enter the size of the software FIFO, in bytes. The xPC Target kernel fills this FIFO with the data to be input to the model. The From File block empties this FIFO as it inputs the data to the model.
This parameter should ideally be
Much larger than Output port width
At least several time the disk read size
If your model has varying Task Execution Times (because of multitasking or because of the use of conditionally executed subsystems), increasing this parameter value helps prevent the real-time application from emptying the buffer faster than the background task can compile it, causing eventual saturation.
Enter the number of bytes to read when necessary. To understand this parameter, assume the following default values:
Buffer size is 2000
Disk read size is 512
Output port width is 8
This means that the data buffer is of size 2000. This buffer is initially full.
Each time the block executes, eight bytes are output to the model, and the number of bytes in the buffer decreases by eight. Each time the number of free bytes in the buffer goes to 512 or higher, the xPC Target kernel attempts to read 512 bytes from the xPC Target data file to fill the buffer.
Setting this parameter to another value, for example 1024, causes the From File block to wait until 1024 bytes are free before attempting the next read.
For efficiency, set this value to a multiple of 512 (a disk sector is 512 bytes).
Select the behavior of the block for when you run the application beyond when you have data in the file. Select
Hold last output — Stops reading and stops the output at the last value
Seek to beginning — Returns to the beginning of the file and starts reading the data (this option results in periodic data)
Enter a base sample time or a multiple of the base sample time.
Select the Show IsValid port check box to make the port IsValid visible in the model. Port IsValid outputs 1 if the file read succeeds and 0 if it fails.

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |