Path: news.mathworks.com!not-for-mail
From: "Vihang Patil" <vihang_patil@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: serial port and figure window
Date: Wed, 5 Mar 2008 05:37:01 +0000 (UTC)
Organization: Konem Solutions
Lines: 54
Message-ID: <fqlbht$qq5$1@fred.mathworks.com>
References: <fqk4ft$l39$1@fred.mathworks.com>
Reply-To: "Vihang Patil" <vihang_patil@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1204695421 27461 172.30.248.38 (5 Mar 2008 05:37:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 5 Mar 2008 05:37:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 413701
Xref: news.mathworks.com comp.soft-sys.matlab:455434


"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