-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialPort.py
52 lines (41 loc) · 1.11 KB
/
SerialPort.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
import serial
# configure the serial connections (the parameters differs on the device you are connecting to)
class Serial(object):
def __init__(self, addr):
self.ser = serial.Serial(
port=addr, #'/dev/rfcomm0'
baudrate=9600,
parity=serial.PARITY_ODD,
stopbits=serial.STOPBITS_TWO,
bytesize=serial.SEVENBITS,
timeout=5,
write_timeout=5
)
self.ser.isOpen()
time.sleep(2)
def write(self, data):
self.ser.write(data)
time.sleep(1)
def close(self):
self.ser.close()
def available(self):
return self.ser.in_waiting
def clean_buffer(self):
self.ser.reset_input_buffer()
def read(self, size):
return self.read(size)
if __name__ == '__main__':
com = Serial("/dev/rfcomm0")
print("Serial init")
time.sleep(2)
print("Serial clean_buffer")
com.clean_buffer()
print("write F")
com.write("F")
time.sleep(2)
print("write 5")
com.write("5")
time.sleep(2)
print("write 5")
com.write("5")