BeagleBoard / Simulink - 将外部命令中的数据捕获到变量中

时间:2013-06-18 02:32:22

标签: simulink beagleboard

我正在尝试从连接我的BeagleBoard xM的传感器捕获输出,同时在Simulink的硬件上运行外部编译代码。我将输出通过管道连接到示波器,我得到一个显示在示波器上的单个整数值“2”。

function y = fcn()
%#codegen

persistent firstTime;
persistent pf;
persistent g;
persistent z;
z = '0';
g='0';

if isempty(firstTime)
    firstTime = 0;   
    pf = coder.opaque('FILE *');
    if isequal(coder.target, 'rtw')
        cmd1 = c_string('i2cset -y 2 0x53 0x2D 0x8');
        coder.ceval('system', coder.rref(cmd1));
    end
end

y = coder.nullcopy(uint8(0));
res = coder.nullcopy(uint8(zeros(1, 10)));
readOnly = c_string('r');
readCmd = c_string('echo 3');
cmd2 = c_string('echo 3');

if isequal(coder.target, 'rtw')
    pf = coder.ceval('popen', coder.rref(readCmd), coder.rref(readOnly));
    coder.ceval('fgets', coder.wref(res), 10, pf);
    g = coder.ceval('printf', c_string('%s'), c_string(res));
    y = uint8(g);

    coder.ceval('pclose', pf);
end

end

function str = c_string(str)
  str = [str, 0];
end

0 个答案:

没有答案