How to import data from a microprocessor

I am making an interface through app designer but I do not know how to receive the data stored in a microprocessor using a tcpip object.

8 Commenti

Can you be more specific in your issue? Are you having networking issues or not sure how to set up a tcp object in matlab?
I am not sure how to set up a tcp object in Matlab. I have done the code but when I run the program the vectors do not receive the data so they are empty.
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
% The data are distributed in 4 vectors
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
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;
app.t_waveforms.BytesAvailableFcnMode = 'byte';
set(app.t_waveforms, 'InputBufferSize', app.buffer+8);
end
function StartButton (app,event)
app.tip=app.IPField.Value;
app.t_waveforms= tcpip('192.168.1.100', 80);
fopen(app.t_waveforms);
echotcpip('off');
fprintf(app.t_waveforms,'GET /Interface_waveforms');
pause(0.01);
end
Jonathan Chin
Jonathan Chin il 16 Ott 2017
Modificato: Jonathan Chin il 16 Ott 2017
Can you communicate with the device with out using the ByteAvailableFcn to read back but instead use fread? If so then the device might not be sending a terminator or enough bytes
I have read the data directly using fread without using ByteAvailableFcn and the data has been stored correctly but now I have another problem and this is that in the graph only the first data are represented and these are not updated even if new data is received.
function StartButton(app) If app.Start.Value==1
set(app.t_waveforms, 'InputBufferSize', app.buffer+8);
app.tip=app.IPField.Value;
app.t_waveforms= tcpip('192.168.1.100', 80);
fopen(app.t_waveforms);
echotcpip('off');
fprintf(app.t_waveforms,'GET /Interface_waveforms');
pause(0.01);
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
% The data are distributed in 4 vectors
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)=app.B(1+(0.75*app.H1) : app.H1);
app.z4=app.B4;
flushinput(app.t_waveforms);
pause(0.2);
if strcmp(app.Switch.Value, 'Stop')
fclose(app.t_waveforms); fopen(app.t_waveforms);
fprintf(app.t_waveforms,'GET /Interface_waveforms');
end end
function GraphButton(app)
if app.Graph.Value==1
xlim(app.Grafica1,[1 app.n*length(app.Q)]); plot(app.Grafica1,app.z2,'b','linewidth',1.25);
end
Thanks for your help
fprintf(app.t_waveforms,'GET /Interface_waveforms');
What I would try is to manually send this command, then do a fread to get the data back and send it again. If this works it could be an issue with how your app is sending command and getting the data.
Do you only hit the StartButton once? if so I think you need to have some way of sending the above command
Yes, I only hit the button once but if I disconnect and connect the button again, the new data are represented so I think the problem is that the function is not run cyclically but I do not know why.
try adding a button that runs calls by itself
fprintf(app.t_waveforms,'GET /Interface_waveforms');
I believe you need to call this every time you want data then put a debug point there to see if you can get some data
Yes, that is the problem. I do not know how to execute that command cyclically.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by