serial communication use fscanf

4 次查看(过去 30 天)
zaini
zaini 2011-2-19
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 个评论
Jan
Jan 2011-2-19
Please use the code formatting to make the code more readable.
zaini
zaini 2011-2-20
thanks for your comment,
i've made it readable,
and, could u give some advice to solve my problem?
thanks alot

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2011-2-20
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 个评论
zaini
zaini 2011-2-21
mr roberson, how about ur code above, i have tried it, but the result is same with before, one by one row, (not all data can be shown in one time)...
Walter Roberson
Walter Roberson 2011-2-21
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by