
crc_value |= (ord(frame[index +
7
]) &
0x0F
)
crc_value = crc_value &
0xFFFFFFFF
crc32 = self.crc32(frame[:index])
if
crc32 == crc_value:
return
True
else
:
"Discarding current buffer because of bad checksum"
return
False
A.2 Sample code
The python sample code provides with basic sensor functionality and communication,
including activating data output, reading data, sending commands and validating CRC
checksum. The python file of this sample code is available for download under “
Download
”
section of the TeraRanger Evo 64px product page.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import
numpy
as
np
import
serial
import
crcmod.predefined
import
threading
class
Evo_64px
(object):
def
__init__
(self):
self.portname =
"/dev/ttyACM0"
self.baudrate =
115200
# Configure the serial connections (the parameters differs on the
device you are connecting to)
self.port = serial.Serial(
port=self.portname,
baudrate=self.baudrate,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
self.port.isOpen()
self.crc32 = crcmod.predefined.mkPredefinedCrcFun(
'crc-32-mpeg'
)
self.crc8 = crcmod.predefined.mkPredefinedCrcFun(
'crc-8'
)
self.serial_lock = threading.Lock()
Copyright
©
Terabee 2018
Terabee, 90 Rue Henri Fabre
01630, St Genis-Pouilly, France (next to CERN)
19/22