Beagleboard USB input block code generation

Hi,
Is there any way, using BeageBoard as hardware Target, one can create a simulink model that uses USB port to receive recorded signals from memory stick? I know there is an Embedded Coder BeagleBoard example but there is no mention of using USB ports.
Thanks,
Nasreen

Réponses (1)

Murat Belge
Murat Belge le 4 Oct 2012

1 vote

Yes. It is possible to use data stored in a USB memory stick on BeagleBoard. In R2012a and R2012b, Simulink comes with a BeagleBoard Support Package http://www.mathworks.com/academia/beagleboard/. I recommend using this support package with BeagleBoard.
A memory stick inserted into one of the USB ports of the BeagleBoard appear as a drive. You may need to mount the drive before being able to use it. If the file is a text file for example, you can then use an Embedded MATLAB Function block to open the file on the USB memory stick and read the contents and feed them to the Simulink model. The MATLAB code you will need is in "Read a Text File" demo in MATLAB coder.

4 commentaires

NASREEN
NASREEN le 7 Oct 2012
Hi Murat,
Is there a Embedded Matlab function block which could read a . mat file from USB stick and then feed the variable matrix to simulink block?
As far as I know, you cannot load .mat files using Embedded MATLAB functions (not straightforward). However, you can easily create an Embedded MATLAB function block for reading from and writing to text files. Below is an example for writing a 160x120 image to a text file:
function fcn(Y, counter)
%#codegen
% Save 160x120 grayscale image to a file
format = ['%d ', 0];
fname = coder.nullcopy(uint8(zeros(1, 32)));
coder.ceval('sprintf', coder.wref(fname), ['img%d.dat', 0], counter);
fd = coder.opaque('FILE *');
fd = coder.ceval('fopen', fname, ['w', 0]);
for i = 1:160
for j = 1:120
coder.ceval('fprintf', fd, format, Y(i, j));
end
end
coder.ceval('fclose', fd);
Reading from a text file is very similar.
NASREEN
NASREEN le 16 Oct 2012
I first converted .mat file into .dat file. I tried coding the opening and reading dat file in embedded matlab function block. Yet I face problems in building the code. Can you give me a sample code of reading .dat file which contain multidimentional matirx in embedded code.
Graziano Ullucci
Graziano Ullucci le 25 Juin 2014
To Murat Belge Your answer is inappropiate and do not add any useful information. Please avoid unuseful answer or comment like mine in the future.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by