How can I receive data via TCP/IP in GUI interface?

Hi, I'm working with MATLAB to communicate with other PC which also using MATLAB.
TCP/IP communication is successful. GUI Creation and All the callback function is going well.
But I have a problem.
The GUI is 'event' oriented but the data is continuously sent.
If I don't use GUI, It is ok because I can use while loop.
But, I cannot handle the TCP/IP with GUI callback function.
How can I do both(using GUI and receiving data via TCP/IP) at the same time?

Answers (1)

Set a BytesAvailableFcn callback.

5 Comments

Do you mean that I should create tcpip object and the callback function BytesAvailableFcn like this?
handles.tcpi = tcpip('192.168.0.22', 30000, 'NetworkRole, 'client');
handles.tcpi.BytesAvailableFcn = @RXDATA;
and
function b = RXDATA(hObject, eventdata, handles)
a = fread(tcpi,6,'Float64');
b = mean(a);
Then where should I insert the initialization code for tcpip?
handles.tcpi = tcpip('192.168.0.22', 30000, 'NetworkRole, 'client');
handles.tcpi.BytesAvailableFcn = @RXDATA;
fopen(handles.tcpi);
guidata(hObject, handles);
Add this to the callback you have for your button that means "Yes, Go ahead and connect". If it is intended to connect immediately add it to the *_OpeningFcn for your GUI.
function RXDATA(hObject, eventdata) %does not receive handles
a = fread(tcpi,6,'Float64');
b = mean(a);
and now you probably want to do something with b, such as fprintf() it or display it in a graph or log it to disk. A BytesAvailableFcn does not return any value.
Hi walter,
Thanks for the information. I am using developing a GUI Based application. where multiple GUIs are used. Both Server and client are GUI based and i need to send receive data between them.
I need to validate the incoming data and again send back to the data to server. what all steps need to be followed?
For receiving information i will use callback function, but for sending the data can i write fwrite in callback function.
Please help!!
Yes, you can fwrite() or fprintf() to a tcp connection.
Note: there is also the OutputEmptyFcn callback, to allow you determine when to send to the other side without risking overflowing buffers.
why we use handles.tcpi?
direct we can't use tcpi only?

Sign in to comment.

Tags

Asked:

on 1 Oct 2015

Commented:

on 1 Jun 2021

Community Treasure Hunt

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

Start Hunting!