From: Jorge Luis on
Hi,
for what i have seen it is possible to make an interrupt in matlab when the serial port has for example 6 bytes. So far so good, i was trying to do it and i cant figure it out.

So i have a gui, i chose which com i want to open, and i open like this

port=handles.popupmenu1;
s1 = serial(port, 'BAUDRATE',38400);

s1.BytesAvailableFcnCount = 40;
s1.BytesAvailableFcnMode = 'byte';
s1.BytesAvailableFcn=(a)mycallback;
fopen(s1);

and my callback is defined as


function mycallback(hObject, event, handles)
do something here

so when i have 40 bytes it should go to mycallback right? it doesnt. It gives an error. Do u have any idea how to program this?
From: Ankit Desai on
"Jorge Luis" <jorgefil(a)hotmail.com> wrote in message <hu400s$csv$1(a)fred.mathworks.com>...
> Hi,
> for what i have seen it is possible to make an interrupt in matlab when the serial port has for example 6 bytes. So far so good, i was trying to do it and i cant figure it out.
>
> So i have a gui, i chose which com i want to open, and i open like this
>
> port=handles.popupmenu1;
> s1 = serial(port, 'BAUDRATE',38400);
>
> s1.BytesAvailableFcnCount = 40;
> s1.BytesAvailableFcnMode = 'byte';
> s1.BytesAvailableFcn=(a)mycallback;
> fopen(s1);
>
> and my callback is defined as
>
>
> function mycallback(hObject, event, handles)
> do something here
>
> so when i have 40 bytes it should go to mycallback right? it doesnt. It gives an error. Do u have any idea how to program this?

Hi Jorge,

Can you provide more details about the error you receive? What is the error message?
Conceptually I do not see why it would not work.

I have used the same logic in the demo I wrote: http://www.mathworks.com/matlabcentral/fileexchange/27290-collect-and-plot-data-from-a-tcpip-server-in-real-time

Having the error message might be helpful.

-Ankit
From: Jorge Luis on
"Ankit Desai" <adesai.nospam(a)mathworks.com> wrote in message <hu5ih5$e1a$1(a)fred.mathworks.com>...
> "Jorge Luis" <jorgefil(a)hotmail.com> wrote in message <hu400s$csv$1(a)fred.mathworks.com>...
> > Hi,
> > for what i have seen it is possible to make an interrupt in matlab when the serial port has for example 6 bytes. So far so good, i was trying to do it and i cant figure it out.
> >
> > So i have a gui, i chose which com i want to open, and i open like this
> >
> > port=handles.popupmenu1;
> > s1 = serial(port, 'BAUDRATE',38400);
> >
> > s1.BytesAvailableFcnCount = 40;
> > s1.BytesAvailableFcnMode = 'byte';
> > s1.BytesAvailableFcn=(a)mycallback;
> > fopen(s1);
> >
> > and my callback is defined as
> >
> >
> > function mycallback(hObject, event, handles)
> > do something here
> >
> > so when i have 40 bytes it should go to mycallback right? it doesnt. It gives an error. Do u have any idea how to program this?
>
> Hi Jorge,
>
> Can you provide more details about the error you receive? What is the error message?
> Conceptually I do not see why it would not work.
>
> I have used the same logic in the demo I wrote: http://www.mathworks.com/matlabcentral/fileexchange/27290-collect-and-plot-data-from-a-tcpip-server-in-real-time
>
> Having the error message might be helpful.
>
> -Ankit


Hi, thanks for your answer, so the problem is, when there is an interrupt it goes to mycallback function. But in my callback i want to read the serial port. For that i use handles, the problem is that it cannot find handles, so i cannot read the serial port.
The error its or cannot find handles, or says me that h must be a figure.

i use this in a pushbutton callback, open the serial port and do this,

handles.pushbutton2=s1;
guidata(hObject, handles);

I use this in the mycallback;

handles = guidata(gcbo);
s1=handles.pushbutton2;

And it doesnt work. If it is in a callback from a pushbutton everything is ok.
From: Walter Roberson on
Jorge Luis wrote:

> Hi, thanks for your answer, so the problem is, when there is an
> interrupt it goes to mycallback function. But in my callback i want to
> read the serial port. For that i use handles, the problem is that it
> cannot find handles, so i cannot read the serial port. The error its or
> cannot find handles, or says me that h must be a figure.
>
> i use this in a pushbutton callback, open the serial port and do this,
>
> handles.pushbutton2=s1;
> guidata(hObject, handles);
>
> I use this in the mycallback;
>
> handles = guidata(gcbo);
> s1=handles.pushbutton2;
>
> And it doesnt work. If it is in a callback from a pushbutton everything
> is ok.

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));

The gcf will be executed at the time the timer is created and will evaluate to
the figure number as it is at that time; that number will become a constant
parameter to the callback

function MyTimerCallback(src, event, figureno)
handles = guidata(figureno);
s1 = handles.pushbutton2;
...
end
From: Jorge Luis on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hu6j17$jqq$1(a)canopus.cc.umanitoba.ca>...
> Jorge Luis wrote:
>
> > Hi, thanks for your answer, so the problem is, when there is an
> > interrupt it goes to mycallback function. But in my callback i want to
> > read the serial port. For that i use handles, the problem is that it
> > cannot find handles, so i cannot read the serial port. The error its or
> > cannot find handles, or says me that h must be a figure.
> >
> > i use this in a pushbutton callback, open the serial port and do this,
> >
> > handles.pushbutton2=s1;
> > guidata(hObject, handles);
> >
> > I use this in the mycallback;
> >
> > handles = guidata(gcbo);
> > s1=handles.pushbutton2;
> >
> > And it doesnt work. If it is in a callback from a pushbutton everything
> > is ok.
>
> 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));
>
> The gcf will be executed at the time the timer is created and will evaluate to
> the figure number as it is at that time; that number will become a constant
> parameter to the callback
>
> function MyTimerCallback(src, event, figureno)
> handles = guidata(figureno);
> s1 = handles.pushbutton2;
> ...
> end

Hello,
Walter can you explain me the timer function.


so i still define this as

s1.BytesAvailableFcnCount = 40;
s1.BytesAvailableFcnMode = 'byte';
s1.BytesAvailableFcn=(a)mycallback;
fopen(s1);

handles.pushbutton2=s1;
guidata(hObject, handles);
?