Receive data from a microprocessor
2 ビュー (過去 30 日間)
古いコメントを表示
I am making a user interface with app designer and I want to receive the data stored in a microprocessor. I have performed the following functions but no data is stored in the variables and I do not know where I could be the error. These are the functions:
function read(app)
app.DataReceived_ch=fread(app.t_waveforms);
% Two 8-bit values are read for each 16-bit integer
i=1;
j=1;
while i<length(app.DataReceived_ch)
app.B(j) = 2^8*app.DataReceived_ch(i+1)+app.DataReceived_ch(i);
% The int numbers greater than (2 ^ 16) -1 are converted to negative
if app.B(j) > 32768
app.B(j)=app.B(j)-65536;
end
i=i+2;
j=j+1;
end
app.H1=length(app.B)-4;
app.B=0.1*app.B;
app.B1(1 : app.H1/4)=app.B(1 : 0.25*app.H1);
app.z1=app.B1;
app.z1
app.B2(1 : app.H1/4)=app.B(1+(0.25*app.H1) : 0.5*app.H1);
app.z2=app.B2;
app.B3(1 : app.H1/4)=app.B(1+(0.5*app.H1) : 0.75*app.H1);
app.z3=app.B3;
app.B4(1 : app.H1/4)=appp.B(1+(0.75*app.H1) : app.H1);
app.z4=app.B4;
flushinput(app.t_waveforms);
pause(0.2);
end % function read
and the start function is:
function startupFcn(app)
app.tip=app.IPField.Value;
app.t_waveforms = tcpip(app.tip, 80);
app.t_buttons = tcpip(app.tip, 80);
app.t_waveforms.BytesAvailableFcn = @read;
app.t_waveforms.BytesAvailableFcnCount = app.buffer+8; % to specify that the event be set to "Number of bytes" instead of "Terminator"
app.t_waveforms.BytesAvailableFcnMode = 'byte';
set(app.t_waveforms, 'InputBufferSize',app.buffer+8);
app.z1 %To see if data are stored in z1
end
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!