views:

1608

answers:

3

Hi, i'm readin file from serialport using x-modem protocol and 133 bytes packet i'm reading in that 1 byte is SOH 2 byte packet number 3 byte nagative of packet number next 128 bytes data 2 bytes CRC sent from other side.

i've to calculate CRC of 128 bytes data and 2 bytes crc sent form other side that i've to make it single byte and have to comapare with my calculated crc,how can do this in java plz give sample code.

thanks in advance

+1  A: 

Sun JDK 1.6 contains sun.misc.CRC16, but there is a possibility this is not the CRC16 you're looking for, since there's several different polynomials in use.

krosenvold
+4  A: 

Try using Jacksum.

Sandy
End-user page for Jacksum: http://www.jonelo.de/java/jacksum/index.html
Matt Ball
+1  A: 

Here is my C code, which is trivial to port to Java - you are free to use it in any way you like. The references to word are for a 16 bit unsigned value - you should be able to use a char instead in Java.

It's been too long since I worked with 16 bit CRC's so I don't recall if there are variations based on seeding. I am pretty sure I used this code in a C implementation of X-Modem way back when.

The source is posted on www.SoftwareMonkey.org.

Software Monkey