How to use edit text with serial communications

Hi all,
I get data from Arduino with serial communication. I want to write this data to edit text. And i can do it by the way:
function deneme_OpeningFcn(hObject, eventdata, handles, varargin)
global arduino;
global oku;
global oku_s;
arduino=serial('COM4','BaudRate',9600); % create serial communication object on port COM4
fopen(arduino); % initiate arduino communication
oku=fscanf(arduino,'%d');
oku_s=num2str(oku);
set(handles.edit1,'String',oku_s);
Data changes with sensor control. And i want to write this data to edit text automatically everytime i get data from Arduino.

Answers (1)

set(arduino, 'BytesAvailableFcn', @(src,event) function_to_do_automatically(src, event, handles.edit1);
function function_to_do_automatically(src, event, whichcontrol)
oku = fscanf(src, '%d');
oku_s = num2str(oku);
set(whichcontrol, 'String', oku_s);
end

Categories

Asked:

on 23 May 2015

Edited:

on 23 May 2015

Community Treasure Hunt

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

Start Hunting!