Checksum for CTX35

Forum about Xanura, Eaton Holec and Marmitek and other brand X10 and A10 devices.
Post Reply
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Checksum for CTX35

Post by RDNZL »

Trying to make a driver for the CTX35. Been strugling with the checksum calculating bit, can someone post a vb or other basic code snippet how todo that? That would make my day!

Thanks,
Ron.

Edit:
Did just found out this one:
---

PUBLIC SUB Main()
DIM sCommand AS String
DIM Checksum AS Integer
DIM i AS Integer

sCommand = "$>28001E03E03"

FOR i = 1 TO Len(sCommand)
Checksum = Checksum + Asc(Mid$(sCommand, i, 1)) AND 255
NEXT

PRINT Hex$(Checksum)
END
---
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Checksum for CTX35

Post by Bwired »

Code: Select all

Private Function CheckSum(x)
Dim q, l, i
x = "$>28001" + x
l = Len(x)
For i = 1 To l
    q = q + Asc(Mid(x, i, 1))
Next i
ChSm = Right(Hex(q), 2)
End Function
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Checksum for CTX35

Post by RDNZL »

Ok, you won ;-)

This is my second version, the first one didn't return 2 chars when the checksum was less than 16

Code: Select all

PUBLIC SUB AddChecksum(sCommand AS String) AS String
  
  DIM iChecksum, iLoop AS Integer

  sCommand = "$>28001" & sCommand

  FOR iLoop = 1 TO Len(sCommand)
    iCheckSum = iChecksum + Asc(Mid$(sCommand, iLoop, 1))
  NEXT
  
  RETURN sCommand & Right$(Hex$(iChecksum), 2) & "#"
  
END
Developing DomotiGa - Gambas powered Domotics.
Digit
Global Moderator
Global Moderator
Posts: 3388
Joined: Sat Mar 25, 2006 10:23 am
Location: Netherlands
Contact:

Checksum for CTX35

Post by Digit »

Yeah, and you saved Len(sCommand) times an AND to execute.[:)]
I know, not very usefull post, just trying to get my mind off of some other things...[xx(]
User avatar
RDNZL
Forum Moderator
Forum Moderator
Posts: 1008
Joined: Sun Sep 24, 2006 1:45 pm
Location: Dordrecht, The Netherlands
Contact:

Checksum for CTX35

Post by RDNZL »

Yes, makeing my code more efficient is still on my list.
This helps.

For the past weeks I have been writeing a domotics program in Gambas basic on Linux.
Oh boy, now I have even more respect for builders of sites like Bwired, so many things to want, so little time to code.. ;-)
And the things you think are the hardest to build are done before you know it, but it's those 'easy things' that costs the most time.
And because I have no written blueprint, I tend to chance the framework every now and then, those periods costs liters of coffee! ;-)
I'm thinking about releasing the code under GPL, so other coders can donate their work, or parts of it, to speed up development.
But I guess I'm the only Gambas programmer here...

Regards,
Ron.

Developing DomotiGa - Gambas powered Domotics.
Jfn
Member
Member
Posts: 332
Joined: Tue Feb 26, 2008 2:01 pm
Location: Netherlands
Contact:

Checksum for CTX35

Post by Jfn »

@RDNLZ:

About releasing code, I am always interested in learning how you programmed certain things. How did you end up using Gamba to program stuff? I am developping my domotica system under Linux too. I do not use Gamba. I use perl/php and javascript.
Post Reply

Return to “X10, A10 Xanura Marmitek Forum”