PNI TCM 5 User Manual

Page 53

Advertising
background image

PNI Sensor Corporation

Doc #1007537 r12

TCM3 & TCM5 User Manual

– Sept 2012

Page 53

UInt16 crc, crcReceived;

// calculated and received crcs.

// Read block will return the number of requested (or available) bytes that

are in the

// serial objects input buffer.

mSerialPort->ReadBlock(&mInData[

2

], mExpectedLen -

2

);

// in CRC verification, don't include the CRC in the recalculation (-2)

crc = CRC(mInData, mExpectedLen -

2

);

// CRC is also ALWAYS transmitted in big endian

crcReceived = (mInData[mExpectedLen -

2

] <<

8

) | mInData[mExpectedLen -

1

] ;

if

(crc == crcReceived)

{

// the crc is correct, so pass the frame up for processing.

if

(mHandler) mHandler->HandleComm(mInData[

2

], &mInData[

3

], mExpectedLen

- kPacketMinSize);

}

else

{

// crc's don't match so clear everything that is currently in the input

buffer since

// the data is not reliable.

mSerialPort->InClear();

}

// go back to looking for the length bytes.

mStep =

1

;

}

else

{

// Ticks is a timer function. 1 tick = 10msec.

if

(Ticks() > mTime)

{

// Corrupted message. We did not get the length we were expecting within

1/2sec of receiving

// the length bytes. Clear everything in the input buffer since the data

is unreliable

mSerialPort->InClear();

mStep =

1

;

// Look for the next length bytes

}

}

break

;

}

default

:

break

;

}

Advertising
This manual is related to the following products: