Omega RD100B User Manual page 75

Programmable recorder communication interface
Hide thumbs Also See for RD100B:
Table of Contents

Advertisement

5.1 Response Syntax
5-4
If the data length of the buffer is odd, a "0" is padded so that it is even. (1) through (6)
are summed as unsigned two-byte integers (unsigned short). If the digit overflows a
"1" is added. Finally, the result is bit-wise inverted.
Sample Program
The sum value is determined using the following sample program, and the calculated
result is returned. The sum determined by the sample program can be compared with
the header sum of the output BINARY header section and the data sum of the output
BINARY footer section.
/*
* Sum Calculation Function (for a 32-bit CPU)
*
* Parameters buff: Pointer to the top of the data on which the sum is calculated
*
len: Length of the data on which the sum is calculated
* Return value:
Calculated sum
*/
intcksum(unsigned char *buff, int len)
{
unsigned short *p;
unsigned int
csum;
int
i;
int
odd;
csum = 0;
odd = len%2;
len >>= 1;
p = (unsigned short *)buff;
for(i=0;i<len;i++)
csum += *p++;
if(odd){
union tmp{
unsigned short s;
unsigned char
c[2];
}tmp;
tmp.c[1] = 0;
tmp.c[0] = *((unsigned char *)p);
csum += tmp.s;
}
if((csum = (csum & 0xffff) + ((csum>>16) & 0xffff)) > 0xffff)
csum = csum - 0xffff;/* If the digit overflows again, add a 1. */
return((~csum) &
}
/* Pointer to the next two-byte data word in the buffer
that is to be summed. */
/* Checksum value */
/* Initialize. */
/* Check whether or not the number of data points is
even. */
/* Determine the number of data points using a
"short" data type. */
/* Sum using an unsigned short data type. */
/* When the data length is odd */
/* Pad with a 0, and add to the unsigned short data.
*/
/* Add the overflowed digits */
0xffff); /* bit inversion */

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rd1800b

Table of Contents