-
Notifications
You must be signed in to change notification settings - Fork 8
/
pyrplidar_serial.py
37 lines (26 loc) · 1.01 KB
/
pyrplidar_serial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import serial
class PyRPlidarSerial:
def __init__(self):
self._serial = None
def open(self, port, baudrate, timeout):
if self._serial is not None:
self.disconnect()
try:
self._serial = serial.Serial(port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout, dsrdtr=True)
#self._serial = serial.Serial(port, baudrate, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=timeout)
except serial.SerialException as err:
print("Failed to connect to the rplidar")
def close(self):
if self._serial is None:
return
self._serial.close()
def wait_data(self):
pass
def send_data(self, data):
self._serial.write(data)
def receive_data(self, size):
return self._serial.read(size)
def set_dtr(self, value):
self._serial.dtr = value
def clear_input(self):
self._serial.read_all()