Sending vector data in the bus

时间:2015-06-15 15:08:34

标签: vector simulink bus

I have a vector data (an array variable for example float32 mydata[5];). for transmitting a single primitve/basic data in a bus its pretty simple.

inside_data=Simulink.BusElement;
inside_data.Name='somename';
inside_data.SampleTime = -1;
inside_data.datatype='single';

this element can be put inside a using

Bus=Simulink.Bus;
Bus.Elements=inside_data;

But this works when the input is a primitive. But what if my data is a vector. like float32 a[5]; then how can i send this data element in a bus.

UPDATE So I tried to use a constant block named a with datatype single in which the input part i changed it as [1 2 3] which is a vector input. another element is b with uint8 datatype.

i used the s-function builder just to check the working of this model. i already set everything (bus_mode on , datatype to be bus type etc). in the output part i used something like:

y0[0]=u0->a[0];
y0[1]=u0->a[1];
y0[2]=u0->a[2];
y1[0]=u0->b;

But it throws error as

c:\program files (x86)\matlab_v7111_r10bsp1\extern\include\matrix.h(313) : error C2061: syntax error : identifier 'mxLogical' 
c:\program files (x86)\matlab_v7111_r10bsp1\extern\include\matrix.h(313) : error C2059: syntax error : ';' 

my final aim is to use it for s_function

so if i declare a variable in s_func as

real32_T *a_output[5]=(real32_T *)ssGetOutputPortRealSignal(S,0); 

and then i have a strcuture(because am transmitting data with a bus so the bus header file has this structure) and how do i declare and assign the input to the output.

a_output[0]=my_struct->a_input[0];
a_output[1]=my_struct->a_input[1];
a_output[2]=my_struct->a_input[2];
a_output[3]=my_struct->a_input[3];
a_output[4]=my_struct->a_input[4];

but the problem is with the declaration. it gives me error cannot convert from real32_T to real32_T * .

1 个答案:

答案 0 :(得分:0)

主要思想是创建您需要的类型的总线。 我是这样做的:

num = zeros(15,15,15);
move   = zeros(15,15,15);
a = struct('number',num,'movement', move);

busInfo = Simulink.Bus.createObject(a);

你可以看到它可以创建任何你想要的数据结构,数组,矢量,然后创建相同类型的总线信号。

我在回调/ preLoadFcn(模型资源管理器)中使用它在工作空间中定义这个类型,它创建了slBus1变量(我的类型的总线信号),所以我需要定义任何块的输出(或必要时输入)仅限slBus1。然后使用总线选择器来处理数组数据。

对你有帮助吗?

添加新信息

这取决于你想要什么。 例如:我为反馈系统创建了s函数。它使用我的结构:

function a = fcn(BusSignal)
%#codegen
num = zeros(15,15,15);
move   = zeros(15,15,15);
%...some math actions with num and move...
a = struct('number',num,'movement', move);
%...and some action with a structure... for example:
if (c>b)
    a.number(1,2,3) = 15;
    a.movement(1,2,3)   = 42;
else
    a = BusSignal;
end

看看这个 - 我在入口和出口处使用总线信号,并使用总线选择器来处理它的数据。 请记住将输入和输出数据定义为总线信号!