Reading data from a serial device

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Reading data from a serial device

Post by Simon Knight » Wed Feb 03, 2010 9:55 am

I am attempting to read and process data from an old GPS unit connected via RS232 and a RS232 to USB converter to my mac. I have connected and read data o.k. but I seek advice on the best design strategy to employ to ensure that I process all the required data in near real time.

The device connects at 4800 baud and I think that the serial to USB converter buffers data. The GPS broadcasts it data with no flow control or request messages. I am interested in position data which is broadcast by the GPS once a second. I have managed to read my data and process it inside a handler that recalls itself on a timer but the process is very time dependant and I am sure that must be a better way.

Code: Select all

On readDataPort
   global gTimerID
   --Start Loop to search for words of interest
   Repeat forever
   Read from driver "/dev/cu.usbserial-FTBOBOGT" for 6 characters
   If it is "$GPRMC" OR it is "$GPGGA" then 
      Read from driver "/dev/cu.usbserial-FTBOBOGT" until linefeed
      --Now work on data sentence
      Put it  into field "thedata" 
      exit repeat
   else
      -- We are not interested in the data word found so prepare for next header
      Read from driver "/dev/cu.usbserial-FTBOBOGT" until linefeed
   end if
   End Repeat
   send readDataPort to me in 500 milliseconds
   put the result into gTimerID
end readDataPort
I have tried flushing the buffer by using the read from drive n until end but I have discovered that this may cause the revolution environment to crash.

Any thoughts or advice
best wishes
Skids

Post Reply