Serial communication

David Vaughan dvk at dvkconsult.com.au
Tue Jan 10 15:17:03 EST 2006


On 10/01/2006, at 21:48, Camm29" <Camm29 at tesco.net> wrote:
>
> I have some custom made Hardware that i communicate to in Serial.
>
> This Hardware returns the Character ">" when ready and able to Receive
> and/or finished replying.
>
> so before any write to file "COM:1"  or  read from file "COM:1" (I  
> must have
> received the Char ">")
>
> i have tried many combinations in trying to get this to work !!!!!!
>
> somehow if i loop like below i still manage to send before ">" is  
> received
> it would seem which causes errors ???
>
> repeat 100
> write -------
> wait for ">"
> read -------
> end
if you must wait for ">" before "any write or ... read" then firstly  
your code needs another wait statement. The above code will write  
after reading and without waiting for a ready character, which is the  
problem you report.

The following will work _provided_ you are happy that you will always  
receive the requisite characters )and that the device is ready the  
first time) or else it will wait forever.
repeat N
   write something
   wait for ">"
   read something
   wait for ">"
end repeat

In the basic form of the loop above you will need an outside "send"  
statement to make sure things are still alive and get you out of  
problems, which would require a construct along the lines of 'wait  
for ">" with messages'

This might be done better with "wait for messages" then test whether  
the message was one which allows you to read/write or if you must  
exit the loop.

HTH
David
>
> It's a mystery or i lost the plot.
> Nothing wrong with comm settings or hardware for sure.
>
> Regards Camm



More information about the use-livecode mailing list