From: Walter Roberson on 2 Jun 2010 18:06 Jorge Luis wrote: > Walter Roberson <roberson(a)hushmail.com> wrote in message >> Pass the figure number (or any object in the figure) as a parameter to >> the callback when you create it. >> >> timer('TimerFcn', @(src,event) MyTimerCallback(src, event, gcf)); > Walter can you explain me the timer function. Not unless you have a more specific question. It would take too long to write everything I know or can deduce about timer functions and their usage and interaction with other items. > so i still define this as > s1.BytesAvailableFcnCount = 40; > s1.BytesAvailableFcnMode = 'byte'; > s1.BytesAvailableFcn=(a)mycallback; > fopen(s1); > > handles.pushbutton2=s1; > guidata(hObject, handles); s1.BytesAvailableFcnCount = 40; s1.BytesAvailableFcnMode = 'byte'; s1.BytesAvailableFcn = @(src, event) mycallback(src, event, hObject); fopen(s1); handles.pushbutton2 = s1; %why is a serial port object being stored in %field named as a pushbutton ?? handles.inputdata = uint8([]); guidata(hObject, handles); while true pause(0); %give callback a chance to read some data if feof(s1); break; end %reached end of data handles = guidata(hObject); %The callback might have changed the values currentdata = handles.inputdata; %read pending data handles.inputdata = uint8([]); %clear pending data %now do something with the currentdata ... end function mycallback(src, event, FigureObject) handles = guidata(FigureObject); thisdata = fread(s1, s1.BytesAvailable); handles.inputdata = [handles.inputdata thisdata]; guidata(FigureObject, handles); end
From: Jorge Luis on 2 Jun 2010 20:35 Walter Roberson <roberson(a)hushmail.com> wrote in message <hu6kna$mcv$1(a)canopus.cc.umanitoba.ca>... > Jorge Luis wrote: > > Walter Roberson <roberson(a)hushmail.com> wrote in message > > >> Pass the figure number (or any object in the figure) as a parameter to > >> the callback when you create it. > >> > >> timer('TimerFcn', @(src,event) MyTimerCallback(src, event, gcf)); > > > Walter can you explain me the timer function. > > Not unless you have a more specific question. It would take too long to write > everything I know or can deduce about timer functions and their usage and > interaction with other items. > > > > so i still define this as > > s1.BytesAvailableFcnCount = 40; > > s1.BytesAvailableFcnMode = 'byte'; > > s1.BytesAvailableFcn=(a)mycallback; > > fopen(s1); > > > > handles.pushbutton2=s1; > > guidata(hObject, handles); > > s1.BytesAvailableFcnCount = 40; > s1.BytesAvailableFcnMode = 'byte'; > s1.BytesAvailableFcn = @(src, event) mycallback(src, event, hObject); > fopen(s1); > > handles.pushbutton2 = s1; %why is a serial port object being stored in > %field named as a pushbutton ?? > > handles.inputdata = uint8([]); > > guidata(hObject, handles); > > while true > pause(0); %give callback a chance to read some data > if feof(s1); break; end %reached end of data > handles = guidata(hObject); %The callback might have changed the values > currentdata = handles.inputdata; %read pending data > handles.inputdata = uint8([]); %clear pending data > %now do something with the currentdata > ... > end > > > function mycallback(src, event, FigureObject) > handles = guidata(FigureObject); > thisdata = fread(s1, s1.BytesAvailable); > handles.inputdata = [handles.inputdata thisdata]; > guidata(FigureObject, handles); > end Walter, It works, thank you very much. I also wanted to know something. The interrupt is working, and i process the data everytime the interrupt is called, and i also want to put an image in my axes, when i dont have mycallback and do it in other callback, i only do imshow(); but know i do that in mycallback and it opens a new figure and appears the image, instead of putting it on the current axes.
From: Walter Roberson on 2 Jun 2010 23:57 Jorge Luis wrote: > I also wanted to know something. The interrupt is working, and i process > the data everytime the interrupt is called, and i also want to put an > image in my axes, when i dont have mycallback and do it in other > callback, i only do imshow(); but know i do that in mycallback and it > opens a new figure and appears the image, instead of putting it on the > current axes. The current axes is subject to change at any mouse click, which makes it difficult to communicate it correctly to the serial callback. How about instead of the _current_ axes, you instead plot on a _known_ axes, the one associated with the plot? The difference is that if the user goes off and clicks on something else, the graph would still go to where you expect instead of to the place the user had clicked on. If a _known_ axes is good, then create a field in the handles structure to store the axes you want the plot to appear in, and call guidata() to update the known handles structure. Then in whatever callback you want, use guidata() to retrieve the handles (already done in mycallback to get s1), and use the appropriate field of that as the axes handle. However, I warn that if you wish to avoid losing data, you should avoid doing any kind of complicated processing in the callback. Recall too that the callback is not going to be generated every 40 bytes of input exactly: it will be generated when there are 40 bytes of input, but it might not be served until later, by which time there might be more input bytes. The code structure I showed earlier, the loop with pause() and so on, pulls off all data that has accumulated since the data was last cleared, and would thus be a more appropriate place to plot the data.
From: Ankit Desai on 3 Jun 2010 04:06
Walter Roberson <roberson(a)hushmail.com> wrote in message <wKFNn.25314$yx.5045(a)newsfe13.iad>... > Jorge Luis wrote: > > > I also wanted to know something. The interrupt is working, and i process > > the data everytime the interrupt is called, and i also want to put an > > image in my axes, when i dont have mycallback and do it in other > > callback, i only do imshow(); but know i do that in mycallback and it > > opens a new figure and appears the image, instead of putting it on the > > current axes. > > The current axes is subject to change at any mouse click, which makes it > difficult to communicate it correctly to the serial callback. > > How about instead of the _current_ axes, you instead plot on a _known_ > axes, the one associated with the plot? The difference is that if the > user goes off and clicks on something else, the graph would still go to > where you expect instead of to the place the user had clicked on. > > If a _known_ axes is good, then create a field in the handles structure > to store the axes you want the plot to appear in, and call guidata() to > update the known handles structure. Then in whatever callback you want, > use guidata() to retrieve the handles (already done in mycallback to get > s1), and use the appropriate field of that as the axes handle. > > However, I warn that if you wish to avoid losing data, you should avoid > doing any kind of complicated processing in the callback. > > Recall too that the callback is not going to be generated every 40 bytes > of input exactly: it will be generated when there are 40 bytes of input, > but it might not be served until later, by which time there might be > more input bytes. The code structure I showed earlier, the loop with > pause() and so on, pulls off all data that has accumulated since the > data was last cleared, and would thus be a more appropriate place to > plot the data. Nicely summarized Walter. To put what Walter suggested in code: axesHandle = axes('PropertyName',propertyvalue,...); plotHandle = plot(axesHandle,X1,Y1,LineSpec,'PropertyName',PropertyValue); handles.axesHandle = axesHandle; handles.plotHandle = plotHandle; guidata(hObject,handles); Hope this helps, -Ankit |