📄 readhex.m
字号:
function resp = readhex(rn,index,timeout)
%READ2HEX Retrieves a block of DSP memory as hexadecimal strings.
% DN = READ2HEX(NN)
% DN = READ2HEX(NN,[],TIMEOUT)
% DN = READ2HEX(NN,INDEX)
% DN = READ2HEX(NN,INDEX,TIMEOUT)
%
% HS = READ2HEX(NN) - returns a hex representation of the DSP's numeric
% values. For arrays, the returned values will be a cell array
% of hex strings. Conversely, if NN.SIZE equals 1,
% (indicating a scalar), the output is an array of hex characters.
%
% DN = READ2HEX(NN,TIMEOUT) - The time alloted to perform the read is
% limited by the NN.TIMEOUT property of the NN 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:27 $
error(nargchk(1,3,nargin));
if ~ishandle(rn),
error('First Parameter must be a MEMORYOBJ Handle.');
end
% Call base class (memoryobj) 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),
resp = read_registerobj(rn,1,timeout);
% TBD
% resp = read_memoryobj(rn,?,autype,1,timeout);
else
resp = read_registerobj(rn,1,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 hex array
if nvalues == 1,
resp{1} = reshape(fliplr(dec2hex(double(uidata),ceil(rn.bitsperstorageunit/4))'),1,[]);
else % create cell array TBD
for iv=1:nvalues,
resp{iv} = reshape(fliplr(dec2hex(double(uidata(:,iv)),ceil(rn.bitsperstorageunit/4))'),1,[]);
end
if length(rn.size) > 1,
resp = reshape(resp,rn.size);
end
end
% [EOF] readhex.m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -