How can I look at the data in a file created by the File Scope block on the host machine in xPC Target 2.7.2 (R14SP2)?

6 views (last 30 days)
I am using a File Scope to log data to a file on the target. Using the file system commands:
f=xpctarget.ftp;
f.get('data.dat');
I have the file on my host computer. However, when I open the file, it is unreadable.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
The files stored on a target PC are in the xPC Target file format. To access these files, use the xPC Target commands. The easiest way to get data from the target PC is to read it from the target PC. The xPC Target documentation discusses this.
There are two ways that you can access the data:
  • Retrieving the Contents of a File from the Target PC to the Host PC
  • Retrieving a File from the Target PC to the Host PC
Retrieving the Contents of a File from the Target PC to the Host PC
You can retrieve the contents of a file from the target PC to the host PC, then convert the data.
The xPC Target documentation describes this procedure. If you have installed the help documentation for your licensed product, you can locally access the help page associated with this procedure by typing the following at the MATLAB prompt:
web([docroot,'/toolbox/xpc/ch_fs11.html'])
This returns an article titled "Retrieving the Contents of a File from the Target PC to the Host PC". In summary, these steps are:
% Create file system object
fsys = xpctarget.fs
% Open file on the target file system
h = fsys.fopen('testdata.dat')
% Read the data from the target file into a MATLAB variable. Note that
% this data will still be represented in xPC Target file
% format (i.e. not bytes)
data = fsys.fread(h);
% Close file on file system
fsys.fclose(h);
% Call READXPCFILE to convert the data from xPC Target
% file format to bytes for use in MATLAB
new_data = readxpcfile(data);
Retrieving a File from the Target PC to the Host PC
You can retrieve a file from the target PC to the host PC, then convert the contents of that file.
The xPC Target documentation describes this procedure. If you have installed the help documentation for your licensed product, you can locally access the help page associated with this procedure by typing the following at the MATLAB prompt:
web([docroot,'/toolbox/xpc/ch_fs7.html#35548'])
This returns an article titled "Retrieving the Contents of a File from the Target PC to the Host PC". After you retrieve the
file, use steps like the following to convert the file format.
% Open file on the host and get the file id handle
h = fopen('testdata.dat');
% Read data from the file into 'data'
data = fread(h);
% 'data' must be changed so that READXPCFILE will accept it. According to
% 'help readxpcfile', the function takes a uint8 row vector as input. The 'data'
% from above is a column vector and is of type double. The following
% command changes 'data' to be compatible with readxpcfile.
data = uint8(data');
% Return the data in a readable format (i.e. convert to bytes from xPC
% Target file format)
new_data = readxpcfile(data);

More Answers (0)

Products


Release

R14SP2

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!