Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
serial port and figure window

Subject: serial port and figure window

From: tkeil

Date: 4 Mar, 2008 18:30:21

Message: 1 of 3

Hi, I am trying to write code that will display an image in
a figure window until the viewer pushes a button on a
button box connected through a serial port.

I have tried using fread(obj,1) after the image is
displayed in the figure window. This works, but only if I
insert pauses in my code or step through using the
debugger. When I let the code run without pausing, the
image is not displayed in the figure window but the system
is waiting for a response from the button box. This is odd
because the code is written so the image should appear in
the figure window BEFORE ever executing the fread command.

I have also tried doing this asynchronously without
success. When using the 'BytesAvailableFcn' approach, I'm
not sure how I can get the image to display up until the
callback function is called. Also, can you return values to
the original function when a callback function is called?

Please let me know if anyone has any thoughts or ideas.

Thanks!

Subject: serial port and figure window

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 4 Mar, 2008 18:32:35

Message: 2 of 3

In article <fqk4ft$l39$1@fred.mathworks.com>, tkeil <tlkeil@vradc.com> wrote:
>Hi, I am trying to write code that will display an image in
>a figure window until the viewer pushes a button on a
>button box connected through a serial port.

>I have tried using fread(obj,1) after the image is
>displayed in the figure window. This works, but only if I
>insert pauses in my code or step through using the
>debugger. When I let the code run without pausing, the
>image is not displayed in the figure window but the system
>is waiting for a response from the button box.

Sounds like you might need some drawnow() calls to allow
events to be processed during the current callback.
--
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec

Subject: serial port and figure window

From: Vihang Patil

Date: 5 Mar, 2008 05:37:01

Message: 3 of 3

"tkeil " <tlkeil@vradc.com> wrote in message <fqk4ft$l39
$1@fred.mathworks.com>...
> Hi, I am trying to write code that will display an image
in
> a figure window until the viewer pushes a button on a
> button box connected through a serial port.
>
> I have tried using fread(obj,1) after the image is
> displayed in the figure window. This works, but only if
I
> insert pauses in my code or step through using the
> debugger. When I let the code run without pausing, the
> image is not displayed in the figure window but the
system
> is waiting for a response from the button box. This is
odd
> because the code is written so the image should appear
in
> the figure window BEFORE ever executing the fread
command.
>
> I have also tried doing this asynchronously without
> success. When using the 'BytesAvailableFcn' approach,
I'm
> not sure how I can get the image to display up until the
> callback function is called. Also, can you return values
to
> the original function when a callback function is called?
>
> Please let me know if anyone has any thoughts or ideas.
>
> Thanks!

You might try using clear to send (CTS) function of the
serial port for this kind of application.
Just apply some potential like 12v on this pin and check
its status

ex:
   handles.s = serial('COM1','BaudRate',4800); %
Constructs the serial object
    fopen(handles.s);%opens the serial port for
communication
val = handles.s.PinStatus.ClearToSend;

if strcmp(val,'on')
<your steps>
<use drawnow or pause as Walter Suggested somewhere in the
code after you have placed the image on the axis>
end

HTH
VIhang

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us