|
Hi,
I am new with MATLAB and I found a way to transfer data between 2 computers using udp at
http://www.mathworks.com/support/solutions/en/data/1-OUCYT/index.html?solution=1-OUCYT
I tried the code at the command window and it is working.
However, when I tried to put it into my GUI, the code does not work and I don't know how to correct it.
example of my send_pushbutton
% --- Executes on button press in send_pushbutton.
function send_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to send_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = get(handles.answer_statictext,'String')
a2= eval(a)
b = get(handles.Input1_editText,'String'), %plaintext
if a2==0 %% actually if a=nothing
d=b
else
d=a
end
%% Define computer-specific variables
ipA = '1xxx'; portA = 3034; % Modify these values to be those of your first computer.
ipB = '1xxx'; portB = 3035; % Modify these values to be those of your second computer.
%% Create UDP Object
udpA = udp(ipB,portB,'LocalPort',portA)
%% Connect to UDP Object
fopen(udpA)
fprintf(udpA,d)
and example of my receive_pushbutton
% --- Executes on button press in RECEIVE_pushbutton.
function RECEIVE_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to RECEIVE_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% Define computer-specific variables
% Modify these values to be those of your first computer:
ipA = '1xxxx; portA = 3034;
% Modify these values to be those of your second computer:
ipB = '1xxxx'; portB = 3035;
%% Create UDP Object
udpB = udp(ipA,portA,'LocalPort',portB);
%% Connect to UDP Object
fopen(udpB)
fscanf(udpB)
set(handles.answer_statictext,'String',udpB)
Is my code correct? Is there anything wrong with it?
And what should I do if I want to use tcpip to communicate between the 2 computers?
Please help me, I really appreciate your help.
|