Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

iio_sys_obj_matlab persistence between step calls #6

Open
icchalmers opened this issue Oct 18, 2018 · 1 comment
Open

iio_sys_obj_matlab persistence between step calls #6

icchalmers opened this issue Oct 18, 2018 · 1 comment

Comments

@icchalmers
Copy link

Currently, iio_sys_obj_matlab has no persistence in state between step calls. This is an issue when calling stepImpl() with changes in attribute values. The attributes are always compared to the default initialized values of 0, and not to what attributes were previously written as.

The code to write to IIO attributes shows this:

% Implement the device configuration flow
for i = 1 : length(obj.iio_dev_cfg.cfg_ch)
if(~isempty(varargin{1}{i + obj.in_ch_no}))
if(length(varargin{1}{i + obj.in_ch_no}) == 1)
new_data = (varargin{1}{i + obj.in_ch_no} ~= obj.num_cfg_in(i));
else
new_data = ~strncmp(char(varargin{1}{i + obj.in_ch_no}'), char(obj.str_cfg_in(i,:)), length(varargin{1}{i + obj.in_ch_no}));
end
if(new_data == 1)
if(length(varargin{1}{i + obj.in_ch_no}) == 1)
obj.num_cfg_in(i) = varargin{1}{i + obj.in_ch_no};
str = num2str(obj.num_cfg_in(i));
else
for j = 1:length(varargin{1}{i + obj.in_ch_no})
obj.str_cfg_in(i,j) = varargin{1}{i + obj.in_ch_no}(j);
end
obj.str_cfg_in(i,j+1) = 0;
str = char(obj.str_cfg_in(i,:));
end
writeAttributeString(obj.iio_dev_cfg.cfg_ch(i).ctrl_dev, obj.iio_dev_cfg.cfg_ch(i).port_attr, str);
end
end
end

obj.num_cfg_in(i) will always be zero in the comparison on line 296. This means even attributes that haven't changed will always get written. For me, this bug became apparent when I was actually trying to write a 0 to an attribute - the write never happens as it assumes the attribute is already 0.

There are two potential solutions:

  1. Have iio_sys_obj_matlab inherit from the 'handle' class. This makes sense to me, as the object represents a piece of hardware anyway. This would also get rid of needing to return and store the object when you call setup i.e in the example ad9361_ModeS.m s = s.setupImpl(); simply becomes s.setupImpl();. This is more standard MATLAB system object behavior for hardware (I think?).

  2. return obj after each stepImpl(), and store it back into s.

@tfcollins
Copy link
Contributor

We are migrating everything to use standard system objects which are currently in a development branch here: https://github.com/analogdevicesinc/MathWorks_tools/tree/new-sys-objs (under the +adi folder). Example usages here: https://github.com/analogdevicesinc/MathWorks_tools/blob/new-sys-objs/test/AD9361Tests.m

In terms of this current issue, it might be easier to just initialize the attributes to empty elements which would fix that initialization issue. Let me look at a few options including the ones you suggested.

Thanks for reporting.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants