📄 readbin.m
字号:
function resp = readbin(rn,index,timeout)
%READ2BIN Retrieves a block of DSP memory as binary strings.
% DN = READ2BIN(NN)
% DN = READ2BIN(NN,[],TIMEOUT)
% DN = READ2BIN(NN,INDEX)
% DN = READ2BIN(NN,INDEX,TIMEOUT)
%
% HS = READ2BIN(NN) - returns a binary string representation of
% the DSP's numeric values. For arrays, the returned values will
% be a cell array of binary strings. Conversely, if MM.SIZE equals 1,
% (indicating a scalar), the output is an array of hex characters.
%
% DN = READ2BIN(MM,TIMEOUT) - The time alloted to perform the read is
% limited by the MM.TIMEOUT property of the MM object. However,
% this method can be used to explicitly define a different timeout
% for the read. For example, this may be necessary for very large
% data transfers.
%
% See also WRITE, READ, CAST, NUMERICMEM.
% Copyright 2002 The MathWorks, Inc.
% $Revision: 1.3 $ $Date: 2002/03/23 02:46:28 $
error(nargchk(1,3,nargin));
if ~ishandle(rn),
error('First Parameter must be an RNUMERIC Handle.');
end
if nargin == 1,
data{1} = readhex(rn);
elseif nargin == 2, % index only (1 value)
if index~=1
error('Register data is always scalar.');
end
data = readhex(rn,index);
elseif nargin == 3 & isempty(index),
data{1} = readhex(rn,1,timeout);
else
if any(index>1)
error('Register data is always scalar.');
end
data{1} = readhex(rn,index,timeout);
end
resp{1} = dec2bin(hex2dec(data{1}),rn.bitsperstorageunit * rn.storageunitspervalue);
% % Call base class (registerobj) to get unformatted data
% if nargin == 1,
% uidata = read_registerobj(rn);
% elseif nargin == 2, % index only (1 value)
% uidata = read_registerobj(rn,index);
% elseif nargin == 3 & isempty(index),
% uidata = read_registerobj(rn,1,timeout);
% % TBD
% % resp = read_memoryobj(rn,?,autype,1,timeout);
% else
% if any(index>1)
% error('Register data is always scalar.');
% end
% uidata = read_registerobj(rn,index,timeout);
% end
%
% % Re-arrange data as described by object
% nvalues = prod(rn.size);
% uidata = reshape(uidata,[rn.storageunitspervalue nvalues]);
%
% % Endianness swap (if necessary)
% if ~strcmp( rn.endianness,'little') & (rn.storageunitspervalue > 1),
% uidata = flipud(uidata);
% end
%
% % Trim pre/post bytes (if necessary)
% % For now, limited to increments of bitsperstorageunit
% if rn.prepad > 0 | rn.postpad > 0,
% if rn.prepad + rn.postpad > rn.storageunitspervalue * rn.bitsperstorageunit,
% error(' Pre/Post padding exceeds available memory area');
% end
% % prepad
% uidata(1) = bitshift(uidata(1),-1 * rn.prepad,rn.bitsperstorageunit);
% % postpad
% uidata(end) = bitand( uidata(end),bitshift(2^rn.bitsperstorageunit-1,-rn.postpad,rn.bitsperstorageunit) );
% end
%
% % Convert adjusted array of 'valid' au into binary array
% switch (rn.represent),
% case 'float'
% if nvalues == 1,
% resp{1} = reshape(fliplr(dec2bin(double(uidata),rn.bitsperstorageunit)'),1,[]);
% else % create cell array TBD
% for iv=1:nvalues,
% resp{iv} = reshape(fliplr(dec2bin(double(uidata(:,iv)),rn.bitsperstorageunit)'),1,[]);
% end
% if length(rn.size) > 1,
% resp = reshape(resp,rn.size);
% end
% end
% otherwise
% if nvalues == 1,
% resp{1} = reshape(fliplr(dec2bin(double(uidata),rn.bitsperstorageunit)'),1,[]);
% else % create cell array TBD
% for iv=1:nvalues,
% resp{iv} = reshape(fliplr(dec2bin(double(uidata(:,iv)),rn.bitsperstorageunit)'),1,[]);
% end
% if length(rn.size) > 1,
% resp = reshape(resp,rn.size);
% end
% end
% end
% [EOF] readbin.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -