Search Backwards (Last Line to First)

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Search Backwards (Last Line to First)

Post by Simon Knight » Fri Feb 05, 2010 9:32 pm

I need to search a field for a substring which may be repeated many times. I am only interested in the last occurrence of the sub string and I wish to avoid searching the very last line.

At present I am using:

Code: Select all

repeat for each line tLine in gDatabuffer
      If item 1 of tLine ="$GPGGA" then put tLine into tFixData
 end repeat
which is a traditional forward pass through the data and it also includes the last line of data in the search which I do not want included. I have tried to write a similar loop using negative indexes but the syntax has defeated me.

Any ideas?

Thanks.
best wishes
Skids

massung
Posts: 93
Joined: Thu Mar 19, 2009 5:34 pm

Re: Search Backwards (Last Line to First)

Post by massung » Fri Feb 05, 2010 9:46 pm

Code: Select all

repeat with tLineIdx = the number of lines in gDataBuffer down to 1
   if item 1 of line tLineIdx of gDataBuffer is "$GPGGA" then ...
end repeat
HTH,

Jeff M.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Search Backwards (Last Line to First)

Post by bn » Fri Feb 05, 2010 10:09 pm

Simon,

to exclude the last line and to proceed from the line last line - 1 to the first line try this (same as Jeff's, Jeff just forgot to exclude the last line)

Code: Select all

   repeat with tLineIdx = the number of lines in gDataBuffer - 1 down to 1
         if item 1 of line tLineIdx of gDataBuffer is "$GPGGA" then ...
   end repeat
this is slower then the "repeat for each " but depending on your needs it will do the trick.
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Search Backwards (Last Line to First)

Post by bn » Fri Feb 05, 2010 10:22 pm

Simon,
if you want the speed of repeat for each try this

Code: Select all

   put the number of lines of gDatabuffer into tLastLine
   put 1 into tCounter
   repeat for each line tLine in gDatabuffer
      if tCounter = tLastLine then exit repeat  -- exit before processing the last line
      If item 1 of tLine ="$GPGGA" then put tLine into tFixData
      add 1 to tCounter
   end repeat
you will notice the speed gain of this only if you have a fair amount of lines (guessing > 500 to 1000)
regards
Bernd

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

Re: Search Backwards (Last Line to First)

Post by Simon Knight » Sat Feb 06, 2010 12:26 am

Jeff & Bernd,

Thanks for the code snips, I will experiment with them over the week end and report back. Jeff I have to ask: what does HTH mean in your post?

Simon
best wishes
Skids

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Search Backwards (Last Line to First)

Post by Klaus » Sat Feb 06, 2010 12:53 am

Hope That Helps :)

HTH

Best

Klaus

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

Re: Search Backwards (Last Line to First)

Post by Simon Knight » Sat Feb 06, 2010 10:25 am

YID!



(Yes it Does) :D

Thanks
best wishes
Skids

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Search Backwards (Last Line to First)

Post by Klaus » Sat Feb 06, 2010 11:47 am

:D :D :D

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

Re: Search Backwards (Last Line to First)

Post by Simon Knight » Mon Feb 08, 2010 3:24 pm

I promised to report back...
I have tried the code snippets above and they all seem to work fast enough for the task which is to scan a block of less than 20 lines of CSV text.

Unfortunately my code has a bug which is resisting my attempts to locate. The code below is inside a routine that is called once a second, its purpose is to extract a single line of data from the block presented and then process the fields. It works for a while say 30 - 60 seconds but then it stops. I have proved that the repeating routine is still being called and that none of the sub routines are causing the failure. Its as if the if statement at line 5 fails on one read and then remains in a failed state until the routine is stopped and started. Please will you assess my mess? For example should I be checking that item 9 is a number before I do a comparison. Thanks.

Code: Select all

put the number of lines of gDatabuffer into tLastLine
     put 1 into tCounter
      repeat for each line tLine in gDatabuffer
      if tCounter = tLastLine then exit repeat  -- exit before processing the last line
      If item 1 of tLine ="$GPGGA" AND item 7 of tLine= "1" AND item 9 of tLine <gHDOP then
         beep
         --store the start time if required
         if gStartTime="000000" then 
            put item 2 of tLine into gStartTime
            --answer gstartTime
         end if
         DisplayTime (item 2 of tLine)
         DisplayPosition tLine
         If gLastFix<>"" then  SetDistanceMoved gLastFix, tLine
         put item 8 of tLine into fld"satcount"
         put item 9 of tLine into fld"HDop"
         put tLine into gLastFix
         CalculateAvSpeed item 2 of tLine
         --exit repeat
      ELSE  if item 1 of tLine ="$GPGGA" then
         put tLine & "XXX" after gRejectedFixs
         beep
         beep
         beep
      end if
            add 1 to tCounter
      end repeat
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Search Backwards (Last Line to First)

Post by bn » Mon Feb 08, 2010 4:15 pm

Simon,
I don't see anything that is wrong as far as syntax is concerned. I reread your initial post and you just wanted the most recent occurence of the event. The way it is now you do actually start with the oldest event assuming that the most recent lines are added after the older ones. Does that matter? If so I would go for Jeff's "repeat with i = the number of lines - 1 down to 1" and exit if you found the most recent occurence, which would be the first one meeting your conditions, I suppose.

Of course if the global gDataBuffer is empty then nothing happens even though you enter the handler. If gDatabuffer is just empty lines you would enter the repeat loop.
What happens to gHDOP? Do any of the lines you would want show up in gRejectedFixs?
I would change this but just out of a habbit, probably nothing wrong with it (I sometimes get confused by the many ways you can do a conditional with if, then,else

Code: Select all

  ELSE 
         if item 1 of tLine ="$GPGGA" then
            put tLine & "XXX" after gRejectedFixs
            beep
            beep
            beep
         end if
      end if
Sorry, maybe someone else sees something obvious, but at this point I would check how the globals are filled. You are shure that your handler is indeed called?
regards
Bernd

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

Re: Search Backwards (Last Line to First)

Post by Simon Knight » Mon Feb 08, 2010 9:49 pm

Hi Bernd et al,

In the way of things I realised that I only wanted a single line of data, the GPS position fix. This is reported once a second along with quite a lot of other data. I realised that once I had extracted the newest fix I could set the global to "" ready for refilling by the serial port reader. Once it was running the search routine only had to parse a maximum of ten lines so I decided that I would stick with searching forwards. I was also confused by the user guide which states that the earliest position in the data should be requested first in any chunk expressions. Anyway that seems a long time ago....

The global gHDOP is used as part of the selection of valid data, the nearer it is to 1 the better the accuracy of the fix data. I was concerned that as it was my only numeric comparison that it might be causing the problems. However, it is not the source of the problems. The code following the ELSE does not report any "missing" messages, when it fails the whole IF construct stops operating.

I am sure the handler is being called as I put a heartbeat indicator on the card and the following code is just before the IF construct that is causing the problems:

Code: Select all

--  Modulate the heart beat
    If the hilite of btn"heartbeat" is false then
      set the hilite of btn"heartbeat" to true
   Else
      set the hilite of btn"heartbeat" to false
   end if
The code I posted included much of my debug code put in to trace the bug I touched on above. When the bug bit it seems that the whole IF ELSE ENDIf construct was being ignored. RunRev would only re-start conducting the IF test once the repeating call to the routine had been stopped and then restarted. I have spent this afternoon tracking this bug down and have decided that it is probably caused by odd data being stored in the global gDataBuffer : every so often the code that reads the serial port writes extra linefeeds Hex(0D) into the variable and I think that these were causing a problem with the detection of line ends within the loop. The odd thing is that no errors were posted and the construct just went to sleep. I decided to rewrite the portion of the code that extracts the data from the buffer and this is what I have come up with:

Code: Select all

put 1 into tPTR
   put the number of characters of gDatabuffer into tCharCount
   Repeat until tPTR = tCharCount
      put character tPTR of gDataBuffer into theChar
      --put "Position " & tPTR & " " & theChar & LF after fld"buffer"
      If theChar = "$" then
         --we are at the start of a data word, so read the header word
         --and see if it is the one required
         put character tPTR to tPTR+5 of gDataBuffer into tID
         if tID="$GPGGA" then
            --extract the word from the buffer
            put False into tISLast
            Repeat Until tIsLast=True
               put character tPTR of gDataBuffer into theChar
               If theChar="*" then
                  --end of data sentence, so exit the loop
                  put theChar after tDataSentence
                  put True into tIsLast
               Else
                  put theChar after tDataSentence
               end if
               put tPTR+1 into tPTR
            end Repeat
         end if
         exit repeat
      end if
      put tPTR+1 into tPTR
   end Repeat
   --debug code
This code snip just ignores and LF or CRs and searches on the data for key characters. I would be interested in how it may be improved as I feel some of it is rather clumsy and overall it is far to complex. It searches through the global gDataBuffer seeking the ID word "$GPGGA" it then reads the ID word and all the characters following up to and including the "*" character. I need to add more code to protect against the case where the sentence starts near the end of the buffer and is incomplete i.e no "*" is found; in this situation the data sentence is completed at the start of the next set of data passed as gDataBuffer is set to "" on each pass.

I need some rest....!

Best wishes
Simon
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Search Backwards (Last Line to First)

Post by bn » Mon Feb 08, 2010 10:25 pm

Good night Simon,

try something like this:

Code: Select all

on extractData
   put line 1 to - 2 of gDataBuffer into tMyData -- leave out last line
   put lineOffset("$GPGGA",tMyData) into tLineNo
   if tLineNo > 0 then  -- found "$GPGGA"
      put line tLineNo of tMyData into tLineToAnalyse
      put offset("*",tLineToAnalyse) into tEndOfInfo
      if tEndOfInfo = 0 then 
         --- no "*" found, proceed appropriately
      else
         put char 1 to tEndOfInfo of tLineToAnalyse into tLineToAnalyse -- cut off after "*"
         -- do something to item 1
         -- do something to item x
         -- etc
      end if -- tEndOfInfo = 0
   end if -- tLineNo > 0
end extractData
I dont know if this helps. But you might also look at a the offset function that you could use in a repeat loop.

You could use above posted code in a repeat loop by taking (in case you found a line)

Code: Select all

put line tLineNo + 1 to line - 2 of gDataBuffer into tMyData
and test anew for "$GPGGA"

maybe you could post 10-20 lines of sample data and an example of what your extracted and rejected data is supposed to look like, also some typical "dirty" lines of valid data.
regards
Bernd

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

Re: Search Backwards (Last Line to First)

Post by Simon Knight » Tue Feb 09, 2010 10:52 am

Dear Bernd,
I have posted some sample data below. I have two routines running on repeat timers the first repeating every 250 ms, this reads the contents of the serial buffer and appends it to the global gDataBuffer. The second routine is where the problem occurs, it is called once per second and processes the contents of the data buffer. If all is well it ignores the last line, which is often incomplete and when it has processed all the other lines they are deleted leaving the part line still in the buffer. The next read operation will complete the line and all will be well. While attempting to track down what was causing the with each line construct to fail I added code that reported the number of lines in the data buffer followed by the buffer contents. When eight lines were present the code ran as expected, however once in a while 7 lines were reported (despite there being eight) and the routine failed. Close inspection of the data revealed that normally the line ends were indicated by two Hex(0D) characters but every so often three Hex(0D) were present. When there were three Hex(0D) characters present the "with each line" construct hangs. It will restart after a period of time and all is well if the timer is canceled and the routine is recalled.

I have attached two text files. The first is recorded from the routine that reads the serial port, the second is the same data as read by the second routine but with the following "//////////////FLThe buffer contains 8 lines of data" inserted to indicate the buffer start and ends. You will notice that extra blank lines are present indicating the third hex(0D) character.

I tried to attache the two files but .txt files are not allowed! I have put them in a zip and displayed some different data from the two recording points below:

RECORDED BY THE SERIAL PORT READ ROUTINE
056,33*70

$GPGSV,3,3,12,19,70,287,29,21,11,067,33,22,52,101,29,26,05,102,00*7F

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,0844,08,1j±Õäbä¬bíöbÇ¢∫bí bä b¬öbí™∫bí bííb™ÇbÇ∫¬böäR∫öj§DÈ
’‘*ii)Iì)S Säbí∫bí¬bäíböí™böäR∫
’§àÈï’âââ©äâ…äâiä…JI”THà“*™S(KLS¶”&&K©”ì¶ì í™öbr≈ÇÇÇ¢∫räíä∫b∫≈bbǬÇíäÇbÇÇíröb∫≈r•Çäj§¸$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091447,09,02,2010,+00,00*64

$GPGSV,3,1,11,03,59,145,31,06,51,133,29,08,12,297,29,11,23,261,31*74

$GPGSV,3,2,11,14,09,114,27,18,23,047,27,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,29,28,13,325,31,32,05,195,00*4C

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091448,09,02,2010,+00,00*6B

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,29,11,23,261,29*74

$GPGSV,3,2,11,14,09,114,31,18,23,047,29,19,84,253,29,22,50,077,27*79

$GPGSV,3,3,11,26,15,090,27,28,13,325,31,32,05,195,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091449,09,02,2010,+00,00*6A

$GPGSV,3,1,11,03,59,145,33,06,51,133,27,08,12,297,31,11,23,261,27*76

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,27,22,50,077,29*70

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091450,09,02,2010,+00,00*62

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,29,11,23,261,31*7D

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,31,28,13,325,27,32,05,195,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091451,09,02,2010,+00,00*63

$GPGSV,3,1,11,03,59,145,29,06,51,133,31,08,12,297,31,11,23,261,31*7D

$GPGSV,3,2,11,14,09,114,31,18,23,047,31,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091452,09,02,2010,+00,00*60

$GPGSV,3,1,11,03,59,145,27,06,51,133,31,08,12,297,29,11,23,261,31*7A

$GPGSV,3,2,11,14,09,114,29,18,23,047,27,19,84,253,27,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,27,28,13,325,29,32,05,195,00*4B

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091453,09,02,2010,+00,00*61

$GPGSV,3,1,11,03,59,145,29,06,51,133,27,08,12,297,29,11,23,261,27*74

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,27*70

$GPGSV,3,3,11,26,15,090,31,28,13,325,31,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091454,09,02,2010,+00,00*66

$GPGSV,3,1,11,03,59,145,31,06,51,133,29,08,12,297,31,11,23,261,31*7D

$GPGSV,3,2,11,14,09,114,29,18,23,047,31,19,84,253,31,22,50,077,27*70

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091455,09,02,2010,+00,00*67

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,27,11,23,261,29*7A

$GPGSV,3,2,11,14,09,114,29,18,23,047,27,19,84,253,27,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091456,09,02,2010,+00,00*64

$GPGSV,3,1,11,03,59,145,29,06,51,133,31,08,12,297,31,11,23,261,29*74

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,31*77

$GPGSV,3,3,11,26,15,090,27,28,13,325,29,32,05,195,00*4B

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091457,09,02,2010,+00,00*65

$GPGSV,3,1,11,03,59,145,31,06,51,133,31,08,12,297,31,11,23,261,29*7D

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,31,22,50,077,29*77

$GPGSV,3,3,11,26,15,090,31,28,13,325,27,32,05,195,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091458,09,02,2010,+00,00*6A

$GPGSV,3,1,11,03,59,145,31,06,51,133,27,08,12,297,31,11,23,261,31*73

$GPGSV,3,2,11,14,09,114,29,18,23,047,31,19,84,253,29,22,50,077,29*77

$GPGSV,3,3,11,26,15,090,29,28,13,325,31,32,05,195,00*4C

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091459,09,02,2010,+00,00*6B

$GPGSV,3,1,11,03,59,145,29,06,51,133,31,08,12,297,31,11,23,261,29*74

$GPGSV,3,2,11,14,09,114,27,18,23,047,29,19,84,253,31,22,50,077,29*79

$GPGSV,3,3,11,26,15,090,27,28,13,325,29,32,05,195,00*4B

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091500,09,02,2010,+00,00*66

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,31,11,23,261,31*74

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,31,28,13,325,29,32,05,195,00*4C

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091501,09,02,2010,+00,00*67

$GPGSV,3,1,11,03,59,145,27,06,51,133,29,08,12,297,29,11,23,261,29*7A

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,31*77

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091502,09,02,2010,+00,00*64

$GPGSV,3,1,11,03,59,145,29,06,51,133,31,08,12,297,29,11,23,261,29*7D

$GPGSV,3,2,11,14,09,114,29,18,23,047,33,19,84,253,29,22,50,077,29*75

$GPGSV,3,3,11,26,15,090,27,28,13,325,27,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091503,09,02,2010,+00,00*65

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,31,11,23,261,27*73

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091504,09,02,2010,+00,00*62

$GPGSV,3,1,11,03,59,145,29,06,51,133,31,08,12,297,33,11,23,261,29*76

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091505,09,02,2010,+00,00*63

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,29,11,23,261,29*74

$GPGSV,3,2,11,14,09,114,29,18,23,047,29,19,84,253,29,22,50,077,29*7E

$GPGSV,3,3,11,26,15,090,27,28,13,325,27,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091506,09,02,2010,+00,00*60

$GPGSV,3,1,11,03,59,145,27,06,51,133,31,08,12,297,29,11,23,261,31*7A

$GPGSV,3,2,11,14,09,114,27,18,23,047,31,19,84,253,29,22,50,077,29*79

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091507,09,02,2010,+00,00*61

$GPGSV,3,1,11,03,59,145,29,06,51,133,29,08,12,297,29,11,23,261,31*7D

$GPGSV,3,2,11,14,09,114,31,18,23,047,29,19,84,253,31,22,50,077,31*77

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,091508,09,02,2010,+00,00*6E

$GPGSV,3,1,11,03,59,145,31,06,51,133,27,08,12,297,29,11,23,261,31*7A

$GPGSV,3,2,11,14,09,114,27,18,23,047,31,19,84,253,29,22,50,077,31*70

$GPGSV,3,3,11,26,15,090,29,28,13,325,29,32,05,195,00*45

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63


Now for the problem as seen by the second routine:
//////////////FLThe buffer contains 8 lines of data
27.8253,N,00047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,093427,09,02,2010,+00,00*60

$GPGSV,3,1,11,03,50,146,31,06,42,136,29,08,08,290,27,11,31,265,29*75

$GPGSV,3,2,11,14,15,109,29,18,16,045,29,19,81,170,31,22,45,067,27*7E

$GPGSV,3,3,11,26,20,083,29,28,19,321,31,32,13,196,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00
//////////////FLThe buffer contains 8 lines of data
047.1217,W,,,080210,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,093428,09,02,2010,+00,00*6F

$GPGSV,3,1,11,03,50,146,27,06,42,136,29,08,08,290,27,11,31,265,29*72

$GPGSV,3,2,11,14,15,109,29,18,16,045,29,19,81,170,29,22,45,067,29*79

$GPGSV,3,3,11,26,20,083,31,28,19,321,29,32,13,196,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210
//////////////FLThe buffer contains 8 lines of data
,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,093429,09,02,2010,+00,00*6E

$GPGSV,3,1,11,03,50,146,29,06,42,136,29,08,08,290,31,11,31,265,29*7B

$GPGSV,3,2,11,14,15,109,31,18,16,045,27,19,81,170,31,22,45,067,29*77

$GPGSV,3,3,11,26,20,083,29,28,19,321,29,32,13,196,00*4B

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01


//////////////FLThe buffer contains 7 lines of data

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,093430,09,02,2010,+00,00*66

$GPGSV,3,1,11,03,50,146,29,06,42,136,29,08,08,290,29,11,31,265,29*72

$GPGSV,3,2,11,14,15,109,27,18,16,045,31,19,81,170,29,22,45,067,29*7E

$GPGSV,3,3,11,26,20,083,31,28,19,321,27,32,13,196,00*4C

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01


//////////////FLThe buffer contains 7 lines of data

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,093431,09,02,2010,+00,00*67

$GPGSV,3,1,11,03,50,146,29,06,42,136,29,08,08,290,29,11,31,265,31*7B

$GPGSV,3,2,11,14,15,109,27,18,16,045,31,19,81,170,31,22,45,067,29*77

$GPGSV,3,3,11,26,20,083,29,28,19,321,31,32,13,196,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01


//////////////FLThe buffer contains 7 lines of data
$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63


$GPZDA,093432,09,02,2010,+00,00*64

$GPGSV,3,1,11,03,50,146,31,06,42,136,29,08,08,290,31,11,31,265,31*7B

$GPGSV,3,2,11,14,15,109,31,18,16,045,31,19,81,170,27,22,45,067,29*77

$GPGSV,3,3,11,26,20,083,29,28,19,321,31,32,13,196,00*42

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210
//////////////FLThe buffer contains 8 lines of data
,002.3,W,N*01

$GPGGA,171530,5327.8253,N,00047.1217,W,0,00,00.00,000009.1,M,0047.1,M,,*63

$GPZDA,093433,09,02,2010,+00,00*65

$GPGSV,3,1,11,03,50,146,31,06,42,136,29,08,08,290,27,11,31,265,29*75

$GPGSV,3,2,11,14,15,109,29,18,16,045,33,19,81,170,29,22,45,067,29*72

$GPGSV,3,3,11,26,20,083,29,28,19,321,29,32,13,196,00*4B

$GPVTG,,T,,M,,N,,K,N*2C

$GPRMC,171530,V,5327.8253,N,00047.1217,W,,,080210,002.3,W,N*01
Attachments
SerialPortProblem.zip
Two files displaying the same data
(4.32 KiB) Downloaded 307 times
best wishes
Skids

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Search Backwards (Last Line to First)

Post by bn » Tue Feb 09, 2010 12:23 pm

Simon,
is it correct that Hex 0D is 13 and that ascii 13 is your linedelimiter? ASCII 13 beeing a return?
Assuming this, your could set the "lineDelimiter" to that. Or you could clean the data with a replace before processing.
Just trying to understand the data structure. I suppose you do a binary read?
regards
Bernd

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Search Backwards (Last Line to First)

Post by bn » Tue Feb 09, 2010 1:07 pm

Simon,
could you make a binary file of your buffered data and zip it and uploaod it?
like this before Rev does anything to the data, i.e. in a field Rev changes the linedelimiter or when writing to a file Rev changes the lineendings to the lineendings of the platform.
All this is avoided by writing it as a binary file. This should do the trick:

Code: Select all

on mouseUp
   put specialfolderpath ("desktop") & "/" into aPath
   put "BinaryExportPortData" after aPath
   put myGlobalPortData into URL ("binfile:" & aPath)
end mouseUp
regards
Bernd

Post Reply