Friday, 13 September 2013

Checksum serial message

Checksum serial message

I must calculated a checksum, but i'm very news on hardware programing...
the doc say :
All the serial command are 12-byte command packet format
The values of the first 11 bytes of the packet (excluding the checksum
byte) are summed and then divided by 0x0100 (256). This will create a
1-byte shift. The remaining value from this shift is the checksum byte.
during word transmission the high word value is transmitted followed by
the low word value
example of command :
0x00 0x05 0x0000 0x0000 0x0000 0x0000 0x00 Chksum
0x00 : channel
0x05 : command
0x0000 : param1
0x0000 : param2
0x0000 : lwExtraData
0x0000 : hwExtraData
0x00 : ErrorCode
????? : check sum
i have this code in python :
ser = serial.Serial('/dev/ttyUSB0', 115200,parity='N',timeout=1)
ser.open()
ser.write(chr(0x00)) # channel 1 byte (alway the same)
ser.write(chr(0x05)) # command 1 byte
ser.write(chr(0x00)) # param1 2 bytes (byte low)
ser.write(chr(0x00)) # param1 2 bytes (byte hight)
ser.write(chr(0x00)) # param2 2 bytes (byte low)
ser.write(chr(0x00)) # param2 2 bytes (byte hight)
ser.write(chr(0x00)) # lwExtraData 2 bytes (byte low)
ser.write(chr(0x00)) # lwExtraData 2 bytes (byte hight)
ser.write(chr(0x00)) # hwExtraData 2 bytes (byte low)
ser.write(chr(0x00)) # hwExtraData 2 bytes (byte hight)
ser.write(chr(0x00)) # ErrorCode 1 byte
How i can calculated my checksum ?? if i sum i have 5 but how i can divide
?????

No comments:

Post a Comment