serial communication use fscanf
4 views (last 30 days)
Show older comments
it's pleasure to join in this group.
i have a problem in showing all of data from ARF5479b when i use fscanf. data contains of m-rows and n-colums, but when i use the listing program below:
RxText = fscanf(handles.serConn);
currList = get(handles.history_box, 'String');
if length(RxText) < 1
RxText = 'Timeout @ ';
set(handles.history_box, 'String', ...
[currList ; [RxText datestr(now)] ]);
else
set(handles.history_box, 'String', ...
[currList ; ['Received @ ' datestr(now) ': ' RxText ] ]);
end
set(handles.history_box, 'Value', length(currList) + 1 );
catch e
disp(e)
data only contains 1 row. how to show all of it? thanks in advance
2 Comments
Answers (1)
Walter Roberson
on 20 Feb 2011
You have a 'catch' with no 'try'.
You have no apparent loop, and you have not given any indication of how you know the run is complete if this is within a callback.
You are using vertcat (the ';' operator) with strings without ensuring that the existing rows of the string are exactly the same width. That's almost certain to bomb on the second run.
You use length(currList) + 1 to set the Value of the control. length() returns the longest dimension. For a character array with a single row, that's going to be the width of the string, and trying to set the control Value to that width instead of to a row number is going to generate a warning and possibly cause the list to un-render.
What you should do in constructing your String is use cell arrays. That can be tricky for the empty list or the list with one entry: sometimes those are converted by the control to a single char entry. So start your code with:
currList = cellstr(get(handles.history_box, 'String'));
to ensure you have a cell string.
Then, construct your new row by using
currList{end+1} = 'Appropriate text for this case';
and after the 'if' use
set(handles.history_box, 'String', currList, 'Value', length(currList));
length() is not a problem here because it is being applied to the cell array rather than the contents of the cell array.
4 Comments
Walter Roberson
on 21 Feb 2011
Show how you are initializing the history box, and show how you are calling the update routine each time you get new data.
If not all data can be shown at one time, then your uicontrol might be set small enough to only show one line.
As you might eventually accumulate a lot of data, you probably want a scrollable window rather than a listbox. To get a scrollable list, one of the easiest ways is to use a uicontrol('Style', 'edit', 'Enable', 'disabled')
Notice that is not 'Enable' 'off', but 'Enable' 'disable'. With disable, the scroll bar remains but the text is not editable.
This technique only gives you vertical scroll bars though. If you need vertical and horizontal scroll bars, then there are contributions in the Matlab File Exchange that can provide that.
See Also
Categories
Find more on Data Type Conversion 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!