Vögtlin Instruction Manual
SmartTrak
®
Series
100
106
Below is the routine used to calculate the CRC bytes in C#.
Comments are between the /*
*/.
private static uint
CalcCRC(
byte
[] cmnd)
/* cmnd is a byte array containing the command ASCII string … cmnd[]=”Sinv2.000” */
/* An unsigned 32 bit integer is return to the calling program */
/* only the lower 16 bits contain the crc */
{
int
i,j; /* interating indexes for the for loops */
uint
crc;
/* crc variable that will be returned */
crc=
0xffff
;
/* initialize crc to hex value 0xffff */
for
(i=
0
; i<cmnd.Length; i++)
/* this for loop starts with ASCCII ‘S’ and loops through to the last ASCII ‘0’ */
{
crc=crc^((
uint
)(cmnd[i]*
0x0100
));
/* the ASCII value is times by 0x0100 first then XORED to the current crc value */
for
(j=
0
; j<
8
; j++)
/* the crc is hashed 8 times with this for loop */
/* if the 15
th
bit is set (tested by ANDING with hex 0x8000 and testing for 0x8000 result)
then crc is shifted left one bit (same as times 2) XORED with hex 0x1021 and ANDED
to hex 0xffff to limit the crc to lower 16 bits. If the 15
th
bit is not set then the crc is shifted
left one bit and ANDED with hex 0xffff to limit the crc to lower 16 bits. */
{
if
((crc&
0x8000
)==
0x8000
)
crc=((crc<<
1
)^
0x1021
)&
0xffff
;
/* end of j loop */
}
/* end of i loop */
}
else
crc=(crc<<
1
)&
0xffff
;
/* There are some crc values that are not allowed, 0x00 and 0x0d */
/* These are byte values so the high byte and the low byte of the crc must be checked and
incremented if the bytes are either 0x00 0r 0x0d. */
if
((crc&
0xff00
)==
0x0d00
) crc +=
0x0100
;
if
((crc&
0x00ff
)==
0x000d
) crc +=
0x0001
;
if
((crc&
0xff00
)==
0x0000
) crc +=
0x0100
;
if
((crc&
0x00ff
)==
0x0000
) crc +=
0x0001
;
return
crc;
}
/* If the string Sinv2.000 is sent through this routine the crc = 0x8f55 */
/* The complete command “Sinv2.000” will look like this in hex
0x53 0x69 0x6E 0x76 0x32 0x2e 0x30 0x30 0x30 0x8f 0x55 0x0d */
Below is the c# routine with no comments.
Содержание SmartTrak 100 Series
Страница 63: ...63 C ADJUSTMENTS Clicking on adjustments brings up the meter settings screen ...
Страница 74: ...72 Appendix A C100 M100 SmartTrak Product Specifications Dimensions and Mounting ...
Страница 75: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 73 ...
Страница 76: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 4 7 ...
Страница 77: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 75 ...
Страница 78: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 76 ...
Страница 79: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 77 ...
Страница 80: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 78 ...
Страница 82: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 80 ...
Страница 83: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 81 ...
Страница 85: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 83 ...
Страница 86: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 84 ...
Страница 87: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 85 ...
Страница 89: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 87 ...
Страница 90: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 88 ...
Страница 91: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 89 ...
Страница 92: ...Vögtlin Instruments Instruction Manual SmartTrak 100 Series 90 ...
Страница 109: ...Vögtlin Instruction Manual SmartTrak Series 100 107 private static uint CalcCRC byte cmnd ...
Страница 111: ...Vögtlin Instruction Manual SmartTrak Series 100 109 Else ...
Страница 112: ...Vögtlin Instruction Manual SmartTrak Series 100 110 crcWord crcWord 2 ...