Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Sep 20, 2019 9:32 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Checksum calculation for NMEA sentence output from GPS
PostPosted: Sun Feb 27, 2011 9:26 am 
Offline

Joined: Tue Jul 27, 2010 4:27 am
Posts: 12
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!


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
 Profile  
Reply with quote  
 Post subject: Re: Checksum calculation for NMEA sentence output from GPS
PostPosted: Sun Feb 27, 2011 9:59 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
Function Checksum(mySum As String) As String
Dim Char(-1) As String
dim Checksum As Integer
dim n As Integer
dim Result As String

char = split(mySum,"")

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

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

Return Result
End Function

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group