New topic: 

Checksum calculation for NMEA sentence output from GPS

<http://forums.realsoftware.com/viewtopic.php?t=37876>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        Talisker          Post subject: Checksum calculation for NMEA 
sentence output from GPSPosted: Sun Feb 27, 2011 9:26 am                        
 
Joined: Tue Jul 27, 2010 4:27 am
Posts: 8                Converted from VB for use with Real Studio.

If anyone has a better idea of how to return the two character string, I'd like 
to hear it!


Code:Function Checksum(mySum As String) As String
  Dim Char(-1) As String, Checksum As Integer, n As Integer, Result As String
  
  ReDim Char(Len(mySum))
  
  For n = 0 to Len(mySum) -1
  Char(n) = Mid(mySum,n + 1,1)
  next n
  
  for n = 0 to UBound(Char)
  if Char(n) = "$" then continue
  if Char(n) = "*" then exit
  If Checksum = 0 then
  ' Yes. Set the checksum to the value
  Checksum = Asc(Char(n))
  Else
  ' No. XOR the checksum with this character's value
  Checksum = Checksum XOR Asc(Char(n))
  End If
  next n

  'add preceding zero
  if Len(Str(Hex(Checksum))) < 2 then
  Result = "0" + Str(Hex(Checksum))
  else
  Result = Str(Hex(Checksum))
  end if
  
  Return Result
  
End Function



Steve   
                             Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

rbforumnotifier@monkeybreadsoftware.de

Reply via email to