How can I receive data via TCP/IP in GUI interface?
Show older comments
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)
Walter Roberson
on 2 Oct 2015
0 votes
5 Comments
JangHo Cho
on 2 Oct 2015
Walter Roberson
on 2 Oct 2015
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.
Yogesh
on 16 Mar 2017
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!!
Walter Roberson
on 16 Mar 2017
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.
Harsh Sonani
on 1 Jun 2021
why we use handles.tcpi?
direct we can't use tcpi only?
Categories
Find more on TCP/IP Communication in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!