Concatenating individual incoming bytes into a string on a static text box.

7 views (last 30 days)
Hi, I am trying to concatenate incoming bytes from a comport so that they appear in a static textbox in my GUI. I have also tried to set it up so that when there is a character return, the data will move to the next line and continue concatenating. I have pasted the code below. Right now I have it so that the individual bytes will appear, however they won't append each other, and the incoming byte will replace the previous byte.
function rxbyte_Callback(hObject, eventdata, thisfig)
handles = guidata(thisfig);
% pingport = getappdata(handles.main_window,'port_handle');
% bytes=fread(pingport,pingport.BytesAvailable);
bytes=(fread(hObject,hObject.BytesAvailable));
class(bytes)
hello=(get(handles.Incoming))
class(hello.String)
variable=[strcat(hello.String,char(bytes))]
hello
variable=['']
if(bytes==13)
variable =[''; variable];
set(handles.Incoming,'String',strcat(variable))
else
variable=[variable char(bytes)]
set(handles.Incoming,'String',strcat(variable))
end
strcat(handles.Incoming,'String',variable)
set(handles.Incoming,'String',variable);
Thanks,
Malik

Answers (1)

Walter Roberson
Walter Roberson on 9 Jul 2012
One thing that occurs to me immediately is that multiple bytes might be read with the fread(), but your "if" is testing as if only a single byte had been read.
Oh yes, and you are initializing "variable" to '' each time rather than starting with whatever was already in the uicontrol.

Categories

Find more on Argument Definitions 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!