checksum for ComPort

For general discussion related FlowStone
Post Reply
clamprod
Posts: 7
Joined: Mon Aug 02, 2010 3:33 pm

checksum for ComPort

Post by clamprod »

I need to include a Checksum byte in my command line to the ComPort. Any direction in generating the packet checksum would be appreciated.

Thanks, folks!
Tronic
Posts: 539
Joined: Wed Dec 21, 2011 12:59 pm

Re: checksum for ComPort

Post by Tronic »

this is an example in ruby

Code: Select all

string_data = @ins[0]

# this is line for test only, comment this to use input
string_data = "this is the data string"
####

checksum = 0
string_data.each_byte {|x| checksum ^= x }
output 0, checksum # with test line active this output have, checksum => 96
clamprod
Posts: 7
Joined: Mon Aug 02, 2010 3:33 pm

Re: checksum for ComPort

Post by clamprod »

Ah, awesome, Tronic!
Thank you!

clammy
Post Reply