我想使用C#编一个向STM32F10x发送程序的小程序,但发现一开头就无法传送第一个包, 请各位高手指教 waitfor('C');//可以通过
byte[] byteFile[];
byteFile = getFileBytes("d:\mlbinV01.bin"); //取得文件名和文件长度
sp.Write(byteFile , 0, byteFile.Length);//发送
waitforack();//在这无法收到ACK信号
waitfor('C'); CRC如下: public enum InitialCrcValue { Zeros, NonZero1 = 0xffff, NonZero2 = 0x1D0F } public class Crc16Ccitt { const ushort poly = 0x1021; ushort[] table = new ushort[256]; ushort initialValue = 0; public ushort ComputeChecksum(byte[] bytes) { ushort crc = this.initialValue; for (int i = 0; i < bytes.Length; i++) { crc = (ushort)((crc << 8) ^ table[((crc >> 8) ^ (0xff & bytes))]); } return crc; } public byte[] ComputeChecksumBytes(byte[] bytes) { ushort crc = ComputeChecksum(bytes); return new byte[] { (byte)(crc >> 8), (byte)(crc & 0x00ff) }; } public Crc16Ccitt(InitialCrcValue initialValue) { this.initialValue = (ushort)initialValue; ushort temp, a; for (int i = 0; i < table.Length; i++) { temp = 0; a = (ushort)(i << 8); for (int j = 0; j < 8; j++) { if (((temp ^ a) & 0x8000) != 0) { temp = (ushort)((temp << 1) ^ poly); } else { temp <<= 1; } a <<= 1; } table = temp; } } }
|